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
, char **envp
);
45 int main(int argc
, char **argv
)
47 return qemu_main(argc
, argv
, NULL
);
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 "qemu/cache-utils.h"
86 #include "sysemu/blockdev.h"
87 #include "hw/block/block.h"
88 #include "migration/block.h"
89 #include "sysemu/tpm.h"
90 #include "sysemu/dma.h"
91 #include "audio/audio.h"
92 #include "migration/migration.h"
93 #include "sysemu/kvm.h"
94 #include "qapi/qmp/qjson.h"
95 #include "qemu/option.h"
96 #include "qemu/config-file.h"
97 #include "qemu-options.h"
98 #include "qmp-commands.h"
99 #include "qemu/main-loop.h"
101 #include "fsdev/qemu-fsdev.h"
103 #include "sysemu/qtest.h"
105 #include "disas/disas.h"
108 #include "slirp/libslirp.h"
111 #include "trace/control.h"
112 #include "qemu/queue.h"
113 #include "sysemu/cpus.h"
114 #include "sysemu/arch_init.h"
115 #include "qemu/osdep.h"
117 #include "ui/qemu-spice.h"
118 #include "qapi/string-input-visitor.h"
119 #include "qom/object_interfaces.h"
121 #define DEFAULT_RAM_SIZE 128
123 #define MAX_VIRTIO_CONSOLES 1
124 #define MAX_SCLP_CONSOLES 1
126 static const char *data_dir
[16];
127 static int data_dir_idx
;
128 const char *bios_name
= NULL
;
129 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
130 DisplayType display_type
= DT_DEFAULT
;
131 static int display_remote
;
132 const char* keyboard_layout
= NULL
;
134 const char *mem_path
= NULL
;
135 int mem_prealloc
= 0; /* force preallocation of physical target memory */
137 NICInfo nd_table
[MAX_NICS
];
139 static int rtc_utc
= 1;
140 static int rtc_date_offset
= -1; /* -1 means no change */
141 QEMUClockType rtc_clock
;
142 int vga_interface_type
= VGA_NONE
;
143 static int full_screen
= 0;
144 static int no_frame
= 0;
147 static bool grab_on_hover
;
149 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
150 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
151 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
152 CharDriverState
*sclp_hds
[MAX_SCLP_CONSOLES
];
153 int win2k_install_hack
= 0;
160 const char *vnc_display
;
162 int acpi_enabled
= 1;
165 static int no_reboot
;
168 int graphic_rotate
= 0;
169 const char *watchdog
;
170 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
172 int semihosting_enabled
= 0;
174 const char *qemu_name
;
177 unsigned int nb_prom_envs
= 0;
178 const char *prom_envs
[MAX_PROM_ENVS
];
180 static bool boot_strict
;
181 uint8_t *boot_splash_filedata
;
182 size_t boot_splash_filedata_size
;
183 uint8_t qemu_extra_params_fw
[2];
185 typedef struct FWBootEntry FWBootEntry
;
188 QTAILQ_ENTRY(FWBootEntry
) link
;
194 static QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
=
195 QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
198 uint64_t node_mem
[MAX_NODES
];
199 unsigned long *node_cpumask
[MAX_NODES
];
201 uint8_t qemu_uuid
[16];
204 static QEMUBootSetHandler
*boot_set_handler
;
205 static void *boot_set_opaque
;
207 static NotifierList exit_notifiers
=
208 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
210 static NotifierList machine_init_done_notifiers
=
211 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
213 static bool tcg_allowed
= true;
216 enum xen_mode xen_mode
= XEN_EMULATE
;
217 static int tcg_tb_size
;
219 static int has_defaults
= 1;
220 static int default_serial
= 1;
221 static int default_parallel
= 1;
222 static int default_virtcon
= 1;
223 static int default_sclp
= 1;
224 static int default_monitor
= 1;
225 static int default_floppy
= 1;
226 static int default_cdrom
= 1;
227 static int default_sdcard
= 1;
228 static int default_vga
= 1;
234 { .driver
= "isa-serial", .flag
= &default_serial
},
235 { .driver
= "isa-parallel", .flag
= &default_parallel
},
236 { .driver
= "isa-fdc", .flag
= &default_floppy
},
237 { .driver
= "ide-cd", .flag
= &default_cdrom
},
238 { .driver
= "ide-hd", .flag
= &default_cdrom
},
239 { .driver
= "ide-drive", .flag
= &default_cdrom
},
240 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
241 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
242 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
243 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
244 { .driver
= "VGA", .flag
= &default_vga
},
245 { .driver
= "isa-vga", .flag
= &default_vga
},
246 { .driver
= "cirrus-vga", .flag
= &default_vga
},
247 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
248 { .driver
= "vmware-svga", .flag
= &default_vga
},
249 { .driver
= "qxl-vga", .flag
= &default_vga
},
252 static QemuOptsList qemu_rtc_opts
= {
254 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
258 .type
= QEMU_OPT_STRING
,
261 .type
= QEMU_OPT_STRING
,
264 .type
= QEMU_OPT_STRING
,
266 { /* end of list */ }
270 static QemuOptsList qemu_sandbox_opts
= {
272 .implied_opt_name
= "enable",
273 .head
= QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts
.head
),
277 .type
= QEMU_OPT_BOOL
,
279 { /* end of list */ }
283 static QemuOptsList qemu_trace_opts
= {
285 .implied_opt_name
= "trace",
286 .head
= QTAILQ_HEAD_INITIALIZER(qemu_trace_opts
.head
),
290 .type
= QEMU_OPT_STRING
,
293 .type
= QEMU_OPT_STRING
,
295 { /* end of list */ }
299 static QemuOptsList qemu_option_rom_opts
= {
300 .name
= "option-rom",
301 .implied_opt_name
= "romfile",
302 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
306 .type
= QEMU_OPT_NUMBER
,
309 .type
= QEMU_OPT_STRING
,
311 { /* end of list */ }
315 static QemuOptsList qemu_machine_opts
= {
317 .implied_opt_name
= "type",
319 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
323 .type
= QEMU_OPT_STRING
,
324 .help
= "emulated machine"
327 .type
= QEMU_OPT_STRING
,
328 .help
= "accelerator list",
330 .name
= "kernel_irqchip",
331 .type
= QEMU_OPT_BOOL
,
332 .help
= "use KVM in-kernel irqchip",
334 .name
= "kvm_shadow_mem",
335 .type
= QEMU_OPT_SIZE
,
336 .help
= "KVM shadow MMU size",
339 .type
= QEMU_OPT_STRING
,
340 .help
= "Linux kernel image file",
343 .type
= QEMU_OPT_STRING
,
344 .help
= "Linux initial ramdisk file",
347 .type
= QEMU_OPT_STRING
,
348 .help
= "Linux kernel command line",
351 .type
= QEMU_OPT_STRING
,
352 .help
= "Linux kernel device tree file",
355 .type
= QEMU_OPT_STRING
,
356 .help
= "Dump current dtb to a file and quit",
358 .name
= "phandle_start",
359 .type
= QEMU_OPT_NUMBER
,
360 .help
= "The first phandle ID we may generate dynamically",
362 .name
= "dt_compatible",
363 .type
= QEMU_OPT_STRING
,
364 .help
= "Overrides the \"compatible\" property of the dt root node",
366 .name
= "dump-guest-core",
367 .type
= QEMU_OPT_BOOL
,
368 .help
= "Include guest memory in a core dump",
371 .type
= QEMU_OPT_BOOL
,
372 .help
= "enable/disable memory merge support",
375 .type
= QEMU_OPT_BOOL
,
376 .help
= "Set on/off to enable/disable usb",
379 .type
= QEMU_OPT_STRING
,
380 .help
= "firmware image",
383 .type
= QEMU_OPT_STRING
,
384 .help
= "Specifies the KVM virtualization mode (HV, PR)",
386 { /* End of list */ }
390 static QemuOptsList qemu_boot_opts
= {
392 .implied_opt_name
= "order",
394 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
398 .type
= QEMU_OPT_STRING
,
401 .type
= QEMU_OPT_STRING
,
404 .type
= QEMU_OPT_BOOL
,
407 .type
= QEMU_OPT_STRING
,
409 .name
= "splash-time",
410 .type
= QEMU_OPT_STRING
,
412 .name
= "reboot-timeout",
413 .type
= QEMU_OPT_STRING
,
416 .type
= QEMU_OPT_BOOL
,
422 static QemuOptsList qemu_add_fd_opts
= {
424 .head
= QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts
.head
),
428 .type
= QEMU_OPT_NUMBER
,
429 .help
= "file descriptor of which a duplicate is added to fd set",
432 .type
= QEMU_OPT_NUMBER
,
433 .help
= "ID of the fd set to add fd to",
436 .type
= QEMU_OPT_STRING
,
437 .help
= "free-form string used to describe fd",
439 { /* end of list */ }
443 static QemuOptsList qemu_object_opts
= {
445 .implied_opt_name
= "qom-type",
446 .head
= QTAILQ_HEAD_INITIALIZER(qemu_object_opts
.head
),
452 static QemuOptsList qemu_tpmdev_opts
= {
454 .implied_opt_name
= "type",
455 .head
= QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts
.head
),
457 /* options are defined in the TPM backends */
458 { /* end of list */ }
462 static QemuOptsList qemu_realtime_opts
= {
464 .head
= QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts
.head
),
468 .type
= QEMU_OPT_BOOL
,
470 { /* end of list */ }
474 static QemuOptsList qemu_msg_opts
= {
476 .head
= QTAILQ_HEAD_INITIALIZER(qemu_msg_opts
.head
),
480 .type
= QEMU_OPT_BOOL
,
482 { /* end of list */ }
486 static QemuOptsList qemu_name_opts
= {
488 .implied_opt_name
= "guest",
490 .head
= QTAILQ_HEAD_INITIALIZER(qemu_name_opts
.head
),
494 .type
= QEMU_OPT_STRING
,
495 .help
= "Sets the name of the guest.\n"
496 "This name will be displayed in the SDL window caption.\n"
497 "The name will also be used for the VNC server",
500 .type
= QEMU_OPT_STRING
,
501 .help
= "Sets the name of the QEMU process, as shown in top etc",
503 .name
= "debug-threads",
504 .type
= QEMU_OPT_BOOL
,
505 .help
= "When enabled, name the individual threads; defaults off.\n"
506 "NOTE: The thread names are for debugging and not a\n"
509 { /* End of list */ }
513 static QemuOptsList qemu_mem_opts
= {
515 .implied_opt_name
= "size",
516 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mem_opts
.head
),
521 .type
= QEMU_OPT_SIZE
,
525 .type
= QEMU_OPT_NUMBER
,
529 .type
= QEMU_OPT_SIZE
,
531 { /* end of list */ }
536 * Get machine options
538 * Returns: machine options (never null).
540 QemuOpts
*qemu_get_machine_opts(void)
542 return qemu_find_opts_singleton("machine");
545 const char *qemu_get_vm_name(void)
550 static void res_free(void)
552 if (boot_splash_filedata
!= NULL
) {
553 g_free(boot_splash_filedata
);
554 boot_splash_filedata
= NULL
;
558 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
560 const char *driver
= qemu_opt_get(opts
, "driver");
565 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
566 if (strcmp(default_list
[i
].driver
, driver
) != 0)
568 *(default_list
[i
].flag
) = 0;
573 /***********************************************************/
576 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
581 } RunStateTransition
;
583 static const RunStateTransition runstate_transitions_def
[] = {
585 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
586 { RUN_STATE_DEBUG
, RUN_STATE_FINISH_MIGRATE
},
588 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
589 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
591 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
592 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
594 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
595 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
597 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
598 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
600 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
601 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
603 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
604 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
605 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
607 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
608 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
610 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
612 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
613 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
614 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
615 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
616 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
617 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
618 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
619 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
620 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
621 { RUN_STATE_RUNNING
, RUN_STATE_GUEST_PANICKED
},
623 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
625 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
626 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
628 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
629 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
630 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
631 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
633 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
634 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
636 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_RUNNING
},
637 { RUN_STATE_GUEST_PANICKED
, RUN_STATE_FINISH_MIGRATE
},
639 { RUN_STATE_MAX
, RUN_STATE_MAX
},
642 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
644 bool runstate_check(RunState state
)
646 return current_run_state
== state
;
649 static void runstate_init(void)
651 const RunStateTransition
*p
;
653 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
655 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
656 runstate_valid_transitions
[p
->from
][p
->to
] = true;
660 /* This function will abort() on invalid state transitions */
661 void runstate_set(RunState new_state
)
663 assert(new_state
< RUN_STATE_MAX
);
665 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
666 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
667 RunState_lookup
[current_run_state
],
668 RunState_lookup
[new_state
]);
671 trace_runstate_set(new_state
);
672 current_run_state
= new_state
;
675 int runstate_is_running(void)
677 return runstate_check(RUN_STATE_RUNNING
);
680 bool runstate_needs_reset(void)
682 return runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
683 runstate_check(RUN_STATE_SHUTDOWN
);
686 StatusInfo
*qmp_query_status(Error
**errp
)
688 StatusInfo
*info
= g_malloc0(sizeof(*info
));
690 info
->running
= runstate_is_running();
691 info
->singlestep
= singlestep
;
692 info
->status
= current_run_state
;
697 /***********************************************************/
698 /* real time host monotonic timer */
700 /***********************************************************/
701 /* host time/date access */
702 void qemu_get_timedate(struct tm
*tm
, int offset
)
708 if (rtc_date_offset
== -1) {
712 localtime_r(&ti
, tm
);
714 ti
-= rtc_date_offset
;
719 int qemu_timedate_diff(struct tm
*tm
)
723 if (rtc_date_offset
== -1)
725 seconds
= mktimegm(tm
);
728 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
729 seconds
= mktime(&tmp
);
732 seconds
= mktimegm(tm
) + rtc_date_offset
;
734 return seconds
- time(NULL
);
737 void rtc_change_mon_event(struct tm
*tm
)
741 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
742 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
743 qobject_decref(data
);
746 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
748 time_t rtc_start_date
;
751 if (!strcmp(startdate
, "now") && legacy
) {
752 rtc_date_offset
= -1;
754 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
762 } else if (sscanf(startdate
, "%d-%d-%d",
774 rtc_start_date
= mktimegm(&tm
);
775 if (rtc_start_date
== -1) {
777 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
778 "'2006-06-17T16:01:21' or '2006-06-17'\n");
781 rtc_date_offset
= time(NULL
) - rtc_start_date
;
785 static void configure_rtc(QemuOpts
*opts
)
789 value
= qemu_opt_get(opts
, "base");
791 if (!strcmp(value
, "utc")) {
793 } else if (!strcmp(value
, "localtime")) {
796 configure_rtc_date_offset(value
, 0);
799 value
= qemu_opt_get(opts
, "clock");
801 if (!strcmp(value
, "host")) {
802 rtc_clock
= QEMU_CLOCK_HOST
;
803 } else if (!strcmp(value
, "rt")) {
804 rtc_clock
= QEMU_CLOCK_REALTIME
;
805 } else if (!strcmp(value
, "vm")) {
806 rtc_clock
= QEMU_CLOCK_VIRTUAL
;
808 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
812 value
= qemu_opt_get(opts
, "driftfix");
814 if (!strcmp(value
, "slew")) {
815 static GlobalProperty slew_lost_ticks
[] = {
817 .driver
= "mc146818rtc",
818 .property
= "lost_tick_policy",
821 { /* end of list */ }
824 qdev_prop_register_global_list(slew_lost_ticks
);
825 } else if (!strcmp(value
, "none")) {
826 /* discard is default */
828 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
834 /***********************************************************/
835 /* Bluetooth support */
838 static struct HCIInfo
*hci_table
[MAX_NICS
];
840 struct HCIInfo
*qemu_next_hci(void)
842 if (cur_hci
== nb_hcis
)
845 return hci_table
[cur_hci
++];
848 static int bt_hci_parse(const char *str
)
853 if (nb_hcis
>= MAX_NICS
) {
854 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
867 bdaddr
.b
[5] = 0x56 + nb_hcis
;
868 hci
->bdaddr_set(hci
, bdaddr
.b
);
870 hci_table
[nb_hcis
++] = hci
;
875 static void bt_vhci_add(int vlan_id
)
877 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
880 fprintf(stderr
, "qemu: warning: adding a VHCI to "
881 "an empty scatternet %i\n", vlan_id
);
883 bt_vhci_init(bt_new_hci(vlan
));
886 static struct bt_device_s
*bt_device_add(const char *opt
)
888 struct bt_scatternet_s
*vlan
;
890 char *endp
= strstr(opt
, ",vlan=");
891 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
894 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
897 vlan_id
= strtol(endp
+ 6, &endp
, 0);
899 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
904 vlan
= qemu_find_bt_vlan(vlan_id
);
907 fprintf(stderr
, "qemu: warning: adding a slave device to "
908 "an empty scatternet %i\n", vlan_id
);
910 if (!strcmp(devname
, "keyboard"))
911 return bt_keyboard_init(vlan
);
913 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
917 static int bt_parse(const char *opt
)
919 const char *endp
, *p
;
922 if (strstart(opt
, "hci", &endp
)) {
923 if (!*endp
|| *endp
== ',') {
925 if (!strstart(endp
, ",vlan=", 0))
928 return bt_hci_parse(opt
);
930 } else if (strstart(opt
, "vhci", &endp
)) {
931 if (!*endp
|| *endp
== ',') {
933 if (strstart(endp
, ",vlan=", &p
)) {
934 vlan
= strtol(p
, (char **) &endp
, 0);
936 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
940 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
949 } else if (strstart(opt
, "device:", &endp
))
950 return !bt_device_add(endp
);
952 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
956 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
958 /* FIXME: change this to true for 1.3 */
959 if (qemu_opt_get_bool(opts
, "enable", false)) {
960 #ifdef CONFIG_SECCOMP
961 if (seccomp_start() < 0) {
962 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
963 "failed to install seccomp syscall filter in the kernel");
967 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
968 "sandboxing request but seccomp is not compiled into this build");
976 static int parse_name(QemuOpts
*opts
, void *opaque
)
978 const char *proc_name
;
980 if (qemu_opt_get(opts
, "debug-threads")) {
981 qemu_thread_naming(qemu_opt_get_bool(opts
, "debug-threads", false));
983 qemu_name
= qemu_opt_get(opts
, "guest");
985 proc_name
= qemu_opt_get(opts
, "process");
987 os_set_proc_name(proc_name
);
993 bool usb_enabled(bool default_usb
)
995 return qemu_opt_get_bool(qemu_get_machine_opts(), "usb",
996 has_defaults
&& default_usb
);
1000 static int parse_add_fd(QemuOpts
*opts
, void *opaque
)
1002 int fd
, dupfd
, flags
;
1004 const char *fd_opaque
= NULL
;
1006 fd
= qemu_opt_get_number(opts
, "fd", -1);
1007 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
1008 fd_opaque
= qemu_opt_get(opts
, "opaque");
1011 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1012 "fd option is required and must be non-negative");
1016 if (fd
<= STDERR_FILENO
) {
1017 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1018 "fd cannot be a standard I/O stream");
1023 * All fds inherited across exec() necessarily have FD_CLOEXEC
1024 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
1026 flags
= fcntl(fd
, F_GETFD
);
1027 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
1028 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1029 "fd is not valid or already in use");
1034 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1035 "set option is required and must be non-negative");
1039 #ifdef F_DUPFD_CLOEXEC
1040 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
1044 qemu_set_cloexec(dupfd
);
1048 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
1049 "Error duplicating fd: %s", strerror(errno
));
1053 /* add the duplicate fd, and optionally the opaque string, to the fd set */
1054 monitor_fdset_add_fd(dupfd
, true, fdset_id
, fd_opaque
? true : false,
1060 static int cleanup_add_fd(QemuOpts
*opts
, void *opaque
)
1064 fd
= qemu_opt_get_number(opts
, "fd", -1);
1071 /***********************************************************/
1072 /* QEMU Block devices */
1074 #define HD_OPTS "media=disk"
1075 #define CDROM_OPTS "media=cdrom"
1077 #define PFLASH_OPTS ""
1081 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
1083 BlockInterfaceType
*block_default_type
= opaque
;
1085 return drive_new(opts
, *block_default_type
) == NULL
;
1088 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
1090 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
1091 qemu_opt_set(opts
, "snapshot", "on");
1096 static void default_drive(int enable
, int snapshot
, BlockInterfaceType type
,
1097 int index
, const char *optstr
)
1101 if (!enable
|| drive_get_by_index(type
, index
)) {
1105 opts
= drive_add(type
, index
, NULL
, optstr
);
1107 drive_enable_snapshot(opts
, NULL
);
1109 if (!drive_new(opts
, type
)) {
1114 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
1116 boot_set_handler
= func
;
1117 boot_set_opaque
= opaque
;
1120 int qemu_boot_set(const char *boot_order
)
1122 if (!boot_set_handler
) {
1125 return boot_set_handler(boot_set_opaque
, boot_order
);
1128 static void validate_bootdevices(const char *devices
)
1130 /* We just do some generic consistency checks */
1134 for (p
= devices
; *p
!= '\0'; p
++) {
1135 /* Allowed boot devices are:
1136 * a-b: floppy disk drives
1137 * c-f: IDE disk drives
1138 * g-m: machine implementation dependent drives
1139 * n-p: network devices
1140 * It's up to each machine implementation to check if the given boot
1141 * devices match the actual hardware implementation and firmware
1144 if (*p
< 'a' || *p
> 'p') {
1145 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
1148 if (bitmap
& (1 << (*p
- 'a'))) {
1149 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
1152 bitmap
|= 1 << (*p
- 'a');
1156 static void restore_boot_order(void *opaque
)
1158 char *normal_boot_order
= opaque
;
1159 static int first
= 1;
1161 /* Restore boot order and remove ourselves after the first boot */
1167 qemu_boot_set(normal_boot_order
);
1169 qemu_unregister_reset(restore_boot_order
, normal_boot_order
);
1170 g_free(normal_boot_order
);
1173 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
1176 FWBootEntry
*node
, *i
;
1178 if (bootindex
< 0) {
1182 assert(dev
!= NULL
|| suffix
!= NULL
);
1184 node
= g_malloc0(sizeof(FWBootEntry
));
1185 node
->bootindex
= bootindex
;
1186 node
->suffix
= g_strdup(suffix
);
1189 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1190 if (i
->bootindex
== bootindex
) {
1191 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
1193 } else if (i
->bootindex
< bootindex
) {
1196 QTAILQ_INSERT_BEFORE(i
, node
, link
);
1199 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
1202 DeviceState
*get_boot_device(uint32_t position
)
1204 uint32_t counter
= 0;
1205 FWBootEntry
*i
= NULL
;
1206 DeviceState
*res
= NULL
;
1208 if (!QTAILQ_EMPTY(&fw_boot_order
)) {
1209 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1210 if (counter
== position
) {
1221 * This function returns null terminated string that consist of new line
1222 * separated device paths.
1224 * memory pointed by "size" is assigned total length of the array in bytes
1227 char *get_boot_devices_list(size_t *size
, bool ignore_suffixes
)
1233 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1234 char *devpath
= NULL
, *bootpath
;
1238 devpath
= qdev_get_fw_dev_path(i
->dev
);
1242 if (i
->suffix
&& !ignore_suffixes
&& devpath
) {
1243 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
1245 bootpath
= g_malloc(bootpathlen
);
1246 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
1248 } else if (devpath
) {
1250 } else if (!ignore_suffixes
) {
1252 bootpath
= g_strdup(i
->suffix
);
1254 bootpath
= g_strdup("");
1258 list
[total
-1] = '\n';
1260 len
= strlen(bootpath
) + 1;
1261 list
= g_realloc(list
, total
+ len
);
1262 memcpy(&list
[total
], bootpath
, len
);
1269 if (boot_strict
&& *size
> 0) {
1270 list
[total
-1] = '\n';
1271 list
= g_realloc(list
, total
+ 5);
1272 memcpy(&list
[total
], "HALT", 5);
1278 static void numa_node_parse_cpus(int nodenr
, const char *cpus
)
1281 unsigned long long value
, endvalue
;
1283 /* Empty CPU range strings will be considered valid, they will simply
1284 * not set any bit in the CPU bitmap.
1290 if (parse_uint(cpus
, &value
, &endptr
, 10) < 0) {
1293 if (*endptr
== '-') {
1294 if (parse_uint_full(endptr
+ 1, &endvalue
, 10) < 0) {
1297 } else if (*endptr
== '\0') {
1303 if (endvalue
>= MAX_CPUMASK_BITS
) {
1304 endvalue
= MAX_CPUMASK_BITS
- 1;
1306 "qemu: NUMA: A max of %d VCPUs are supported\n",
1310 if (endvalue
< value
) {
1314 bitmap_set(node_cpumask
[nodenr
], value
, endvalue
-value
+1);
1318 fprintf(stderr
, "qemu: Invalid NUMA CPU range: %s\n", cpus
);
1322 static void numa_add(const char *optarg
)
1326 unsigned long long nodenr
;
1328 optarg
= get_opt_name(option
, 128, optarg
, ',');
1329 if (*optarg
== ',') {
1332 if (!strcmp(option
, "node")) {
1334 if (nb_numa_nodes
>= MAX_NODES
) {
1335 fprintf(stderr
, "qemu: too many NUMA nodes\n");
1339 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
1340 nodenr
= nb_numa_nodes
;
1342 if (parse_uint_full(option
, &nodenr
, 10) < 0) {
1343 fprintf(stderr
, "qemu: Invalid NUMA nodeid: %s\n", option
);
1348 if (nodenr
>= MAX_NODES
) {
1349 fprintf(stderr
, "qemu: invalid NUMA nodeid: %llu\n", nodenr
);
1353 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
1354 node_mem
[nodenr
] = 0;
1357 sval
= strtosz(option
, &endptr
);
1358 if (sval
< 0 || *endptr
) {
1359 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
1362 node_mem
[nodenr
] = sval
;
1364 if (get_param_value(option
, 128, "cpus", optarg
) != 0) {
1365 numa_node_parse_cpus(nodenr
, option
);
1369 fprintf(stderr
, "Invalid -numa option: %s\n", option
);
1374 static QemuOptsList qemu_smp_opts
= {
1376 .implied_opt_name
= "cpus",
1377 .merge_lists
= true,
1378 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smp_opts
.head
),
1382 .type
= QEMU_OPT_NUMBER
,
1385 .type
= QEMU_OPT_NUMBER
,
1388 .type
= QEMU_OPT_NUMBER
,
1391 .type
= QEMU_OPT_NUMBER
,
1394 .type
= QEMU_OPT_NUMBER
,
1396 { /*End of list */ }
1400 static void smp_parse(QemuOpts
*opts
)
1404 unsigned cpus
= qemu_opt_get_number(opts
, "cpus", 0);
1405 unsigned sockets
= qemu_opt_get_number(opts
, "sockets", 0);
1406 unsigned cores
= qemu_opt_get_number(opts
, "cores", 0);
1407 unsigned threads
= qemu_opt_get_number(opts
, "threads", 0);
1409 /* compute missing values, prefer sockets over cores over threads */
1410 if (cpus
== 0 || sockets
== 0) {
1411 sockets
= sockets
> 0 ? sockets
: 1;
1412 cores
= cores
> 0 ? cores
: 1;
1413 threads
= threads
> 0 ? threads
: 1;
1415 cpus
= cores
* threads
* sockets
;
1419 threads
= threads
> 0 ? threads
: 1;
1420 cores
= cpus
/ (sockets
* threads
);
1422 threads
= cpus
/ (cores
* sockets
);
1426 max_cpus
= qemu_opt_get_number(opts
, "maxcpus", 0);
1429 smp_cores
= cores
> 0 ? cores
: 1;
1430 smp_threads
= threads
> 0 ? threads
: 1;
1434 if (max_cpus
== 0) {
1435 max_cpus
= smp_cpus
;
1438 if (max_cpus
> MAX_CPUMASK_BITS
) {
1439 fprintf(stderr
, "Unsupported number of maxcpus\n");
1442 if (max_cpus
< smp_cpus
) {
1443 fprintf(stderr
, "maxcpus must be equal to or greater than smp\n");
1449 static void configure_realtime(QemuOpts
*opts
)
1453 enable_mlock
= qemu_opt_get_bool(opts
, "mlock", true);
1456 if (os_mlock() < 0) {
1457 fprintf(stderr
, "qemu: locking memory failed\n");
1464 static void configure_msg(QemuOpts
*opts
)
1466 enable_timestamp_msg
= qemu_opt_get_bool(opts
, "timestamp", true);
1469 /***********************************************************/
1472 static int usb_device_add(const char *devname
)
1474 USBDevice
*dev
= NULL
;
1475 #ifndef CONFIG_LINUX
1479 if (!usb_enabled(false)) {
1483 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1484 dev
= usbdevice_create(devname
);
1488 /* the other ones */
1489 #ifndef CONFIG_LINUX
1490 /* only the linux version is qdev-ified, usb-bsd still needs this */
1491 if (strstart(devname
, "host:", &p
)) {
1492 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1502 static int usb_device_del(const char *devname
)
1507 if (strstart(devname
, "host:", &p
)) {
1511 if (!usb_enabled(false)) {
1515 p
= strchr(devname
, '.');
1518 bus_num
= strtoul(devname
, NULL
, 0);
1519 addr
= strtoul(p
+ 1, NULL
, 0);
1521 return usb_device_delete_addr(bus_num
, addr
);
1524 static int usb_parse(const char *cmdline
)
1527 r
= usb_device_add(cmdline
);
1529 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1534 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1536 const char *devname
= qdict_get_str(qdict
, "devname");
1537 if (usb_device_add(devname
) < 0) {
1538 error_report("could not add USB device '%s'", devname
);
1542 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1544 const char *devname
= qdict_get_str(qdict
, "devname");
1545 if (usb_device_del(devname
) < 0) {
1546 error_report("could not delete USB device '%s'", devname
);
1550 /***********************************************************/
1551 /* PCMCIA/Cardbus */
1553 static struct pcmcia_socket_entry_s
{
1554 PCMCIASocket
*socket
;
1555 struct pcmcia_socket_entry_s
*next
;
1556 } *pcmcia_sockets
= 0;
1558 void pcmcia_socket_register(PCMCIASocket
*socket
)
1560 struct pcmcia_socket_entry_s
*entry
;
1562 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1563 entry
->socket
= socket
;
1564 entry
->next
= pcmcia_sockets
;
1565 pcmcia_sockets
= entry
;
1568 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1570 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1572 ptr
= &pcmcia_sockets
;
1573 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1574 if (entry
->socket
== socket
) {
1580 void pcmcia_info(Monitor
*mon
, const QDict
*qdict
)
1582 struct pcmcia_socket_entry_s
*iter
;
1584 if (!pcmcia_sockets
)
1585 monitor_printf(mon
, "No PCMCIA sockets\n");
1587 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1588 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1589 iter
->socket
->attached
? iter
->socket
->card_string
:
1593 /***********************************************************/
1594 /* machine registration */
1596 MachineState
*current_machine
;
1598 static void machine_class_init(ObjectClass
*oc
, void *data
)
1600 MachineClass
*mc
= MACHINE_CLASS(oc
);
1601 QEMUMachine
*qm
= data
;
1603 mc
->name
= qm
->name
;
1604 mc
->alias
= qm
->alias
;
1605 mc
->desc
= qm
->desc
;
1606 mc
->init
= qm
->init
;
1607 mc
->reset
= qm
->reset
;
1608 mc
->hot_add_cpu
= qm
->hot_add_cpu
;
1609 mc
->kvm_type
= qm
->kvm_type
;
1610 mc
->block_default_type
= qm
->block_default_type
;
1611 mc
->max_cpus
= qm
->max_cpus
;
1612 mc
->no_serial
= qm
->no_serial
;
1613 mc
->no_parallel
= qm
->no_parallel
;
1614 mc
->use_virtcon
= qm
->use_virtcon
;
1615 mc
->use_sclp
= qm
->use_sclp
;
1616 mc
->no_floppy
= qm
->no_floppy
;
1617 mc
->no_cdrom
= qm
->no_cdrom
;
1618 mc
->no_sdcard
= qm
->no_sdcard
;
1619 mc
->is_default
= qm
->is_default
;
1620 mc
->default_machine_opts
= qm
->default_machine_opts
;
1621 mc
->default_boot_order
= qm
->default_boot_order
;
1622 mc
->compat_props
= qm
->compat_props
;
1623 mc
->hw_version
= qm
->hw_version
;
1626 int qemu_register_machine(QEMUMachine
*m
)
1628 char *name
= g_strconcat(m
->name
, TYPE_MACHINE_SUFFIX
, NULL
);
1631 .parent
= TYPE_MACHINE
,
1632 .class_init
= machine_class_init
,
1633 .class_data
= (void *)m
,
1642 static MachineClass
*find_machine(const char *name
)
1644 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1645 MachineClass
*mc
= NULL
;
1647 for (el
= machines
; el
; el
= el
->next
) {
1648 MachineClass
*temp
= el
->data
;
1650 if (!strcmp(temp
->name
, name
)) {
1655 !strcmp(temp
->alias
, name
)) {
1661 g_slist_free(machines
);
1665 MachineClass
*find_default_machine(void)
1667 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1668 MachineClass
*mc
= NULL
;
1670 for (el
= machines
; el
; el
= el
->next
) {
1671 MachineClass
*temp
= el
->data
;
1673 if (temp
->is_default
) {
1679 g_slist_free(machines
);
1683 MachineInfoList
*qmp_query_machines(Error
**errp
)
1685 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
1686 MachineInfoList
*mach_list
= NULL
;
1688 for (el
= machines
; el
; el
= el
->next
) {
1689 MachineClass
*mc
= el
->data
;
1690 MachineInfoList
*entry
;
1693 info
= g_malloc0(sizeof(*info
));
1694 if (mc
->is_default
) {
1695 info
->has_is_default
= true;
1696 info
->is_default
= true;
1700 info
->has_alias
= true;
1701 info
->alias
= g_strdup(mc
->alias
);
1704 info
->name
= g_strdup(mc
->name
);
1705 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
1707 entry
= g_malloc0(sizeof(*entry
));
1708 entry
->value
= info
;
1709 entry
->next
= mach_list
;
1713 g_slist_free(machines
);
1717 /***********************************************************/
1718 /* main execution loop */
1720 struct vm_change_state_entry
{
1721 VMChangeStateHandler
*cb
;
1723 QLIST_ENTRY (vm_change_state_entry
) entries
;
1726 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1728 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1731 VMChangeStateEntry
*e
;
1733 e
= g_malloc0(sizeof (*e
));
1737 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1741 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1743 QLIST_REMOVE (e
, entries
);
1747 void vm_state_notify(int running
, RunState state
)
1749 VMChangeStateEntry
*e
;
1751 trace_vm_state_notify(running
, state
);
1753 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1754 e
->cb(e
->opaque
, running
, state
);
1760 if (!runstate_is_running()) {
1762 runstate_set(RUN_STATE_RUNNING
);
1763 vm_state_notify(1, RUN_STATE_RUNNING
);
1765 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1769 /* reset/shutdown handler */
1771 typedef struct QEMUResetEntry
{
1772 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1773 QEMUResetHandler
*func
;
1777 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1778 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1779 static int reset_requested
;
1780 static int shutdown_requested
, shutdown_signal
= -1;
1781 static pid_t shutdown_pid
;
1782 static int powerdown_requested
;
1783 static int debug_requested
;
1784 static int suspend_requested
;
1785 static WakeupReason wakeup_reason
;
1786 static NotifierList powerdown_notifiers
=
1787 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1788 static NotifierList suspend_notifiers
=
1789 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1790 static NotifierList wakeup_notifiers
=
1791 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1792 static uint32_t wakeup_reason_mask
= ~(1 << QEMU_WAKEUP_REASON_NONE
);
1793 static RunState vmstop_requested
= RUN_STATE_MAX
;
1795 int qemu_shutdown_requested_get(void)
1797 return shutdown_requested
;
1800 int qemu_reset_requested_get(void)
1802 return reset_requested
;
1805 static int qemu_shutdown_requested(void)
1807 int r
= shutdown_requested
;
1808 shutdown_requested
= 0;
1812 static void qemu_kill_report(void)
1814 if (!qtest_driver() && shutdown_signal
!= -1) {
1815 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1816 if (shutdown_pid
== 0) {
1817 /* This happens for eg ^C at the terminal, so it's worth
1818 * avoiding printing an odd message in that case.
1820 fputc('\n', stderr
);
1822 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1824 shutdown_signal
= -1;
1828 static int qemu_reset_requested(void)
1830 int r
= reset_requested
;
1831 reset_requested
= 0;
1835 static int qemu_suspend_requested(void)
1837 int r
= suspend_requested
;
1838 suspend_requested
= 0;
1842 static WakeupReason
qemu_wakeup_requested(void)
1844 return wakeup_reason
;
1847 static int qemu_powerdown_requested(void)
1849 int r
= powerdown_requested
;
1850 powerdown_requested
= 0;
1854 static int qemu_debug_requested(void)
1856 int r
= debug_requested
;
1857 debug_requested
= 0;
1861 /* We use RUN_STATE_MAX but any invalid value will do */
1862 static bool qemu_vmstop_requested(RunState
*r
)
1864 if (vmstop_requested
< RUN_STATE_MAX
) {
1865 *r
= vmstop_requested
;
1866 vmstop_requested
= RUN_STATE_MAX
;
1873 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1875 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1878 re
->opaque
= opaque
;
1879 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1882 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1886 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1887 if (re
->func
== func
&& re
->opaque
== opaque
) {
1888 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1895 void qemu_devices_reset(void)
1897 QEMUResetEntry
*re
, *nre
;
1899 /* reset all devices */
1900 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1901 re
->func(re
->opaque
);
1905 void qemu_system_reset(bool report
)
1909 mc
= current_machine
? MACHINE_GET_CLASS(current_machine
) : NULL
;
1911 if (mc
&& mc
->reset
) {
1914 qemu_devices_reset();
1917 monitor_protocol_event(QEVENT_RESET
, NULL
);
1919 cpu_synchronize_all_post_reset();
1922 void qemu_system_reset_request(void)
1925 shutdown_requested
= 1;
1927 reset_requested
= 1;
1930 qemu_notify_event();
1933 static void qemu_system_suspend(void)
1936 notifier_list_notify(&suspend_notifiers
, NULL
);
1937 runstate_set(RUN_STATE_SUSPENDED
);
1938 monitor_protocol_event(QEVENT_SUSPEND
, NULL
);
1941 void qemu_system_suspend_request(void)
1943 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1946 suspend_requested
= 1;
1948 qemu_notify_event();
1951 void qemu_register_suspend_notifier(Notifier
*notifier
)
1953 notifier_list_add(&suspend_notifiers
, notifier
);
1956 void qemu_system_wakeup_request(WakeupReason reason
)
1958 trace_system_wakeup_request(reason
);
1960 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1963 if (!(wakeup_reason_mask
& (1 << reason
))) {
1966 runstate_set(RUN_STATE_RUNNING
);
1967 wakeup_reason
= reason
;
1968 qemu_notify_event();
1971 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1974 wakeup_reason_mask
|= (1 << reason
);
1976 wakeup_reason_mask
&= ~(1 << reason
);
1980 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1982 notifier_list_add(&wakeup_notifiers
, notifier
);
1985 void qemu_system_killed(int signal
, pid_t pid
)
1987 shutdown_signal
= signal
;
1990 qemu_system_shutdown_request();
1993 void qemu_system_shutdown_request(void)
1995 shutdown_requested
= 1;
1996 qemu_notify_event();
1999 static void qemu_system_powerdown(void)
2001 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
2002 notifier_list_notify(&powerdown_notifiers
, NULL
);
2005 void qemu_system_powerdown_request(void)
2007 powerdown_requested
= 1;
2008 qemu_notify_event();
2011 void qemu_register_powerdown_notifier(Notifier
*notifier
)
2013 notifier_list_add(&powerdown_notifiers
, notifier
);
2016 void qemu_system_debug_request(void)
2018 debug_requested
= 1;
2019 qemu_notify_event();
2022 void qemu_system_vmstop_request(RunState state
)
2024 vmstop_requested
= state
;
2025 qemu_notify_event();
2028 static bool main_loop_should_exit(void)
2031 if (qemu_debug_requested()) {
2032 vm_stop(RUN_STATE_DEBUG
);
2034 if (qemu_suspend_requested()) {
2035 qemu_system_suspend();
2037 if (qemu_shutdown_requested()) {
2039 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
2041 vm_stop(RUN_STATE_SHUTDOWN
);
2046 if (qemu_reset_requested()) {
2048 cpu_synchronize_all_states();
2049 qemu_system_reset(VMRESET_REPORT
);
2051 if (runstate_needs_reset()) {
2052 runstate_set(RUN_STATE_PAUSED
);
2055 if (qemu_wakeup_requested()) {
2057 cpu_synchronize_all_states();
2058 qemu_system_reset(VMRESET_SILENT
);
2059 notifier_list_notify(&wakeup_notifiers
, &wakeup_reason
);
2060 wakeup_reason
= QEMU_WAKEUP_REASON_NONE
;
2062 monitor_protocol_event(QEVENT_WAKEUP
, NULL
);
2064 if (qemu_powerdown_requested()) {
2065 qemu_system_powerdown();
2067 if (qemu_vmstop_requested(&r
)) {
2073 static void main_loop(void)
2077 #ifdef CONFIG_PROFILER
2081 nonblocking
= !kvm_enabled() && !xen_enabled() && last_io
> 0;
2082 #ifdef CONFIG_PROFILER
2083 ti
= profile_getclock();
2085 last_io
= main_loop_wait(nonblocking
);
2086 #ifdef CONFIG_PROFILER
2087 dev_time
+= profile_getclock() - ti
;
2089 } while (!main_loop_should_exit());
2092 static void version(void)
2094 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
2097 static void help(int exitcode
)
2100 printf("usage: %s [options] [disk_image]\n\n"
2101 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
2102 error_get_progname());
2104 #define QEMU_OPTIONS_GENERATE_HELP
2105 #include "qemu-options-wrapper.h"
2107 printf("\nDuring emulation, the following keys are useful:\n"
2108 "ctrl-alt-f toggle full screen\n"
2109 "ctrl-alt-n switch to virtual console 'n'\n"
2110 "ctrl-alt toggle mouse and keyboard grab\n"
2112 "When using -nographic, press 'ctrl-a h' to get some help.\n");
2117 #define HAS_ARG 0x0001
2119 typedef struct QEMUOption
{
2126 static const QEMUOption qemu_options
[] = {
2127 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
2128 #define QEMU_OPTIONS_GENERATE_OPTIONS
2129 #include "qemu-options-wrapper.h"
2133 static bool vga_available(void)
2135 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
2138 static bool cirrus_vga_available(void)
2140 return object_class_by_name("cirrus-vga")
2141 || object_class_by_name("isa-cirrus-vga");
2144 static bool vmware_vga_available(void)
2146 return object_class_by_name("vmware-svga");
2149 static bool qxl_vga_available(void)
2151 return object_class_by_name("qxl-vga");
2154 static bool tcx_vga_available(void)
2156 return object_class_by_name("SUNW,tcx");
2159 static bool cg3_vga_available(void)
2161 return object_class_by_name("cgthree");
2164 static void select_vgahw (const char *p
)
2168 assert(vga_interface_type
== VGA_NONE
);
2169 if (strstart(p
, "std", &opts
)) {
2170 if (vga_available()) {
2171 vga_interface_type
= VGA_STD
;
2173 fprintf(stderr
, "Error: standard VGA not available\n");
2176 } else if (strstart(p
, "cirrus", &opts
)) {
2177 if (cirrus_vga_available()) {
2178 vga_interface_type
= VGA_CIRRUS
;
2180 fprintf(stderr
, "Error: Cirrus VGA not available\n");
2183 } else if (strstart(p
, "vmware", &opts
)) {
2184 if (vmware_vga_available()) {
2185 vga_interface_type
= VGA_VMWARE
;
2187 fprintf(stderr
, "Error: VMWare SVGA not available\n");
2190 } else if (strstart(p
, "xenfb", &opts
)) {
2191 vga_interface_type
= VGA_XENFB
;
2192 } else if (strstart(p
, "qxl", &opts
)) {
2193 if (qxl_vga_available()) {
2194 vga_interface_type
= VGA_QXL
;
2196 fprintf(stderr
, "Error: QXL VGA not available\n");
2199 } else if (strstart(p
, "tcx", &opts
)) {
2200 if (tcx_vga_available()) {
2201 vga_interface_type
= VGA_TCX
;
2203 fprintf(stderr
, "Error: TCX framebuffer not available\n");
2206 } else if (strstart(p
, "cg3", &opts
)) {
2207 if (cg3_vga_available()) {
2208 vga_interface_type
= VGA_CG3
;
2210 fprintf(stderr
, "Error: CG3 framebuffer not available\n");
2213 } else if (!strstart(p
, "none", &opts
)) {
2215 fprintf(stderr
, "Unknown vga type: %s\n", p
);
2219 const char *nextopt
;
2221 if (strstart(opts
, ",retrace=", &nextopt
)) {
2223 if (strstart(opts
, "dumb", &nextopt
))
2224 vga_retrace_method
= VGA_RETRACE_DUMB
;
2225 else if (strstart(opts
, "precise", &nextopt
))
2226 vga_retrace_method
= VGA_RETRACE_PRECISE
;
2227 else goto invalid_vga
;
2228 } else goto invalid_vga
;
2233 static DisplayType
select_display(const char *p
)
2236 DisplayType display
= DT_DEFAULT
;
2238 if (strstart(p
, "sdl", &opts
)) {
2242 const char *nextopt
;
2244 if (strstart(opts
, ",frame=", &nextopt
)) {
2246 if (strstart(opts
, "on", &nextopt
)) {
2248 } else if (strstart(opts
, "off", &nextopt
)) {
2251 goto invalid_sdl_args
;
2253 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
2255 if (strstart(opts
, "on", &nextopt
)) {
2257 } else if (strstart(opts
, "off", &nextopt
)) {
2260 goto invalid_sdl_args
;
2262 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
2264 if (strstart(opts
, "on", &nextopt
)) {
2266 } else if (strstart(opts
, "off", &nextopt
)) {
2269 goto invalid_sdl_args
;
2271 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
2273 if (strstart(opts
, "on", &nextopt
)) {
2275 } else if (strstart(opts
, "off", &nextopt
)) {
2278 goto invalid_sdl_args
;
2282 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
2288 fprintf(stderr
, "SDL support is disabled\n");
2291 } else if (strstart(p
, "vnc", &opts
)) {
2296 const char *nextopt
;
2298 if (strstart(opts
, "=", &nextopt
)) {
2299 vnc_display
= nextopt
;
2303 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
2307 fprintf(stderr
, "VNC support is disabled\n");
2310 } else if (strstart(p
, "curses", &opts
)) {
2311 #ifdef CONFIG_CURSES
2312 display
= DT_CURSES
;
2314 fprintf(stderr
, "Curses support is disabled\n");
2317 } else if (strstart(p
, "gtk", &opts
)) {
2321 const char *nextopt
;
2323 if (strstart(opts
, ",grab_on_hover=", &nextopt
)) {
2325 if (strstart(opts
, "on", &nextopt
)) {
2326 grab_on_hover
= true;
2327 } else if (strstart(opts
, "off", &nextopt
)) {
2328 grab_on_hover
= false;
2330 goto invalid_gtk_args
;
2334 fprintf(stderr
, "Invalid GTK option string: %s\n", p
);
2340 fprintf(stderr
, "GTK support is disabled\n");
2343 } else if (strstart(p
, "none", &opts
)) {
2346 fprintf(stderr
, "Unknown display type: %s\n", p
);
2353 static int balloon_parse(const char *arg
)
2357 if (strcmp(arg
, "none") == 0) {
2361 if (!strncmp(arg
, "virtio", 6)) {
2362 if (arg
[6] == ',') {
2363 /* have params -> parse them */
2364 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
2368 /* create empty opts */
2369 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2372 qemu_opt_set(opts
, "driver", "virtio-balloon");
2379 char *qemu_find_file(int type
, const char *name
)
2385 /* Try the name as a straight path first */
2386 if (access(name
, R_OK
) == 0) {
2387 trace_load_file(name
, name
);
2388 return g_strdup(name
);
2392 case QEMU_FILE_TYPE_BIOS
:
2395 case QEMU_FILE_TYPE_KEYMAP
:
2396 subdir
= "keymaps/";
2402 for (i
= 0; i
< data_dir_idx
; i
++) {
2403 buf
= g_strdup_printf("%s/%s%s", data_dir
[i
], subdir
, name
);
2404 if (access(buf
, R_OK
) == 0) {
2405 trace_load_file(name
, buf
);
2413 static int device_help_func(QemuOpts
*opts
, void *opaque
)
2415 return qdev_device_help(opts
);
2418 static int device_init_func(QemuOpts
*opts
, void *opaque
)
2422 dev
= qdev_device_add(opts
);
2425 object_unref(OBJECT(dev
));
2429 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
2431 Error
*local_err
= NULL
;
2433 qemu_chr_new_from_opts(opts
, NULL
, &local_err
);
2435 error_report("%s", error_get_pretty(local_err
));
2436 error_free(local_err
);
2442 #ifdef CONFIG_VIRTFS
2443 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
2446 ret
= qemu_fsdev_add(opts
);
2452 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
2454 CharDriverState
*chr
;
2455 const char *chardev
;
2459 mode
= qemu_opt_get(opts
, "mode");
2463 if (strcmp(mode
, "readline") == 0) {
2464 flags
= MONITOR_USE_READLINE
;
2465 } else if (strcmp(mode
, "control") == 0) {
2466 flags
= MONITOR_USE_CONTROL
;
2468 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
2472 if (qemu_opt_get_bool(opts
, "pretty", 0))
2473 flags
|= MONITOR_USE_PRETTY
;
2475 if (qemu_opt_get_bool(opts
, "default", 0))
2476 flags
|= MONITOR_IS_DEFAULT
;
2478 chardev
= qemu_opt_get(opts
, "chardev");
2479 chr
= qemu_chr_find(chardev
);
2481 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
2485 qemu_chr_fe_claim_no_fail(chr
);
2486 monitor_init(chr
, flags
);
2490 static void monitor_parse(const char *optarg
, const char *mode
)
2492 static int monitor_device_index
= 0;
2498 if (strstart(optarg
, "chardev:", &p
)) {
2499 snprintf(label
, sizeof(label
), "%s", p
);
2501 snprintf(label
, sizeof(label
), "compat_monitor%d",
2502 monitor_device_index
);
2503 if (monitor_device_index
== 0) {
2506 opts
= qemu_chr_parse_compat(label
, optarg
);
2508 fprintf(stderr
, "parse error: %s\n", optarg
);
2513 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2515 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2518 qemu_opt_set(opts
, "mode", mode
);
2519 qemu_opt_set(opts
, "chardev", label
);
2521 qemu_opt_set(opts
, "default", "on");
2522 monitor_device_index
++;
2525 struct device_config
{
2527 DEV_USB
, /* -usbdevice */
2529 DEV_SERIAL
, /* -serial */
2530 DEV_PARALLEL
, /* -parallel */
2531 DEV_VIRTCON
, /* -virtioconsole */
2532 DEV_DEBUGCON
, /* -debugcon */
2533 DEV_GDB
, /* -gdb, -s */
2534 DEV_SCLP
, /* s390 sclp */
2536 const char *cmdline
;
2538 QTAILQ_ENTRY(device_config
) next
;
2541 static QTAILQ_HEAD(, device_config
) device_configs
=
2542 QTAILQ_HEAD_INITIALIZER(device_configs
);
2544 static void add_device_config(int type
, const char *cmdline
)
2546 struct device_config
*conf
;
2548 conf
= g_malloc0(sizeof(*conf
));
2550 conf
->cmdline
= cmdline
;
2551 loc_save(&conf
->loc
);
2552 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2555 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2557 struct device_config
*conf
;
2560 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2561 if (conf
->type
!= type
)
2563 loc_push_restore(&conf
->loc
);
2564 rc
= func(conf
->cmdline
);
2565 loc_pop(&conf
->loc
);
2572 static int serial_parse(const char *devname
)
2574 static int index
= 0;
2577 if (strcmp(devname
, "none") == 0)
2579 if (index
== MAX_SERIAL_PORTS
) {
2580 fprintf(stderr
, "qemu: too many serial ports\n");
2583 snprintf(label
, sizeof(label
), "serial%d", index
);
2584 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2585 if (!serial_hds
[index
]) {
2586 fprintf(stderr
, "qemu: could not connect serial device"
2587 " to character backend '%s'\n", devname
);
2594 static int parallel_parse(const char *devname
)
2596 static int index
= 0;
2599 if (strcmp(devname
, "none") == 0)
2601 if (index
== MAX_PARALLEL_PORTS
) {
2602 fprintf(stderr
, "qemu: too many parallel ports\n");
2605 snprintf(label
, sizeof(label
), "parallel%d", index
);
2606 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2607 if (!parallel_hds
[index
]) {
2608 fprintf(stderr
, "qemu: could not connect parallel device"
2609 " to character backend '%s'\n", devname
);
2616 static int virtcon_parse(const char *devname
)
2618 QemuOptsList
*device
= qemu_find_opts("device");
2619 static int index
= 0;
2621 QemuOpts
*bus_opts
, *dev_opts
;
2623 if (strcmp(devname
, "none") == 0)
2625 if (index
== MAX_VIRTIO_CONSOLES
) {
2626 fprintf(stderr
, "qemu: too many virtio consoles\n");
2630 bus_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2631 if (arch_type
== QEMU_ARCH_S390X
) {
2632 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2634 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2637 dev_opts
= qemu_opts_create(device
, NULL
, 0, &error_abort
);
2638 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2640 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2641 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2642 if (!virtcon_hds
[index
]) {
2643 fprintf(stderr
, "qemu: could not connect virtio console"
2644 " to character backend '%s'\n", devname
);
2647 qemu_opt_set(dev_opts
, "chardev", label
);
2653 static int sclp_parse(const char *devname
)
2655 QemuOptsList
*device
= qemu_find_opts("device");
2656 static int index
= 0;
2660 if (strcmp(devname
, "none") == 0) {
2663 if (index
== MAX_SCLP_CONSOLES
) {
2664 fprintf(stderr
, "qemu: too many sclp consoles\n");
2668 assert(arch_type
== QEMU_ARCH_S390X
);
2670 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2671 qemu_opt_set(dev_opts
, "driver", "sclpconsole");
2673 snprintf(label
, sizeof(label
), "sclpcon%d", index
);
2674 sclp_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2675 if (!sclp_hds
[index
]) {
2676 fprintf(stderr
, "qemu: could not connect sclp console"
2677 " to character backend '%s'\n", devname
);
2680 qemu_opt_set(dev_opts
, "chardev", label
);
2686 static int debugcon_parse(const char *devname
)
2690 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2693 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2695 fprintf(stderr
, "qemu: already have a debugcon device\n");
2698 qemu_opt_set(opts
, "driver", "isa-debugcon");
2699 qemu_opt_set(opts
, "chardev", "debugcon");
2703 static MachineClass
*machine_parse(const char *name
)
2705 MachineClass
*mc
= NULL
;
2706 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
2709 mc
= find_machine(name
);
2714 if (name
&& !is_help_option(name
)) {
2715 error_report("Unsupported machine type");
2716 error_printf("Use -machine help to list supported machines!\n");
2718 printf("Supported machines are:\n");
2719 for (el
= machines
; el
; el
= el
->next
) {
2720 MachineClass
*mc
= el
->data
;
2722 printf("%-20s %s (alias of %s)\n", mc
->alias
, mc
->desc
, mc
->name
);
2724 printf("%-20s %s%s\n", mc
->name
, mc
->desc
,
2725 mc
->is_default
? " (default)" : "");
2729 g_slist_free(machines
);
2730 exit(!name
|| !is_help_option(name
));
2733 static int tcg_init(MachineClass
*mc
)
2735 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2740 const char *opt_name
;
2742 int (*available
)(void);
2743 int (*init
)(MachineClass
*mc
);
2746 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2747 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2748 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2749 { "qtest", "QTest", qtest_available
, qtest_init_accel
, &qtest_allowed
},
2752 static int configure_accelerator(MachineClass
*mc
)
2757 bool accel_initialised
= false;
2758 bool init_failed
= false;
2760 p
= qemu_opt_get(qemu_get_machine_opts(), "accel");
2762 /* Use the default "accelerator", tcg */
2766 while (!accel_initialised
&& *p
!= '\0') {
2770 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2771 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2772 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2773 if (!accel_list
[i
].available()) {
2774 printf("%s not supported for this target\n",
2775 accel_list
[i
].name
);
2778 *(accel_list
[i
].allowed
) = true;
2779 ret
= accel_list
[i
].init(mc
);
2782 fprintf(stderr
, "failed to initialize %s: %s\n",
2785 *(accel_list
[i
].allowed
) = false;
2787 accel_initialised
= true;
2792 if (i
== ARRAY_SIZE(accel_list
)) {
2793 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2797 if (!accel_initialised
) {
2799 fprintf(stderr
, "No accelerator found!\n");
2805 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2808 return !accel_initialised
;
2811 void qemu_add_exit_notifier(Notifier
*notify
)
2813 notifier_list_add(&exit_notifiers
, notify
);
2816 void qemu_remove_exit_notifier(Notifier
*notify
)
2818 notifier_remove(notify
);
2821 static void qemu_run_exit_notifiers(void)
2823 notifier_list_notify(&exit_notifiers
, NULL
);
2826 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2828 notifier_list_add(&machine_init_done_notifiers
, notify
);
2831 static void qemu_run_machine_init_done_notifiers(void)
2833 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2836 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2837 const char **poptarg
, int *poptind
)
2839 const QEMUOption
*popt
;
2840 int optind
= *poptind
;
2841 char *r
= argv
[optind
];
2844 loc_set_cmdline(argv
, optind
, 1);
2846 /* Treat --foo the same as -foo. */
2849 popt
= qemu_options
;
2852 error_report("invalid option");
2855 if (!strcmp(popt
->name
, r
+ 1))
2859 if (popt
->flags
& HAS_ARG
) {
2860 if (optind
>= argc
) {
2861 error_report("requires an argument");
2864 optarg
= argv
[optind
++];
2865 loc_set_cmdline(argv
, optind
- 2, 2);
2876 static gpointer
malloc_and_trace(gsize n_bytes
)
2878 void *ptr
= malloc(n_bytes
);
2879 trace_g_malloc(n_bytes
, ptr
);
2883 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2885 void *ptr
= realloc(mem
, n_bytes
);
2886 trace_g_realloc(mem
, n_bytes
, ptr
);
2890 static void free_and_trace(gpointer mem
)
2896 static int object_set_property(const char *name
, const char *value
, void *opaque
)
2898 Object
*obj
= OBJECT(opaque
);
2899 StringInputVisitor
*siv
;
2900 Error
*local_err
= NULL
;
2902 if (strcmp(name
, "qom-type") == 0 || strcmp(name
, "id") == 0 ||
2903 strcmp(name
, "type") == 0) {
2907 siv
= string_input_visitor_new(value
);
2908 object_property_set(obj
, string_input_get_visitor(siv
), name
, &local_err
);
2909 string_input_visitor_cleanup(siv
);
2912 qerror_report_err(local_err
);
2913 error_free(local_err
);
2920 static int object_create(QemuOpts
*opts
, void *opaque
)
2922 const char *type
= qemu_opt_get(opts
, "qom-type");
2923 const char *id
= qemu_opts_id(opts
);
2924 Error
*local_err
= NULL
;
2927 g_assert(type
!= NULL
);
2930 qerror_report(QERR_MISSING_PARAMETER
, "id");
2934 obj
= object_new(type
);
2935 if (qemu_opt_foreach(opts
, object_set_property
, obj
, 1) < 0) {
2940 if (!object_dynamic_cast(obj
, TYPE_USER_CREATABLE
)) {
2941 error_setg(&local_err
, "object '%s' isn't supported by -object",
2946 object_property_add_child(container_get(object_get_root(), "/objects"),
2947 id
, obj
, &local_err
);
2949 user_creatable_complete(obj
, &local_err
);
2951 object_property_del(container_get(object_get_root(), "/objects"),
2958 qerror_report_err(local_err
);
2959 error_free(local_err
);
2965 int main(int argc
, char **argv
, char **envp
)
2968 int snapshot
, linux_boot
;
2969 const char *icount_option
= NULL
;
2970 const char *initrd_filename
;
2971 const char *kernel_filename
, *kernel_cmdline
;
2972 const char *boot_order
;
2974 int cyls
, heads
, secs
, translation
;
2975 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
;
2976 QemuOptsList
*olist
;
2979 const char *loadvm
= NULL
;
2980 MachineClass
*machine_class
;
2981 const char *cpu_model
;
2982 const char *vga_model
= NULL
;
2983 const char *qtest_chrdev
= NULL
;
2984 const char *qtest_log
= NULL
;
2985 const char *pid_file
= NULL
;
2986 const char *incoming
= NULL
;
2988 int show_vnc_port
= 0;
2990 bool defconfig
= true;
2991 bool userconfig
= true;
2992 const char *log_mask
= NULL
;
2993 const char *log_file
= NULL
;
2994 GMemVTable mem_trace
= {
2995 .malloc
= malloc_and_trace
,
2996 .realloc
= realloc_and_trace
,
2997 .free
= free_and_trace
,
2999 const char *trace_events
= NULL
;
3000 const char *trace_file
= NULL
;
3001 const ram_addr_t default_ram_size
= (ram_addr_t
)DEFAULT_RAM_SIZE
*
3003 ram_addr_t maxram_size
= default_ram_size
;
3004 uint64_t ram_slots
= 0;
3006 atexit(qemu_run_exit_notifiers
);
3007 error_set_progname(argv
[0]);
3008 qemu_init_exec_dir(argv
[0]);
3010 g_mem_set_vtable(&mem_trace
);
3012 module_call_init(MODULE_INIT_QOM
);
3014 qemu_add_opts(&qemu_drive_opts
);
3015 qemu_add_drive_opts(&qemu_legacy_drive_opts
);
3016 qemu_add_drive_opts(&qemu_common_drive_opts
);
3017 qemu_add_drive_opts(&qemu_drive_opts
);
3018 qemu_add_opts(&qemu_chardev_opts
);
3019 qemu_add_opts(&qemu_device_opts
);
3020 qemu_add_opts(&qemu_netdev_opts
);
3021 qemu_add_opts(&qemu_net_opts
);
3022 qemu_add_opts(&qemu_rtc_opts
);
3023 qemu_add_opts(&qemu_global_opts
);
3024 qemu_add_opts(&qemu_mon_opts
);
3025 qemu_add_opts(&qemu_trace_opts
);
3026 qemu_add_opts(&qemu_option_rom_opts
);
3027 qemu_add_opts(&qemu_machine_opts
);
3028 qemu_add_opts(&qemu_mem_opts
);
3029 qemu_add_opts(&qemu_smp_opts
);
3030 qemu_add_opts(&qemu_boot_opts
);
3031 qemu_add_opts(&qemu_sandbox_opts
);
3032 qemu_add_opts(&qemu_add_fd_opts
);
3033 qemu_add_opts(&qemu_object_opts
);
3034 qemu_add_opts(&qemu_tpmdev_opts
);
3035 qemu_add_opts(&qemu_realtime_opts
);
3036 qemu_add_opts(&qemu_msg_opts
);
3037 qemu_add_opts(&qemu_name_opts
);
3041 rtc_clock
= QEMU_CLOCK_HOST
;
3043 qemu_init_auxval(envp
);
3044 qemu_cache_utils_init();
3046 QLIST_INIT (&vm_change_state_head
);
3047 os_setup_early_signal_handling();
3049 module_call_init(MODULE_INIT_MACHINE
);
3050 machine_class
= find_default_machine();
3052 ram_size
= default_ram_size
;
3054 cyls
= heads
= secs
= 0;
3055 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3057 for (i
= 0; i
< MAX_NODES
; i
++) {
3059 node_cpumask
[i
] = bitmap_new(MAX_CPUMASK_BITS
);
3065 bdrv_init_with_whitelist();
3069 /* first pass of option parsing */
3071 while (optind
< argc
) {
3072 if (argv
[optind
][0] != '-') {
3076 const QEMUOption
*popt
;
3078 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3079 switch (popt
->index
) {
3080 case QEMU_OPTION_nodefconfig
:
3083 case QEMU_OPTION_nouserconfig
:
3092 ret
= qemu_read_default_config_files(userconfig
);
3098 /* second pass of option parsing */
3103 if (argv
[optind
][0] != '-') {
3104 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
3106 const QEMUOption
*popt
;
3108 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
3109 if (!(popt
->arch_mask
& arch_type
)) {
3110 printf("Option %s not supported for this target\n", popt
->name
);
3113 switch(popt
->index
) {
3115 machine_class
= machine_parse(optarg
);
3117 case QEMU_OPTION_no_kvm_irqchip
: {
3118 olist
= qemu_find_opts("machine");
3119 qemu_opts_parse(olist
, "kernel_irqchip=off", 0);
3122 case QEMU_OPTION_cpu
:
3123 /* hw initialization will check this */
3126 case QEMU_OPTION_hda
:
3130 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
3132 snprintf(buf
, sizeof(buf
),
3133 "%s,cyls=%d,heads=%d,secs=%d%s",
3134 HD_OPTS
, cyls
, heads
, secs
,
3135 translation
== BIOS_ATA_TRANSLATION_LBA
?
3137 translation
== BIOS_ATA_TRANSLATION_NONE
?
3138 ",trans=none" : "");
3139 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
3142 case QEMU_OPTION_hdb
:
3143 case QEMU_OPTION_hdc
:
3144 case QEMU_OPTION_hdd
:
3145 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
3148 case QEMU_OPTION_drive
:
3149 if (drive_def(optarg
) == NULL
) {
3153 case QEMU_OPTION_set
:
3154 if (qemu_set_option(optarg
) != 0)
3157 case QEMU_OPTION_global
:
3158 if (qemu_global_option(optarg
) != 0)
3161 case QEMU_OPTION_mtdblock
:
3162 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
3164 case QEMU_OPTION_sd
:
3165 drive_add(IF_SD
, -1, optarg
, SD_OPTS
);
3167 case QEMU_OPTION_pflash
:
3168 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
3170 case QEMU_OPTION_snapshot
:
3173 case QEMU_OPTION_hdachs
:
3177 cyls
= strtol(p
, (char **)&p
, 0);
3178 if (cyls
< 1 || cyls
> 16383)
3183 heads
= strtol(p
, (char **)&p
, 0);
3184 if (heads
< 1 || heads
> 16)
3189 secs
= strtol(p
, (char **)&p
, 0);
3190 if (secs
< 1 || secs
> 63)
3194 if (!strcmp(p
, "large")) {
3195 translation
= BIOS_ATA_TRANSLATION_LARGE
;
3196 } else if (!strcmp(p
, "rechs")) {
3197 translation
= BIOS_ATA_TRANSLATION_RECHS
;
3198 } else if (!strcmp(p
, "none")) {
3199 translation
= BIOS_ATA_TRANSLATION_NONE
;
3200 } else if (!strcmp(p
, "lba")) {
3201 translation
= BIOS_ATA_TRANSLATION_LBA
;
3202 } else if (!strcmp(p
, "auto")) {
3203 translation
= BIOS_ATA_TRANSLATION_AUTO
;
3207 } else if (*p
!= '\0') {
3209 fprintf(stderr
, "qemu: invalid physical CHS format\n");
3212 if (hda_opts
!= NULL
) {
3214 snprintf(num
, sizeof(num
), "%d", cyls
);
3215 qemu_opt_set(hda_opts
, "cyls", num
);
3216 snprintf(num
, sizeof(num
), "%d", heads
);
3217 qemu_opt_set(hda_opts
, "heads", num
);
3218 snprintf(num
, sizeof(num
), "%d", secs
);
3219 qemu_opt_set(hda_opts
, "secs", num
);
3220 if (translation
== BIOS_ATA_TRANSLATION_LARGE
) {
3221 qemu_opt_set(hda_opts
, "trans", "large");
3222 } else if (translation
== BIOS_ATA_TRANSLATION_RECHS
) {
3223 qemu_opt_set(hda_opts
, "trans", "rechs");
3224 } else if (translation
== BIOS_ATA_TRANSLATION_LBA
) {
3225 qemu_opt_set(hda_opts
, "trans", "lba");
3226 } else if (translation
== BIOS_ATA_TRANSLATION_NONE
) {
3227 qemu_opt_set(hda_opts
, "trans", "none");
3232 case QEMU_OPTION_numa
:
3235 case QEMU_OPTION_display
:
3236 display_type
= select_display(optarg
);
3238 case QEMU_OPTION_nographic
:
3239 display_type
= DT_NOGRAPHIC
;
3241 case QEMU_OPTION_curses
:
3242 #ifdef CONFIG_CURSES
3243 display_type
= DT_CURSES
;
3245 fprintf(stderr
, "Curses support is disabled\n");
3249 case QEMU_OPTION_portrait
:
3250 graphic_rotate
= 90;
3252 case QEMU_OPTION_rotate
:
3253 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
3254 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
3255 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
3257 "qemu: only 90, 180, 270 deg rotation is available\n");
3261 case QEMU_OPTION_kernel
:
3262 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
3264 case QEMU_OPTION_initrd
:
3265 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
3267 case QEMU_OPTION_append
:
3268 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
3270 case QEMU_OPTION_dtb
:
3271 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
3273 case QEMU_OPTION_cdrom
:
3274 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
3276 case QEMU_OPTION_boot
:
3277 opts
= qemu_opts_parse(qemu_find_opts("boot-opts"), optarg
, 1);
3282 case QEMU_OPTION_fda
:
3283 case QEMU_OPTION_fdb
:
3284 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
3287 case QEMU_OPTION_no_fd_bootchk
:
3290 case QEMU_OPTION_netdev
:
3291 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
3295 case QEMU_OPTION_net
:
3296 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
3300 #ifdef CONFIG_LIBISCSI
3301 case QEMU_OPTION_iscsi
:
3302 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
3309 case QEMU_OPTION_tftp
:
3310 legacy_tftp_prefix
= optarg
;
3312 case QEMU_OPTION_bootp
:
3313 legacy_bootp_filename
= optarg
;
3315 case QEMU_OPTION_redir
:
3316 if (net_slirp_redir(optarg
) < 0)
3320 case QEMU_OPTION_bt
:
3321 add_device_config(DEV_BT
, optarg
);
3323 case QEMU_OPTION_audio_help
:
3327 case QEMU_OPTION_soundhw
:
3328 select_soundhw (optarg
);
3333 case QEMU_OPTION_version
:
3337 case QEMU_OPTION_m
: {
3339 const char *mem_str
;
3340 const char *maxmem_str
, *slots_str
;
3342 opts
= qemu_opts_parse(qemu_find_opts("memory"),
3348 mem_str
= qemu_opt_get(opts
, "size");
3350 error_report("invalid -m option, missing 'size' option");
3354 error_report("missing 'size' option value");
3358 sz
= qemu_opt_get_size(opts
, "size", ram_size
);
3360 /* Fix up legacy suffix-less format */
3361 if (g_ascii_isdigit(mem_str
[strlen(mem_str
) - 1])) {
3362 uint64_t overflow_check
= sz
;
3365 if ((sz
>> 20) != overflow_check
) {
3366 error_report("too large 'size' option value");
3371 /* backward compatibility behaviour for case "-m 0" */
3373 sz
= default_ram_size
;
3376 sz
= QEMU_ALIGN_UP(sz
, 8192);
3378 if (ram_size
!= sz
) {
3379 error_report("ram size too large");
3383 maxmem_str
= qemu_opt_get(opts
, "maxmem");
3384 slots_str
= qemu_opt_get(opts
, "slots");
3385 if (maxmem_str
&& slots_str
) {
3388 sz
= qemu_opt_get_size(opts
, "maxmem", 0);
3389 if (sz
< ram_size
) {
3390 fprintf(stderr
, "qemu: invalid -m option value: maxmem "
3391 "(%" PRIu64
") <= initial memory (%"
3392 PRIu64
")\n", sz
, ram_size
);
3396 slots
= qemu_opt_get_number(opts
, "slots", 0);
3397 if ((sz
> ram_size
) && !slots
) {
3398 fprintf(stderr
, "qemu: invalid -m option value: maxmem "
3399 "(%" PRIu64
") more than initial memory (%"
3400 PRIu64
") but no hotplug slots where "
3401 "specified\n", sz
, ram_size
);
3405 if ((sz
<= ram_size
) && slots
) {
3406 fprintf(stderr
, "qemu: invalid -m option value: %"
3407 PRIu64
" hotplug slots where specified but "
3408 "maxmem (%" PRIu64
") <= initial memory (%"
3409 PRIu64
")\n", slots
, sz
, ram_size
);
3414 } else if ((!maxmem_str
&& slots_str
) ||
3415 (maxmem_str
&& !slots_str
)) {
3416 fprintf(stderr
, "qemu: invalid -m option value: missing "
3417 "'%s' option\n", slots_str
? "maxmem" : "slots");
3423 case QEMU_OPTION_tpmdev
:
3424 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg
) < 0) {
3429 case QEMU_OPTION_mempath
:
3432 case QEMU_OPTION_mem_prealloc
:
3442 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
3444 case QEMU_OPTION_gdb
:
3445 add_device_config(DEV_GDB
, optarg
);
3448 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
3449 data_dir
[data_dir_idx
++] = optarg
;
3452 case QEMU_OPTION_bios
:
3453 qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg
);
3455 case QEMU_OPTION_singlestep
:
3462 keyboard_layout
= optarg
;
3464 case QEMU_OPTION_localtime
:
3467 case QEMU_OPTION_vga
:
3476 w
= strtol(p
, (char **)&p
, 10);
3479 fprintf(stderr
, "qemu: invalid resolution or depth\n");
3485 h
= strtol(p
, (char **)&p
, 10);
3490 depth
= strtol(p
, (char **)&p
, 10);
3491 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
3492 depth
!= 24 && depth
!= 32)
3494 } else if (*p
== '\0') {
3495 depth
= graphic_depth
;
3502 graphic_depth
= depth
;
3505 case QEMU_OPTION_echr
:
3508 term_escape_char
= strtol(optarg
, &r
, 0);
3510 printf("Bad argument to echr\n");
3513 case QEMU_OPTION_monitor
:
3514 default_monitor
= 0;
3515 if (strncmp(optarg
, "none", 4)) {
3516 monitor_parse(optarg
, "readline");
3519 case QEMU_OPTION_qmp
:
3520 monitor_parse(optarg
, "control");
3521 default_monitor
= 0;
3523 case QEMU_OPTION_mon
:
3524 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
3528 default_monitor
= 0;
3530 case QEMU_OPTION_chardev
:
3531 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
3536 case QEMU_OPTION_fsdev
:
3537 olist
= qemu_find_opts("fsdev");
3539 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
3542 opts
= qemu_opts_parse(olist
, optarg
, 1);
3547 case QEMU_OPTION_virtfs
: {
3550 const char *writeout
, *sock_fd
, *socket
;
3552 olist
= qemu_find_opts("virtfs");
3554 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
3557 opts
= qemu_opts_parse(olist
, optarg
, 1);
3562 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3563 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3564 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3567 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3568 qemu_opt_get(opts
, "mount_tag"),
3571 fprintf(stderr
, "duplicate fsdev id: %s\n",
3572 qemu_opt_get(opts
, "mount_tag"));
3576 writeout
= qemu_opt_get(opts
, "writeout");
3578 #ifdef CONFIG_SYNC_FILE_RANGE
3579 qemu_opt_set(fsdev
, "writeout", writeout
);
3581 fprintf(stderr
, "writeout=immediate not supported on "
3586 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
3587 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
3588 qemu_opt_set(fsdev
, "security_model",
3589 qemu_opt_get(opts
, "security_model"));
3590 socket
= qemu_opt_get(opts
, "socket");
3592 qemu_opt_set(fsdev
, "socket", socket
);
3594 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3596 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
3599 qemu_opt_set_bool(fsdev
, "readonly",
3600 qemu_opt_get_bool(opts
, "readonly", 0));
3601 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3603 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3604 qemu_opt_set(device
, "fsdev",
3605 qemu_opt_get(opts
, "mount_tag"));
3606 qemu_opt_set(device
, "mount_tag",
3607 qemu_opt_get(opts
, "mount_tag"));
3610 case QEMU_OPTION_virtfs_synth
: {
3614 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3617 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
3620 qemu_opt_set(fsdev
, "fsdriver", "synth");
3622 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3624 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3625 qemu_opt_set(device
, "fsdev", "v_synth");
3626 qemu_opt_set(device
, "mount_tag", "v_synth");
3629 case QEMU_OPTION_serial
:
3630 add_device_config(DEV_SERIAL
, optarg
);
3632 if (strncmp(optarg
, "mon:", 4) == 0) {
3633 default_monitor
= 0;
3636 case QEMU_OPTION_watchdog
:
3639 "qemu: only one watchdog option may be given\n");
3644 case QEMU_OPTION_watchdog_action
:
3645 if (select_watchdog_action(optarg
) == -1) {
3646 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
3650 case QEMU_OPTION_virtiocon
:
3651 add_device_config(DEV_VIRTCON
, optarg
);
3652 default_virtcon
= 0;
3653 if (strncmp(optarg
, "mon:", 4) == 0) {
3654 default_monitor
= 0;
3657 case QEMU_OPTION_parallel
:
3658 add_device_config(DEV_PARALLEL
, optarg
);
3659 default_parallel
= 0;
3660 if (strncmp(optarg
, "mon:", 4) == 0) {
3661 default_monitor
= 0;
3664 case QEMU_OPTION_debugcon
:
3665 add_device_config(DEV_DEBUGCON
, optarg
);
3667 case QEMU_OPTION_loadvm
:
3670 case QEMU_OPTION_full_screen
:
3673 case QEMU_OPTION_no_frame
:
3676 case QEMU_OPTION_alt_grab
:
3679 case QEMU_OPTION_ctrl_grab
:
3682 case QEMU_OPTION_no_quit
:
3685 case QEMU_OPTION_sdl
:
3687 display_type
= DT_SDL
;
3690 fprintf(stderr
, "SDL support is disabled\n");
3693 case QEMU_OPTION_pidfile
:
3696 case QEMU_OPTION_win2k_hack
:
3697 win2k_install_hack
= 1;
3699 case QEMU_OPTION_rtc_td_hack
: {
3700 static GlobalProperty slew_lost_ticks
[] = {
3702 .driver
= "mc146818rtc",
3703 .property
= "lost_tick_policy",
3706 { /* end of list */ }
3709 qdev_prop_register_global_list(slew_lost_ticks
);
3712 case QEMU_OPTION_acpitable
:
3713 opts
= qemu_opts_parse(qemu_find_opts("acpi"), optarg
, 1);
3717 do_acpitable_option(opts
);
3719 case QEMU_OPTION_smbios
:
3720 opts
= qemu_opts_parse(qemu_find_opts("smbios"), optarg
, 0);
3724 do_smbios_option(opts
);
3726 case QEMU_OPTION_enable_kvm
:
3727 olist
= qemu_find_opts("machine");
3728 qemu_opts_parse(olist
, "accel=kvm", 0);
3730 case QEMU_OPTION_machine
:
3731 olist
= qemu_find_opts("machine");
3732 opts
= qemu_opts_parse(olist
, optarg
, 1);
3736 optarg
= qemu_opt_get(opts
, "type");
3738 machine_class
= machine_parse(optarg
);
3741 case QEMU_OPTION_no_kvm
:
3742 olist
= qemu_find_opts("machine");
3743 qemu_opts_parse(olist
, "accel=tcg", 0);
3745 case QEMU_OPTION_no_kvm_pit
: {
3746 fprintf(stderr
, "Warning: KVM PIT can no longer be disabled "
3750 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3751 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3753 .driver
= "kvm-pit",
3754 .property
= "lost_tick_policy",
3757 { /* end of list */ }
3760 fprintf(stderr
, "Warning: option deprecated, use "
3761 "lost_tick_policy property of kvm-pit instead.\n");
3762 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3765 case QEMU_OPTION_usb
:
3766 olist
= qemu_find_opts("machine");
3767 qemu_opts_parse(olist
, "usb=on", 0);
3769 case QEMU_OPTION_usbdevice
:
3770 olist
= qemu_find_opts("machine");
3771 qemu_opts_parse(olist
, "usb=on", 0);
3772 add_device_config(DEV_USB
, optarg
);
3774 case QEMU_OPTION_device
:
3775 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3779 case QEMU_OPTION_smp
:
3780 if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg
, 1)) {
3784 case QEMU_OPTION_vnc
:
3787 vnc_display
= optarg
;
3789 fprintf(stderr
, "VNC support is disabled\n");
3793 case QEMU_OPTION_no_acpi
:
3796 case QEMU_OPTION_no_hpet
:
3799 case QEMU_OPTION_balloon
:
3800 if (balloon_parse(optarg
) < 0) {
3801 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3805 case QEMU_OPTION_no_reboot
:
3808 case QEMU_OPTION_no_shutdown
:
3811 case QEMU_OPTION_show_cursor
:
3814 case QEMU_OPTION_uuid
:
3815 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3816 fprintf(stderr
, "Fail to parse UUID string."
3817 " Wrong format.\n");
3820 qemu_uuid_set
= true;
3822 case QEMU_OPTION_option_rom
:
3823 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3824 fprintf(stderr
, "Too many option ROMs\n");
3827 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3831 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3832 option_rom
[nb_option_roms
].bootindex
=
3833 qemu_opt_get_number(opts
, "bootindex", -1);
3834 if (!option_rom
[nb_option_roms
].name
) {
3835 fprintf(stderr
, "Option ROM file is not specified\n");
3840 case QEMU_OPTION_semihosting
:
3841 semihosting_enabled
= 1;
3843 case QEMU_OPTION_tdf
:
3844 fprintf(stderr
, "Warning: user space PIT time drift fix "
3845 "is no longer supported.\n");
3847 case QEMU_OPTION_name
:
3848 opts
= qemu_opts_parse(qemu_find_opts("name"), optarg
, 1);
3853 case QEMU_OPTION_prom_env
:
3854 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3855 fprintf(stderr
, "Too many prom variables\n");
3858 prom_envs
[nb_prom_envs
] = optarg
;
3861 case QEMU_OPTION_old_param
:
3864 case QEMU_OPTION_clock
:
3865 /* Clock options no longer exist. Keep this option for
3866 * backward compatibility.
3869 case QEMU_OPTION_startdate
:
3870 configure_rtc_date_offset(optarg
, 1);
3872 case QEMU_OPTION_rtc
:
3873 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3877 configure_rtc(opts
);
3879 case QEMU_OPTION_tb_size
:
3880 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3881 if (tcg_tb_size
< 0) {
3885 case QEMU_OPTION_icount
:
3886 icount_option
= optarg
;
3888 case QEMU_OPTION_incoming
:
3890 runstate_set(RUN_STATE_INMIGRATE
);
3892 case QEMU_OPTION_nodefaults
:
3895 case QEMU_OPTION_xen_domid
:
3896 if (!(xen_available())) {
3897 printf("Option %s not supported for this target\n", popt
->name
);
3900 xen_domid
= atoi(optarg
);
3902 case QEMU_OPTION_xen_create
:
3903 if (!(xen_available())) {
3904 printf("Option %s not supported for this target\n", popt
->name
);
3907 xen_mode
= XEN_CREATE
;
3909 case QEMU_OPTION_xen_attach
:
3910 if (!(xen_available())) {
3911 printf("Option %s not supported for this target\n", popt
->name
);
3914 xen_mode
= XEN_ATTACH
;
3916 case QEMU_OPTION_trace
:
3918 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3922 trace_events
= qemu_opt_get(opts
, "events");
3923 trace_file
= qemu_opt_get(opts
, "file");
3926 case QEMU_OPTION_readconfig
:
3928 int ret
= qemu_read_config_file(optarg
);
3930 fprintf(stderr
, "read config %s: %s\n", optarg
,
3936 case QEMU_OPTION_spice
:
3937 olist
= qemu_find_opts("spice");
3939 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3942 opts
= qemu_opts_parse(olist
, optarg
, 0);
3948 case QEMU_OPTION_writeconfig
:
3951 if (strcmp(optarg
, "-") == 0) {
3954 fp
= fopen(optarg
, "w");
3956 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3960 qemu_config_write(fp
);
3966 case QEMU_OPTION_qtest
:
3967 qtest_chrdev
= optarg
;
3969 case QEMU_OPTION_qtest_log
:
3972 case QEMU_OPTION_sandbox
:
3973 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3978 case QEMU_OPTION_add_fd
:
3980 opts
= qemu_opts_parse(qemu_find_opts("add-fd"), optarg
, 0);
3985 error_report("File descriptor passing is disabled on this "
3990 case QEMU_OPTION_object
:
3991 opts
= qemu_opts_parse(qemu_find_opts("object"), optarg
, 1);
3996 case QEMU_OPTION_realtime
:
3997 opts
= qemu_opts_parse(qemu_find_opts("realtime"), optarg
, 0);
4001 configure_realtime(opts
);
4003 case QEMU_OPTION_msg
:
4004 opts
= qemu_opts_parse(qemu_find_opts("msg"), optarg
, 0);
4008 configure_msg(opts
);
4011 os_parse_cmd_args(popt
->index
, optarg
);
4019 if (qemu_init_main_loop()) {
4020 fprintf(stderr
, "qemu_init_main_loop failed\n");
4024 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
4028 if (qemu_opts_foreach(qemu_find_opts("name"), parse_name
, NULL
, 1)) {
4033 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd
, NULL
, 1)) {
4037 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd
, NULL
, 1)) {
4042 if (machine_class
== NULL
) {
4043 fprintf(stderr
, "No machine specified, and there is no default.\n"
4044 "Use -machine help to list supported machines!\n");
4048 current_machine
= MACHINE(object_new(object_class_get_name(
4049 OBJECT_CLASS(machine_class
))));
4050 object_property_add_child(object_get_root(), "machine",
4051 OBJECT(current_machine
), &error_abort
);
4053 if (machine_class
->hw_version
) {
4054 qemu_set_version(machine_class
->hw_version
);
4057 if (qemu_opts_foreach(qemu_find_opts("object"),
4058 object_create
, NULL
, 0) != 0) {
4062 /* Init CPU def lists, based on config
4063 * - Must be called after all the qemu_read_config_file() calls
4064 * - Must be called before list_cpus()
4065 * - Must be called before machine->init()
4069 if (cpu_model
&& is_help_option(cpu_model
)) {
4070 list_cpus(stdout
, &fprintf
, cpu_model
);
4074 /* Open the logfile at this point, if necessary. We can't open the logfile
4075 * when encountering either of the logging options (-d or -D) because the
4076 * other one may be encountered later on the command line, changing the
4077 * location or level of logging.
4082 qemu_set_log_filename(log_file
);
4085 mask
= qemu_str_to_log_mask(log_mask
);
4087 qemu_print_log_usage(stdout
);
4093 if (!is_daemonized()) {
4094 if (!trace_init_backends(trace_events
, trace_file
)) {
4099 /* If no data_dir is specified then try to find it relative to the
4101 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4102 data_dir
[data_dir_idx
] = os_find_datadir();
4103 if (data_dir
[data_dir_idx
] != NULL
) {
4107 /* If all else fails use the install path specified when building. */
4108 if (data_dir_idx
< ARRAY_SIZE(data_dir
)) {
4109 data_dir
[data_dir_idx
++] = CONFIG_QEMU_DATADIR
;
4112 smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL
));
4114 machine_class
->max_cpus
= machine_class
->max_cpus
?: 1; /* Default to UP */
4115 if (smp_cpus
> machine_class
->max_cpus
) {
4116 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
4117 "supported by machine `%s' (%d)\n", smp_cpus
,
4118 machine_class
->name
, machine_class
->max_cpus
);
4123 * Get the default machine options from the machine if it is not already
4124 * specified either by the configuration file or by the command line.
4126 if (machine_class
->default_machine_opts
) {
4127 qemu_opts_set_defaults(qemu_find_opts("machine"),
4128 machine_class
->default_machine_opts
, 0);
4131 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
4132 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
4134 if (!vga_model
&& !default_vga
) {
4135 vga_interface_type
= VGA_DEVICE
;
4137 if (!has_defaults
|| machine_class
->no_serial
) {
4140 if (!has_defaults
|| machine_class
->no_parallel
) {
4141 default_parallel
= 0;
4143 if (!has_defaults
|| !machine_class
->use_virtcon
) {
4144 default_virtcon
= 0;
4146 if (!has_defaults
|| !machine_class
->use_sclp
) {
4149 if (!has_defaults
|| machine_class
->no_floppy
) {
4152 if (!has_defaults
|| machine_class
->no_cdrom
) {
4155 if (!has_defaults
|| machine_class
->no_sdcard
) {
4158 if (!has_defaults
) {
4159 default_monitor
= 0;
4164 if (is_daemonized()) {
4165 /* According to documentation and historically, -nographic redirects
4166 * serial port, parallel port and monitor to stdio, which does not work
4167 * with -daemonize. We can redirect these to null instead, but since
4168 * -nographic is legacy, let's just error out.
4169 * We disallow -nographic only if all other ports are not redirected
4170 * explicitly, to not break existing legacy setups which uses
4171 * -nographic _and_ redirects all ports explicitly - this is valid
4172 * usage, -nographic is just a no-op in this case.
4174 if (display_type
== DT_NOGRAPHIC
4175 && (default_parallel
|| default_serial
4176 || default_monitor
|| default_virtcon
)) {
4177 fprintf(stderr
, "-nographic can not be used with -daemonize\n");
4180 #ifdef CONFIG_CURSES
4181 if (display_type
== DT_CURSES
) {
4182 fprintf(stderr
, "curses display can not be used with -daemonize\n");
4188 if (display_type
== DT_NOGRAPHIC
) {
4189 if (default_parallel
)
4190 add_device_config(DEV_PARALLEL
, "null");
4191 if (default_serial
&& default_monitor
) {
4192 add_device_config(DEV_SERIAL
, "mon:stdio");
4193 } else if (default_virtcon
&& default_monitor
) {
4194 add_device_config(DEV_VIRTCON
, "mon:stdio");
4195 } else if (default_sclp
&& default_monitor
) {
4196 add_device_config(DEV_SCLP
, "mon:stdio");
4199 add_device_config(DEV_SERIAL
, "stdio");
4200 if (default_virtcon
)
4201 add_device_config(DEV_VIRTCON
, "stdio");
4203 add_device_config(DEV_SCLP
, "stdio");
4205 if (default_monitor
)
4206 monitor_parse("stdio", "readline");
4210 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
4211 if (default_parallel
)
4212 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
4213 if (default_monitor
)
4214 monitor_parse("vc:80Cx24C", "readline");
4215 if (default_virtcon
)
4216 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
4218 add_device_config(DEV_SCLP
, "vc:80Cx24C");
4222 if (display_type
== DT_DEFAULT
&& !display_remote
) {
4223 #if defined(CONFIG_GTK)
4224 display_type
= DT_GTK
;
4225 #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4226 display_type
= DT_SDL
;
4227 #elif defined(CONFIG_VNC)
4228 vnc_display
= "localhost:0,to=99";
4231 display_type
= DT_NONE
;
4235 if ((no_frame
|| alt_grab
|| ctrl_grab
) && display_type
!= DT_SDL
) {
4236 fprintf(stderr
, "-no-frame, -alt-grab and -ctrl-grab are only valid "
4237 "for SDL, ignoring option\n");
4239 if (no_quit
&& (display_type
!= DT_GTK
&& display_type
!= DT_SDL
)) {
4240 fprintf(stderr
, "-no-quit is only valid for GTK and SDL, "
4241 "ignoring option\n");
4244 #if defined(CONFIG_GTK)
4245 if (display_type
== DT_GTK
) {
4246 early_gtk_display_init();
4252 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
4254 #ifdef CONFIG_VIRTFS
4255 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
4260 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
4265 /* store value for the future use */
4266 qemu_opt_set_number(qemu_find_opts_singleton("memory"), "size", ram_size
);
4268 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
4273 machine_opts
= qemu_get_machine_opts();
4274 if (qemu_opt_foreach(machine_opts
, object_set_property
, current_machine
,
4276 object_unref(OBJECT(current_machine
));
4280 configure_accelerator(machine_class
);
4283 Error
*local_err
= NULL
;
4284 qtest_init(qtest_chrdev
, qtest_log
, &local_err
);
4286 error_report("%s", error_get_pretty(local_err
));
4287 error_free(local_err
);
4292 machine_opts
= qemu_get_machine_opts();
4293 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
4294 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
4295 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
4296 bios_name
= qemu_opt_get(machine_opts
, "firmware");
4298 boot_order
= machine_class
->default_boot_order
;
4299 opts
= qemu_opts_find(qemu_find_opts("boot-opts"), NULL
);
4301 char *normal_boot_order
;
4302 const char *order
, *once
;
4304 order
= qemu_opt_get(opts
, "order");
4306 validate_bootdevices(order
);
4310 once
= qemu_opt_get(opts
, "once");
4312 validate_bootdevices(once
);
4313 normal_boot_order
= g_strdup(boot_order
);
4315 qemu_register_reset(restore_boot_order
, normal_boot_order
);
4318 boot_menu
= qemu_opt_get_bool(opts
, "menu", boot_menu
);
4319 boot_strict
= qemu_opt_get_bool(opts
, "strict", false);
4322 if (!kernel_cmdline
) {
4323 kernel_cmdline
= "";
4324 current_machine
->kernel_cmdline
= (char *)kernel_cmdline
;
4327 linux_boot
= (kernel_filename
!= NULL
);
4329 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
4330 fprintf(stderr
, "-append only allowed with -kernel option\n");
4334 if (!linux_boot
&& initrd_filename
!= NULL
) {
4335 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
4339 if (!linux_boot
&& qemu_opt_get(machine_opts
, "dtb")) {
4340 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
4344 os_set_line_buffering();
4346 qemu_init_cpu_loop();
4347 qemu_mutex_lock_iothread();
4350 /* spice needs the timers to be initialized by this point */
4354 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
4355 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
4358 configure_icount(icount_option
);
4360 /* clean up network at qemu process termination */
4361 atexit(&net_cleanup
);
4363 if (net_init_clients() < 0) {
4368 if (tpm_init() < 0) {
4373 /* init the bluetooth world */
4374 if (foreach_device_config(DEV_BT
, bt_parse
))
4377 if (!xen_enabled()) {
4378 /* On 32-bit hosts, QEMU is limited by virtual address space */
4379 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
4380 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
4385 cpu_exec_init_all();
4390 /* open the virtual block devices */
4392 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
4393 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
,
4394 &machine_class
->block_default_type
, 1) != 0) {
4398 default_drive(default_cdrom
, snapshot
, machine_class
->block_default_type
, 2,
4400 default_drive(default_floppy
, snapshot
, IF_FLOPPY
, 0, FD_OPTS
);
4401 default_drive(default_sdcard
, snapshot
, IF_SD
, 0, SD_OPTS
);
4403 if (nb_numa_nodes
> 0) {
4406 if (nb_numa_nodes
> MAX_NODES
) {
4407 nb_numa_nodes
= MAX_NODES
;
4410 /* If no memory size if given for any node, assume the default case
4411 * and distribute the available memory equally across all nodes
4413 for (i
= 0; i
< nb_numa_nodes
; i
++) {
4414 if (node_mem
[i
] != 0)
4417 if (i
== nb_numa_nodes
) {
4418 uint64_t usedmem
= 0;
4420 /* On Linux, the each node's border has to be 8MB aligned,
4421 * the final node gets the rest.
4423 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
4424 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
4425 usedmem
+= node_mem
[i
];
4427 node_mem
[i
] = ram_size
- usedmem
;
4430 for (i
= 0; i
< nb_numa_nodes
; i
++) {
4431 if (!bitmap_empty(node_cpumask
[i
], MAX_CPUMASK_BITS
)) {
4435 /* assigning the VCPUs round-robin is easier to implement, guest OSes
4436 * must cope with this anyway, because there are BIOSes out there in
4437 * real machines which also use this scheme.
4439 if (i
== nb_numa_nodes
) {
4440 for (i
= 0; i
< max_cpus
; i
++) {
4441 set_bit(i
, node_cpumask
[i
% nb_numa_nodes
]);
4446 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
4450 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
4452 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
4454 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
4456 if (foreach_device_config(DEV_SCLP
, sclp_parse
) < 0) {
4459 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
4462 /* If no default VGA is requested, the default is "none". */
4464 if (cirrus_vga_available()) {
4465 vga_model
= "cirrus";
4466 } else if (vga_available()) {
4471 select_vgahw(vga_model
);
4475 i
= select_watchdog(watchdog
);
4477 exit (i
== 1 ? 1 : 0);
4480 if (machine_class
->compat_props
) {
4481 qdev_prop_register_global_list(machine_class
->compat_props
);
4485 qdev_machine_init();
4487 current_machine
->ram_size
= ram_size
;
4488 current_machine
->maxram_size
= maxram_size
;
4489 current_machine
->ram_slots
= ram_slots
;
4490 current_machine
->boot_order
= boot_order
;
4491 current_machine
->cpu_model
= cpu_model
;
4493 machine_class
->init(current_machine
);
4497 cpu_synchronize_all_post_init();
4501 /* init USB devices */
4502 if (usb_enabled(false)) {
4503 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
4507 /* init generic devices */
4508 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
4511 net_check_clients();
4513 ds
= init_displaystate();
4515 /* init local displays */
4516 switch (display_type
) {
4518 (void)ds
; /* avoid warning if no display is configured */
4520 #if defined(CONFIG_CURSES)
4522 curses_display_init(ds
, full_screen
);
4525 #if defined(CONFIG_SDL)
4527 sdl_display_init(ds
, full_screen
, no_frame
);
4529 #elif defined(CONFIG_COCOA)
4531 cocoa_display_init(ds
, full_screen
);
4534 #if defined(CONFIG_GTK)
4536 gtk_display_init(ds
, full_screen
, grab_on_hover
);
4543 /* must be after terminal init, SDL library changes signal handlers */
4544 os_setup_signal_handling();
4547 /* init remote displays */
4549 Error
*local_err
= NULL
;
4550 vnc_display_init(ds
);
4551 vnc_display_open(ds
, vnc_display
, &local_err
);
4552 if (local_err
!= NULL
) {
4553 error_report("Failed to start VNC server on `%s': %s",
4554 vnc_display
, error_get_pretty(local_err
));
4555 error_free(local_err
);
4559 if (show_vnc_port
) {
4560 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
4566 qemu_spice_display_init();
4570 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
4574 qdev_machine_creation_done();
4576 if (rom_load_all() != 0) {
4577 fprintf(stderr
, "rom loading failed\n");
4581 /* TODO: once all bus devices are qdevified, this should be done
4582 * when bus is created by qdev.c */
4583 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
4584 qemu_run_machine_init_done_notifiers();
4586 /* Done notifiers can load ROMs */
4589 qemu_system_reset(VMRESET_SILENT
);
4591 if (load_vmstate(loadvm
) < 0) {
4596 qdev_prop_check_global();
4599 Error
*local_err
= NULL
;
4600 qemu_start_incoming_migration(incoming
, &local_err
);
4602 error_report("-incoming %s: %s", incoming
,
4603 error_get_pretty(local_err
));
4604 error_free(local_err
);
4607 } else if (autostart
) {
4613 if (is_daemonized()) {
4614 if (!trace_init_backends(trace_events
, trace_file
)) {