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;
212 const char *vnc_display
;
214 int acpi_enabled
= 1;
220 int graphic_rotate
= 0;
221 const char *watchdog
;
222 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
224 int semihosting_enabled
= 0;
226 const char *qemu_name
;
229 unsigned int nb_prom_envs
= 0;
230 const char *prom_envs
[MAX_PROM_ENVS
];
232 uint8_t *boot_splash_filedata
;
233 int boot_splash_filedata_size
;
234 uint8_t qemu_extra_params_fw
[2];
236 typedef struct FWBootEntry FWBootEntry
;
239 QTAILQ_ENTRY(FWBootEntry
) link
;
245 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
248 uint64_t node_mem
[MAX_NODES
];
249 unsigned long *node_cpumask
[MAX_NODES
];
251 uint8_t qemu_uuid
[16];
253 static QEMUBootSetHandler
*boot_set_handler
;
254 static void *boot_set_opaque
;
256 static NotifierList exit_notifiers
=
257 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
259 static NotifierList machine_init_done_notifiers
=
260 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
262 static int tcg_allowed
= 1;
266 enum xen_mode xen_mode
= XEN_EMULATE
;
267 static int tcg_tb_size
;
269 static int default_serial
= 1;
270 static int default_parallel
= 1;
271 static int default_virtcon
= 1;
272 static int default_monitor
= 1;
273 static int default_floppy
= 1;
274 static int default_cdrom
= 1;
275 static int default_sdcard
= 1;
276 static int default_vga
= 1;
282 { .driver
= "isa-serial", .flag
= &default_serial
},
283 { .driver
= "isa-parallel", .flag
= &default_parallel
},
284 { .driver
= "isa-fdc", .flag
= &default_floppy
},
285 { .driver
= "ide-cd", .flag
= &default_cdrom
},
286 { .driver
= "ide-hd", .flag
= &default_cdrom
},
287 { .driver
= "ide-drive", .flag
= &default_cdrom
},
288 { .driver
= "scsi-cd", .flag
= &default_cdrom
},
289 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
290 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
291 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
292 { .driver
= "VGA", .flag
= &default_vga
},
293 { .driver
= "isa-vga", .flag
= &default_vga
},
294 { .driver
= "cirrus-vga", .flag
= &default_vga
},
295 { .driver
= "isa-cirrus-vga", .flag
= &default_vga
},
296 { .driver
= "vmware-svga", .flag
= &default_vga
},
297 { .driver
= "qxl-vga", .flag
= &default_vga
},
300 const char *qemu_get_vm_name(void)
305 static void res_free(void)
307 if (boot_splash_filedata
!= NULL
) {
308 g_free(boot_splash_filedata
);
309 boot_splash_filedata
= NULL
;
313 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
315 const char *driver
= qemu_opt_get(opts
, "driver");
320 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
321 if (strcmp(default_list
[i
].driver
, driver
) != 0)
323 *(default_list
[i
].flag
) = 0;
328 /***********************************************************/
331 static RunState current_run_state
= RUN_STATE_PRELAUNCH
;
336 } RunStateTransition
;
338 static const RunStateTransition runstate_transitions_def
[] = {
340 { RUN_STATE_DEBUG
, RUN_STATE_RUNNING
},
342 { RUN_STATE_INMIGRATE
, RUN_STATE_RUNNING
},
343 { RUN_STATE_INMIGRATE
, RUN_STATE_PAUSED
},
345 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_PAUSED
},
346 { RUN_STATE_INTERNAL_ERROR
, RUN_STATE_FINISH_MIGRATE
},
348 { RUN_STATE_IO_ERROR
, RUN_STATE_RUNNING
},
349 { RUN_STATE_IO_ERROR
, RUN_STATE_FINISH_MIGRATE
},
351 { RUN_STATE_PAUSED
, RUN_STATE_RUNNING
},
352 { RUN_STATE_PAUSED
, RUN_STATE_FINISH_MIGRATE
},
354 { RUN_STATE_POSTMIGRATE
, RUN_STATE_RUNNING
},
355 { RUN_STATE_POSTMIGRATE
, RUN_STATE_FINISH_MIGRATE
},
357 { RUN_STATE_PRELAUNCH
, RUN_STATE_RUNNING
},
358 { RUN_STATE_PRELAUNCH
, RUN_STATE_FINISH_MIGRATE
},
359 { RUN_STATE_PRELAUNCH
, RUN_STATE_INMIGRATE
},
361 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_RUNNING
},
362 { RUN_STATE_FINISH_MIGRATE
, RUN_STATE_POSTMIGRATE
},
364 { RUN_STATE_RESTORE_VM
, RUN_STATE_RUNNING
},
366 { RUN_STATE_RUNNING
, RUN_STATE_DEBUG
},
367 { RUN_STATE_RUNNING
, RUN_STATE_INTERNAL_ERROR
},
368 { RUN_STATE_RUNNING
, RUN_STATE_IO_ERROR
},
369 { RUN_STATE_RUNNING
, RUN_STATE_PAUSED
},
370 { RUN_STATE_RUNNING
, RUN_STATE_FINISH_MIGRATE
},
371 { RUN_STATE_RUNNING
, RUN_STATE_RESTORE_VM
},
372 { RUN_STATE_RUNNING
, RUN_STATE_SAVE_VM
},
373 { RUN_STATE_RUNNING
, RUN_STATE_SHUTDOWN
},
374 { RUN_STATE_RUNNING
, RUN_STATE_WATCHDOG
},
376 { RUN_STATE_SAVE_VM
, RUN_STATE_RUNNING
},
378 { RUN_STATE_SHUTDOWN
, RUN_STATE_PAUSED
},
379 { RUN_STATE_SHUTDOWN
, RUN_STATE_FINISH_MIGRATE
},
381 { RUN_STATE_DEBUG
, RUN_STATE_SUSPENDED
},
382 { RUN_STATE_RUNNING
, RUN_STATE_SUSPENDED
},
383 { RUN_STATE_SUSPENDED
, RUN_STATE_RUNNING
},
384 { RUN_STATE_SUSPENDED
, RUN_STATE_FINISH_MIGRATE
},
386 { RUN_STATE_WATCHDOG
, RUN_STATE_RUNNING
},
387 { RUN_STATE_WATCHDOG
, RUN_STATE_FINISH_MIGRATE
},
389 { RUN_STATE_MAX
, RUN_STATE_MAX
},
392 static bool runstate_valid_transitions
[RUN_STATE_MAX
][RUN_STATE_MAX
];
394 bool runstate_check(RunState state
)
396 return current_run_state
== state
;
399 void runstate_init(void)
401 const RunStateTransition
*p
;
403 memset(&runstate_valid_transitions
, 0, sizeof(runstate_valid_transitions
));
405 for (p
= &runstate_transitions_def
[0]; p
->from
!= RUN_STATE_MAX
; p
++) {
406 runstate_valid_transitions
[p
->from
][p
->to
] = true;
410 /* This function will abort() on invalid state transitions */
411 void runstate_set(RunState new_state
)
413 assert(new_state
< RUN_STATE_MAX
);
415 if (!runstate_valid_transitions
[current_run_state
][new_state
]) {
416 fprintf(stderr
, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
417 RunState_lookup
[current_run_state
],
418 RunState_lookup
[new_state
]);
422 current_run_state
= new_state
;
425 int runstate_is_running(void)
427 return runstate_check(RUN_STATE_RUNNING
);
430 StatusInfo
*qmp_query_status(Error
**errp
)
432 StatusInfo
*info
= g_malloc0(sizeof(*info
));
434 info
->running
= runstate_is_running();
435 info
->singlestep
= singlestep
;
436 info
->status
= current_run_state
;
441 /***********************************************************/
442 /* real time host monotonic timer */
444 /***********************************************************/
445 /* host time/date access */
446 void qemu_get_timedate(struct tm
*tm
, int offset
)
453 if (rtc_date_offset
== -1) {
457 ret
= localtime(&ti
);
459 ti
-= rtc_date_offset
;
463 memcpy(tm
, ret
, sizeof(struct tm
));
466 int qemu_timedate_diff(struct tm
*tm
)
470 if (rtc_date_offset
== -1)
472 seconds
= mktimegm(tm
);
475 tmp
.tm_isdst
= -1; /* use timezone to figure it out */
476 seconds
= mktime(&tmp
);
479 seconds
= mktimegm(tm
) + rtc_date_offset
;
481 return seconds
- time(NULL
);
484 void rtc_change_mon_event(struct tm
*tm
)
488 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
489 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
490 qobject_decref(data
);
493 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
495 time_t rtc_start_date
;
498 if (!strcmp(startdate
, "now") && legacy
) {
499 rtc_date_offset
= -1;
501 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
509 } else if (sscanf(startdate
, "%d-%d-%d",
521 rtc_start_date
= mktimegm(&tm
);
522 if (rtc_start_date
== -1) {
524 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
525 "'2006-06-17T16:01:21' or '2006-06-17'\n");
528 rtc_date_offset
= time(NULL
) - rtc_start_date
;
532 static void configure_rtc(QemuOpts
*opts
)
536 value
= qemu_opt_get(opts
, "base");
538 if (!strcmp(value
, "utc")) {
540 } else if (!strcmp(value
, "localtime")) {
543 configure_rtc_date_offset(value
, 0);
546 value
= qemu_opt_get(opts
, "clock");
548 if (!strcmp(value
, "host")) {
549 rtc_clock
= host_clock
;
550 } else if (!strcmp(value
, "rt")) {
551 rtc_clock
= rt_clock
;
552 } else if (!strcmp(value
, "vm")) {
553 rtc_clock
= vm_clock
;
555 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
559 value
= qemu_opt_get(opts
, "driftfix");
561 if (!strcmp(value
, "slew")) {
562 static GlobalProperty slew_lost_ticks
[] = {
564 .driver
= "mc146818rtc",
565 .property
= "lost_tick_policy",
568 { /* end of list */ }
571 qdev_prop_register_global_list(slew_lost_ticks
);
572 } else if (!strcmp(value
, "none")) {
573 /* discard is default */
575 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
581 /***********************************************************/
582 /* Bluetooth support */
585 static struct HCIInfo
*hci_table
[MAX_NICS
];
587 static struct bt_vlan_s
{
588 struct bt_scatternet_s net
;
590 struct bt_vlan_s
*next
;
593 /* find or alloc a new bluetooth "VLAN" */
594 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
596 struct bt_vlan_s
**pvlan
, *vlan
;
597 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
601 vlan
= g_malloc0(sizeof(struct bt_vlan_s
));
603 pvlan
= &first_bt_vlan
;
604 while (*pvlan
!= NULL
)
605 pvlan
= &(*pvlan
)->next
;
610 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
614 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
619 static struct HCIInfo null_hci
= {
620 .cmd_send
= null_hci_send
,
621 .sco_send
= null_hci_send
,
622 .acl_send
= null_hci_send
,
623 .bdaddr_set
= null_hci_addr_set
,
626 struct HCIInfo
*qemu_next_hci(void)
628 if (cur_hci
== nb_hcis
)
631 return hci_table
[cur_hci
++];
634 static struct HCIInfo
*hci_init(const char *str
)
637 struct bt_scatternet_s
*vlan
= 0;
639 if (!strcmp(str
, "null"))
642 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
644 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
645 else if (!strncmp(str
, "hci", 3)) {
648 if (!strncmp(str
+ 3, ",vlan=", 6)) {
649 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
654 vlan
= qemu_find_bt_vlan(0);
656 return bt_new_hci(vlan
);
659 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
664 static int bt_hci_parse(const char *str
)
669 if (nb_hcis
>= MAX_NICS
) {
670 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
683 bdaddr
.b
[5] = 0x56 + nb_hcis
;
684 hci
->bdaddr_set(hci
, bdaddr
.b
);
686 hci_table
[nb_hcis
++] = hci
;
691 static void bt_vhci_add(int vlan_id
)
693 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
696 fprintf(stderr
, "qemu: warning: adding a VHCI to "
697 "an empty scatternet %i\n", vlan_id
);
699 bt_vhci_init(bt_new_hci(vlan
));
702 static struct bt_device_s
*bt_device_add(const char *opt
)
704 struct bt_scatternet_s
*vlan
;
706 char *endp
= strstr(opt
, ",vlan=");
707 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
710 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
713 vlan_id
= strtol(endp
+ 6, &endp
, 0);
715 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
720 vlan
= qemu_find_bt_vlan(vlan_id
);
723 fprintf(stderr
, "qemu: warning: adding a slave device to "
724 "an empty scatternet %i\n", vlan_id
);
726 if (!strcmp(devname
, "keyboard"))
727 return bt_keyboard_init(vlan
);
729 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
733 static int bt_parse(const char *opt
)
735 const char *endp
, *p
;
738 if (strstart(opt
, "hci", &endp
)) {
739 if (!*endp
|| *endp
== ',') {
741 if (!strstart(endp
, ",vlan=", 0))
744 return bt_hci_parse(opt
);
746 } else if (strstart(opt
, "vhci", &endp
)) {
747 if (!*endp
|| *endp
== ',') {
749 if (strstart(endp
, ",vlan=", &p
)) {
750 vlan
= strtol(p
, (char **) &endp
, 0);
752 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
756 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
765 } else if (strstart(opt
, "device:", &endp
))
766 return !bt_device_add(endp
);
768 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
772 static int parse_sandbox(QemuOpts
*opts
, void *opaque
)
774 /* FIXME: change this to true for 1.3 */
775 if (qemu_opt_get_bool(opts
, "enable", false)) {
776 #ifdef CONFIG_SECCOMP
777 if (seccomp_start() < 0) {
778 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
779 "failed to install seccomp syscall filter in the kernel");
783 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
784 "sandboxing request but seccomp is not compiled into this build");
792 /*********QEMU USB setting******/
793 bool usb_enabled(bool default_usb
)
796 mach_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
798 return qemu_opt_get_bool(mach_opts
, "usb", default_usb
);
804 static int parse_add_fd(QemuOpts
*opts
, void *opaque
)
806 int fd
, dupfd
, flags
;
808 const char *fd_opaque
= NULL
;
810 fd
= qemu_opt_get_number(opts
, "fd", -1);
811 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
812 fd_opaque
= qemu_opt_get(opts
, "opaque");
815 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
816 "fd option is required and must be non-negative");
820 if (fd
<= STDERR_FILENO
) {
821 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
822 "fd cannot be a standard I/O stream");
827 * All fds inherited across exec() necessarily have FD_CLOEXEC
828 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
830 flags
= fcntl(fd
, F_GETFD
);
831 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
832 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
833 "fd is not valid or already in use");
838 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
839 "set option is required and must be non-negative");
843 #ifdef F_DUPFD_CLOEXEC
844 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
848 qemu_set_cloexec(dupfd
);
852 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
853 "Error duplicating fd: %s", strerror(errno
));
857 /* add the duplicate fd, and optionally the opaque string, to the fd set */
858 monitor_fdset_add_fd(dupfd
, true, fdset_id
, fd_opaque
? true : false,
864 static int cleanup_add_fd(QemuOpts
*opts
, void *opaque
)
868 fd
= qemu_opt_get_number(opts
, "fd", -1);
875 /***********************************************************/
876 /* QEMU Block devices */
878 #define HD_OPTS "media=disk"
879 #define CDROM_OPTS "media=cdrom"
881 #define PFLASH_OPTS ""
885 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
887 int *use_scsi
= opaque
;
889 return drive_init(opts
, *use_scsi
) == NULL
;
892 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
894 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
895 qemu_opt_set(opts
, "snapshot", "on");
900 static void default_drive(int enable
, int snapshot
, int use_scsi
,
901 BlockInterfaceType type
, int index
,
906 if (type
== IF_DEFAULT
) {
907 type
= use_scsi
? IF_SCSI
: IF_IDE
;
910 if (!enable
|| drive_get_by_index(type
, index
)) {
914 opts
= drive_add(type
, index
, NULL
, optstr
);
916 drive_enable_snapshot(opts
, NULL
);
918 if (!drive_init(opts
, use_scsi
)) {
923 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
925 boot_set_handler
= func
;
926 boot_set_opaque
= opaque
;
929 int qemu_boot_set(const char *boot_devices
)
931 if (!boot_set_handler
) {
934 return boot_set_handler(boot_set_opaque
, boot_devices
);
937 static void validate_bootdevices(char *devices
)
939 /* We just do some generic consistency checks */
943 for (p
= devices
; *p
!= '\0'; p
++) {
944 /* Allowed boot devices are:
945 * a-b: floppy disk drives
946 * c-f: IDE disk drives
947 * g-m: machine implementation dependent drives
948 * n-p: network devices
949 * It's up to each machine implementation to check if the given boot
950 * devices match the actual hardware implementation and firmware
953 if (*p
< 'a' || *p
> 'p') {
954 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
957 if (bitmap
& (1 << (*p
- 'a'))) {
958 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
961 bitmap
|= 1 << (*p
- 'a');
965 static void restore_boot_devices(void *opaque
)
967 char *standard_boot_devices
= opaque
;
968 static int first
= 1;
970 /* Restore boot order and remove ourselves after the first boot */
976 qemu_boot_set(standard_boot_devices
);
978 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
979 g_free(standard_boot_devices
);
982 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
985 FWBootEntry
*node
, *i
;
991 assert(dev
!= NULL
|| suffix
!= NULL
);
993 node
= g_malloc0(sizeof(FWBootEntry
));
994 node
->bootindex
= bootindex
;
995 node
->suffix
= suffix
? g_strdup(suffix
) : NULL
;
998 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
999 if (i
->bootindex
== bootindex
) {
1000 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
1002 } else if (i
->bootindex
< bootindex
) {
1005 QTAILQ_INSERT_BEFORE(i
, node
, link
);
1008 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
1012 * This function returns null terminated string that consist of new line
1013 * separated device paths.
1015 * memory pointed by "size" is assigned total length of the array in bytes
1018 char *get_boot_devices_list(uint32_t *size
)
1024 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1025 char *devpath
= NULL
, *bootpath
;
1029 devpath
= qdev_get_fw_dev_path(i
->dev
);
1033 if (i
->suffix
&& devpath
) {
1034 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
1036 bootpath
= g_malloc(bootpathlen
);
1037 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
1039 } else if (devpath
) {
1043 bootpath
= g_strdup(i
->suffix
);
1047 list
[total
-1] = '\n';
1049 len
= strlen(bootpath
) + 1;
1050 list
= g_realloc(list
, total
+ len
);
1051 memcpy(&list
[total
], bootpath
, len
);
1061 static void numa_add(const char *optarg
)
1065 unsigned long long value
, endvalue
;
1068 value
= endvalue
= 0ULL;
1070 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
1071 if (!strcmp(option
, "node")) {
1072 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
1073 nodenr
= nb_numa_nodes
;
1075 nodenr
= strtoull(option
, NULL
, 10);
1078 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
1079 node_mem
[nodenr
] = 0;
1082 sval
= strtosz(option
, &endptr
);
1083 if (sval
< 0 || *endptr
) {
1084 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
1087 node_mem
[nodenr
] = sval
;
1089 if (get_param_value(option
, 128, "cpus", optarg
) != 0) {
1090 value
= strtoull(option
, &endptr
, 10);
1091 if (*endptr
== '-') {
1092 endvalue
= strtoull(endptr
+1, &endptr
, 10);
1097 if (!(endvalue
< MAX_CPUMASK_BITS
)) {
1098 endvalue
= MAX_CPUMASK_BITS
- 1;
1100 "A max of %d CPUs are supported in a guest\n",
1104 bitmap_set(node_cpumask
[nodenr
], value
, endvalue
-value
+1);
1110 static void smp_parse(const char *optarg
)
1112 int smp
, sockets
= 0, threads
= 0, cores
= 0;
1116 smp
= strtoul(optarg
, &endptr
, 10);
1117 if (endptr
!= optarg
) {
1118 if (*endptr
== ',') {
1122 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
1123 sockets
= strtoull(option
, NULL
, 10);
1124 if (get_param_value(option
, 128, "cores", endptr
) != 0)
1125 cores
= strtoull(option
, NULL
, 10);
1126 if (get_param_value(option
, 128, "threads", endptr
) != 0)
1127 threads
= strtoull(option
, NULL
, 10);
1128 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
1129 max_cpus
= strtoull(option
, NULL
, 10);
1131 /* compute missing values, prefer sockets over cores over threads */
1132 if (smp
== 0 || sockets
== 0) {
1133 sockets
= sockets
> 0 ? sockets
: 1;
1134 cores
= cores
> 0 ? cores
: 1;
1135 threads
= threads
> 0 ? threads
: 1;
1137 smp
= cores
* threads
* sockets
;
1141 threads
= threads
> 0 ? threads
: 1;
1142 cores
= smp
/ (sockets
* threads
);
1144 threads
= smp
/ (cores
* sockets
);
1148 smp_cores
= cores
> 0 ? cores
: 1;
1149 smp_threads
= threads
> 0 ? threads
: 1;
1151 max_cpus
= smp_cpus
;
1154 /***********************************************************/
1157 static int usb_device_add(const char *devname
)
1160 USBDevice
*dev
= NULL
;
1162 if (!usb_enabled(false)) {
1166 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1167 dev
= usbdevice_create(devname
);
1171 /* the other ones */
1172 #ifndef CONFIG_LINUX
1173 /* only the linux version is qdev-ified, usb-bsd still needs this */
1174 if (strstart(devname
, "host:", &p
)) {
1175 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1178 if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
1179 dev
= usb_bt_init(usb_bus_find(-1),
1180 devname
[2] ? hci_init(p
)
1181 : bt_new_hci(qemu_find_bt_vlan(0)));
1192 static int usb_device_del(const char *devname
)
1197 if (strstart(devname
, "host:", &p
))
1198 return usb_host_device_close(p
);
1200 if (!usb_enabled(false)) {
1204 p
= strchr(devname
, '.');
1207 bus_num
= strtoul(devname
, NULL
, 0);
1208 addr
= strtoul(p
+ 1, NULL
, 0);
1210 return usb_device_delete_addr(bus_num
, addr
);
1213 static int usb_parse(const char *cmdline
)
1216 r
= usb_device_add(cmdline
);
1218 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1223 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1225 const char *devname
= qdict_get_str(qdict
, "devname");
1226 if (usb_device_add(devname
) < 0) {
1227 error_report("could not add USB device '%s'", devname
);
1231 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1233 const char *devname
= qdict_get_str(qdict
, "devname");
1234 if (usb_device_del(devname
) < 0) {
1235 error_report("could not delete USB device '%s'", devname
);
1239 /***********************************************************/
1240 /* PCMCIA/Cardbus */
1242 static struct pcmcia_socket_entry_s
{
1243 PCMCIASocket
*socket
;
1244 struct pcmcia_socket_entry_s
*next
;
1245 } *pcmcia_sockets
= 0;
1247 void pcmcia_socket_register(PCMCIASocket
*socket
)
1249 struct pcmcia_socket_entry_s
*entry
;
1251 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1252 entry
->socket
= socket
;
1253 entry
->next
= pcmcia_sockets
;
1254 pcmcia_sockets
= entry
;
1257 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1259 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1261 ptr
= &pcmcia_sockets
;
1262 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1263 if (entry
->socket
== socket
) {
1269 void pcmcia_info(Monitor
*mon
)
1271 struct pcmcia_socket_entry_s
*iter
;
1273 if (!pcmcia_sockets
)
1274 monitor_printf(mon
, "No PCMCIA sockets\n");
1276 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1277 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1278 iter
->socket
->attached
? iter
->socket
->card_string
:
1282 /***********************************************************/
1283 /* machine registration */
1285 static QEMUMachine
*first_machine
= NULL
;
1286 QEMUMachine
*current_machine
= NULL
;
1288 int qemu_register_machine(QEMUMachine
*m
)
1291 pm
= &first_machine
;
1299 static QEMUMachine
*find_machine(const char *name
)
1303 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1304 if (!strcmp(m
->name
, name
))
1306 if (m
->alias
&& !strcmp(m
->alias
, name
))
1312 QEMUMachine
*find_default_machine(void)
1316 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1317 if (m
->is_default
) {
1324 MachineInfoList
*qmp_query_machines(Error
**errp
)
1326 MachineInfoList
*mach_list
= NULL
;
1329 for (m
= first_machine
; m
; m
= m
->next
) {
1330 MachineInfoList
*entry
;
1333 info
= g_malloc0(sizeof(*info
));
1334 if (m
->is_default
) {
1335 info
->has_is_default
= true;
1336 info
->is_default
= true;
1340 info
->has_alias
= true;
1341 info
->alias
= g_strdup(m
->alias
);
1344 info
->name
= g_strdup(m
->name
);
1346 entry
= g_malloc0(sizeof(*entry
));
1347 entry
->value
= info
;
1348 entry
->next
= mach_list
;
1355 /***********************************************************/
1356 /* main execution loop */
1358 static void gui_update(void *opaque
)
1360 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1361 DisplayState
*ds
= opaque
;
1362 DisplayChangeListener
*dcl
;
1366 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1367 if (dcl
->gui_timer_interval
&&
1368 dcl
->gui_timer_interval
< interval
)
1369 interval
= dcl
->gui_timer_interval
;
1371 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1374 void gui_setup_refresh(DisplayState
*ds
)
1376 DisplayChangeListener
*dcl
;
1377 bool need_timer
= false;
1379 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1380 if (dcl
->dpy_refresh
!= NULL
) {
1386 if (need_timer
&& ds
->gui_timer
== NULL
) {
1387 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
1388 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
1390 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
1391 qemu_del_timer(ds
->gui_timer
);
1392 qemu_free_timer(ds
->gui_timer
);
1393 ds
->gui_timer
= NULL
;
1397 struct vm_change_state_entry
{
1398 VMChangeStateHandler
*cb
;
1400 QLIST_ENTRY (vm_change_state_entry
) entries
;
1403 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1405 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1408 VMChangeStateEntry
*e
;
1410 e
= g_malloc0(sizeof (*e
));
1414 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1418 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1420 QLIST_REMOVE (e
, entries
);
1424 void vm_state_notify(int running
, RunState state
)
1426 VMChangeStateEntry
*e
;
1428 trace_vm_state_notify(running
, state
);
1430 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1431 e
->cb(e
->opaque
, running
, state
);
1437 if (!runstate_is_running()) {
1439 runstate_set(RUN_STATE_RUNNING
);
1440 vm_state_notify(1, RUN_STATE_RUNNING
);
1442 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1446 /* reset/shutdown handler */
1448 typedef struct QEMUResetEntry
{
1449 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1450 QEMUResetHandler
*func
;
1454 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1455 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1456 static int reset_requested
;
1457 static int shutdown_requested
, shutdown_signal
= -1;
1458 static pid_t shutdown_pid
;
1459 static int powerdown_requested
;
1460 static int debug_requested
;
1461 static int suspend_requested
;
1462 static int wakeup_requested
;
1463 static NotifierList powerdown_notifiers
=
1464 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1465 static NotifierList suspend_notifiers
=
1466 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1467 static NotifierList wakeup_notifiers
=
1468 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1469 static uint32_t wakeup_reason_mask
= ~0;
1470 static RunState vmstop_requested
= RUN_STATE_MAX
;
1472 int qemu_shutdown_requested_get(void)
1474 return shutdown_requested
;
1477 int qemu_reset_requested_get(void)
1479 return reset_requested
;
1482 int qemu_shutdown_requested(void)
1484 int r
= shutdown_requested
;
1485 shutdown_requested
= 0;
1489 void qemu_kill_report(void)
1491 if (!qtest_enabled() && shutdown_signal
!= -1) {
1492 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1493 if (shutdown_pid
== 0) {
1494 /* This happens for eg ^C at the terminal, so it's worth
1495 * avoiding printing an odd message in that case.
1497 fputc('\n', stderr
);
1499 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1501 shutdown_signal
= -1;
1505 int qemu_reset_requested(void)
1507 int r
= reset_requested
;
1508 reset_requested
= 0;
1512 static int qemu_suspend_requested(void)
1514 int r
= suspend_requested
;
1515 suspend_requested
= 0;
1519 static int qemu_wakeup_requested(void)
1521 int r
= wakeup_requested
;
1522 wakeup_requested
= 0;
1526 int qemu_powerdown_requested(void)
1528 int r
= powerdown_requested
;
1529 powerdown_requested
= 0;
1533 static int qemu_debug_requested(void)
1535 int r
= debug_requested
;
1536 debug_requested
= 0;
1540 /* We use RUN_STATE_MAX but any invalid value will do */
1541 static bool qemu_vmstop_requested(RunState
*r
)
1543 if (vmstop_requested
< RUN_STATE_MAX
) {
1544 *r
= vmstop_requested
;
1545 vmstop_requested
= RUN_STATE_MAX
;
1552 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1554 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1557 re
->opaque
= opaque
;
1558 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1561 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1565 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1566 if (re
->func
== func
&& re
->opaque
== opaque
) {
1567 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1574 void qemu_devices_reset(void)
1576 QEMUResetEntry
*re
, *nre
;
1578 /* reset all devices */
1579 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1580 re
->func(re
->opaque
);
1584 void qemu_system_reset(bool report
)
1586 if (current_machine
&& current_machine
->reset
) {
1587 current_machine
->reset();
1589 qemu_devices_reset();
1592 monitor_protocol_event(QEVENT_RESET
, NULL
);
1594 cpu_synchronize_all_post_reset();
1597 void qemu_system_reset_request(void)
1600 shutdown_requested
= 1;
1602 reset_requested
= 1;
1605 qemu_notify_event();
1608 static void qemu_system_suspend(void)
1611 notifier_list_notify(&suspend_notifiers
, NULL
);
1612 runstate_set(RUN_STATE_SUSPENDED
);
1613 monitor_protocol_event(QEVENT_SUSPEND
, NULL
);
1616 void qemu_system_suspend_request(void)
1618 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1621 suspend_requested
= 1;
1623 qemu_notify_event();
1626 void qemu_register_suspend_notifier(Notifier
*notifier
)
1628 notifier_list_add(&suspend_notifiers
, notifier
);
1631 void qemu_system_wakeup_request(WakeupReason reason
)
1633 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1636 if (!(wakeup_reason_mask
& (1 << reason
))) {
1639 runstate_set(RUN_STATE_RUNNING
);
1640 notifier_list_notify(&wakeup_notifiers
, &reason
);
1641 wakeup_requested
= 1;
1642 qemu_notify_event();
1645 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1648 wakeup_reason_mask
|= (1 << reason
);
1650 wakeup_reason_mask
&= ~(1 << reason
);
1654 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1656 notifier_list_add(&wakeup_notifiers
, notifier
);
1659 void qemu_system_killed(int signal
, pid_t pid
)
1661 shutdown_signal
= signal
;
1664 qemu_system_shutdown_request();
1667 void qemu_system_shutdown_request(void)
1669 shutdown_requested
= 1;
1670 qemu_notify_event();
1673 static void qemu_system_powerdown(void)
1675 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1676 notifier_list_notify(&powerdown_notifiers
, NULL
);
1679 void qemu_system_powerdown_request(void)
1681 powerdown_requested
= 1;
1682 qemu_notify_event();
1685 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1687 notifier_list_add(&powerdown_notifiers
, notifier
);
1690 void qemu_system_debug_request(void)
1692 debug_requested
= 1;
1693 qemu_notify_event();
1696 void qemu_system_vmstop_request(RunState state
)
1698 vmstop_requested
= state
;
1699 qemu_notify_event();
1702 static bool main_loop_should_exit(void)
1705 if (qemu_debug_requested()) {
1706 vm_stop(RUN_STATE_DEBUG
);
1708 if (qemu_suspend_requested()) {
1709 qemu_system_suspend();
1711 if (qemu_shutdown_requested()) {
1713 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1715 vm_stop(RUN_STATE_SHUTDOWN
);
1720 if (qemu_reset_requested()) {
1722 cpu_synchronize_all_states();
1723 qemu_system_reset(VMRESET_REPORT
);
1725 if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
1726 runstate_check(RUN_STATE_SHUTDOWN
)) {
1727 runstate_set(RUN_STATE_PAUSED
);
1730 if (qemu_wakeup_requested()) {
1732 cpu_synchronize_all_states();
1733 qemu_system_reset(VMRESET_SILENT
);
1735 monitor_protocol_event(QEVENT_WAKEUP
, NULL
);
1737 if (qemu_powerdown_requested()) {
1738 qemu_system_powerdown();
1740 if (qemu_vmstop_requested(&r
)) {
1746 static void main_loop(void)
1750 #ifdef CONFIG_PROFILER
1754 nonblocking
= !kvm_enabled() && last_io
> 0;
1755 #ifdef CONFIG_PROFILER
1756 ti
= profile_getclock();
1758 last_io
= main_loop_wait(nonblocking
);
1759 #ifdef CONFIG_PROFILER
1760 dev_time
+= profile_getclock() - ti
;
1762 } while (!main_loop_should_exit());
1765 static void version(void)
1767 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1770 static void help(int exitcode
)
1773 printf("usage: %s [options] [disk_image]\n\n"
1774 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1775 error_get_progname());
1777 #define QEMU_OPTIONS_GENERATE_HELP
1778 #include "qemu-options-wrapper.h"
1780 printf("\nDuring emulation, the following keys are useful:\n"
1781 "ctrl-alt-f toggle full screen\n"
1782 "ctrl-alt-n switch to virtual console 'n'\n"
1783 "ctrl-alt toggle mouse and keyboard grab\n"
1785 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1790 #define HAS_ARG 0x0001
1792 typedef struct QEMUOption
{
1799 static const QEMUOption qemu_options
[] = {
1800 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1801 #define QEMU_OPTIONS_GENERATE_OPTIONS
1802 #include "qemu-options-wrapper.h"
1806 static bool vga_available(void)
1808 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1811 static bool cirrus_vga_available(void)
1813 return object_class_by_name("cirrus-vga")
1814 || object_class_by_name("isa-cirrus-vga");
1817 static bool vmware_vga_available(void)
1819 return object_class_by_name("vmware-svga");
1822 static bool qxl_vga_available(void)
1824 return object_class_by_name("qxl-vga");
1827 static void select_vgahw (const char *p
)
1831 vga_interface_type
= VGA_NONE
;
1832 if (strstart(p
, "std", &opts
)) {
1833 if (vga_available()) {
1834 vga_interface_type
= VGA_STD
;
1836 fprintf(stderr
, "Error: standard VGA not available\n");
1839 } else if (strstart(p
, "cirrus", &opts
)) {
1840 if (cirrus_vga_available()) {
1841 vga_interface_type
= VGA_CIRRUS
;
1843 fprintf(stderr
, "Error: Cirrus VGA not available\n");
1846 } else if (strstart(p
, "vmware", &opts
)) {
1847 if (vmware_vga_available()) {
1848 vga_interface_type
= VGA_VMWARE
;
1850 fprintf(stderr
, "Error: VMWare SVGA not available\n");
1853 } else if (strstart(p
, "xenfb", &opts
)) {
1854 vga_interface_type
= VGA_XENFB
;
1855 } else if (strstart(p
, "qxl", &opts
)) {
1856 if (qxl_vga_available()) {
1857 vga_interface_type
= VGA_QXL
;
1859 fprintf(stderr
, "Error: QXL VGA not available\n");
1862 } else if (!strstart(p
, "none", &opts
)) {
1864 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1868 const char *nextopt
;
1870 if (strstart(opts
, ",retrace=", &nextopt
)) {
1872 if (strstart(opts
, "dumb", &nextopt
))
1873 vga_retrace_method
= VGA_RETRACE_DUMB
;
1874 else if (strstart(opts
, "precise", &nextopt
))
1875 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1876 else goto invalid_vga
;
1877 } else goto invalid_vga
;
1882 static DisplayType
select_display(const char *p
)
1885 DisplayType display
= DT_DEFAULT
;
1887 if (strstart(p
, "sdl", &opts
)) {
1891 const char *nextopt
;
1893 if (strstart(opts
, ",frame=", &nextopt
)) {
1895 if (strstart(opts
, "on", &nextopt
)) {
1897 } else if (strstart(opts
, "off", &nextopt
)) {
1900 goto invalid_sdl_args
;
1902 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1904 if (strstart(opts
, "on", &nextopt
)) {
1906 } else if (strstart(opts
, "off", &nextopt
)) {
1909 goto invalid_sdl_args
;
1911 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1913 if (strstart(opts
, "on", &nextopt
)) {
1915 } else if (strstart(opts
, "off", &nextopt
)) {
1918 goto invalid_sdl_args
;
1920 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1922 if (strstart(opts
, "on", &nextopt
)) {
1924 } else if (strstart(opts
, "off", &nextopt
)) {
1927 goto invalid_sdl_args
;
1931 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1937 fprintf(stderr
, "SDL support is disabled\n");
1940 } else if (strstart(p
, "vnc", &opts
)) {
1945 const char *nextopt
;
1947 if (strstart(opts
, "=", &nextopt
)) {
1948 vnc_display
= nextopt
;
1952 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1956 fprintf(stderr
, "VNC support is disabled\n");
1959 } else if (strstart(p
, "curses", &opts
)) {
1960 #ifdef CONFIG_CURSES
1961 display
= DT_CURSES
;
1963 fprintf(stderr
, "Curses support is disabled\n");
1966 } else if (strstart(p
, "none", &opts
)) {
1969 fprintf(stderr
, "Unknown display type: %s\n", p
);
1976 static int balloon_parse(const char *arg
)
1980 if (strcmp(arg
, "none") == 0) {
1984 if (!strncmp(arg
, "virtio", 6)) {
1985 if (arg
[6] == ',') {
1986 /* have params -> parse them */
1987 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1991 /* create empty opts */
1992 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0, NULL
);
1994 qemu_opt_set(opts
, "driver", "virtio-balloon");
2001 char *qemu_find_file(int type
, const char *name
)
2007 /* Try the name as a straight path first */
2008 if (access(name
, R_OK
) == 0) {
2009 return g_strdup(name
);
2012 case QEMU_FILE_TYPE_BIOS
:
2015 case QEMU_FILE_TYPE_KEYMAP
:
2016 subdir
= "keymaps/";
2021 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
2022 buf
= g_malloc0(len
);
2023 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
2024 if (access(buf
, R_OK
)) {
2031 static int device_help_func(QemuOpts
*opts
, void *opaque
)
2033 return qdev_device_help(opts
);
2036 static int device_init_func(QemuOpts
*opts
, void *opaque
)
2040 dev
= qdev_device_add(opts
);
2046 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
2048 CharDriverState
*chr
;
2050 chr
= qemu_chr_new_from_opts(opts
, NULL
);
2056 #ifdef CONFIG_VIRTFS
2057 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
2060 ret
= qemu_fsdev_add(opts
);
2066 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
2068 CharDriverState
*chr
;
2069 const char *chardev
;
2073 mode
= qemu_opt_get(opts
, "mode");
2077 if (strcmp(mode
, "readline") == 0) {
2078 flags
= MONITOR_USE_READLINE
;
2079 } else if (strcmp(mode
, "control") == 0) {
2080 flags
= MONITOR_USE_CONTROL
;
2082 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
2086 if (qemu_opt_get_bool(opts
, "pretty", 0))
2087 flags
|= MONITOR_USE_PRETTY
;
2089 if (qemu_opt_get_bool(opts
, "default", 0))
2090 flags
|= MONITOR_IS_DEFAULT
;
2092 chardev
= qemu_opt_get(opts
, "chardev");
2093 chr
= qemu_chr_find(chardev
);
2095 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
2099 monitor_init(chr
, flags
);
2103 static void monitor_parse(const char *optarg
, const char *mode
)
2105 static int monitor_device_index
= 0;
2111 if (strstart(optarg
, "chardev:", &p
)) {
2112 snprintf(label
, sizeof(label
), "%s", p
);
2114 snprintf(label
, sizeof(label
), "compat_monitor%d",
2115 monitor_device_index
);
2116 if (monitor_device_index
== 0) {
2119 opts
= qemu_chr_parse_compat(label
, optarg
);
2121 fprintf(stderr
, "parse error: %s\n", optarg
);
2126 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2128 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2131 qemu_opt_set(opts
, "mode", mode
);
2132 qemu_opt_set(opts
, "chardev", label
);
2134 qemu_opt_set(opts
, "default", "on");
2135 monitor_device_index
++;
2138 struct device_config
{
2140 DEV_USB
, /* -usbdevice */
2142 DEV_SERIAL
, /* -serial */
2143 DEV_PARALLEL
, /* -parallel */
2144 DEV_VIRTCON
, /* -virtioconsole */
2145 DEV_DEBUGCON
, /* -debugcon */
2146 DEV_GDB
, /* -gdb, -s */
2148 const char *cmdline
;
2150 QTAILQ_ENTRY(device_config
) next
;
2152 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
2154 static void add_device_config(int type
, const char *cmdline
)
2156 struct device_config
*conf
;
2158 conf
= g_malloc0(sizeof(*conf
));
2160 conf
->cmdline
= cmdline
;
2161 loc_save(&conf
->loc
);
2162 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2165 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2167 struct device_config
*conf
;
2170 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2171 if (conf
->type
!= type
)
2173 loc_push_restore(&conf
->loc
);
2174 rc
= func(conf
->cmdline
);
2175 loc_pop(&conf
->loc
);
2182 static int serial_parse(const char *devname
)
2184 static int index
= 0;
2187 if (strcmp(devname
, "none") == 0)
2189 if (index
== MAX_SERIAL_PORTS
) {
2190 fprintf(stderr
, "qemu: too many serial ports\n");
2193 snprintf(label
, sizeof(label
), "serial%d", index
);
2194 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2195 if (!serial_hds
[index
]) {
2196 fprintf(stderr
, "qemu: could not connect serial device"
2197 " to character backend '%s'\n", devname
);
2204 static int parallel_parse(const char *devname
)
2206 static int index
= 0;
2209 if (strcmp(devname
, "none") == 0)
2211 if (index
== MAX_PARALLEL_PORTS
) {
2212 fprintf(stderr
, "qemu: too many parallel ports\n");
2215 snprintf(label
, sizeof(label
), "parallel%d", index
);
2216 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2217 if (!parallel_hds
[index
]) {
2218 fprintf(stderr
, "qemu: could not connect parallel device"
2219 " to character backend '%s'\n", devname
);
2226 static int virtcon_parse(const char *devname
)
2228 QemuOptsList
*device
= qemu_find_opts("device");
2229 static int index
= 0;
2231 QemuOpts
*bus_opts
, *dev_opts
;
2233 if (strcmp(devname
, "none") == 0)
2235 if (index
== MAX_VIRTIO_CONSOLES
) {
2236 fprintf(stderr
, "qemu: too many virtio consoles\n");
2240 bus_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2241 if (arch_type
== QEMU_ARCH_S390X
) {
2242 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2244 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2247 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2248 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2250 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2251 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2252 if (!virtcon_hds
[index
]) {
2253 fprintf(stderr
, "qemu: could not connect virtio console"
2254 " to character backend '%s'\n", devname
);
2257 qemu_opt_set(dev_opts
, "chardev", label
);
2263 static int debugcon_parse(const char *devname
)
2267 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2270 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2272 fprintf(stderr
, "qemu: already have a debugcon device\n");
2275 qemu_opt_set(opts
, "driver", "isa-debugcon");
2276 qemu_opt_set(opts
, "chardev", "debugcon");
2280 static QEMUMachine
*machine_parse(const char *name
)
2282 QEMUMachine
*m
, *machine
= NULL
;
2285 machine
= find_machine(name
);
2290 printf("Supported machines are:\n");
2291 for (m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2293 printf("%-20s %s (alias of %s)\n", m
->alias
, m
->desc
, m
->name
);
2295 printf("%-20s %s%s\n", m
->name
, m
->desc
,
2296 m
->is_default
? " (default)" : "");
2298 exit(!name
|| !is_help_option(name
));
2301 static int tcg_init(void)
2303 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2308 const char *opt_name
;
2310 int (*available
)(void);
2314 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2315 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2316 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2317 { "qtest", "QTest", qtest_available
, qtest_init
, &qtest_allowed
},
2320 static int configure_accelerator(void)
2322 const char *p
= NULL
;
2325 bool accel_initialised
= 0;
2326 bool init_failed
= 0;
2328 QemuOptsList
*list
= qemu_find_opts("machine");
2329 if (!QTAILQ_EMPTY(&list
->head
)) {
2330 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2334 /* Use the default "accelerator", tcg */
2338 while (!accel_initialised
&& *p
!= '\0') {
2342 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2343 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2344 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2345 *(accel_list
[i
].allowed
) = 1;
2346 ret
= accel_list
[i
].init();
2349 if (!accel_list
[i
].available()) {
2350 printf("%s not supported for this target\n",
2351 accel_list
[i
].name
);
2353 fprintf(stderr
, "failed to initialize %s: %s\n",
2357 *(accel_list
[i
].allowed
) = 0;
2359 accel_initialised
= 1;
2364 if (i
== ARRAY_SIZE(accel_list
)) {
2365 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2369 if (!accel_initialised
) {
2370 fprintf(stderr
, "No accelerator found!\n");
2375 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2378 return !accel_initialised
;
2381 void qemu_add_exit_notifier(Notifier
*notify
)
2383 notifier_list_add(&exit_notifiers
, notify
);
2386 void qemu_remove_exit_notifier(Notifier
*notify
)
2388 notifier_remove(notify
);
2391 static void qemu_run_exit_notifiers(void)
2393 notifier_list_notify(&exit_notifiers
, NULL
);
2396 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2398 notifier_list_add(&machine_init_done_notifiers
, notify
);
2401 static void qemu_run_machine_init_done_notifiers(void)
2403 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2406 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2407 const char **poptarg
, int *poptind
)
2409 const QEMUOption
*popt
;
2410 int optind
= *poptind
;
2411 char *r
= argv
[optind
];
2414 loc_set_cmdline(argv
, optind
, 1);
2416 /* Treat --foo the same as -foo. */
2419 popt
= qemu_options
;
2422 error_report("invalid option");
2425 if (!strcmp(popt
->name
, r
+ 1))
2429 if (popt
->flags
& HAS_ARG
) {
2430 if (optind
>= argc
) {
2431 error_report("requires an argument");
2434 optarg
= argv
[optind
++];
2435 loc_set_cmdline(argv
, optind
- 2, 2);
2446 static gpointer
malloc_and_trace(gsize n_bytes
)
2448 void *ptr
= malloc(n_bytes
);
2449 trace_g_malloc(n_bytes
, ptr
);
2453 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2455 void *ptr
= realloc(mem
, n_bytes
);
2456 trace_g_realloc(mem
, n_bytes
, ptr
);
2460 static void free_and_trace(gpointer mem
)
2466 int qemu_init_main_loop(void)
2468 return main_loop_init();
2471 int main(int argc
, char **argv
, char **envp
)
2474 int snapshot
, linux_boot
;
2475 const char *icount_option
= NULL
;
2476 const char *initrd_filename
;
2477 const char *kernel_filename
, *kernel_cmdline
;
2478 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2480 int cyls
, heads
, secs
, translation
;
2481 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
;
2482 QemuOptsList
*olist
;
2485 const char *loadvm
= NULL
;
2486 QEMUMachine
*machine
;
2487 const char *cpu_model
;
2488 const char *vga_model
= "none";
2489 const char *pid_file
= NULL
;
2490 const char *incoming
= NULL
;
2492 int show_vnc_port
= 0;
2494 bool defconfig
= true;
2495 bool userconfig
= true;
2496 const char *log_mask
= NULL
;
2497 const char *log_file
= NULL
;
2498 GMemVTable mem_trace
= {
2499 .malloc
= malloc_and_trace
,
2500 .realloc
= realloc_and_trace
,
2501 .free
= free_and_trace
,
2503 const char *trace_events
= NULL
;
2504 const char *trace_file
= NULL
;
2506 atexit(qemu_run_exit_notifiers
);
2507 error_set_progname(argv
[0]);
2509 g_mem_set_vtable(&mem_trace
);
2510 if (!g_thread_supported()) {
2511 #if !GLIB_CHECK_VERSION(2, 31, 0)
2512 g_thread_init(NULL
);
2514 fprintf(stderr
, "glib threading failed to initialize.\n");
2519 module_call_init(MODULE_INIT_QOM
);
2524 rtc_clock
= host_clock
;
2526 qemu_cache_utils_init(envp
);
2528 QLIST_INIT (&vm_change_state_head
);
2529 os_setup_early_signal_handling();
2531 module_call_init(MODULE_INIT_MACHINE
);
2532 machine
= find_default_machine();
2536 cyls
= heads
= secs
= 0;
2537 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2539 for (i
= 0; i
< MAX_NODES
; i
++) {
2541 node_cpumask
[i
] = bitmap_new(MAX_CPUMASK_BITS
);
2549 /* first pass of option parsing */
2551 while (optind
< argc
) {
2552 if (argv
[optind
][0] != '-') {
2557 const QEMUOption
*popt
;
2559 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2560 switch (popt
->index
) {
2561 case QEMU_OPTION_nodefconfig
:
2564 case QEMU_OPTION_nouserconfig
:
2573 ret
= qemu_read_default_config_files(userconfig
);
2579 /* second pass of option parsing */
2584 if (argv
[optind
][0] != '-') {
2585 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2587 const QEMUOption
*popt
;
2589 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2590 if (!(popt
->arch_mask
& arch_type
)) {
2591 printf("Option %s not supported for this target\n", popt
->name
);
2594 switch(popt
->index
) {
2596 machine
= machine_parse(optarg
);
2598 case QEMU_OPTION_cpu
:
2599 /* hw initialization will check this */
2602 case QEMU_OPTION_hda
:
2606 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2608 snprintf(buf
, sizeof(buf
),
2609 "%s,cyls=%d,heads=%d,secs=%d%s",
2610 HD_OPTS
, cyls
, heads
, secs
,
2611 translation
== BIOS_ATA_TRANSLATION_LBA
?
2613 translation
== BIOS_ATA_TRANSLATION_NONE
?
2614 ",trans=none" : "");
2615 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2618 case QEMU_OPTION_hdb
:
2619 case QEMU_OPTION_hdc
:
2620 case QEMU_OPTION_hdd
:
2621 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2624 case QEMU_OPTION_drive
:
2625 if (drive_def(optarg
) == NULL
) {
2629 case QEMU_OPTION_set
:
2630 if (qemu_set_option(optarg
) != 0)
2633 case QEMU_OPTION_global
:
2634 if (qemu_global_option(optarg
) != 0)
2637 case QEMU_OPTION_mtdblock
:
2638 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2640 case QEMU_OPTION_sd
:
2641 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2643 case QEMU_OPTION_pflash
:
2644 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2646 case QEMU_OPTION_snapshot
:
2649 case QEMU_OPTION_hdachs
:
2653 cyls
= strtol(p
, (char **)&p
, 0);
2654 if (cyls
< 1 || cyls
> 16383)
2659 heads
= strtol(p
, (char **)&p
, 0);
2660 if (heads
< 1 || heads
> 16)
2665 secs
= strtol(p
, (char **)&p
, 0);
2666 if (secs
< 1 || secs
> 63)
2670 if (!strcmp(p
, "none"))
2671 translation
= BIOS_ATA_TRANSLATION_NONE
;
2672 else if (!strcmp(p
, "lba"))
2673 translation
= BIOS_ATA_TRANSLATION_LBA
;
2674 else if (!strcmp(p
, "auto"))
2675 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2678 } else if (*p
!= '\0') {
2680 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2683 if (hda_opts
!= NULL
) {
2685 snprintf(num
, sizeof(num
), "%d", cyls
);
2686 qemu_opt_set(hda_opts
, "cyls", num
);
2687 snprintf(num
, sizeof(num
), "%d", heads
);
2688 qemu_opt_set(hda_opts
, "heads", num
);
2689 snprintf(num
, sizeof(num
), "%d", secs
);
2690 qemu_opt_set(hda_opts
, "secs", num
);
2691 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2692 qemu_opt_set(hda_opts
, "trans", "lba");
2693 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2694 qemu_opt_set(hda_opts
, "trans", "none");
2698 case QEMU_OPTION_numa
:
2699 if (nb_numa_nodes
>= MAX_NODES
) {
2700 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2705 case QEMU_OPTION_display
:
2706 display_type
= select_display(optarg
);
2708 case QEMU_OPTION_nographic
:
2709 display_type
= DT_NOGRAPHIC
;
2711 case QEMU_OPTION_curses
:
2712 #ifdef CONFIG_CURSES
2713 display_type
= DT_CURSES
;
2715 fprintf(stderr
, "Curses support is disabled\n");
2719 case QEMU_OPTION_portrait
:
2720 graphic_rotate
= 90;
2722 case QEMU_OPTION_rotate
:
2723 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2724 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2725 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2727 "qemu: only 90, 180, 270 deg rotation is available\n");
2731 case QEMU_OPTION_kernel
:
2732 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
2734 case QEMU_OPTION_initrd
:
2735 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
2737 case QEMU_OPTION_append
:
2738 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
2740 case QEMU_OPTION_dtb
:
2741 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
2743 case QEMU_OPTION_cdrom
:
2744 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2746 case QEMU_OPTION_boot
:
2748 static const char * const params
[] = {
2749 "order", "once", "menu",
2750 "splash", "splash-time",
2751 "reboot-timeout", NULL
2753 char buf
[sizeof(boot_devices
)];
2754 char *standard_boot_devices
;
2757 if (!strchr(optarg
, '=')) {
2759 pstrcpy(buf
, sizeof(buf
), optarg
);
2760 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2762 "qemu: unknown boot parameter '%s' in '%s'\n",
2768 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2769 validate_bootdevices(buf
);
2770 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2773 if (get_param_value(buf
, sizeof(buf
),
2775 validate_bootdevices(buf
);
2776 standard_boot_devices
= g_strdup(boot_devices
);
2777 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2778 qemu_register_reset(restore_boot_devices
,
2779 standard_boot_devices
);
2781 if (get_param_value(buf
, sizeof(buf
),
2783 if (!strcmp(buf
, "on")) {
2785 } else if (!strcmp(buf
, "off")) {
2789 "qemu: invalid option value '%s'\n",
2794 qemu_opts_parse(qemu_find_opts("boot-opts"),
2799 case QEMU_OPTION_fda
:
2800 case QEMU_OPTION_fdb
:
2801 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2804 case QEMU_OPTION_no_fd_bootchk
:
2807 case QEMU_OPTION_netdev
:
2808 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2812 case QEMU_OPTION_net
:
2813 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2817 #ifdef CONFIG_LIBISCSI
2818 case QEMU_OPTION_iscsi
:
2819 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
2826 case QEMU_OPTION_tftp
:
2827 legacy_tftp_prefix
= optarg
;
2829 case QEMU_OPTION_bootp
:
2830 legacy_bootp_filename
= optarg
;
2832 case QEMU_OPTION_redir
:
2833 if (net_slirp_redir(optarg
) < 0)
2837 case QEMU_OPTION_bt
:
2838 add_device_config(DEV_BT
, optarg
);
2840 case QEMU_OPTION_audio_help
:
2841 if (!(audio_available())) {
2842 printf("Option %s not supported for this target\n", popt
->name
);
2848 case QEMU_OPTION_soundhw
:
2849 if (!(audio_available())) {
2850 printf("Option %s not supported for this target\n", popt
->name
);
2853 select_soundhw (optarg
);
2858 case QEMU_OPTION_version
:
2862 case QEMU_OPTION_m
: {
2867 value
= strtosz(optarg
, &end
);
2868 if (value
< 0 || *end
) {
2869 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2872 sz
= QEMU_ALIGN_UP((uint64_t)value
, 8192);
2874 if (ram_size
!= sz
) {
2875 fprintf(stderr
, "qemu: ram size too large\n");
2880 case QEMU_OPTION_mempath
:
2884 case QEMU_OPTION_mem_prealloc
:
2895 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2897 case QEMU_OPTION_gdb
:
2898 add_device_config(DEV_GDB
, optarg
);
2903 case QEMU_OPTION_bios
:
2906 case QEMU_OPTION_singlestep
:
2913 keyboard_layout
= optarg
;
2915 case QEMU_OPTION_localtime
:
2918 case QEMU_OPTION_vga
:
2927 w
= strtol(p
, (char **)&p
, 10);
2930 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2936 h
= strtol(p
, (char **)&p
, 10);
2941 depth
= strtol(p
, (char **)&p
, 10);
2942 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2943 depth
!= 24 && depth
!= 32)
2945 } else if (*p
== '\0') {
2946 depth
= graphic_depth
;
2953 graphic_depth
= depth
;
2956 case QEMU_OPTION_echr
:
2959 term_escape_char
= strtol(optarg
, &r
, 0);
2961 printf("Bad argument to echr\n");
2964 case QEMU_OPTION_monitor
:
2965 monitor_parse(optarg
, "readline");
2966 default_monitor
= 0;
2968 case QEMU_OPTION_qmp
:
2969 monitor_parse(optarg
, "control");
2970 default_monitor
= 0;
2972 case QEMU_OPTION_mon
:
2973 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2977 default_monitor
= 0;
2979 case QEMU_OPTION_chardev
:
2980 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2985 case QEMU_OPTION_fsdev
:
2986 olist
= qemu_find_opts("fsdev");
2988 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2991 opts
= qemu_opts_parse(olist
, optarg
, 1);
2993 fprintf(stderr
, "parse error: %s\n", optarg
);
2997 case QEMU_OPTION_virtfs
: {
3000 const char *writeout
, *sock_fd
, *socket
;
3002 olist
= qemu_find_opts("virtfs");
3004 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
3007 opts
= qemu_opts_parse(olist
, optarg
, 1);
3009 fprintf(stderr
, "parse error: %s\n", optarg
);
3013 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3014 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3015 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3018 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3019 qemu_opt_get(opts
, "mount_tag"),
3022 fprintf(stderr
, "duplicate fsdev id: %s\n",
3023 qemu_opt_get(opts
, "mount_tag"));
3027 writeout
= qemu_opt_get(opts
, "writeout");
3029 #ifdef CONFIG_SYNC_FILE_RANGE
3030 qemu_opt_set(fsdev
, "writeout", writeout
);
3032 fprintf(stderr
, "writeout=immediate not supported on "
3037 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
3038 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
3039 qemu_opt_set(fsdev
, "security_model",
3040 qemu_opt_get(opts
, "security_model"));
3041 socket
= qemu_opt_get(opts
, "socket");
3043 qemu_opt_set(fsdev
, "socket", socket
);
3045 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3047 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
3050 qemu_opt_set_bool(fsdev
, "readonly",
3051 qemu_opt_get_bool(opts
, "readonly", 0));
3052 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3054 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3055 qemu_opt_set(device
, "fsdev",
3056 qemu_opt_get(opts
, "mount_tag"));
3057 qemu_opt_set(device
, "mount_tag",
3058 qemu_opt_get(opts
, "mount_tag"));
3061 case QEMU_OPTION_virtfs_synth
: {
3065 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3068 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
3071 qemu_opt_set(fsdev
, "fsdriver", "synth");
3073 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3075 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3076 qemu_opt_set(device
, "fsdev", "v_synth");
3077 qemu_opt_set(device
, "mount_tag", "v_synth");
3080 case QEMU_OPTION_serial
:
3081 add_device_config(DEV_SERIAL
, optarg
);
3083 if (strncmp(optarg
, "mon:", 4) == 0) {
3084 default_monitor
= 0;
3087 case QEMU_OPTION_watchdog
:
3090 "qemu: only one watchdog option may be given\n");
3095 case QEMU_OPTION_watchdog_action
:
3096 if (select_watchdog_action(optarg
) == -1) {
3097 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
3101 case QEMU_OPTION_virtiocon
:
3102 add_device_config(DEV_VIRTCON
, optarg
);
3103 default_virtcon
= 0;
3104 if (strncmp(optarg
, "mon:", 4) == 0) {
3105 default_monitor
= 0;
3108 case QEMU_OPTION_parallel
:
3109 add_device_config(DEV_PARALLEL
, optarg
);
3110 default_parallel
= 0;
3111 if (strncmp(optarg
, "mon:", 4) == 0) {
3112 default_monitor
= 0;
3115 case QEMU_OPTION_debugcon
:
3116 add_device_config(DEV_DEBUGCON
, optarg
);
3118 case QEMU_OPTION_loadvm
:
3121 case QEMU_OPTION_full_screen
:
3125 case QEMU_OPTION_no_frame
:
3128 case QEMU_OPTION_alt_grab
:
3131 case QEMU_OPTION_ctrl_grab
:
3134 case QEMU_OPTION_no_quit
:
3137 case QEMU_OPTION_sdl
:
3138 display_type
= DT_SDL
;
3141 case QEMU_OPTION_no_frame
:
3142 case QEMU_OPTION_alt_grab
:
3143 case QEMU_OPTION_ctrl_grab
:
3144 case QEMU_OPTION_no_quit
:
3145 case QEMU_OPTION_sdl
:
3146 fprintf(stderr
, "SDL support is disabled\n");
3149 case QEMU_OPTION_pidfile
:
3152 case QEMU_OPTION_win2k_hack
:
3153 win2k_install_hack
= 1;
3155 case QEMU_OPTION_rtc_td_hack
: {
3156 static GlobalProperty slew_lost_ticks
[] = {
3158 .driver
= "mc146818rtc",
3159 .property
= "lost_tick_policy",
3162 { /* end of list */ }
3165 qdev_prop_register_global_list(slew_lost_ticks
);
3168 case QEMU_OPTION_acpitable
:
3169 do_acpitable_option(optarg
);
3171 case QEMU_OPTION_smbios
:
3172 do_smbios_option(optarg
);
3174 case QEMU_OPTION_enable_kvm
:
3175 olist
= qemu_find_opts("machine");
3176 qemu_opts_parse(olist
, "accel=kvm", 0);
3178 case QEMU_OPTION_machine
:
3179 olist
= qemu_find_opts("machine");
3180 opts
= qemu_opts_parse(olist
, optarg
, 1);
3182 fprintf(stderr
, "parse error: %s\n", optarg
);
3185 optarg
= qemu_opt_get(opts
, "type");
3187 machine
= machine_parse(optarg
);
3190 case QEMU_OPTION_usb
:
3191 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3193 qemu_opt_set_bool(machine_opts
, "usb", true);
3196 case QEMU_OPTION_usbdevice
:
3197 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3199 qemu_opt_set_bool(machine_opts
, "usb", true);
3201 add_device_config(DEV_USB
, optarg
);
3203 case QEMU_OPTION_device
:
3204 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3208 case QEMU_OPTION_smp
:
3211 fprintf(stderr
, "Invalid number of CPUs\n");
3214 if (max_cpus
< smp_cpus
) {
3215 fprintf(stderr
, "maxcpus must be equal to or greater than "
3219 if (max_cpus
> 255) {
3220 fprintf(stderr
, "Unsupported number of maxcpus\n");
3224 case QEMU_OPTION_vnc
:
3227 vnc_display
= optarg
;
3229 fprintf(stderr
, "VNC support is disabled\n");
3233 case QEMU_OPTION_no_acpi
:
3236 case QEMU_OPTION_no_hpet
:
3239 case QEMU_OPTION_balloon
:
3240 if (balloon_parse(optarg
) < 0) {
3241 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3245 case QEMU_OPTION_no_reboot
:
3248 case QEMU_OPTION_no_shutdown
:
3251 case QEMU_OPTION_show_cursor
:
3254 case QEMU_OPTION_uuid
:
3255 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3256 fprintf(stderr
, "Fail to parse UUID string."
3257 " Wrong format.\n");
3261 case QEMU_OPTION_option_rom
:
3262 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3263 fprintf(stderr
, "Too many option ROMs\n");
3266 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3267 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3268 option_rom
[nb_option_roms
].bootindex
=
3269 qemu_opt_get_number(opts
, "bootindex", -1);
3270 if (!option_rom
[nb_option_roms
].name
) {
3271 fprintf(stderr
, "Option ROM file is not specified\n");
3276 case QEMU_OPTION_semihosting
:
3277 semihosting_enabled
= 1;
3279 case QEMU_OPTION_name
:
3280 qemu_name
= g_strdup(optarg
);
3282 char *p
= strchr(qemu_name
, ',');
3285 if (strncmp(p
, "process=", 8)) {
3286 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
3290 os_set_proc_name(p
);
3294 case QEMU_OPTION_prom_env
:
3295 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3296 fprintf(stderr
, "Too many prom variables\n");
3299 prom_envs
[nb_prom_envs
] = optarg
;
3302 case QEMU_OPTION_old_param
:
3305 case QEMU_OPTION_clock
:
3306 configure_alarms(optarg
);
3308 case QEMU_OPTION_startdate
:
3309 configure_rtc_date_offset(optarg
, 1);
3311 case QEMU_OPTION_rtc
:
3312 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3316 configure_rtc(opts
);
3318 case QEMU_OPTION_tb_size
:
3319 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3320 if (tcg_tb_size
< 0) {
3324 case QEMU_OPTION_icount
:
3325 icount_option
= optarg
;
3327 case QEMU_OPTION_incoming
:
3329 runstate_set(RUN_STATE_INMIGRATE
);
3331 case QEMU_OPTION_nodefaults
:
3333 default_parallel
= 0;
3334 default_virtcon
= 0;
3335 default_monitor
= 0;
3342 case QEMU_OPTION_xen_domid
:
3343 if (!(xen_available())) {
3344 printf("Option %s not supported for this target\n", popt
->name
);
3347 xen_domid
= atoi(optarg
);
3349 case QEMU_OPTION_xen_create
:
3350 if (!(xen_available())) {
3351 printf("Option %s not supported for this target\n", popt
->name
);
3354 xen_mode
= XEN_CREATE
;
3356 case QEMU_OPTION_xen_attach
:
3357 if (!(xen_available())) {
3358 printf("Option %s not supported for this target\n", popt
->name
);
3361 xen_mode
= XEN_ATTACH
;
3363 case QEMU_OPTION_trace
:
3365 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3369 trace_events
= qemu_opt_get(opts
, "events");
3370 trace_file
= qemu_opt_get(opts
, "file");
3373 case QEMU_OPTION_readconfig
:
3375 int ret
= qemu_read_config_file(optarg
);
3377 fprintf(stderr
, "read config %s: %s\n", optarg
,
3383 case QEMU_OPTION_spice
:
3384 olist
= qemu_find_opts("spice");
3386 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3389 opts
= qemu_opts_parse(olist
, optarg
, 0);
3391 fprintf(stderr
, "parse error: %s\n", optarg
);
3395 case QEMU_OPTION_writeconfig
:
3398 if (strcmp(optarg
, "-") == 0) {
3401 fp
= fopen(optarg
, "w");
3403 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3407 qemu_config_write(fp
);
3411 case QEMU_OPTION_qtest
:
3412 qtest_chrdev
= optarg
;
3414 case QEMU_OPTION_qtest_log
:
3417 case QEMU_OPTION_sandbox
:
3418 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3423 case QEMU_OPTION_add_fd
:
3425 opts
= qemu_opts_parse(qemu_find_opts("add-fd"), optarg
, 0);
3430 error_report("File descriptor passing is disabled on this "
3436 os_parse_cmd_args(popt
->index
, optarg
);
3442 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
3447 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd
, NULL
, 1)) {
3451 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd
, NULL
, 1)) {
3456 if (machine
== NULL
) {
3457 fprintf(stderr
, "No machine found.\n");
3461 if (machine
->hw_version
) {
3462 qemu_set_version(machine
->hw_version
);
3465 /* Init CPU def lists, based on config
3466 * - Must be called after all the qemu_read_config_file() calls
3467 * - Must be called before list_cpus()
3468 * - Must be called before machine->init()
3472 if (cpu_model
&& is_help_option(cpu_model
)) {
3473 list_cpus(stdout
, &fprintf
, cpu_model
);
3477 /* Open the logfile at this point, if necessary. We can't open the logfile
3478 * when encountering either of the logging options (-d or -D) because the
3479 * other one may be encountered later on the command line, changing the
3480 * location or level of logging.
3484 set_cpu_log_filename(log_file
);
3486 set_cpu_log(log_mask
);
3489 if (!trace_backend_init(trace_events
, trace_file
)) {
3493 /* If no data_dir is specified then try to find it relative to the
3496 data_dir
= os_find_datadir(argv
[0]);
3498 /* If all else fails use the install path specified when building. */
3500 data_dir
= CONFIG_QEMU_DATADIR
;
3504 * Default to max_cpus = smp_cpus, in case the user doesn't
3505 * specify a max_cpus value.
3508 max_cpus
= smp_cpus
;
3510 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
3511 if (smp_cpus
> machine
->max_cpus
) {
3512 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
3513 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
3519 * Get the default machine options from the machine if it is not already
3520 * specified either by the configuration file or by the command line.
3522 if (machine
->default_machine_opts
) {
3523 qemu_opts_set_defaults(qemu_find_opts("machine"),
3524 machine
->default_machine_opts
, 0);
3527 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3528 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3530 if (machine
->no_serial
) {
3533 if (machine
->no_parallel
) {
3534 default_parallel
= 0;
3536 if (!machine
->use_virtcon
) {
3537 default_virtcon
= 0;
3539 if (machine
->no_floppy
) {
3542 if (machine
->no_cdrom
) {
3545 if (machine
->no_sdcard
) {
3549 if (display_type
== DT_NOGRAPHIC
) {
3550 if (default_parallel
)
3551 add_device_config(DEV_PARALLEL
, "null");
3552 if (default_serial
&& default_monitor
) {
3553 add_device_config(DEV_SERIAL
, "mon:stdio");
3554 } else if (default_virtcon
&& default_monitor
) {
3555 add_device_config(DEV_VIRTCON
, "mon:stdio");
3558 add_device_config(DEV_SERIAL
, "stdio");
3559 if (default_virtcon
)
3560 add_device_config(DEV_VIRTCON
, "stdio");
3561 if (default_monitor
)
3562 monitor_parse("stdio", "readline");
3566 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3567 if (default_parallel
)
3568 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3569 if (default_monitor
)
3570 monitor_parse("vc:80Cx24C", "readline");
3571 if (default_virtcon
)
3572 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3575 if (init_timer_alarm() < 0) {
3576 fprintf(stderr
, "could not initialize alarm timer\n");
3582 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3584 #ifdef CONFIG_VIRTFS
3585 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3592 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3597 /* init the memory */
3598 if (ram_size
== 0) {
3599 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3602 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
3607 configure_accelerator();
3609 qemu_init_cpu_loop();
3610 if (qemu_init_main_loop()) {
3611 fprintf(stderr
, "qemu_init_main_loop failed\n");
3615 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3617 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
3618 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
3619 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
3621 kernel_filename
= initrd_filename
= kernel_cmdline
= NULL
;
3624 if (!kernel_cmdline
) {
3625 kernel_cmdline
= "";
3628 linux_boot
= (kernel_filename
!= NULL
);
3630 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3631 fprintf(stderr
, "-append only allowed with -kernel option\n");
3635 if (!linux_boot
&& initrd_filename
!= NULL
) {
3636 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3640 if (!linux_boot
&& machine_opts
&& qemu_opt_get(machine_opts
, "dtb")) {
3641 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
3645 os_set_line_buffering();
3648 /* spice needs the timers to be initialized by this point */
3652 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
3653 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
3656 configure_icount(icount_option
);
3658 if (net_init_clients() < 0) {
3662 /* init the bluetooth world */
3663 if (foreach_device_config(DEV_BT
, bt_parse
))
3666 if (!xen_enabled()) {
3667 /* On 32-bit hosts, QEMU is limited by virtual address space */
3668 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
3669 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
3674 cpu_exec_init_all();
3676 bdrv_init_with_whitelist();
3680 /* open the virtual block devices */
3682 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3683 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3686 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3687 IF_DEFAULT
, 2, CDROM_OPTS
);
3688 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3689 IF_FLOPPY
, 0, FD_OPTS
);
3690 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3693 register_savevm_live(NULL
, "ram", 0, 4, &savevm_ram_handlers
, NULL
);
3695 if (nb_numa_nodes
> 0) {
3698 if (nb_numa_nodes
> MAX_NODES
) {
3699 nb_numa_nodes
= MAX_NODES
;
3702 /* If no memory size if given for any node, assume the default case
3703 * and distribute the available memory equally across all nodes
3705 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3706 if (node_mem
[i
] != 0)
3709 if (i
== nb_numa_nodes
) {
3710 uint64_t usedmem
= 0;
3712 /* On Linux, the each node's border has to be 8MB aligned,
3713 * the final node gets the rest.
3715 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3716 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3717 usedmem
+= node_mem
[i
];
3719 node_mem
[i
] = ram_size
- usedmem
;
3722 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3723 if (!bitmap_empty(node_cpumask
[i
], MAX_CPUMASK_BITS
)) {
3727 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3728 * must cope with this anyway, because there are BIOSes out there in
3729 * real machines which also use this scheme.
3731 if (i
== nb_numa_nodes
) {
3732 for (i
= 0; i
< max_cpus
; i
++) {
3733 set_bit(i
, node_cpumask
[i
% nb_numa_nodes
]);
3738 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3742 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3744 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3746 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3748 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3751 /* If no default VGA is requested, the default is "none". */
3753 if (cirrus_vga_available()) {
3754 vga_model
= "cirrus";
3755 } else if (vga_available()) {
3759 select_vgahw(vga_model
);
3762 i
= select_watchdog(watchdog
);
3764 exit (i
== 1 ? 1 : 0);
3767 if (machine
->compat_props
) {
3768 qdev_prop_register_global_list(machine
->compat_props
);
3772 qdev_machine_init();
3774 QEMUMachineInitArgs args
= { .ram_size
= ram_size
,
3775 .boot_device
= boot_devices
,
3776 .kernel_filename
= kernel_filename
,
3777 .kernel_cmdline
= kernel_cmdline
,
3778 .initrd_filename
= initrd_filename
,
3779 .cpu_model
= cpu_model
};
3780 machine
->init(&args
);
3782 cpu_synchronize_all_post_init();
3786 current_machine
= machine
;
3788 /* init USB devices */
3789 if (usb_enabled(false)) {
3790 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3794 /* init generic devices */
3795 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3798 net_check_clients();
3800 /* just use the first displaystate for the moment */
3801 ds
= get_displaystate();
3805 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3806 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3807 display_type
= DT_SDL
;
3808 #elif defined(CONFIG_VNC)
3809 vnc_display
= "localhost:0,to=99";
3812 display_type
= DT_NONE
;
3817 /* init local displays */
3818 switch (display_type
) {
3821 #if defined(CONFIG_CURSES)
3823 if (!is_daemonized()) {
3824 curses_display_init(ds
, full_screen
);
3828 #if defined(CONFIG_SDL)
3830 sdl_display_init(ds
, full_screen
, no_frame
);
3832 #elif defined(CONFIG_COCOA)
3834 cocoa_display_init(ds
, full_screen
);
3841 /* must be after terminal init, SDL library changes signal handlers */
3842 os_setup_signal_handling();
3845 /* init remote displays */
3847 Error
*local_err
= NULL
;
3848 vnc_display_init(ds
);
3849 vnc_display_open(ds
, vnc_display
, &local_err
);
3850 if (local_err
!= NULL
) {
3851 fprintf(stderr
, "Failed to start VNC server on `%s': %s\n",
3852 vnc_display
, error_get_pretty(local_err
));
3853 error_free(local_err
);
3857 if (show_vnc_port
) {
3858 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3863 if (using_spice
&& !qxl_enabled
) {
3864 qemu_spice_display_init(ds
);
3870 text_consoles_set_display(ds
);
3872 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
3876 qdev_machine_creation_done();
3878 if (rom_load_all() != 0) {
3879 fprintf(stderr
, "rom loading failed\n");
3883 /* TODO: once all bus devices are qdevified, this should be done
3884 * when bus is created by qdev.c */
3885 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3886 qemu_run_machine_init_done_notifiers();
3888 qemu_system_reset(VMRESET_SILENT
);
3890 if (load_vmstate(loadvm
) < 0) {
3896 Error
*local_err
= NULL
;
3897 qemu_start_incoming_migration(incoming
, &local_err
);
3899 fprintf(stderr
, "-incoming %s: %s\n", incoming
, error_get_pretty(local_err
));
3900 error_free(local_err
);
3903 } else if (autostart
) {