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
33 /* Needed early for CONFIG_BSD etc. */
34 #include "config-host.h"
38 #include <sys/times.h>
42 #include <sys/ioctl.h>
43 #include <sys/resource.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
47 #include <arpa/inet.h>
50 #include <sys/select.h>
54 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include "qemu-seccomp.h"
73 #include <sys/ethernet.h>
74 #include <sys/sockio.h>
75 #include <netinet/arp.h>
76 #include <netinet/in_systm.h>
77 #include <netinet/ip.h>
78 #include <netinet/ip_icmp.h> // must come after ip.h
79 #include <netinet/udp.h>
80 #include <netinet/tcp.h>
88 #if defined(CONFIG_VDE)
89 #include <libvdeplug.h>
97 #if defined(__APPLE__) || defined(main)
99 int qemu_main(int argc
, char **argv
, char **envp
);
100 int main(int argc
, char **argv
)
102 return qemu_main(argc
, argv
, NULL
);
105 #define main qemu_main
107 #endif /* CONFIG_SDL */
111 #define main qemu_main
112 #endif /* CONFIG_COCOA */
117 #include "hw/boards.h"
119 #include "hw/pcmcia.h"
124 #include "hw/watchdog.h"
125 #include "hw/smbios.h"
128 #include "hw/loader.h"
131 #include "net/slirp.h"
136 #include "qemu-timer.h"
137 #include "qemu-char.h"
138 #include "cache-utils.h"
139 #include "blockdev.h"
140 #include "hw/block-common.h"
141 #include "block-migration.h"
143 #include "audio/audio.h"
144 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-options.h"
150 #include "qmp-commands.h"
151 #include "main-loop.h"
153 #include "fsdev/qemu-fsdev.h"
159 #include "qemu_socket.h"
161 #include "slirp/libslirp.h"
164 #include "trace/control.h"
165 #include "qemu-queue.h"
167 #include "arch_init.h"
170 #include "ui/qemu-spice.h"
173 //#define DEBUG_SLIRP
175 #define DEFAULT_RAM_SIZE 128
177 #define MAX_VIRTIO_CONSOLES 1
179 static const char *data_dir
;
180 const char *bios_name
= NULL
;
181 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
182 DisplayType display_type
= DT_DEFAULT
;
183 int display_remote
= 0;
184 const char* keyboard_layout
= NULL
;
186 const char *mem_path
= NULL
;
188 int mem_prealloc
= 0; /* force preallocation of physical target memory */
191 NICInfo nd_table
[MAX_NICS
];
193 static int rtc_utc
= 1;
194 static int rtc_date_offset
= -1; /* -1 means no change */
195 QEMUClock
*rtc_clock
;
196 int vga_interface_type
= VGA_NONE
;
197 static int full_screen
= 0;
199 static int no_frame
= 0;
202 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
203 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
204 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
205 int win2k_install_hack
= 0;
213 const char *vnc_display
;
215 int acpi_enabled
= 1;
221 int graphic_rotate
= 0;
222 const char *watchdog
;
223 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
225 int semihosting_enabled
= 0;
227 const char *qemu_name
;
230 unsigned int nb_prom_envs
= 0;
231 const char *prom_envs
[MAX_PROM_ENVS
];
233 uint8_t *boot_splash_filedata
;
234 int boot_splash_filedata_size
;
235 uint8_t qemu_extra_params_fw
[2];
237 typedef struct FWBootEntry FWBootEntry
;
240 QTAILQ_ENTRY(FWBootEntry
) link
;
246 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
249 uint64_t node_mem
[MAX_NODES
];
250 unsigned long *node_cpumask
[MAX_NODES
];
252 uint8_t qemu_uuid
[16];
254 static QEMUBootSetHandler
*boot_set_handler
;
255 static void *boot_set_opaque
;
257 static NotifierList exit_notifiers
=
258 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
260 static NotifierList machine_init_done_notifiers
=
261 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
263 static int tcg_allowed
= 1;
267 enum xen_mode xen_mode
= XEN_EMULATE
;
268 static int tcg_tb_size
;
270 static int default_serial
= 1;
271 static int default_parallel
= 1;
272 static int default_virtcon
= 1;
273 static int default_monitor
= 1;
274 static int default_floppy
= 1;
275 static int default_cdrom
= 1;
276 static int default_sdcard
= 1;
277 static int default_vga
= 1;
283 { .driver
= "isa-serial", .flag
= &default_serial
},
284 { .driver
= "isa-parallel", .flag
= &default_parallel
},
285 { .driver
= "isa-fdc", .flag
= &default_floppy
},
286 { .driver
= "ide-cd", .flag
= &default_cdrom
},
287 { .driver
= "ide-hd", .flag
= &default_cdrom
},
288 { .driver
= "ide-drive", .flag
= &default_cdrom
},
289 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
290 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
291 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
292 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
293 { .driver
= "VGA", .flag
= &default_vga
},
294 { .driver
= "isa-vga", .flag
= &default_vga
},
295 { .driver
= "cirrus-vga", .flag
= &default_vga
},
296 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
297 { .driver
= "vmware-svga", .flag
= &default_vga
},
298 { .driver
= "qxl-vga", .flag
= &default_vga
},
301 const char *qemu_get_vm_name(void)
306 static void res_free(void)
308 if (boot_splash_filedata
!= NULL
) {
309 g_free(boot_splash_filedata
);
310 boot_splash_filedata
= NULL
;
314 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
316 const char *driver
= qemu_opt_get(opts
, "driver");
321 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
322 if (strcmp(default_list
[i
].driver
, driver
) != 0)
324 *(default_list
[i
].flag
) = 0;
329 /***********************************************************/
332 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
337 } RunStateTransition
;
339 static const RunStateTransition runstate_transitions_def
[] = {
341 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
343 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
344 { RUN_STATE_INMIGRATE
, RUN_STATE_PRELAUNCH
},
346 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
347 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
349 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
350 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
352 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
353 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
355 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
356 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
358 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
359 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
360 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
362 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
363 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
365 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
367 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
368 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
369 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
370 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
371 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
372 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
373 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
374 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
375 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
377 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
379 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
380 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
382 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
383 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
384 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
385 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
387 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
388 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
390 { RUN_STATE_MAX
, RUN_STATE_MAX
},
393 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
395 bool runstate_check(RunState state
)
397 return current_run_state
== state
;
400 void runstate_init(void)
402 const RunStateTransition
*p
;
404 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
406 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
407 runstate_valid_transitions
[p
->from
][p
->to
] = true;
411 /* This function will abort() on invalid state transitions */
412 void runstate_set(RunState new_state
)
414 assert(new_state
< RUN_STATE_MAX
);
416 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
417 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
418 RunState_lookup
[current_run_state
],
419 RunState_lookup
[new_state
]);
423 current_run_state
= new_state
;
426 int runstate_is_running(void)
428 return runstate_check(RUN_STATE_RUNNING
);
431 StatusInfo
*qmp_query_status(Error
**errp
)
433 StatusInfo
*info
= g_malloc0(sizeof(*info
));
435 info
->running
= runstate_is_running();
436 info
->singlestep
= singlestep
;
437 info
->status
= current_run_state
;
442 /***********************************************************/
443 /* real time host monotonic timer */
445 /***********************************************************/
446 /* host time/date access */
447 void qemu_get_timedate(struct tm
*tm
, int offset
)
454 if (rtc_date_offset
== -1) {
458 ret
= localtime(&ti
);
460 ti
-= rtc_date_offset
;
464 memcpy(tm
, ret
, sizeof(struct tm
));
467 int qemu_timedate_diff(struct tm
*tm
)
471 if (rtc_date_offset
== -1)
473 seconds
= mktimegm(tm
);
476 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
477 seconds
= mktime(&tmp
);
480 seconds
= mktimegm(tm
) + rtc_date_offset
;
482 return seconds
- time(NULL
);
485 void rtc_change_mon_event(struct tm
*tm
)
489 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
490 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
491 qobject_decref(data
);
494 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
496 time_t rtc_start_date
;
499 if (!strcmp(startdate
, "now") && legacy
) {
500 rtc_date_offset
= -1;
502 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
510 } else if (sscanf(startdate
, "%d-%d-%d",
522 rtc_start_date
= mktimegm(&tm
);
523 if (rtc_start_date
== -1) {
525 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
526 "'2006-06-17T16:01:21' or '2006-06-17'\n");
529 rtc_date_offset
= time(NULL
) - rtc_start_date
;
533 static void configure_rtc(QemuOpts
*opts
)
537 value
= qemu_opt_get(opts
, "base");
539 if (!strcmp(value
, "utc")) {
541 } else if (!strcmp(value
, "localtime")) {
544 configure_rtc_date_offset(value
, 0);
547 value
= qemu_opt_get(opts
, "clock");
549 if (!strcmp(value
, "host")) {
550 rtc_clock
= host_clock
;
551 } else if (!strcmp(value
, "rt")) {
552 rtc_clock
= rt_clock
;
553 } else if (!strcmp(value
, "vm")) {
554 rtc_clock
= vm_clock
;
556 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
560 value
= qemu_opt_get(opts
, "driftfix");
562 if (!strcmp(value
, "slew")) {
563 static GlobalProperty slew_lost_ticks
[] = {
565 .driver
= "mc146818rtc",
566 .property
= "lost_tick_policy",
569 { /* end of list */ }
572 qdev_prop_register_global_list(slew_lost_ticks
);
573 } else if (!strcmp(value
, "none")) {
574 /* discard is default */
576 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
582 /***********************************************************/
583 /* Bluetooth support */
586 static struct HCIInfo
*hci_table
[MAX_NICS
];
588 static struct bt_vlan_s
{
589 struct bt_scatternet_s net
;
591 struct bt_vlan_s
*next
;
594 /* find or alloc a new bluetooth "VLAN" */
595 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
597 struct bt_vlan_s
**pvlan
, *vlan
;
598 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
602 vlan
= g_malloc0(sizeof(struct bt_vlan_s
));
604 pvlan
= &first_bt_vlan
;
605 while (*pvlan
!= NULL
)
606 pvlan
= &(*pvlan
)->next
;
611 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
615 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
620 static struct HCIInfo null_hci
= {
621 .cmd_send
= null_hci_send
,
622 .sco_send
= null_hci_send
,
623 .acl_send
= null_hci_send
,
624 .bdaddr_set
= null_hci_addr_set
,
627 struct HCIInfo
*qemu_next_hci(void)
629 if (cur_hci
== nb_hcis
)
632 return hci_table
[cur_hci
++];
635 static struct HCIInfo
*hci_init(const char *str
)
638 struct bt_scatternet_s
*vlan
= 0;
640 if (!strcmp(str
, "null"))
643 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
645 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
646 else if (!strncmp(str
, "hci", 3)) {
649 if (!strncmp(str
+ 3, ",vlan=", 6)) {
650 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
655 vlan
= qemu_find_bt_vlan(0);
657 return bt_new_hci(vlan
);
660 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
665 static int bt_hci_parse(const char *str
)
670 if (nb_hcis
>= MAX_NICS
) {
671 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
684 bdaddr
.b
[5] = 0x56 + nb_hcis
;
685 hci
->bdaddr_set(hci
, bdaddr
.b
);
687 hci_table
[nb_hcis
++] = hci
;
692 static void bt_vhci_add(int vlan_id
)
694 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
697 fprintf(stderr
, "qemu: warning: adding a VHCI to "
698 "an empty scatternet %i\n", vlan_id
);
700 bt_vhci_init(bt_new_hci(vlan
));
703 static struct bt_device_s
*bt_device_add(const char *opt
)
705 struct bt_scatternet_s
*vlan
;
707 char *endp
= strstr(opt
, ",vlan=");
708 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
711 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
714 vlan_id
= strtol(endp
+ 6, &endp
, 0);
716 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
721 vlan
= qemu_find_bt_vlan(vlan_id
);
724 fprintf(stderr
, "qemu: warning: adding a slave device to "
725 "an empty scatternet %i\n", vlan_id
);
727 if (!strcmp(devname
, "keyboard"))
728 return bt_keyboard_init(vlan
);
730 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
734 static int bt_parse(const char *opt
)
736 const char *endp
, *p
;
739 if (strstart(opt
, "hci", &endp
)) {
740 if (!*endp
|| *endp
== ',') {
742 if (!strstart(endp
, ",vlan=", 0))
745 return bt_hci_parse(opt
);
747 } else if (strstart(opt
, "vhci", &endp
)) {
748 if (!*endp
|| *endp
== ',') {
750 if (strstart(endp
, ",vlan=", &p
)) {
751 vlan
= strtol(p
, (char **) &endp
, 0);
753 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
757 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
766 } else if (strstart(opt
, "device:", &endp
))
767 return !bt_device_add(endp
);
769 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
773 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
775 /* FIXME: change this to true for 1.3 */
776 if (qemu_opt_get_bool(opts
, "enable", false)) {
777 #ifdef CONFIG_SECCOMP
778 if (seccomp_start() < 0) {
779 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
780 "failed to install seccomp syscall filter in the kernel");
784 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
785 "sandboxing request but seccomp is not compiled into this build");
793 /***********************************************************/
794 /* QEMU Block devices */
796 #define HD_OPTS "media=disk"
797 #define CDROM_OPTS "media=cdrom"
799 #define PFLASH_OPTS ""
803 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
805 int *use_scsi
= opaque
;
807 return drive_init(opts
, *use_scsi
) == NULL
;
810 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
812 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
813 qemu_opt_set(opts
, "snapshot", "on");
818 static void default_drive(int enable
, int snapshot
, int use_scsi
,
819 BlockInterfaceType type
, int index
,
824 if (type
== IF_DEFAULT
) {
825 type
= use_scsi
? IF_SCSI
: IF_IDE
;
828 if (!enable
|| drive_get_by_index(type
, index
)) {
832 opts
= drive_add(type
, index
, NULL
, optstr
);
834 drive_enable_snapshot(opts
, NULL
);
836 if (!drive_init(opts
, use_scsi
)) {
841 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
843 boot_set_handler
= func
;
844 boot_set_opaque
= opaque
;
847 int qemu_boot_set(const char *boot_devices
)
849 if (!boot_set_handler
) {
852 return boot_set_handler(boot_set_opaque
, boot_devices
);
855 static void validate_bootdevices(char *devices
)
857 /* We just do some generic consistency checks */
861 for (p
= devices
; *p
!= '\0'; p
++) {
862 /* Allowed boot devices are:
863 * a-b: floppy disk drives
864 * c-f: IDE disk drives
865 * g-m: machine implementation dependent drives
866 * n-p: network devices
867 * It's up to each machine implementation to check if the given boot
868 * devices match the actual hardware implementation and firmware
871 if (*p
< 'a' || *p
> 'p') {
872 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
875 if (bitmap
& (1 << (*p
- 'a'))) {
876 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
879 bitmap
|= 1 << (*p
- 'a');
883 static void restore_boot_devices(void *opaque
)
885 char *standard_boot_devices
= opaque
;
886 static int first
= 1;
888 /* Restore boot order and remove ourselves after the first boot */
894 qemu_boot_set(standard_boot_devices
);
896 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
897 g_free(standard_boot_devices
);
900 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
903 FWBootEntry
*node
, *i
;
909 assert(dev
!= NULL
|| suffix
!= NULL
);
911 node
= g_malloc0(sizeof(FWBootEntry
));
912 node
->bootindex
= bootindex
;
913 node
->suffix
= suffix
? g_strdup(suffix
) : NULL
;
916 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
917 if (i
->bootindex
== bootindex
) {
918 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
920 } else if (i
->bootindex
< bootindex
) {
923 QTAILQ_INSERT_BEFORE(i
, node
, link
);
926 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
930 * This function returns null terminated string that consist of new line
931 * separated device paths.
933 * memory pointed by "size" is assigned total length of the array in bytes
936 char *get_boot_devices_list(uint32_t *size
)
942 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
943 char *devpath
= NULL
, *bootpath
;
947 devpath
= qdev_get_fw_dev_path(i
->dev
);
951 if (i
->suffix
&& devpath
) {
952 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
954 bootpath
= g_malloc(bootpathlen
);
955 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
957 } else if (devpath
) {
961 bootpath
= g_strdup(i
->suffix
);
965 list
[total
-1] = '\n';
967 len
= strlen(bootpath
) + 1;
968 list
= g_realloc(list
, total
+ len
);
969 memcpy(&list
[total
], bootpath
, len
);
979 static void numa_add(const char *optarg
)
983 unsigned long long value
, endvalue
;
986 value
= endvalue
= 0ULL;
988 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
989 if (!strcmp(option
, "node")) {
990 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
991 nodenr
= nb_numa_nodes
;
993 nodenr
= strtoull(option
, NULL
, 10);
996 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
997 node_mem
[nodenr
] = 0;
1000 sval
= strtosz(option
, &endptr
);
1001 if (sval
< 0 || *endptr
) {
1002 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
1005 node_mem
[nodenr
] = sval
;
1007 if (get_param_value(option
, 128, "cpus", optarg
) != 0) {
1008 value
= strtoull(option
, &endptr
, 10);
1009 if (*endptr
== '-') {
1010 endvalue
= strtoull(endptr
+1, &endptr
, 10);
1015 if (!(endvalue
< MAX_CPUMASK_BITS
)) {
1016 endvalue
= MAX_CPUMASK_BITS
- 1;
1018 "A max of %d CPUs are supported in a guest\n",
1022 bitmap_set(node_cpumask
[nodenr
], value
, endvalue
-value
+1);
1028 static void smp_parse(const char *optarg
)
1030 int smp
, sockets
= 0, threads
= 0, cores
= 0;
1034 smp
= strtoul(optarg
, &endptr
, 10);
1035 if (endptr
!= optarg
) {
1036 if (*endptr
== ',') {
1040 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
1041 sockets
= strtoull(option
, NULL
, 10);
1042 if (get_param_value(option
, 128, "cores", endptr
) != 0)
1043 cores
= strtoull(option
, NULL
, 10);
1044 if (get_param_value(option
, 128, "threads", endptr
) != 0)
1045 threads
= strtoull(option
, NULL
, 10);
1046 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
1047 max_cpus
= strtoull(option
, NULL
, 10);
1049 /* compute missing values, prefer sockets over cores over threads */
1050 if (smp
== 0 || sockets
== 0) {
1051 sockets
= sockets
> 0 ? sockets
: 1;
1052 cores
= cores
> 0 ? cores
: 1;
1053 threads
= threads
> 0 ? threads
: 1;
1055 smp
= cores
* threads
* sockets
;
1059 threads
= threads
> 0 ? threads
: 1;
1060 cores
= smp
/ (sockets
* threads
);
1062 threads
= smp
/ (cores
* sockets
);
1066 smp_cores
= cores
> 0 ? cores
: 1;
1067 smp_threads
= threads
> 0 ? threads
: 1;
1069 max_cpus
= smp_cpus
;
1072 /***********************************************************/
1075 static int usb_device_add(const char *devname
)
1078 USBDevice
*dev
= NULL
;
1083 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1084 dev
= usbdevice_create(devname
);
1088 /* the other ones */
1089 #ifndef CONFIG_LINUX
1090 /* only the linux version is qdev-ified, usb-bsd still needs this */
1091 if (strstart(devname
, "host:", &p
)) {
1092 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1095 if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
1096 dev
= usb_bt_init(usb_bus_find(-1),
1097 devname
[2] ? hci_init(p
)
1098 : bt_new_hci(qemu_find_bt_vlan(0)));
1109 static int usb_device_del(const char *devname
)
1114 if (strstart(devname
, "host:", &p
))
1115 return usb_host_device_close(p
);
1120 p
= strchr(devname
, '.');
1123 bus_num
= strtoul(devname
, NULL
, 0);
1124 addr
= strtoul(p
+ 1, NULL
, 0);
1126 return usb_device_delete_addr(bus_num
, addr
);
1129 static int usb_parse(const char *cmdline
)
1132 r
= usb_device_add(cmdline
);
1134 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1139 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1141 const char *devname
= qdict_get_str(qdict
, "devname");
1142 if (usb_device_add(devname
) < 0) {
1143 error_report("could not add USB device '%s'", devname
);
1147 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1149 const char *devname
= qdict_get_str(qdict
, "devname");
1150 if (usb_device_del(devname
) < 0) {
1151 error_report("could not delete USB device '%s'", devname
);
1155 /***********************************************************/
1156 /* PCMCIA/Cardbus */
1158 static struct pcmcia_socket_entry_s
{
1159 PCMCIASocket
*socket
;
1160 struct pcmcia_socket_entry_s
*next
;
1161 } *pcmcia_sockets
= 0;
1163 void pcmcia_socket_register(PCMCIASocket
*socket
)
1165 struct pcmcia_socket_entry_s
*entry
;
1167 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1168 entry
->socket
= socket
;
1169 entry
->next
= pcmcia_sockets
;
1170 pcmcia_sockets
= entry
;
1173 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1175 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1177 ptr
= &pcmcia_sockets
;
1178 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1179 if (entry
->socket
== socket
) {
1185 void pcmcia_info(Monitor
*mon
)
1187 struct pcmcia_socket_entry_s
*iter
;
1189 if (!pcmcia_sockets
)
1190 monitor_printf(mon
, "No PCMCIA sockets\n");
1192 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1193 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1194 iter
->socket
->attached
? iter
->socket
->card_string
:
1198 /***********************************************************/
1199 /* machine registration */
1201 static QEMUMachine
*first_machine
= NULL
;
1202 QEMUMachine
*current_machine
= NULL
;
1204 int qemu_register_machine(QEMUMachine
*m
)
1207 pm
= &first_machine
;
1215 static QEMUMachine
*find_machine(const char *name
)
1219 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1220 if (!strcmp(m
->name
, name
))
1222 if (m
->alias
&& !strcmp(m
->alias
, name
))
1228 QEMUMachine
*find_default_machine(void)
1232 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1233 if (m
->is_default
) {
1240 MachineInfoList
*qmp_query_machines(Error
**errp
)
1242 MachineInfoList
*mach_list
= NULL
;
1245 for (m
= first_machine
; m
; m
= m
->next
) {
1246 MachineInfoList
*entry
;
1249 info
= g_malloc0(sizeof(*info
));
1250 if (m
->is_default
) {
1251 info
->has_is_default
= true;
1252 info
->is_default
= true;
1256 info
->has_alias
= true;
1257 info
->alias
= g_strdup(m
->alias
);
1260 info
->name
= g_strdup(m
->name
);
1262 entry
= g_malloc0(sizeof(*entry
));
1263 entry
->value
= info
;
1264 entry
->next
= mach_list
;
1271 /***********************************************************/
1272 /* main execution loop */
1274 static void gui_update(void *opaque
)
1276 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1277 DisplayState
*ds
= opaque
;
1278 DisplayChangeListener
*dcl
= ds
->listeners
;
1282 while (dcl
!= NULL
) {
1283 if (dcl
->gui_timer_interval
&&
1284 dcl
->gui_timer_interval
< interval
)
1285 interval
= dcl
->gui_timer_interval
;
1288 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1291 struct vm_change_state_entry
{
1292 VMChangeStateHandler
*cb
;
1294 QLIST_ENTRY (vm_change_state_entry
) entries
;
1297 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1299 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1302 VMChangeStateEntry
*e
;
1304 e
= g_malloc0(sizeof (*e
));
1308 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1312 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1314 QLIST_REMOVE (e
, entries
);
1318 void vm_state_notify(int running
, RunState state
)
1320 VMChangeStateEntry
*e
;
1322 trace_vm_state_notify(running
, state
);
1324 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1325 e
->cb(e
->opaque
, running
, state
);
1331 if (!runstate_is_running()) {
1333 runstate_set(RUN_STATE_RUNNING
);
1334 vm_state_notify(1, RUN_STATE_RUNNING
);
1336 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1340 /* reset/shutdown handler */
1342 typedef struct QEMUResetEntry
{
1343 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1344 QEMUResetHandler
*func
;
1348 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1349 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1350 static int reset_requested
;
1351 static int shutdown_requested
, shutdown_signal
= -1;
1352 static pid_t shutdown_pid
;
1353 static int powerdown_requested
;
1354 static int debug_requested
;
1355 static int suspend_requested
;
1356 static int wakeup_requested
;
1357 static NotifierList powerdown_notifiers
=
1358 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1359 static NotifierList suspend_notifiers
=
1360 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1361 static NotifierList wakeup_notifiers
=
1362 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1363 static uint32_t wakeup_reason_mask
= ~0;
1364 static RunState vmstop_requested
= RUN_STATE_MAX
;
1366 int qemu_shutdown_requested_get(void)
1368 return shutdown_requested
;
1371 int qemu_reset_requested_get(void)
1373 return reset_requested
;
1376 int qemu_shutdown_requested(void)
1378 int r
= shutdown_requested
;
1379 shutdown_requested
= 0;
1383 void qemu_kill_report(void)
1385 if (!qtest_enabled() && shutdown_signal
!= -1) {
1386 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1387 if (shutdown_pid
== 0) {
1388 /* This happens for eg ^C at the terminal, so it's worth
1389 * avoiding printing an odd message in that case.
1391 fputc('\n', stderr
);
1393 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1395 shutdown_signal
= -1;
1399 int qemu_reset_requested(void)
1401 int r
= reset_requested
;
1402 reset_requested
= 0;
1406 static int qemu_suspend_requested(void)
1408 int r
= suspend_requested
;
1409 suspend_requested
= 0;
1413 static int qemu_wakeup_requested(void)
1415 int r
= wakeup_requested
;
1416 wakeup_requested
= 0;
1420 int qemu_powerdown_requested(void)
1422 int r
= powerdown_requested
;
1423 powerdown_requested
= 0;
1427 static int qemu_debug_requested(void)
1429 int r
= debug_requested
;
1430 debug_requested
= 0;
1434 /* We use RUN_STATE_MAX but any invalid value will do */
1435 static bool qemu_vmstop_requested(RunState
*r
)
1437 if (vmstop_requested
< RUN_STATE_MAX
) {
1438 *r
= vmstop_requested
;
1439 vmstop_requested
= RUN_STATE_MAX
;
1446 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1448 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1451 re
->opaque
= opaque
;
1452 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1455 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1459 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1460 if (re
->func
== func
&& re
->opaque
== opaque
) {
1461 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1468 void qemu_devices_reset(void)
1470 QEMUResetEntry
*re
, *nre
;
1472 /* reset all devices */
1473 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1474 re
->func(re
->opaque
);
1478 void qemu_system_reset(bool report
)
1480 if (current_machine
&& current_machine
->reset
) {
1481 current_machine
->reset();
1483 qemu_devices_reset();
1486 monitor_protocol_event(QEVENT_RESET
, NULL
);
1488 cpu_synchronize_all_post_reset();
1491 void qemu_system_reset_request(void)
1494 shutdown_requested
= 1;
1496 reset_requested
= 1;
1499 qemu_notify_event();
1502 static void qemu_system_suspend(void)
1505 notifier_list_notify(&suspend_notifiers
, NULL
);
1506 runstate_set(RUN_STATE_SUSPENDED
);
1507 monitor_protocol_event(QEVENT_SUSPEND
, NULL
);
1510 void qemu_system_suspend_request(void)
1512 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1515 suspend_requested
= 1;
1517 qemu_notify_event();
1520 void qemu_register_suspend_notifier(Notifier
*notifier
)
1522 notifier_list_add(&suspend_notifiers
, notifier
);
1525 void qemu_system_wakeup_request(WakeupReason reason
)
1527 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1530 if (!(wakeup_reason_mask
& (1 << reason
))) {
1533 runstate_set(RUN_STATE_RUNNING
);
1534 notifier_list_notify(&wakeup_notifiers
, &reason
);
1535 wakeup_requested
= 1;
1536 qemu_notify_event();
1539 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1542 wakeup_reason_mask
|= (1 << reason
);
1544 wakeup_reason_mask
&= ~(1 << reason
);
1548 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1550 notifier_list_add(&wakeup_notifiers
, notifier
);
1553 void qemu_system_killed(int signal
, pid_t pid
)
1555 shutdown_signal
= signal
;
1558 qemu_system_shutdown_request();
1561 void qemu_system_shutdown_request(void)
1563 shutdown_requested
= 1;
1564 qemu_notify_event();
1567 static void qemu_system_powerdown(void)
1569 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1570 notifier_list_notify(&powerdown_notifiers
, NULL
);
1573 void qemu_system_powerdown_request(void)
1575 powerdown_requested
= 1;
1576 qemu_notify_event();
1579 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1581 notifier_list_add(&powerdown_notifiers
, notifier
);
1584 void qemu_system_debug_request(void)
1586 debug_requested
= 1;
1587 qemu_notify_event();
1590 void qemu_system_vmstop_request(RunState state
)
1592 vmstop_requested
= state
;
1593 qemu_notify_event();
1596 static bool main_loop_should_exit(void)
1599 if (qemu_debug_requested()) {
1600 vm_stop(RUN_STATE_DEBUG
);
1602 if (qemu_suspend_requested()) {
1603 qemu_system_suspend();
1605 if (qemu_shutdown_requested()) {
1607 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1609 vm_stop(RUN_STATE_SHUTDOWN
);
1614 if (qemu_reset_requested()) {
1616 cpu_synchronize_all_states();
1617 qemu_system_reset(VMRESET_REPORT
);
1619 if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
1620 runstate_check(RUN_STATE_SHUTDOWN
)) {
1621 runstate_set(RUN_STATE_PAUSED
);
1624 if (qemu_wakeup_requested()) {
1626 cpu_synchronize_all_states();
1627 qemu_system_reset(VMRESET_SILENT
);
1629 monitor_protocol_event(QEVENT_WAKEUP
, NULL
);
1631 if (qemu_powerdown_requested()) {
1632 qemu_system_powerdown();
1634 if (qemu_vmstop_requested(&r
)) {
1640 static void main_loop(void)
1644 #ifdef CONFIG_PROFILER
1648 nonblocking
= !kvm_enabled() && last_io
> 0;
1649 #ifdef CONFIG_PROFILER
1650 ti
= profile_getclock();
1652 last_io
= main_loop_wait(nonblocking
);
1653 #ifdef CONFIG_PROFILER
1654 dev_time
+= profile_getclock() - ti
;
1656 } while (!main_loop_should_exit());
1659 static void version(void)
1661 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1664 static void help(int exitcode
)
1667 printf("usage: %s [options] [disk_image]\n\n"
1668 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1669 error_get_progname());
1671 #define QEMU_OPTIONS_GENERATE_HELP
1672 #include "qemu-options-wrapper.h"
1674 printf("\nDuring emulation, the following keys are useful:\n"
1675 "ctrl-alt-f toggle full screen\n"
1676 "ctrl-alt-n switch to virtual console 'n'\n"
1677 "ctrl-alt toggle mouse and keyboard grab\n"
1679 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1684 #define HAS_ARG 0x0001
1686 typedef struct QEMUOption
{
1693 static const QEMUOption qemu_options
[] = {
1694 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1695 #define QEMU_OPTIONS_GENERATE_OPTIONS
1696 #include "qemu-options-wrapper.h"
1700 static bool vga_available(void)
1702 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1705 static bool cirrus_vga_available(void)
1707 return object_class_by_name("cirrus-vga")
1708 || object_class_by_name("isa-cirrus-vga");
1711 static bool vmware_vga_available(void)
1713 return object_class_by_name("vmware-svga");
1716 static bool qxl_vga_available(void)
1718 return object_class_by_name("qxl-vga");
1721 static void select_vgahw (const char *p
)
1725 vga_interface_type
= VGA_NONE
;
1726 if (strstart(p
, "std", &opts
)) {
1727 if (vga_available()) {
1728 vga_interface_type
= VGA_STD
;
1730 fprintf(stderr
, "Error: standard VGA not available\n");
1733 } else if (strstart(p
, "cirrus", &opts
)) {
1734 if (cirrus_vga_available()) {
1735 vga_interface_type
= VGA_CIRRUS
;
1737 fprintf(stderr
, "Error: Cirrus VGA not available\n");
1740 } else if (strstart(p
, "vmware", &opts
)) {
1741 if (vmware_vga_available()) {
1742 vga_interface_type
= VGA_VMWARE
;
1744 fprintf(stderr
, "Error: VMWare SVGA not available\n");
1747 } else if (strstart(p
, "xenfb", &opts
)) {
1748 vga_interface_type
= VGA_XENFB
;
1749 } else if (strstart(p
, "qxl", &opts
)) {
1750 if (qxl_vga_available()) {
1751 vga_interface_type
= VGA_QXL
;
1753 fprintf(stderr
, "Error: QXL VGA not available\n");
1756 } else if (!strstart(p
, "none", &opts
)) {
1758 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1762 const char *nextopt
;
1764 if (strstart(opts
, ",retrace=", &nextopt
)) {
1766 if (strstart(opts
, "dumb", &nextopt
))
1767 vga_retrace_method
= VGA_RETRACE_DUMB
;
1768 else if (strstart(opts
, "precise", &nextopt
))
1769 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1770 else goto invalid_vga
;
1771 } else goto invalid_vga
;
1776 static DisplayType
select_display(const char *p
)
1779 DisplayType display
= DT_DEFAULT
;
1781 if (strstart(p
, "sdl", &opts
)) {
1785 const char *nextopt
;
1787 if (strstart(opts
, ",frame=", &nextopt
)) {
1789 if (strstart(opts
, "on", &nextopt
)) {
1791 } else if (strstart(opts
, "off", &nextopt
)) {
1794 goto invalid_sdl_args
;
1796 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1798 if (strstart(opts
, "on", &nextopt
)) {
1800 } else if (strstart(opts
, "off", &nextopt
)) {
1803 goto invalid_sdl_args
;
1805 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1807 if (strstart(opts
, "on", &nextopt
)) {
1809 } else if (strstart(opts
, "off", &nextopt
)) {
1812 goto invalid_sdl_args
;
1814 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1816 if (strstart(opts
, "on", &nextopt
)) {
1818 } else if (strstart(opts
, "off", &nextopt
)) {
1821 goto invalid_sdl_args
;
1825 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1831 fprintf(stderr
, "SDL support is disabled\n");
1834 } else if (strstart(p
, "vnc", &opts
)) {
1839 const char *nextopt
;
1841 if (strstart(opts
, "=", &nextopt
)) {
1842 vnc_display
= nextopt
;
1846 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1850 fprintf(stderr
, "VNC support is disabled\n");
1853 } else if (strstart(p
, "curses", &opts
)) {
1854 #ifdef CONFIG_CURSES
1855 display
= DT_CURSES
;
1857 fprintf(stderr
, "Curses support is disabled\n");
1860 } else if (strstart(p
, "none", &opts
)) {
1863 fprintf(stderr
, "Unknown display type: %s\n", p
);
1870 static int balloon_parse(const char *arg
)
1874 if (strcmp(arg
, "none") == 0) {
1878 if (!strncmp(arg
, "virtio", 6)) {
1879 if (arg
[6] == ',') {
1880 /* have params -> parse them */
1881 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1885 /* create empty opts */
1886 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0, NULL
);
1888 qemu_opt_set(opts
, "driver", "virtio-balloon");
1895 char *qemu_find_file(int type
, const char *name
)
1901 /* Try the name as a straight path first */
1902 if (access(name
, R_OK
) == 0) {
1903 return g_strdup(name
);
1906 case QEMU_FILE_TYPE_BIOS
:
1909 case QEMU_FILE_TYPE_KEYMAP
:
1910 subdir
= "keymaps/";
1915 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1916 buf
= g_malloc0(len
);
1917 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1918 if (access(buf
, R_OK
)) {
1925 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1927 return qdev_device_help(opts
);
1930 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1934 dev
= qdev_device_add(opts
);
1940 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1942 CharDriverState
*chr
;
1944 chr
= qemu_chr_new_from_opts(opts
, NULL
);
1950 #ifdef CONFIG_VIRTFS
1951 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1954 ret
= qemu_fsdev_add(opts
);
1960 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1962 CharDriverState
*chr
;
1963 const char *chardev
;
1967 mode
= qemu_opt_get(opts
, "mode");
1971 if (strcmp(mode
, "readline") == 0) {
1972 flags
= MONITOR_USE_READLINE
;
1973 } else if (strcmp(mode
, "control") == 0) {
1974 flags
= MONITOR_USE_CONTROL
;
1976 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1980 if (qemu_opt_get_bool(opts
, "pretty", 0))
1981 flags
|= MONITOR_USE_PRETTY
;
1983 if (qemu_opt_get_bool(opts
, "default", 0))
1984 flags
|= MONITOR_IS_DEFAULT
;
1986 chardev
= qemu_opt_get(opts
, "chardev");
1987 chr
= qemu_chr_find(chardev
);
1989 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1993 monitor_init(chr
, flags
);
1997 static void monitor_parse(const char *optarg
, const char *mode
)
1999 static int monitor_device_index
= 0;
2005 if (strstart(optarg
, "chardev:", &p
)) {
2006 snprintf(label
, sizeof(label
), "%s", p
);
2008 snprintf(label
, sizeof(label
), "compat_monitor%d",
2009 monitor_device_index
);
2010 if (monitor_device_index
== 0) {
2013 opts
= qemu_chr_parse_compat(label
, optarg
);
2015 fprintf(stderr
, "parse error: %s\n", optarg
);
2020 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2022 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2025 qemu_opt_set(opts
, "mode", mode
);
2026 qemu_opt_set(opts
, "chardev", label
);
2028 qemu_opt_set(opts
, "default", "on");
2029 monitor_device_index
++;
2032 struct device_config
{
2034 DEV_USB
, /* -usbdevice */
2036 DEV_SERIAL
, /* -serial */
2037 DEV_PARALLEL
, /* -parallel */
2038 DEV_VIRTCON
, /* -virtioconsole */
2039 DEV_DEBUGCON
, /* -debugcon */
2040 DEV_GDB
, /* -gdb, -s */
2042 const char *cmdline
;
2044 QTAILQ_ENTRY(device_config
) next
;
2046 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
2048 static void add_device_config(int type
, const char *cmdline
)
2050 struct device_config
*conf
;
2052 conf
= g_malloc0(sizeof(*conf
));
2054 conf
->cmdline
= cmdline
;
2055 loc_save(&conf
->loc
);
2056 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2059 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2061 struct device_config
*conf
;
2064 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2065 if (conf
->type
!= type
)
2067 loc_push_restore(&conf
->loc
);
2068 rc
= func(conf
->cmdline
);
2069 loc_pop(&conf
->loc
);
2076 static int serial_parse(const char *devname
)
2078 static int index
= 0;
2081 if (strcmp(devname
, "none") == 0)
2083 if (index
== MAX_SERIAL_PORTS
) {
2084 fprintf(stderr
, "qemu: too many serial ports\n");
2087 snprintf(label
, sizeof(label
), "serial%d", index
);
2088 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2089 if (!serial_hds
[index
]) {
2090 fprintf(stderr
, "qemu: could not connect serial device"
2091 " to character backend '%s'\n", devname
);
2098 static int parallel_parse(const char *devname
)
2100 static int index
= 0;
2103 if (strcmp(devname
, "none") == 0)
2105 if (index
== MAX_PARALLEL_PORTS
) {
2106 fprintf(stderr
, "qemu: too many parallel ports\n");
2109 snprintf(label
, sizeof(label
), "parallel%d", index
);
2110 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2111 if (!parallel_hds
[index
]) {
2112 fprintf(stderr
, "qemu: could not connect parallel device"
2113 " to character backend '%s'\n", devname
);
2120 static int virtcon_parse(const char *devname
)
2122 QemuOptsList
*device
= qemu_find_opts("device");
2123 static int index
= 0;
2125 QemuOpts
*bus_opts
, *dev_opts
;
2127 if (strcmp(devname
, "none") == 0)
2129 if (index
== MAX_VIRTIO_CONSOLES
) {
2130 fprintf(stderr
, "qemu: too many virtio consoles\n");
2134 bus_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2135 if (arch_type
== QEMU_ARCH_S390X
) {
2136 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2138 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2141 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2142 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2144 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2145 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2146 if (!virtcon_hds
[index
]) {
2147 fprintf(stderr
, "qemu: could not connect virtio console"
2148 " to character backend '%s'\n", devname
);
2151 qemu_opt_set(dev_opts
, "chardev", label
);
2157 static int debugcon_parse(const char *devname
)
2161 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2164 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2166 fprintf(stderr
, "qemu: already have a debugcon device\n");
2169 qemu_opt_set(opts
, "driver", "isa-debugcon");
2170 qemu_opt_set(opts
, "chardev", "debugcon");
2174 static QEMUMachine
*machine_parse(const char *name
)
2176 QEMUMachine
*m
, *machine
= NULL
;
2179 machine
= find_machine(name
);
2184 printf("Supported machines are:\n");
2185 for (m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2187 printf("%-20s %s (alias of %s)\n", m
->alias
, m
->desc
, m
->name
);
2189 printf("%-20s %s%s\n", m
->name
, m
->desc
,
2190 m
->is_default
? " (default)" : "");
2192 exit(!name
|| !is_help_option(name
));
2195 static int tcg_init(void)
2197 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2202 const char *opt_name
;
2204 int (*available
)(void);
2208 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2209 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2210 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2211 { "qtest", "QTest", qtest_available
, qtest_init
, &qtest_allowed
},
2214 static int configure_accelerator(void)
2216 const char *p
= NULL
;
2219 bool accel_initialised
= 0;
2220 bool init_failed
= 0;
2222 QemuOptsList
*list
= qemu_find_opts("machine");
2223 if (!QTAILQ_EMPTY(&list
->head
)) {
2224 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2228 /* Use the default "accelerator", tcg */
2232 while (!accel_initialised
&& *p
!= '\0') {
2236 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2237 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2238 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2239 *(accel_list
[i
].allowed
) = 1;
2240 ret
= accel_list
[i
].init();
2243 if (!accel_list
[i
].available()) {
2244 printf("%s not supported for this target\n",
2245 accel_list
[i
].name
);
2247 fprintf(stderr
, "failed to initialize %s: %s\n",
2251 *(accel_list
[i
].allowed
) = 0;
2253 accel_initialised
= 1;
2258 if (i
== ARRAY_SIZE(accel_list
)) {
2259 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2263 if (!accel_initialised
) {
2264 fprintf(stderr
, "No accelerator found!\n");
2269 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2272 return !accel_initialised
;
2275 void qemu_add_exit_notifier(Notifier
*notify
)
2277 notifier_list_add(&exit_notifiers
, notify
);
2280 void qemu_remove_exit_notifier(Notifier
*notify
)
2282 notifier_remove(notify
);
2285 static void qemu_run_exit_notifiers(void)
2287 notifier_list_notify(&exit_notifiers
, NULL
);
2290 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2292 notifier_list_add(&machine_init_done_notifiers
, notify
);
2295 static void qemu_run_machine_init_done_notifiers(void)
2297 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2300 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2301 const char **poptarg
, int *poptind
)
2303 const QEMUOption
*popt
;
2304 int optind
= *poptind
;
2305 char *r
= argv
[optind
];
2308 loc_set_cmdline(argv
, optind
, 1);
2310 /* Treat --foo the same as -foo. */
2313 popt
= qemu_options
;
2316 error_report("invalid option");
2319 if (!strcmp(popt
->name
, r
+ 1))
2323 if (popt
->flags
& HAS_ARG
) {
2324 if (optind
>= argc
) {
2325 error_report("requires an argument");
2328 optarg
= argv
[optind
++];
2329 loc_set_cmdline(argv
, optind
- 2, 2);
2340 static gpointer
malloc_and_trace(gsize n_bytes
)
2342 void *ptr
= malloc(n_bytes
);
2343 trace_g_malloc(n_bytes
, ptr
);
2347 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2349 void *ptr
= realloc(mem
, n_bytes
);
2350 trace_g_realloc(mem
, n_bytes
, ptr
);
2354 static void free_and_trace(gpointer mem
)
2360 int main(int argc
, char **argv
, char **envp
)
2363 int snapshot
, linux_boot
;
2364 const char *icount_option
= NULL
;
2365 const char *initrd_filename
;
2366 const char *kernel_filename
, *kernel_cmdline
;
2367 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2369 DisplayChangeListener
*dcl
;
2370 int cyls
, heads
, secs
, translation
;
2371 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
;
2372 QemuOptsList
*olist
;
2375 const char *loadvm
= NULL
;
2376 QEMUMachine
*machine
;
2377 const char *cpu_model
;
2378 const char *vga_model
= "none";
2379 const char *pid_file
= NULL
;
2380 const char *incoming
= NULL
;
2382 int show_vnc_port
= 0;
2384 bool defconfig
= true;
2385 bool userconfig
= true;
2386 const char *log_mask
= NULL
;
2387 const char *log_file
= NULL
;
2388 GMemVTable mem_trace
= {
2389 .malloc
= malloc_and_trace
,
2390 .realloc
= realloc_and_trace
,
2391 .free
= free_and_trace
,
2393 const char *trace_events
= NULL
;
2394 const char *trace_file
= NULL
;
2396 atexit(qemu_run_exit_notifiers
);
2397 error_set_progname(argv
[0]);
2399 g_mem_set_vtable(&mem_trace
);
2400 if (!g_thread_supported()) {
2401 #if !GLIB_CHECK_VERSION(2, 31, 0)
2402 g_thread_init(NULL
);
2404 fprintf(stderr
, "glib threading failed to initialize.\n");
2409 module_call_init(MODULE_INIT_QOM
);
2414 rtc_clock
= host_clock
;
2416 qemu_cache_utils_init(envp
);
2418 QLIST_INIT (&vm_change_state_head
);
2419 os_setup_early_signal_handling();
2421 module_call_init(MODULE_INIT_MACHINE
);
2422 machine
= find_default_machine();
2426 cyls
= heads
= secs
= 0;
2427 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2429 for (i
= 0; i
< MAX_NODES
; i
++) {
2431 node_cpumask
[i
] = bitmap_new(MAX_CPUMASK_BITS
);
2439 /* first pass of option parsing */
2441 while (optind
< argc
) {
2442 if (argv
[optind
][0] != '-') {
2447 const QEMUOption
*popt
;
2449 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2450 switch (popt
->index
) {
2451 case QEMU_OPTION_nodefconfig
:
2454 case QEMU_OPTION_nouserconfig
:
2463 ret
= qemu_read_default_config_files(userconfig
);
2469 /* second pass of option parsing */
2474 if (argv
[optind
][0] != '-') {
2475 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2477 const QEMUOption
*popt
;
2479 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2480 if (!(popt
->arch_mask
& arch_type
)) {
2481 printf("Option %s not supported for this target\n", popt
->name
);
2484 switch(popt
->index
) {
2486 machine
= machine_parse(optarg
);
2488 case QEMU_OPTION_cpu
:
2489 /* hw initialization will check this */
2492 case QEMU_OPTION_hda
:
2496 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2498 snprintf(buf
, sizeof(buf
),
2499 "%s,cyls=%d,heads=%d,secs=%d%s",
2500 HD_OPTS
, cyls
, heads
, secs
,
2501 translation
== BIOS_ATA_TRANSLATION_LBA
?
2503 translation
== BIOS_ATA_TRANSLATION_NONE
?
2504 ",trans=none" : "");
2505 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2508 case QEMU_OPTION_hdb
:
2509 case QEMU_OPTION_hdc
:
2510 case QEMU_OPTION_hdd
:
2511 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2514 case QEMU_OPTION_drive
:
2515 if (drive_def(optarg
) == NULL
) {
2519 case QEMU_OPTION_set
:
2520 if (qemu_set_option(optarg
) != 0)
2523 case QEMU_OPTION_global
:
2524 if (qemu_global_option(optarg
) != 0)
2527 case QEMU_OPTION_mtdblock
:
2528 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2530 case QEMU_OPTION_sd
:
2531 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2533 case QEMU_OPTION_pflash
:
2534 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2536 case QEMU_OPTION_snapshot
:
2539 case QEMU_OPTION_hdachs
:
2543 cyls
= strtol(p
, (char **)&p
, 0);
2544 if (cyls
< 1 || cyls
> 16383)
2549 heads
= strtol(p
, (char **)&p
, 0);
2550 if (heads
< 1 || heads
> 16)
2555 secs
= strtol(p
, (char **)&p
, 0);
2556 if (secs
< 1 || secs
> 63)
2560 if (!strcmp(p
, "none"))
2561 translation
= BIOS_ATA_TRANSLATION_NONE
;
2562 else if (!strcmp(p
, "lba"))
2563 translation
= BIOS_ATA_TRANSLATION_LBA
;
2564 else if (!strcmp(p
, "auto"))
2565 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2568 } else if (*p
!= '\0') {
2570 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2573 if (hda_opts
!= NULL
) {
2575 snprintf(num
, sizeof(num
), "%d", cyls
);
2576 qemu_opt_set(hda_opts
, "cyls", num
);
2577 snprintf(num
, sizeof(num
), "%d", heads
);
2578 qemu_opt_set(hda_opts
, "heads", num
);
2579 snprintf(num
, sizeof(num
), "%d", secs
);
2580 qemu_opt_set(hda_opts
, "secs", num
);
2581 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2582 qemu_opt_set(hda_opts
, "trans", "lba");
2583 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2584 qemu_opt_set(hda_opts
, "trans", "none");
2588 case QEMU_OPTION_numa
:
2589 if (nb_numa_nodes
>= MAX_NODES
) {
2590 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2595 case QEMU_OPTION_display
:
2596 display_type
= select_display(optarg
);
2598 case QEMU_OPTION_nographic
:
2599 display_type
= DT_NOGRAPHIC
;
2601 case QEMU_OPTION_curses
:
2602 #ifdef CONFIG_CURSES
2603 display_type
= DT_CURSES
;
2605 fprintf(stderr
, "Curses support is disabled\n");
2609 case QEMU_OPTION_portrait
:
2610 graphic_rotate
= 90;
2612 case QEMU_OPTION_rotate
:
2613 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2614 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2615 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2617 "qemu: only 90, 180, 270 deg rotation is available\n");
2621 case QEMU_OPTION_kernel
:
2622 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
2624 case QEMU_OPTION_initrd
:
2625 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
2627 case QEMU_OPTION_append
:
2628 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
2630 case QEMU_OPTION_dtb
:
2631 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
2633 case QEMU_OPTION_cdrom
:
2634 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2636 case QEMU_OPTION_boot
:
2638 static const char * const params
[] = {
2639 "order", "once", "menu",
2640 "splash", "splash-time",
2641 "reboot-timeout", NULL
2643 char buf
[sizeof(boot_devices
)];
2644 char *standard_boot_devices
;
2647 if (!strchr(optarg
, '=')) {
2649 pstrcpy(buf
, sizeof(buf
), optarg
);
2650 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2652 "qemu: unknown boot parameter '%s' in '%s'\n",
2658 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2659 validate_bootdevices(buf
);
2660 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2663 if (get_param_value(buf
, sizeof(buf
),
2665 validate_bootdevices(buf
);
2666 standard_boot_devices
= g_strdup(boot_devices
);
2667 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2668 qemu_register_reset(restore_boot_devices
,
2669 standard_boot_devices
);
2671 if (get_param_value(buf
, sizeof(buf
),
2673 if (!strcmp(buf
, "on")) {
2675 } else if (!strcmp(buf
, "off")) {
2679 "qemu: invalid option value '%s'\n",
2684 qemu_opts_parse(qemu_find_opts("boot-opts"),
2689 case QEMU_OPTION_fda
:
2690 case QEMU_OPTION_fdb
:
2691 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2694 case QEMU_OPTION_no_fd_bootchk
:
2697 case QEMU_OPTION_netdev
:
2698 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2702 case QEMU_OPTION_net
:
2703 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2707 #ifdef CONFIG_LIBISCSI
2708 case QEMU_OPTION_iscsi
:
2709 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
2716 case QEMU_OPTION_tftp
:
2717 legacy_tftp_prefix
= optarg
;
2719 case QEMU_OPTION_bootp
:
2720 legacy_bootp_filename
= optarg
;
2722 case QEMU_OPTION_redir
:
2723 if (net_slirp_redir(optarg
) < 0)
2727 case QEMU_OPTION_bt
:
2728 add_device_config(DEV_BT
, optarg
);
2730 case QEMU_OPTION_audio_help
:
2731 if (!(audio_available())) {
2732 printf("Option %s not supported for this target\n", popt
->name
);
2738 case QEMU_OPTION_soundhw
:
2739 if (!(audio_available())) {
2740 printf("Option %s not supported for this target\n", popt
->name
);
2743 select_soundhw (optarg
);
2748 case QEMU_OPTION_version
:
2752 case QEMU_OPTION_m
: {
2757 value
= strtosz(optarg
, &end
);
2758 if (value
< 0 || *end
) {
2759 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2762 sz
= QEMU_ALIGN_UP((uint64_t)value
, 8192);
2764 if (ram_size
!= sz
) {
2765 fprintf(stderr
, "qemu: ram size too large\n");
2770 case QEMU_OPTION_mempath
:
2774 case QEMU_OPTION_mem_prealloc
:
2785 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2787 case QEMU_OPTION_gdb
:
2788 add_device_config(DEV_GDB
, optarg
);
2793 case QEMU_OPTION_bios
:
2796 case QEMU_OPTION_singlestep
:
2803 keyboard_layout
= optarg
;
2805 case QEMU_OPTION_localtime
:
2808 case QEMU_OPTION_vga
:
2817 w
= strtol(p
, (char **)&p
, 10);
2820 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2826 h
= strtol(p
, (char **)&p
, 10);
2831 depth
= strtol(p
, (char **)&p
, 10);
2832 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2833 depth
!= 24 && depth
!= 32)
2835 } else if (*p
== '\0') {
2836 depth
= graphic_depth
;
2843 graphic_depth
= depth
;
2846 case QEMU_OPTION_echr
:
2849 term_escape_char
= strtol(optarg
, &r
, 0);
2851 printf("Bad argument to echr\n");
2854 case QEMU_OPTION_monitor
:
2855 monitor_parse(optarg
, "readline");
2856 default_monitor
= 0;
2858 case QEMU_OPTION_qmp
:
2859 monitor_parse(optarg
, "control");
2860 default_monitor
= 0;
2862 case QEMU_OPTION_mon
:
2863 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2867 default_monitor
= 0;
2869 case QEMU_OPTION_chardev
:
2870 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2875 case QEMU_OPTION_fsdev
:
2876 olist
= qemu_find_opts("fsdev");
2878 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2881 opts
= qemu_opts_parse(olist
, optarg
, 1);
2883 fprintf(stderr
, "parse error: %s\n", optarg
);
2887 case QEMU_OPTION_virtfs
: {
2890 const char *writeout
, *sock_fd
, *socket
;
2892 olist
= qemu_find_opts("virtfs");
2894 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2897 opts
= qemu_opts_parse(olist
, optarg
, 1);
2899 fprintf(stderr
, "parse error: %s\n", optarg
);
2903 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
2904 qemu_opt_get(opts
, "mount_tag") == NULL
) {
2905 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
2908 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
2909 qemu_opt_get(opts
, "mount_tag"),
2912 fprintf(stderr
, "duplicate fsdev id: %s\n",
2913 qemu_opt_get(opts
, "mount_tag"));
2917 writeout
= qemu_opt_get(opts
, "writeout");
2919 #ifdef CONFIG_SYNC_FILE_RANGE
2920 qemu_opt_set(fsdev
, "writeout", writeout
);
2922 fprintf(stderr
, "writeout=immediate not supported on "
2927 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
2928 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
2929 qemu_opt_set(fsdev
, "security_model",
2930 qemu_opt_get(opts
, "security_model"));
2931 socket
= qemu_opt_get(opts
, "socket");
2933 qemu_opt_set(fsdev
, "socket", socket
);
2935 sock_fd
= qemu_opt_get(opts
, "sock_fd");
2937 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
2940 qemu_opt_set_bool(fsdev
, "readonly",
2941 qemu_opt_get_bool(opts
, "readonly", 0));
2942 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2944 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2945 qemu_opt_set(device
, "fsdev",
2946 qemu_opt_get(opts
, "mount_tag"));
2947 qemu_opt_set(device
, "mount_tag",
2948 qemu_opt_get(opts
, "mount_tag"));
2951 case QEMU_OPTION_virtfs_synth
: {
2955 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
2958 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
2961 qemu_opt_set(fsdev
, "fsdriver", "synth");
2963 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
2965 qemu_opt_set(device
, "driver", "virtio-9p-pci");
2966 qemu_opt_set(device
, "fsdev", "v_synth");
2967 qemu_opt_set(device
, "mount_tag", "v_synth");
2970 case QEMU_OPTION_serial
:
2971 add_device_config(DEV_SERIAL
, optarg
);
2973 if (strncmp(optarg
, "mon:", 4) == 0) {
2974 default_monitor
= 0;
2977 case QEMU_OPTION_watchdog
:
2980 "qemu: only one watchdog option may be given\n");
2985 case QEMU_OPTION_watchdog_action
:
2986 if (select_watchdog_action(optarg
) == -1) {
2987 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2991 case QEMU_OPTION_virtiocon
:
2992 add_device_config(DEV_VIRTCON
, optarg
);
2993 default_virtcon
= 0;
2994 if (strncmp(optarg
, "mon:", 4) == 0) {
2995 default_monitor
= 0;
2998 case QEMU_OPTION_parallel
:
2999 add_device_config(DEV_PARALLEL
, optarg
);
3000 default_parallel
= 0;
3001 if (strncmp(optarg
, "mon:", 4) == 0) {
3002 default_monitor
= 0;
3005 case QEMU_OPTION_debugcon
:
3006 add_device_config(DEV_DEBUGCON
, optarg
);
3008 case QEMU_OPTION_loadvm
:
3011 case QEMU_OPTION_full_screen
:
3015 case QEMU_OPTION_no_frame
:
3018 case QEMU_OPTION_alt_grab
:
3021 case QEMU_OPTION_ctrl_grab
:
3024 case QEMU_OPTION_no_quit
:
3027 case QEMU_OPTION_sdl
:
3028 display_type
= DT_SDL
;
3031 case QEMU_OPTION_no_frame
:
3032 case QEMU_OPTION_alt_grab
:
3033 case QEMU_OPTION_ctrl_grab
:
3034 case QEMU_OPTION_no_quit
:
3035 case QEMU_OPTION_sdl
:
3036 fprintf(stderr
, "SDL support is disabled\n");
3039 case QEMU_OPTION_pidfile
:
3042 case QEMU_OPTION_win2k_hack
:
3043 win2k_install_hack
= 1;
3045 case QEMU_OPTION_rtc_td_hack
: {
3046 static GlobalProperty slew_lost_ticks
[] = {
3048 .driver
= "mc146818rtc",
3049 .property
= "lost_tick_policy",
3052 { /* end of list */ }
3055 qdev_prop_register_global_list(slew_lost_ticks
);
3058 case QEMU_OPTION_acpitable
:
3059 do_acpitable_option(optarg
);
3061 case QEMU_OPTION_smbios
:
3062 do_smbios_option(optarg
);
3064 case QEMU_OPTION_enable_kvm
:
3065 olist
= qemu_find_opts("machine");
3066 qemu_opts_parse(olist
, "accel=kvm", 0);
3068 case QEMU_OPTION_machine
:
3069 olist
= qemu_find_opts("machine");
3070 opts
= qemu_opts_parse(olist
, optarg
, 1);
3072 fprintf(stderr
, "parse error: %s\n", optarg
);
3075 optarg
= qemu_opt_get(opts
, "type");
3077 machine
= machine_parse(optarg
);
3080 case QEMU_OPTION_usb
:
3083 case QEMU_OPTION_usbdevice
:
3085 add_device_config(DEV_USB
, optarg
);
3087 case QEMU_OPTION_device
:
3088 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3092 case QEMU_OPTION_smp
:
3095 fprintf(stderr
, "Invalid number of CPUs\n");
3098 if (max_cpus
< smp_cpus
) {
3099 fprintf(stderr
, "maxcpus must be equal to or greater than "
3103 if (max_cpus
> 255) {
3104 fprintf(stderr
, "Unsupported number of maxcpus\n");
3108 case QEMU_OPTION_vnc
:
3111 vnc_display
= optarg
;
3113 fprintf(stderr
, "VNC support is disabled\n");
3117 case QEMU_OPTION_no_acpi
:
3120 case QEMU_OPTION_no_hpet
:
3123 case QEMU_OPTION_balloon
:
3124 if (balloon_parse(optarg
) < 0) {
3125 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3129 case QEMU_OPTION_no_reboot
:
3132 case QEMU_OPTION_no_shutdown
:
3135 case QEMU_OPTION_show_cursor
:
3138 case QEMU_OPTION_uuid
:
3139 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3140 fprintf(stderr
, "Fail to parse UUID string."
3141 " Wrong format.\n");
3145 case QEMU_OPTION_option_rom
:
3146 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3147 fprintf(stderr
, "Too many option ROMs\n");
3150 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3151 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3152 option_rom
[nb_option_roms
].bootindex
=
3153 qemu_opt_get_number(opts
, "bootindex", -1);
3154 if (!option_rom
[nb_option_roms
].name
) {
3155 fprintf(stderr
, "Option ROM file is not specified\n");
3160 case QEMU_OPTION_semihosting
:
3161 semihosting_enabled
= 1;
3163 case QEMU_OPTION_name
:
3164 qemu_name
= g_strdup(optarg
);
3166 char *p
= strchr(qemu_name
, ',');
3169 if (strncmp(p
, "process=", 8)) {
3170 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
3174 os_set_proc_name(p
);
3178 case QEMU_OPTION_prom_env
:
3179 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3180 fprintf(stderr
, "Too many prom variables\n");
3183 prom_envs
[nb_prom_envs
] = optarg
;
3186 case QEMU_OPTION_old_param
:
3189 case QEMU_OPTION_clock
:
3190 configure_alarms(optarg
);
3192 case QEMU_OPTION_startdate
:
3193 configure_rtc_date_offset(optarg
, 1);
3195 case QEMU_OPTION_rtc
:
3196 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3200 configure_rtc(opts
);
3202 case QEMU_OPTION_tb_size
:
3203 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3204 if (tcg_tb_size
< 0) {
3208 case QEMU_OPTION_icount
:
3209 icount_option
= optarg
;
3211 case QEMU_OPTION_incoming
:
3213 runstate_set(RUN_STATE_INMIGRATE
);
3215 case QEMU_OPTION_nodefaults
:
3217 default_parallel
= 0;
3218 default_virtcon
= 0;
3219 default_monitor
= 0;
3226 case QEMU_OPTION_xen_domid
:
3227 if (!(xen_available())) {
3228 printf("Option %s not supported for this target\n", popt
->name
);
3231 xen_domid
= atoi(optarg
);
3233 case QEMU_OPTION_xen_create
:
3234 if (!(xen_available())) {
3235 printf("Option %s not supported for this target\n", popt
->name
);
3238 xen_mode
= XEN_CREATE
;
3240 case QEMU_OPTION_xen_attach
:
3241 if (!(xen_available())) {
3242 printf("Option %s not supported for this target\n", popt
->name
);
3245 xen_mode
= XEN_ATTACH
;
3247 case QEMU_OPTION_trace
:
3249 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3253 trace_events
= qemu_opt_get(opts
, "events");
3254 trace_file
= qemu_opt_get(opts
, "file");
3257 case QEMU_OPTION_readconfig
:
3259 int ret
= qemu_read_config_file(optarg
);
3261 fprintf(stderr
, "read config %s: %s\n", optarg
,
3267 case QEMU_OPTION_spice
:
3268 olist
= qemu_find_opts("spice");
3270 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3273 opts
= qemu_opts_parse(olist
, optarg
, 0);
3275 fprintf(stderr
, "parse error: %s\n", optarg
);
3279 case QEMU_OPTION_writeconfig
:
3282 if (strcmp(optarg
, "-") == 0) {
3285 fp
= fopen(optarg
, "w");
3287 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3291 qemu_config_write(fp
);
3295 case QEMU_OPTION_qtest
:
3296 qtest_chrdev
= optarg
;
3298 case QEMU_OPTION_qtest_log
:
3301 case QEMU_OPTION_sandbox
:
3302 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3308 os_parse_cmd_args(popt
->index
, optarg
);
3314 qemu_init_cpu_loop();
3315 if (qemu_init_main_loop()) {
3316 fprintf(stderr
, "qemu_init_main_loop failed\n");
3320 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
3324 if (machine
== NULL
) {
3325 fprintf(stderr
, "No machine found.\n");
3329 if (machine
->hw_version
) {
3330 qemu_set_version(machine
->hw_version
);
3333 /* Init CPU def lists, based on config
3334 * - Must be called after all the qemu_read_config_file() calls
3335 * - Must be called before list_cpus()
3336 * - Must be called before machine->init()
3340 if (cpu_model
&& is_help_option(cpu_model
)) {
3341 list_cpus(stdout
, &fprintf
, cpu_model
);
3345 /* Open the logfile at this point, if necessary. We can't open the logfile
3346 * when encountering either of the logging options (-d or -D) because the
3347 * other one may be encountered later on the command line, changing the
3348 * location or level of logging.
3352 set_cpu_log_filename(log_file
);
3354 set_cpu_log(log_mask
);
3357 if (!trace_backend_init(trace_events
, trace_file
)) {
3361 /* If no data_dir is specified then try to find it relative to the
3364 data_dir
= os_find_datadir(argv
[0]);
3366 /* If all else fails use the install path specified when building. */
3368 data_dir
= CONFIG_QEMU_DATADIR
;
3372 * Default to max_cpus = smp_cpus, in case the user doesn't
3373 * specify a max_cpus value.
3376 max_cpus
= smp_cpus
;
3378 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
3379 if (smp_cpus
> machine
->max_cpus
) {
3380 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
3381 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
3387 * Get the default machine options from the machine if it is not already
3388 * specified either by the configuration file or by the command line.
3390 if (machine
->default_machine_opts
) {
3391 qemu_opts_set_defaults(qemu_find_opts("machine"),
3392 machine
->default_machine_opts
, 0);
3395 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3396 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3398 if (machine
->no_serial
) {
3401 if (machine
->no_parallel
) {
3402 default_parallel
= 0;
3404 if (!machine
->use_virtcon
) {
3405 default_virtcon
= 0;
3407 if (machine
->no_floppy
) {
3410 if (machine
->no_cdrom
) {
3413 if (machine
->no_sdcard
) {
3417 if (display_type
== DT_NOGRAPHIC
) {
3418 if (default_parallel
)
3419 add_device_config(DEV_PARALLEL
, "null");
3420 if (default_serial
&& default_monitor
) {
3421 add_device_config(DEV_SERIAL
, "mon:stdio");
3422 } else if (default_virtcon
&& default_monitor
) {
3423 add_device_config(DEV_VIRTCON
, "mon:stdio");
3426 add_device_config(DEV_SERIAL
, "stdio");
3427 if (default_virtcon
)
3428 add_device_config(DEV_VIRTCON
, "stdio");
3429 if (default_monitor
)
3430 monitor_parse("stdio", "readline");
3434 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3435 if (default_parallel
)
3436 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3437 if (default_monitor
)
3438 monitor_parse("vc:80Cx24C", "readline");
3439 if (default_virtcon
)
3440 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3445 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3447 #ifdef CONFIG_VIRTFS
3448 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3455 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3460 /* init the memory */
3461 if (ram_size
== 0) {
3462 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3465 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
3470 configure_accelerator();
3472 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3474 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
3475 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
3476 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
3478 kernel_filename
= initrd_filename
= kernel_cmdline
= NULL
;
3481 if (!kernel_cmdline
) {
3482 kernel_cmdline
= "";
3485 linux_boot
= (kernel_filename
!= NULL
);
3487 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3488 fprintf(stderr
, "-append only allowed with -kernel option\n");
3492 if (!linux_boot
&& initrd_filename
!= NULL
) {
3493 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3497 if (!linux_boot
&& machine_opts
&& qemu_opt_get(machine_opts
, "dtb")) {
3498 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
3502 os_set_line_buffering();
3504 if (init_timer_alarm() < 0) {
3505 fprintf(stderr
, "could not initialize alarm timer\n");
3510 /* spice needs the timers to be initialized by this point */
3514 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
3515 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
3518 configure_icount(icount_option
);
3520 if (net_init_clients() < 0) {
3524 /* init the bluetooth world */
3525 if (foreach_device_config(DEV_BT
, bt_parse
))
3528 if (!xen_enabled()) {
3529 /* On 32-bit hosts, QEMU is limited by virtual address space */
3530 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
3531 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
3536 cpu_exec_init_all();
3538 bdrv_init_with_whitelist();
3542 /* open the virtual block devices */
3544 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3545 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3548 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3549 IF_DEFAULT
, 2, CDROM_OPTS
);
3550 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3551 IF_FLOPPY
, 0, FD_OPTS
);
3552 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3555 register_savevm_live(NULL
, "ram", 0, 4, &savevm_ram_handlers
, NULL
);
3557 if (nb_numa_nodes
> 0) {
3560 if (nb_numa_nodes
> MAX_NODES
) {
3561 nb_numa_nodes
= MAX_NODES
;
3564 /* If no memory size if given for any node, assume the default case
3565 * and distribute the available memory equally across all nodes
3567 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3568 if (node_mem
[i
] != 0)
3571 if (i
== nb_numa_nodes
) {
3572 uint64_t usedmem
= 0;
3574 /* On Linux, the each node's border has to be 8MB aligned,
3575 * the final node gets the rest.
3577 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3578 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3579 usedmem
+= node_mem
[i
];
3581 node_mem
[i
] = ram_size
- usedmem
;
3584 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3585 if (!bitmap_empty(node_cpumask
[i
], MAX_CPUMASK_BITS
)) {
3589 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3590 * must cope with this anyway, because there are BIOSes out there in
3591 * real machines which also use this scheme.
3593 if (i
== nb_numa_nodes
) {
3594 for (i
= 0; i
< max_cpus
; i
++) {
3595 set_bit(i
, node_cpumask
[i
% nb_numa_nodes
]);
3600 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3604 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3606 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3608 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3610 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3613 /* If no default VGA is requested, the default is "none". */
3615 if (cirrus_vga_available()) {
3616 vga_model
= "cirrus";
3617 } else if (vga_available()) {
3621 select_vgahw(vga_model
);
3624 i
= select_watchdog(watchdog
);
3626 exit (i
== 1 ? 1 : 0);
3629 if (machine
->compat_props
) {
3630 qdev_prop_register_global_list(machine
->compat_props
);
3634 qdev_machine_init();
3636 QEMUMachineInitArgs args
= { .ram_size
= ram_size
,
3637 .boot_device
= boot_devices
,
3638 .kernel_filename
= kernel_filename
,
3639 .kernel_cmdline
= kernel_cmdline
,
3640 .initrd_filename
= initrd_filename
,
3641 .cpu_model
= cpu_model
};
3642 machine
->init(&args
);
3644 cpu_synchronize_all_post_init();
3648 current_machine
= machine
;
3650 /* init USB devices */
3652 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3656 /* init generic devices */
3657 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3660 net_check_clients();
3662 /* just use the first displaystate for the moment */
3663 ds
= get_displaystate();
3667 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3668 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3669 display_type
= DT_SDL
;
3670 #elif defined(CONFIG_VNC)
3671 vnc_display
= "localhost:0,to=99";
3674 display_type
= DT_NONE
;
3679 /* init local displays */
3680 switch (display_type
) {
3683 #if defined(CONFIG_CURSES)
3685 if (!is_daemonized()) {
3686 curses_display_init(ds
, full_screen
);
3690 #if defined(CONFIG_SDL)
3692 sdl_display_init(ds
, full_screen
, no_frame
);
3694 #elif defined(CONFIG_COCOA)
3696 cocoa_display_init(ds
, full_screen
);
3703 /* must be after terminal init, SDL library changes signal handlers */
3704 os_setup_signal_handling();
3707 /* init remote displays */
3709 Error
*local_err
= NULL
;
3710 vnc_display_init(ds
);
3711 vnc_display_open(ds
, vnc_display
, &local_err
);
3712 if (local_err
!= NULL
) {
3713 fprintf(stderr
, "Failed to start VNC server on `%s': %s\n",
3714 vnc_display
, error_get_pretty(local_err
));
3715 error_free(local_err
);
3719 if (show_vnc_port
) {
3720 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3725 if (using_spice
&& !qxl_enabled
) {
3726 qemu_spice_display_init(ds
);
3732 dcl
= ds
->listeners
;
3733 while (dcl
!= NULL
) {
3734 if (dcl
->dpy_refresh
!= NULL
) {
3735 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
3736 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
3741 text_consoles_set_display(ds
);
3743 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
3747 qdev_machine_creation_done();
3749 if (rom_load_all() != 0) {
3750 fprintf(stderr
, "rom loading failed\n");
3754 /* TODO: once all bus devices are qdevified, this should be done
3755 * when bus is created by qdev.c */
3756 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3757 qemu_run_machine_init_done_notifiers();
3759 qemu_system_reset(VMRESET_SILENT
);
3761 if (load_vmstate(loadvm
) < 0) {
3767 Error
*local_err
= NULL
;
3768 qemu_start_incoming_migration(incoming
, &local_err
);
3770 fprintf(stderr
, "-incoming %s: %s\n", incoming
, error_get_pretty(local_err
));
3771 error_free(local_err
);
3774 } else if (autostart
) {