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 static int display_remote
;
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;
217 static int no_reboot
;
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 static QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
=
246 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_PAUSED
},
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 static 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 /*********QEMU USB setting******/
794 bool usb_enabled(bool default_usb
)
797 mach_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
799 return qemu_opt_get_bool(mach_opts
, "usb", default_usb
);
805 static int parse_add_fd(QemuOpts
*opts
, void *opaque
)
807 int fd
, dupfd
, flags
;
809 const char *fd_opaque
= NULL
;
811 fd
= qemu_opt_get_number(opts
, "fd", -1);
812 fdset_id
= qemu_opt_get_number(opts
, "set", -1);
813 fd_opaque
= qemu_opt_get(opts
, "opaque");
816 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
817 "fd option is required and must be non-negative");
821 if (fd
<= STDERR_FILENO
) {
822 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
823 "fd cannot be a standard I/O stream");
828 * All fds inherited across exec() necessarily have FD_CLOEXEC
829 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
831 flags
= fcntl(fd
, F_GETFD
);
832 if (flags
== -1 || (flags
& FD_CLOEXEC
)) {
833 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
834 "fd is not valid or already in use");
839 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
840 "set option is required and must be non-negative");
844 #ifdef F_DUPFD_CLOEXEC
845 dupfd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 0);
849 qemu_set_cloexec(dupfd
);
853 qerror_report(ERROR_CLASS_GENERIC_ERROR
,
854 "Error duplicating fd: %s", strerror(errno
));
858 /* add the duplicate fd, and optionally the opaque string, to the fd set */
859 monitor_fdset_add_fd(dupfd
, true, fdset_id
, fd_opaque
? true : false,
865 static int cleanup_add_fd(QemuOpts
*opts
, void *opaque
)
869 fd
= qemu_opt_get_number(opts
, "fd", -1);
876 /***********************************************************/
877 /* QEMU Block devices */
879 #define HD_OPTS "media=disk"
880 #define CDROM_OPTS "media=cdrom"
882 #define PFLASH_OPTS ""
886 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
888 int *use_scsi
= opaque
;
890 return drive_init(opts
, *use_scsi
) == NULL
;
893 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
895 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
896 qemu_opt_set(opts
, "snapshot", "on");
901 static void default_drive(int enable
, int snapshot
, int use_scsi
,
902 BlockInterfaceType type
, int index
,
907 if (type
== IF_DEFAULT
) {
908 type
= use_scsi
? IF_SCSI
: IF_IDE
;
911 if (!enable
|| drive_get_by_index(type
, index
)) {
915 opts
= drive_add(type
, index
, NULL
, optstr
);
917 drive_enable_snapshot(opts
, NULL
);
919 if (!drive_init(opts
, use_scsi
)) {
924 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
926 boot_set_handler
= func
;
927 boot_set_opaque
= opaque
;
930 int qemu_boot_set(const char *boot_devices
)
932 if (!boot_set_handler
) {
935 return boot_set_handler(boot_set_opaque
, boot_devices
);
938 static void validate_bootdevices(char *devices
)
940 /* We just do some generic consistency checks */
944 for (p
= devices
; *p
!= '\0'; p
++) {
945 /* Allowed boot devices are:
946 * a-b: floppy disk drives
947 * c-f: IDE disk drives
948 * g-m: machine implementation dependent drives
949 * n-p: network devices
950 * It's up to each machine implementation to check if the given boot
951 * devices match the actual hardware implementation and firmware
954 if (*p
< 'a' || *p
> 'p') {
955 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
958 if (bitmap
& (1 << (*p
- 'a'))) {
959 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
962 bitmap
|= 1 << (*p
- 'a');
966 static void restore_boot_devices(void *opaque
)
968 char *standard_boot_devices
= opaque
;
969 static int first
= 1;
971 /* Restore boot order and remove ourselves after the first boot */
977 qemu_boot_set(standard_boot_devices
);
979 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
980 g_free(standard_boot_devices
);
983 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
986 FWBootEntry
*node
, *i
;
992 assert(dev
!= NULL
|| suffix
!= NULL
);
994 node
= g_malloc0(sizeof(FWBootEntry
));
995 node
->bootindex
= bootindex
;
996 node
->suffix
= suffix
? g_strdup(suffix
) : NULL
;
999 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1000 if (i
->bootindex
== bootindex
) {
1001 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
1003 } else if (i
->bootindex
< bootindex
) {
1006 QTAILQ_INSERT_BEFORE(i
, node
, link
);
1009 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
1013 * This function returns null terminated string that consist of new line
1014 * separated device paths.
1016 * memory pointed by "size" is assigned total length of the array in bytes
1019 char *get_boot_devices_list(uint32_t *size
)
1025 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
1026 char *devpath
= NULL
, *bootpath
;
1030 devpath
= qdev_get_fw_dev_path(i
->dev
);
1034 if (i
->suffix
&& devpath
) {
1035 size_t bootpathlen
= strlen(devpath
) + strlen(i
->suffix
) + 1;
1037 bootpath
= g_malloc(bootpathlen
);
1038 snprintf(bootpath
, bootpathlen
, "%s%s", devpath
, i
->suffix
);
1040 } else if (devpath
) {
1044 bootpath
= g_strdup(i
->suffix
);
1048 list
[total
-1] = '\n';
1050 len
= strlen(bootpath
) + 1;
1051 list
= g_realloc(list
, total
+ len
);
1052 memcpy(&list
[total
], bootpath
, len
);
1062 static void numa_add(const char *optarg
)
1066 unsigned long long value
, endvalue
;
1069 value
= endvalue
= 0ULL;
1071 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
1072 if (!strcmp(option
, "node")) {
1073 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
1074 nodenr
= nb_numa_nodes
;
1076 nodenr
= strtoull(option
, NULL
, 10);
1079 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
1080 node_mem
[nodenr
] = 0;
1083 sval
= strtosz(option
, &endptr
);
1084 if (sval
< 0 || *endptr
) {
1085 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
1088 node_mem
[nodenr
] = sval
;
1090 if (get_param_value(option
, 128, "cpus", optarg
) != 0) {
1091 value
= strtoull(option
, &endptr
, 10);
1092 if (*endptr
== '-') {
1093 endvalue
= strtoull(endptr
+1, &endptr
, 10);
1098 if (!(endvalue
< MAX_CPUMASK_BITS
)) {
1099 endvalue
= MAX_CPUMASK_BITS
- 1;
1101 "A max of %d CPUs are supported in a guest\n",
1105 bitmap_set(node_cpumask
[nodenr
], value
, endvalue
-value
+1);
1111 static void smp_parse(const char *optarg
)
1113 int smp
, sockets
= 0, threads
= 0, cores
= 0;
1117 smp
= strtoul(optarg
, &endptr
, 10);
1118 if (endptr
!= optarg
) {
1119 if (*endptr
== ',') {
1123 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
1124 sockets
= strtoull(option
, NULL
, 10);
1125 if (get_param_value(option
, 128, "cores", endptr
) != 0)
1126 cores
= strtoull(option
, NULL
, 10);
1127 if (get_param_value(option
, 128, "threads", endptr
) != 0)
1128 threads
= strtoull(option
, NULL
, 10);
1129 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
1130 max_cpus
= strtoull(option
, NULL
, 10);
1132 /* compute missing values, prefer sockets over cores over threads */
1133 if (smp
== 0 || sockets
== 0) {
1134 sockets
= sockets
> 0 ? sockets
: 1;
1135 cores
= cores
> 0 ? cores
: 1;
1136 threads
= threads
> 0 ? threads
: 1;
1138 smp
= cores
* threads
* sockets
;
1142 threads
= threads
> 0 ? threads
: 1;
1143 cores
= smp
/ (sockets
* threads
);
1145 threads
= smp
/ (cores
* sockets
);
1149 smp_cores
= cores
> 0 ? cores
: 1;
1150 smp_threads
= threads
> 0 ? threads
: 1;
1152 max_cpus
= smp_cpus
;
1155 /***********************************************************/
1158 static int usb_device_add(const char *devname
)
1161 USBDevice
*dev
= NULL
;
1163 if (!usb_enabled(false)) {
1167 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1168 dev
= usbdevice_create(devname
);
1172 /* the other ones */
1173 #ifndef CONFIG_LINUX
1174 /* only the linux version is qdev-ified, usb-bsd still needs this */
1175 if (strstart(devname
, "host:", &p
)) {
1176 dev
= usb_host_device_open(usb_bus_find(-1), p
);
1179 if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
1180 dev
= usb_bt_init(usb_bus_find(-1),
1181 devname
[2] ? hci_init(p
)
1182 : bt_new_hci(qemu_find_bt_vlan(0)));
1193 static int usb_device_del(const char *devname
)
1198 if (strstart(devname
, "host:", &p
))
1199 return usb_host_device_close(p
);
1201 if (!usb_enabled(false)) {
1205 p
= strchr(devname
, '.');
1208 bus_num
= strtoul(devname
, NULL
, 0);
1209 addr
= strtoul(p
+ 1, NULL
, 0);
1211 return usb_device_delete_addr(bus_num
, addr
);
1214 static int usb_parse(const char *cmdline
)
1217 r
= usb_device_add(cmdline
);
1219 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
1224 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
1226 const char *devname
= qdict_get_str(qdict
, "devname");
1227 if (usb_device_add(devname
) < 0) {
1228 error_report("could not add USB device '%s'", devname
);
1232 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
1234 const char *devname
= qdict_get_str(qdict
, "devname");
1235 if (usb_device_del(devname
) < 0) {
1236 error_report("could not delete USB device '%s'", devname
);
1240 /***********************************************************/
1241 /* PCMCIA/Cardbus */
1243 static struct pcmcia_socket_entry_s
{
1244 PCMCIASocket
*socket
;
1245 struct pcmcia_socket_entry_s
*next
;
1246 } *pcmcia_sockets
= 0;
1248 void pcmcia_socket_register(PCMCIASocket
*socket
)
1250 struct pcmcia_socket_entry_s
*entry
;
1252 entry
= g_malloc(sizeof(struct pcmcia_socket_entry_s
));
1253 entry
->socket
= socket
;
1254 entry
->next
= pcmcia_sockets
;
1255 pcmcia_sockets
= entry
;
1258 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
1260 struct pcmcia_socket_entry_s
*entry
, **ptr
;
1262 ptr
= &pcmcia_sockets
;
1263 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
1264 if (entry
->socket
== socket
) {
1270 void pcmcia_info(Monitor
*mon
)
1272 struct pcmcia_socket_entry_s
*iter
;
1274 if (!pcmcia_sockets
)
1275 monitor_printf(mon
, "No PCMCIA sockets\n");
1277 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
1278 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
1279 iter
->socket
->attached
? iter
->socket
->card_string
:
1283 /***********************************************************/
1284 /* machine registration */
1286 static QEMUMachine
*first_machine
= NULL
;
1287 QEMUMachine
*current_machine
= NULL
;
1289 int qemu_register_machine(QEMUMachine
*m
)
1292 pm
= &first_machine
;
1300 static QEMUMachine
*find_machine(const char *name
)
1304 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1305 if (!strcmp(m
->name
, name
))
1307 if (m
->alias
&& !strcmp(m
->alias
, name
))
1313 QEMUMachine
*find_default_machine(void)
1317 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1318 if (m
->is_default
) {
1325 MachineInfoList
*qmp_query_machines(Error
**errp
)
1327 MachineInfoList
*mach_list
= NULL
;
1330 for (m
= first_machine
; m
; m
= m
->next
) {
1331 MachineInfoList
*entry
;
1334 info
= g_malloc0(sizeof(*info
));
1335 if (m
->is_default
) {
1336 info
->has_is_default
= true;
1337 info
->is_default
= true;
1341 info
->has_alias
= true;
1342 info
->alias
= g_strdup(m
->alias
);
1345 info
->name
= g_strdup(m
->name
);
1347 entry
= g_malloc0(sizeof(*entry
));
1348 entry
->value
= info
;
1349 entry
->next
= mach_list
;
1356 /***********************************************************/
1357 /* main execution loop */
1359 static void gui_update(void *opaque
)
1361 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1362 DisplayState
*ds
= opaque
;
1363 DisplayChangeListener
*dcl
;
1367 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1368 if (dcl
->gui_timer_interval
&&
1369 dcl
->gui_timer_interval
< interval
)
1370 interval
= dcl
->gui_timer_interval
;
1372 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock_ms(rt_clock
));
1375 void gui_setup_refresh(DisplayState
*ds
)
1377 DisplayChangeListener
*dcl
;
1378 bool need_timer
= false;
1379 bool have_gfx
= false;
1380 bool have_text
= false;
1382 QLIST_FOREACH(dcl
, &ds
->listeners
, next
) {
1383 if (dcl
->dpy_refresh
!= NULL
) {
1386 if (dcl
->dpy_gfx_update
!= NULL
) {
1389 if (dcl
->dpy_text_update
!= NULL
) {
1394 if (need_timer
&& ds
->gui_timer
== NULL
) {
1395 ds
->gui_timer
= qemu_new_timer_ms(rt_clock
, gui_update
, ds
);
1396 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock_ms(rt_clock
));
1398 if (!need_timer
&& ds
->gui_timer
!= NULL
) {
1399 qemu_del_timer(ds
->gui_timer
);
1400 qemu_free_timer(ds
->gui_timer
);
1401 ds
->gui_timer
= NULL
;
1404 ds
->have_gfx
= have_gfx
;
1405 ds
->have_text
= have_text
;
1408 struct vm_change_state_entry
{
1409 VMChangeStateHandler
*cb
;
1411 QLIST_ENTRY (vm_change_state_entry
) entries
;
1414 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1416 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1419 VMChangeStateEntry
*e
;
1421 e
= g_malloc0(sizeof (*e
));
1425 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1429 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1431 QLIST_REMOVE (e
, entries
);
1435 void vm_state_notify(int running
, RunState state
)
1437 VMChangeStateEntry
*e
;
1439 trace_vm_state_notify(running
, state
);
1441 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1442 e
->cb(e
->opaque
, running
, state
);
1448 if (!runstate_is_running()) {
1450 runstate_set(RUN_STATE_RUNNING
);
1451 vm_state_notify(1, RUN_STATE_RUNNING
);
1453 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1457 /* reset/shutdown handler */
1459 typedef struct QEMUResetEntry
{
1460 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1461 QEMUResetHandler
*func
;
1465 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1466 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1467 static int reset_requested
;
1468 static int shutdown_requested
, shutdown_signal
= -1;
1469 static pid_t shutdown_pid
;
1470 static int powerdown_requested
;
1471 static int debug_requested
;
1472 static int suspend_requested
;
1473 static int wakeup_requested
;
1474 static NotifierList powerdown_notifiers
=
1475 NOTIFIER_LIST_INITIALIZER(powerdown_notifiers
);
1476 static NotifierList suspend_notifiers
=
1477 NOTIFIER_LIST_INITIALIZER(suspend_notifiers
);
1478 static NotifierList wakeup_notifiers
=
1479 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers
);
1480 static uint32_t wakeup_reason_mask
= ~0;
1481 static RunState vmstop_requested
= RUN_STATE_MAX
;
1483 int qemu_shutdown_requested_get(void)
1485 return shutdown_requested
;
1488 int qemu_reset_requested_get(void)
1490 return reset_requested
;
1493 static int qemu_shutdown_requested(void)
1495 int r
= shutdown_requested
;
1496 shutdown_requested
= 0;
1500 static void qemu_kill_report(void)
1502 if (!qtest_enabled() && shutdown_signal
!= -1) {
1503 fprintf(stderr
, "qemu: terminating on signal %d", shutdown_signal
);
1504 if (shutdown_pid
== 0) {
1505 /* This happens for eg ^C at the terminal, so it's worth
1506 * avoiding printing an odd message in that case.
1508 fputc('\n', stderr
);
1510 fprintf(stderr
, " from pid " FMT_pid
"\n", shutdown_pid
);
1512 shutdown_signal
= -1;
1516 static int qemu_reset_requested(void)
1518 int r
= reset_requested
;
1519 reset_requested
= 0;
1523 static int qemu_suspend_requested(void)
1525 int r
= suspend_requested
;
1526 suspend_requested
= 0;
1530 static int qemu_wakeup_requested(void)
1532 int r
= wakeup_requested
;
1533 wakeup_requested
= 0;
1537 static int qemu_powerdown_requested(void)
1539 int r
= powerdown_requested
;
1540 powerdown_requested
= 0;
1544 static int qemu_debug_requested(void)
1546 int r
= debug_requested
;
1547 debug_requested
= 0;
1551 /* We use RUN_STATE_MAX but any invalid value will do */
1552 static bool qemu_vmstop_requested(RunState
*r
)
1554 if (vmstop_requested
< RUN_STATE_MAX
) {
1555 *r
= vmstop_requested
;
1556 vmstop_requested
= RUN_STATE_MAX
;
1563 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1565 QEMUResetEntry
*re
= g_malloc0(sizeof(QEMUResetEntry
));
1568 re
->opaque
= opaque
;
1569 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1572 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1576 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1577 if (re
->func
== func
&& re
->opaque
== opaque
) {
1578 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1585 void qemu_devices_reset(void)
1587 QEMUResetEntry
*re
, *nre
;
1589 /* reset all devices */
1590 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1591 re
->func(re
->opaque
);
1595 void qemu_system_reset(bool report
)
1597 if (current_machine
&& current_machine
->reset
) {
1598 current_machine
->reset();
1600 qemu_devices_reset();
1603 monitor_protocol_event(QEVENT_RESET
, NULL
);
1605 cpu_synchronize_all_post_reset();
1608 void qemu_system_reset_request(void)
1611 shutdown_requested
= 1;
1613 reset_requested
= 1;
1616 qemu_notify_event();
1619 static void qemu_system_suspend(void)
1622 notifier_list_notify(&suspend_notifiers
, NULL
);
1623 runstate_set(RUN_STATE_SUSPENDED
);
1624 monitor_protocol_event(QEVENT_SUSPEND
, NULL
);
1627 void qemu_system_suspend_request(void)
1629 if (runstate_check(RUN_STATE_SUSPENDED
)) {
1632 suspend_requested
= 1;
1634 qemu_notify_event();
1637 void qemu_register_suspend_notifier(Notifier
*notifier
)
1639 notifier_list_add(&suspend_notifiers
, notifier
);
1642 void qemu_system_wakeup_request(WakeupReason reason
)
1644 if (!runstate_check(RUN_STATE_SUSPENDED
)) {
1647 if (!(wakeup_reason_mask
& (1 << reason
))) {
1650 runstate_set(RUN_STATE_RUNNING
);
1651 notifier_list_notify(&wakeup_notifiers
, &reason
);
1652 wakeup_requested
= 1;
1653 qemu_notify_event();
1656 void qemu_system_wakeup_enable(WakeupReason reason
, bool enabled
)
1659 wakeup_reason_mask
|= (1 << reason
);
1661 wakeup_reason_mask
&= ~(1 << reason
);
1665 void qemu_register_wakeup_notifier(Notifier
*notifier
)
1667 notifier_list_add(&wakeup_notifiers
, notifier
);
1670 void qemu_system_killed(int signal
, pid_t pid
)
1672 shutdown_signal
= signal
;
1675 qemu_system_shutdown_request();
1678 void qemu_system_shutdown_request(void)
1680 shutdown_requested
= 1;
1681 qemu_notify_event();
1684 static void qemu_system_powerdown(void)
1686 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1687 notifier_list_notify(&powerdown_notifiers
, NULL
);
1690 void qemu_system_powerdown_request(void)
1692 powerdown_requested
= 1;
1693 qemu_notify_event();
1696 void qemu_register_powerdown_notifier(Notifier
*notifier
)
1698 notifier_list_add(&powerdown_notifiers
, notifier
);
1701 void qemu_system_debug_request(void)
1703 debug_requested
= 1;
1704 qemu_notify_event();
1707 void qemu_system_vmstop_request(RunState state
)
1709 vmstop_requested
= state
;
1710 qemu_notify_event();
1713 static bool main_loop_should_exit(void)
1716 if (qemu_debug_requested()) {
1717 vm_stop(RUN_STATE_DEBUG
);
1719 if (qemu_suspend_requested()) {
1720 qemu_system_suspend();
1722 if (qemu_shutdown_requested()) {
1724 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1726 vm_stop(RUN_STATE_SHUTDOWN
);
1731 if (qemu_reset_requested()) {
1733 cpu_synchronize_all_states();
1734 qemu_system_reset(VMRESET_REPORT
);
1736 if (runstate_check(RUN_STATE_INTERNAL_ERROR
) ||
1737 runstate_check(RUN_STATE_SHUTDOWN
)) {
1738 runstate_set(RUN_STATE_PAUSED
);
1741 if (qemu_wakeup_requested()) {
1743 cpu_synchronize_all_states();
1744 qemu_system_reset(VMRESET_SILENT
);
1746 monitor_protocol_event(QEVENT_WAKEUP
, NULL
);
1748 if (qemu_powerdown_requested()) {
1749 qemu_system_powerdown();
1751 if (qemu_vmstop_requested(&r
)) {
1757 static void main_loop(void)
1761 #ifdef CONFIG_PROFILER
1765 nonblocking
= !kvm_enabled() && last_io
> 0;
1766 #ifdef CONFIG_PROFILER
1767 ti
= profile_getclock();
1769 last_io
= main_loop_wait(nonblocking
);
1770 #ifdef CONFIG_PROFILER
1771 dev_time
+= profile_getclock() - ti
;
1773 } while (!main_loop_should_exit());
1776 static void version(void)
1778 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1781 static void help(int exitcode
)
1784 printf("usage: %s [options] [disk_image]\n\n"
1785 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1786 error_get_progname());
1788 #define QEMU_OPTIONS_GENERATE_HELP
1789 #include "qemu-options-wrapper.h"
1791 printf("\nDuring emulation, the following keys are useful:\n"
1792 "ctrl-alt-f toggle full screen\n"
1793 "ctrl-alt-n switch to virtual console 'n'\n"
1794 "ctrl-alt toggle mouse and keyboard grab\n"
1796 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1801 #define HAS_ARG 0x0001
1803 typedef struct QEMUOption
{
1810 static const QEMUOption qemu_options
[] = {
1811 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1812 #define QEMU_OPTIONS_GENERATE_OPTIONS
1813 #include "qemu-options-wrapper.h"
1817 static bool vga_available(void)
1819 return object_class_by_name("VGA") || object_class_by_name("isa-vga");
1822 static bool cirrus_vga_available(void)
1824 return object_class_by_name("cirrus-vga")
1825 || object_class_by_name("isa-cirrus-vga");
1828 static bool vmware_vga_available(void)
1830 return object_class_by_name("vmware-svga");
1833 static bool qxl_vga_available(void)
1835 return object_class_by_name("qxl-vga");
1838 static void select_vgahw (const char *p
)
1842 vga_interface_type
= VGA_NONE
;
1843 if (strstart(p
, "std", &opts
)) {
1844 if (vga_available()) {
1845 vga_interface_type
= VGA_STD
;
1847 fprintf(stderr
, "Error: standard VGA not available\n");
1850 } else if (strstart(p
, "cirrus", &opts
)) {
1851 if (cirrus_vga_available()) {
1852 vga_interface_type
= VGA_CIRRUS
;
1854 fprintf(stderr
, "Error: Cirrus VGA not available\n");
1857 } else if (strstart(p
, "vmware", &opts
)) {
1858 if (vmware_vga_available()) {
1859 vga_interface_type
= VGA_VMWARE
;
1861 fprintf(stderr
, "Error: VMWare SVGA not available\n");
1864 } else if (strstart(p
, "xenfb", &opts
)) {
1865 vga_interface_type
= VGA_XENFB
;
1866 } else if (strstart(p
, "qxl", &opts
)) {
1867 if (qxl_vga_available()) {
1868 vga_interface_type
= VGA_QXL
;
1870 fprintf(stderr
, "Error: QXL VGA not available\n");
1873 } else if (!strstart(p
, "none", &opts
)) {
1875 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1879 const char *nextopt
;
1881 if (strstart(opts
, ",retrace=", &nextopt
)) {
1883 if (strstart(opts
, "dumb", &nextopt
))
1884 vga_retrace_method
= VGA_RETRACE_DUMB
;
1885 else if (strstart(opts
, "precise", &nextopt
))
1886 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1887 else goto invalid_vga
;
1888 } else goto invalid_vga
;
1893 static DisplayType
select_display(const char *p
)
1896 DisplayType display
= DT_DEFAULT
;
1898 if (strstart(p
, "sdl", &opts
)) {
1902 const char *nextopt
;
1904 if (strstart(opts
, ",frame=", &nextopt
)) {
1906 if (strstart(opts
, "on", &nextopt
)) {
1908 } else if (strstart(opts
, "off", &nextopt
)) {
1911 goto invalid_sdl_args
;
1913 } else if (strstart(opts
, ",alt_grab=", &nextopt
)) {
1915 if (strstart(opts
, "on", &nextopt
)) {
1917 } else if (strstart(opts
, "off", &nextopt
)) {
1920 goto invalid_sdl_args
;
1922 } else if (strstart(opts
, ",ctrl_grab=", &nextopt
)) {
1924 if (strstart(opts
, "on", &nextopt
)) {
1926 } else if (strstart(opts
, "off", &nextopt
)) {
1929 goto invalid_sdl_args
;
1931 } else if (strstart(opts
, ",window_close=", &nextopt
)) {
1933 if (strstart(opts
, "on", &nextopt
)) {
1935 } else if (strstart(opts
, "off", &nextopt
)) {
1938 goto invalid_sdl_args
;
1942 fprintf(stderr
, "Invalid SDL option string: %s\n", p
);
1948 fprintf(stderr
, "SDL support is disabled\n");
1951 } else if (strstart(p
, "vnc", &opts
)) {
1956 const char *nextopt
;
1958 if (strstart(opts
, "=", &nextopt
)) {
1959 vnc_display
= nextopt
;
1963 fprintf(stderr
, "VNC requires a display argument vnc=<display>\n");
1967 fprintf(stderr
, "VNC support is disabled\n");
1970 } else if (strstart(p
, "curses", &opts
)) {
1971 #ifdef CONFIG_CURSES
1972 display
= DT_CURSES
;
1974 fprintf(stderr
, "Curses support is disabled\n");
1977 } else if (strstart(p
, "none", &opts
)) {
1980 fprintf(stderr
, "Unknown display type: %s\n", p
);
1987 static int balloon_parse(const char *arg
)
1991 if (strcmp(arg
, "none") == 0) {
1995 if (!strncmp(arg
, "virtio", 6)) {
1996 if (arg
[6] == ',') {
1997 /* have params -> parse them */
1998 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
2002 /* create empty opts */
2003 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0, NULL
);
2005 qemu_opt_set(opts
, "driver", "virtio-balloon");
2012 char *qemu_find_file(int type
, const char *name
)
2018 /* Try the name as a straight path first */
2019 if (access(name
, R_OK
) == 0) {
2020 return g_strdup(name
);
2023 case QEMU_FILE_TYPE_BIOS
:
2026 case QEMU_FILE_TYPE_KEYMAP
:
2027 subdir
= "keymaps/";
2032 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
2033 buf
= g_malloc0(len
);
2034 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
2035 if (access(buf
, R_OK
)) {
2042 static int device_help_func(QemuOpts
*opts
, void *opaque
)
2044 return qdev_device_help(opts
);
2047 static int device_init_func(QemuOpts
*opts
, void *opaque
)
2051 dev
= qdev_device_add(opts
);
2057 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
2059 CharDriverState
*chr
;
2061 chr
= qemu_chr_new_from_opts(opts
, NULL
);
2067 #ifdef CONFIG_VIRTFS
2068 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
2071 ret
= qemu_fsdev_add(opts
);
2077 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
2079 CharDriverState
*chr
;
2080 const char *chardev
;
2084 mode
= qemu_opt_get(opts
, "mode");
2088 if (strcmp(mode
, "readline") == 0) {
2089 flags
= MONITOR_USE_READLINE
;
2090 } else if (strcmp(mode
, "control") == 0) {
2091 flags
= MONITOR_USE_CONTROL
;
2093 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
2097 if (qemu_opt_get_bool(opts
, "pretty", 0))
2098 flags
|= MONITOR_USE_PRETTY
;
2100 if (qemu_opt_get_bool(opts
, "default", 0))
2101 flags
|= MONITOR_IS_DEFAULT
;
2103 chardev
= qemu_opt_get(opts
, "chardev");
2104 chr
= qemu_chr_find(chardev
);
2106 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
2110 monitor_init(chr
, flags
);
2114 static void monitor_parse(const char *optarg
, const char *mode
)
2116 static int monitor_device_index
= 0;
2122 if (strstart(optarg
, "chardev:", &p
)) {
2123 snprintf(label
, sizeof(label
), "%s", p
);
2125 snprintf(label
, sizeof(label
), "compat_monitor%d",
2126 monitor_device_index
);
2127 if (monitor_device_index
== 0) {
2130 opts
= qemu_chr_parse_compat(label
, optarg
);
2132 fprintf(stderr
, "parse error: %s\n", optarg
);
2137 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1, NULL
);
2139 fprintf(stderr
, "duplicate chardev: %s\n", label
);
2142 qemu_opt_set(opts
, "mode", mode
);
2143 qemu_opt_set(opts
, "chardev", label
);
2145 qemu_opt_set(opts
, "default", "on");
2146 monitor_device_index
++;
2149 struct device_config
{
2151 DEV_USB
, /* -usbdevice */
2153 DEV_SERIAL
, /* -serial */
2154 DEV_PARALLEL
, /* -parallel */
2155 DEV_VIRTCON
, /* -virtioconsole */
2156 DEV_DEBUGCON
, /* -debugcon */
2157 DEV_GDB
, /* -gdb, -s */
2159 const char *cmdline
;
2161 QTAILQ_ENTRY(device_config
) next
;
2164 static QTAILQ_HEAD(, device_config
) device_configs
=
2165 QTAILQ_HEAD_INITIALIZER(device_configs
);
2167 static void add_device_config(int type
, const char *cmdline
)
2169 struct device_config
*conf
;
2171 conf
= g_malloc0(sizeof(*conf
));
2173 conf
->cmdline
= cmdline
;
2174 loc_save(&conf
->loc
);
2175 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
2178 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
2180 struct device_config
*conf
;
2183 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
2184 if (conf
->type
!= type
)
2186 loc_push_restore(&conf
->loc
);
2187 rc
= func(conf
->cmdline
);
2188 loc_pop(&conf
->loc
);
2195 static int serial_parse(const char *devname
)
2197 static int index
= 0;
2200 if (strcmp(devname
, "none") == 0)
2202 if (index
== MAX_SERIAL_PORTS
) {
2203 fprintf(stderr
, "qemu: too many serial ports\n");
2206 snprintf(label
, sizeof(label
), "serial%d", index
);
2207 serial_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2208 if (!serial_hds
[index
]) {
2209 fprintf(stderr
, "qemu: could not connect serial device"
2210 " to character backend '%s'\n", devname
);
2217 static int parallel_parse(const char *devname
)
2219 static int index
= 0;
2222 if (strcmp(devname
, "none") == 0)
2224 if (index
== MAX_PARALLEL_PORTS
) {
2225 fprintf(stderr
, "qemu: too many parallel ports\n");
2228 snprintf(label
, sizeof(label
), "parallel%d", index
);
2229 parallel_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2230 if (!parallel_hds
[index
]) {
2231 fprintf(stderr
, "qemu: could not connect parallel device"
2232 " to character backend '%s'\n", devname
);
2239 static int virtcon_parse(const char *devname
)
2241 QemuOptsList
*device
= qemu_find_opts("device");
2242 static int index
= 0;
2244 QemuOpts
*bus_opts
, *dev_opts
;
2246 if (strcmp(devname
, "none") == 0)
2248 if (index
== MAX_VIRTIO_CONSOLES
) {
2249 fprintf(stderr
, "qemu: too many virtio consoles\n");
2253 bus_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2254 if (arch_type
== QEMU_ARCH_S390X
) {
2255 qemu_opt_set(bus_opts
, "driver", "virtio-serial-s390");
2257 qemu_opt_set(bus_opts
, "driver", "virtio-serial-pci");
2260 dev_opts
= qemu_opts_create(device
, NULL
, 0, NULL
);
2261 qemu_opt_set(dev_opts
, "driver", "virtconsole");
2263 snprintf(label
, sizeof(label
), "virtcon%d", index
);
2264 virtcon_hds
[index
] = qemu_chr_new(label
, devname
, NULL
);
2265 if (!virtcon_hds
[index
]) {
2266 fprintf(stderr
, "qemu: could not connect virtio console"
2267 " to character backend '%s'\n", devname
);
2270 qemu_opt_set(dev_opts
, "chardev", label
);
2276 static int debugcon_parse(const char *devname
)
2280 if (!qemu_chr_new("debugcon", devname
, NULL
)) {
2283 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL
);
2285 fprintf(stderr
, "qemu: already have a debugcon device\n");
2288 qemu_opt_set(opts
, "driver", "isa-debugcon");
2289 qemu_opt_set(opts
, "chardev", "debugcon");
2293 static QEMUMachine
*machine_parse(const char *name
)
2295 QEMUMachine
*m
, *machine
= NULL
;
2298 machine
= find_machine(name
);
2303 printf("Supported machines are:\n");
2304 for (m
= first_machine
; m
!= NULL
; m
= m
->next
) {
2306 printf("%-20s %s (alias of %s)\n", m
->alias
, m
->desc
, m
->name
);
2308 printf("%-20s %s%s\n", m
->name
, m
->desc
,
2309 m
->is_default
? " (default)" : "");
2311 exit(!name
|| !is_help_option(name
));
2314 static int tcg_init(void)
2316 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
2321 const char *opt_name
;
2323 int (*available
)(void);
2327 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
2328 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
2329 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
2330 { "qtest", "QTest", qtest_available
, qtest_init
, &qtest_allowed
},
2333 static int configure_accelerator(void)
2335 const char *p
= NULL
;
2338 bool accel_initialised
= 0;
2339 bool init_failed
= 0;
2341 QemuOptsList
*list
= qemu_find_opts("machine");
2342 if (!QTAILQ_EMPTY(&list
->head
)) {
2343 p
= qemu_opt_get(QTAILQ_FIRST(&list
->head
), "accel");
2347 /* Use the default "accelerator", tcg */
2351 while (!accel_initialised
&& *p
!= '\0') {
2355 p
= get_opt_name(buf
, sizeof (buf
), p
, ':');
2356 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
2357 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
2358 *(accel_list
[i
].allowed
) = 1;
2359 ret
= accel_list
[i
].init();
2362 if (!accel_list
[i
].available()) {
2363 printf("%s not supported for this target\n",
2364 accel_list
[i
].name
);
2366 fprintf(stderr
, "failed to initialize %s: %s\n",
2370 *(accel_list
[i
].allowed
) = 0;
2372 accel_initialised
= 1;
2377 if (i
== ARRAY_SIZE(accel_list
)) {
2378 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
2382 if (!accel_initialised
) {
2383 fprintf(stderr
, "No accelerator found!\n");
2388 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
2391 return !accel_initialised
;
2394 void qemu_add_exit_notifier(Notifier
*notify
)
2396 notifier_list_add(&exit_notifiers
, notify
);
2399 void qemu_remove_exit_notifier(Notifier
*notify
)
2401 notifier_remove(notify
);
2404 static void qemu_run_exit_notifiers(void)
2406 notifier_list_notify(&exit_notifiers
, NULL
);
2409 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
2411 notifier_list_add(&machine_init_done_notifiers
, notify
);
2414 static void qemu_run_machine_init_done_notifiers(void)
2416 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
2419 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
2420 const char **poptarg
, int *poptind
)
2422 const QEMUOption
*popt
;
2423 int optind
= *poptind
;
2424 char *r
= argv
[optind
];
2427 loc_set_cmdline(argv
, optind
, 1);
2429 /* Treat --foo the same as -foo. */
2432 popt
= qemu_options
;
2435 error_report("invalid option");
2438 if (!strcmp(popt
->name
, r
+ 1))
2442 if (popt
->flags
& HAS_ARG
) {
2443 if (optind
>= argc
) {
2444 error_report("requires an argument");
2447 optarg
= argv
[optind
++];
2448 loc_set_cmdline(argv
, optind
- 2, 2);
2459 static gpointer
malloc_and_trace(gsize n_bytes
)
2461 void *ptr
= malloc(n_bytes
);
2462 trace_g_malloc(n_bytes
, ptr
);
2466 static gpointer
realloc_and_trace(gpointer mem
, gsize n_bytes
)
2468 void *ptr
= realloc(mem
, n_bytes
);
2469 trace_g_realloc(mem
, n_bytes
, ptr
);
2473 static void free_and_trace(gpointer mem
)
2479 int main(int argc
, char **argv
, char **envp
)
2482 int snapshot
, linux_boot
;
2483 const char *icount_option
= NULL
;
2484 const char *initrd_filename
;
2485 const char *kernel_filename
, *kernel_cmdline
;
2486 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
2488 int cyls
, heads
, secs
, translation
;
2489 QemuOpts
*hda_opts
= NULL
, *opts
, *machine_opts
;
2490 QemuOptsList
*olist
;
2493 const char *loadvm
= NULL
;
2494 QEMUMachine
*machine
;
2495 const char *cpu_model
;
2496 const char *vga_model
= "none";
2497 const char *pid_file
= NULL
;
2498 const char *incoming
= NULL
;
2500 int show_vnc_port
= 0;
2502 bool defconfig
= true;
2503 bool userconfig
= true;
2504 const char *log_mask
= NULL
;
2505 const char *log_file
= NULL
;
2506 GMemVTable mem_trace
= {
2507 .malloc
= malloc_and_trace
,
2508 .realloc
= realloc_and_trace
,
2509 .free
= free_and_trace
,
2511 const char *trace_events
= NULL
;
2512 const char *trace_file
= NULL
;
2514 atexit(qemu_run_exit_notifiers
);
2515 error_set_progname(argv
[0]);
2517 g_mem_set_vtable(&mem_trace
);
2518 if (!g_thread_supported()) {
2519 #if !GLIB_CHECK_VERSION(2, 31, 0)
2520 g_thread_init(NULL
);
2522 fprintf(stderr
, "glib threading failed to initialize.\n");
2527 module_call_init(MODULE_INIT_QOM
);
2532 rtc_clock
= host_clock
;
2534 qemu_cache_utils_init(envp
);
2536 QLIST_INIT (&vm_change_state_head
);
2537 os_setup_early_signal_handling();
2539 module_call_init(MODULE_INIT_MACHINE
);
2540 machine
= find_default_machine();
2544 cyls
= heads
= secs
= 0;
2545 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2547 for (i
= 0; i
< MAX_NODES
; i
++) {
2549 node_cpumask
[i
] = bitmap_new(MAX_CPUMASK_BITS
);
2557 /* first pass of option parsing */
2559 while (optind
< argc
) {
2560 if (argv
[optind
][0] != '-') {
2565 const QEMUOption
*popt
;
2567 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2568 switch (popt
->index
) {
2569 case QEMU_OPTION_nodefconfig
:
2572 case QEMU_OPTION_nouserconfig
:
2581 ret
= qemu_read_default_config_files(userconfig
);
2587 /* second pass of option parsing */
2592 if (argv
[optind
][0] != '-') {
2593 hda_opts
= drive_add(IF_DEFAULT
, 0, argv
[optind
++], HD_OPTS
);
2595 const QEMUOption
*popt
;
2597 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
2598 if (!(popt
->arch_mask
& arch_type
)) {
2599 printf("Option %s not supported for this target\n", popt
->name
);
2602 switch(popt
->index
) {
2604 machine
= machine_parse(optarg
);
2606 case QEMU_OPTION_no_kvm_irqchip
: {
2607 olist
= qemu_find_opts("machine");
2608 qemu_opts_parse(olist
, "kernel_irqchip=off", 0);
2611 case QEMU_OPTION_cpu
:
2612 /* hw initialization will check this */
2615 case QEMU_OPTION_hda
:
2619 snprintf(buf
, sizeof(buf
), "%s", HD_OPTS
);
2621 snprintf(buf
, sizeof(buf
),
2622 "%s,cyls=%d,heads=%d,secs=%d%s",
2623 HD_OPTS
, cyls
, heads
, secs
,
2624 translation
== BIOS_ATA_TRANSLATION_LBA
?
2626 translation
== BIOS_ATA_TRANSLATION_NONE
?
2627 ",trans=none" : "");
2628 drive_add(IF_DEFAULT
, 0, optarg
, buf
);
2631 case QEMU_OPTION_hdb
:
2632 case QEMU_OPTION_hdc
:
2633 case QEMU_OPTION_hdd
:
2634 drive_add(IF_DEFAULT
, popt
->index
- QEMU_OPTION_hda
, optarg
,
2637 case QEMU_OPTION_drive
:
2638 if (drive_def(optarg
) == NULL
) {
2642 case QEMU_OPTION_set
:
2643 if (qemu_set_option(optarg
) != 0)
2646 case QEMU_OPTION_global
:
2647 if (qemu_global_option(optarg
) != 0)
2650 case QEMU_OPTION_mtdblock
:
2651 drive_add(IF_MTD
, -1, optarg
, MTD_OPTS
);
2653 case QEMU_OPTION_sd
:
2654 drive_add(IF_SD
, 0, optarg
, SD_OPTS
);
2656 case QEMU_OPTION_pflash
:
2657 drive_add(IF_PFLASH
, -1, optarg
, PFLASH_OPTS
);
2659 case QEMU_OPTION_snapshot
:
2662 case QEMU_OPTION_hdachs
:
2666 cyls
= strtol(p
, (char **)&p
, 0);
2667 if (cyls
< 1 || cyls
> 16383)
2672 heads
= strtol(p
, (char **)&p
, 0);
2673 if (heads
< 1 || heads
> 16)
2678 secs
= strtol(p
, (char **)&p
, 0);
2679 if (secs
< 1 || secs
> 63)
2683 if (!strcmp(p
, "none"))
2684 translation
= BIOS_ATA_TRANSLATION_NONE
;
2685 else if (!strcmp(p
, "lba"))
2686 translation
= BIOS_ATA_TRANSLATION_LBA
;
2687 else if (!strcmp(p
, "auto"))
2688 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2691 } else if (*p
!= '\0') {
2693 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2696 if (hda_opts
!= NULL
) {
2698 snprintf(num
, sizeof(num
), "%d", cyls
);
2699 qemu_opt_set(hda_opts
, "cyls", num
);
2700 snprintf(num
, sizeof(num
), "%d", heads
);
2701 qemu_opt_set(hda_opts
, "heads", num
);
2702 snprintf(num
, sizeof(num
), "%d", secs
);
2703 qemu_opt_set(hda_opts
, "secs", num
);
2704 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2705 qemu_opt_set(hda_opts
, "trans", "lba");
2706 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2707 qemu_opt_set(hda_opts
, "trans", "none");
2711 case QEMU_OPTION_numa
:
2712 if (nb_numa_nodes
>= MAX_NODES
) {
2713 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2718 case QEMU_OPTION_display
:
2719 display_type
= select_display(optarg
);
2721 case QEMU_OPTION_nographic
:
2722 display_type
= DT_NOGRAPHIC
;
2724 case QEMU_OPTION_curses
:
2725 #ifdef CONFIG_CURSES
2726 display_type
= DT_CURSES
;
2728 fprintf(stderr
, "Curses support is disabled\n");
2732 case QEMU_OPTION_portrait
:
2733 graphic_rotate
= 90;
2735 case QEMU_OPTION_rotate
:
2736 graphic_rotate
= strtol(optarg
, (char **) &optarg
, 10);
2737 if (graphic_rotate
!= 0 && graphic_rotate
!= 90 &&
2738 graphic_rotate
!= 180 && graphic_rotate
!= 270) {
2740 "qemu: only 90, 180, 270 deg rotation is available\n");
2744 case QEMU_OPTION_kernel
:
2745 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg
);
2747 case QEMU_OPTION_initrd
:
2748 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg
);
2750 case QEMU_OPTION_append
:
2751 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg
);
2753 case QEMU_OPTION_dtb
:
2754 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg
);
2756 case QEMU_OPTION_cdrom
:
2757 drive_add(IF_DEFAULT
, 2, optarg
, CDROM_OPTS
);
2759 case QEMU_OPTION_boot
:
2761 static const char * const params
[] = {
2762 "order", "once", "menu",
2763 "splash", "splash-time",
2764 "reboot-timeout", NULL
2766 char buf
[sizeof(boot_devices
)];
2767 char *standard_boot_devices
;
2770 if (!strchr(optarg
, '=')) {
2772 pstrcpy(buf
, sizeof(buf
), optarg
);
2773 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2775 "qemu: unknown boot parameter '%s' in '%s'\n",
2781 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2782 validate_bootdevices(buf
);
2783 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2786 if (get_param_value(buf
, sizeof(buf
),
2788 validate_bootdevices(buf
);
2789 standard_boot_devices
= g_strdup(boot_devices
);
2790 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2791 qemu_register_reset(restore_boot_devices
,
2792 standard_boot_devices
);
2794 if (get_param_value(buf
, sizeof(buf
),
2796 if (!strcmp(buf
, "on")) {
2798 } else if (!strcmp(buf
, "off")) {
2802 "qemu: invalid option value '%s'\n",
2807 qemu_opts_parse(qemu_find_opts("boot-opts"),
2812 case QEMU_OPTION_fda
:
2813 case QEMU_OPTION_fdb
:
2814 drive_add(IF_FLOPPY
, popt
->index
- QEMU_OPTION_fda
,
2817 case QEMU_OPTION_no_fd_bootchk
:
2820 case QEMU_OPTION_netdev
:
2821 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2825 case QEMU_OPTION_net
:
2826 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2830 #ifdef CONFIG_LIBISCSI
2831 case QEMU_OPTION_iscsi
:
2832 opts
= qemu_opts_parse(qemu_find_opts("iscsi"), optarg
, 0);
2839 case QEMU_OPTION_tftp
:
2840 legacy_tftp_prefix
= optarg
;
2842 case QEMU_OPTION_bootp
:
2843 legacy_bootp_filename
= optarg
;
2845 case QEMU_OPTION_redir
:
2846 if (net_slirp_redir(optarg
) < 0)
2850 case QEMU_OPTION_bt
:
2851 add_device_config(DEV_BT
, optarg
);
2853 case QEMU_OPTION_audio_help
:
2854 if (!(audio_available())) {
2855 printf("Option %s not supported for this target\n", popt
->name
);
2861 case QEMU_OPTION_soundhw
:
2862 if (!(audio_available())) {
2863 printf("Option %s not supported for this target\n", popt
->name
);
2866 select_soundhw (optarg
);
2871 case QEMU_OPTION_version
:
2875 case QEMU_OPTION_m
: {
2880 value
= strtosz(optarg
, &end
);
2881 if (value
< 0 || *end
) {
2882 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2885 sz
= QEMU_ALIGN_UP((uint64_t)value
, 8192);
2887 if (ram_size
!= sz
) {
2888 fprintf(stderr
, "qemu: ram size too large\n");
2893 case QEMU_OPTION_mempath
:
2897 case QEMU_OPTION_mem_prealloc
:
2908 add_device_config(DEV_GDB
, "tcp::" DEFAULT_GDBSTUB_PORT
);
2910 case QEMU_OPTION_gdb
:
2911 add_device_config(DEV_GDB
, optarg
);
2916 case QEMU_OPTION_bios
:
2919 case QEMU_OPTION_singlestep
:
2926 keyboard_layout
= optarg
;
2928 case QEMU_OPTION_localtime
:
2931 case QEMU_OPTION_vga
:
2940 w
= strtol(p
, (char **)&p
, 10);
2943 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2949 h
= strtol(p
, (char **)&p
, 10);
2954 depth
= strtol(p
, (char **)&p
, 10);
2955 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2956 depth
!= 24 && depth
!= 32)
2958 } else if (*p
== '\0') {
2959 depth
= graphic_depth
;
2966 graphic_depth
= depth
;
2969 case QEMU_OPTION_echr
:
2972 term_escape_char
= strtol(optarg
, &r
, 0);
2974 printf("Bad argument to echr\n");
2977 case QEMU_OPTION_monitor
:
2978 monitor_parse(optarg
, "readline");
2979 default_monitor
= 0;
2981 case QEMU_OPTION_qmp
:
2982 monitor_parse(optarg
, "control");
2983 default_monitor
= 0;
2985 case QEMU_OPTION_mon
:
2986 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2990 default_monitor
= 0;
2992 case QEMU_OPTION_chardev
:
2993 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2998 case QEMU_OPTION_fsdev
:
2999 olist
= qemu_find_opts("fsdev");
3001 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
3004 opts
= qemu_opts_parse(olist
, optarg
, 1);
3006 fprintf(stderr
, "parse error: %s\n", optarg
);
3010 case QEMU_OPTION_virtfs
: {
3013 const char *writeout
, *sock_fd
, *socket
;
3015 olist
= qemu_find_opts("virtfs");
3017 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
3020 opts
= qemu_opts_parse(olist
, optarg
, 1);
3022 fprintf(stderr
, "parse error: %s\n", optarg
);
3026 if (qemu_opt_get(opts
, "fsdriver") == NULL
||
3027 qemu_opt_get(opts
, "mount_tag") == NULL
) {
3028 fprintf(stderr
, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
3031 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"),
3032 qemu_opt_get(opts
, "mount_tag"),
3035 fprintf(stderr
, "duplicate fsdev id: %s\n",
3036 qemu_opt_get(opts
, "mount_tag"));
3040 writeout
= qemu_opt_get(opts
, "writeout");
3042 #ifdef CONFIG_SYNC_FILE_RANGE
3043 qemu_opt_set(fsdev
, "writeout", writeout
);
3045 fprintf(stderr
, "writeout=immediate not supported on "
3050 qemu_opt_set(fsdev
, "fsdriver", qemu_opt_get(opts
, "fsdriver"));
3051 qemu_opt_set(fsdev
, "path", qemu_opt_get(opts
, "path"));
3052 qemu_opt_set(fsdev
, "security_model",
3053 qemu_opt_get(opts
, "security_model"));
3054 socket
= qemu_opt_get(opts
, "socket");
3056 qemu_opt_set(fsdev
, "socket", socket
);
3058 sock_fd
= qemu_opt_get(opts
, "sock_fd");
3060 qemu_opt_set(fsdev
, "sock_fd", sock_fd
);
3063 qemu_opt_set_bool(fsdev
, "readonly",
3064 qemu_opt_get_bool(opts
, "readonly", 0));
3065 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3067 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3068 qemu_opt_set(device
, "fsdev",
3069 qemu_opt_get(opts
, "mount_tag"));
3070 qemu_opt_set(device
, "mount_tag",
3071 qemu_opt_get(opts
, "mount_tag"));
3074 case QEMU_OPTION_virtfs_synth
: {
3078 fsdev
= qemu_opts_create(qemu_find_opts("fsdev"), "v_synth",
3081 fprintf(stderr
, "duplicate option: %s\n", "virtfs_synth");
3084 qemu_opt_set(fsdev
, "fsdriver", "synth");
3086 device
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
3088 qemu_opt_set(device
, "driver", "virtio-9p-pci");
3089 qemu_opt_set(device
, "fsdev", "v_synth");
3090 qemu_opt_set(device
, "mount_tag", "v_synth");
3093 case QEMU_OPTION_serial
:
3094 add_device_config(DEV_SERIAL
, optarg
);
3096 if (strncmp(optarg
, "mon:", 4) == 0) {
3097 default_monitor
= 0;
3100 case QEMU_OPTION_watchdog
:
3103 "qemu: only one watchdog option may be given\n");
3108 case QEMU_OPTION_watchdog_action
:
3109 if (select_watchdog_action(optarg
) == -1) {
3110 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
3114 case QEMU_OPTION_virtiocon
:
3115 add_device_config(DEV_VIRTCON
, optarg
);
3116 default_virtcon
= 0;
3117 if (strncmp(optarg
, "mon:", 4) == 0) {
3118 default_monitor
= 0;
3121 case QEMU_OPTION_parallel
:
3122 add_device_config(DEV_PARALLEL
, optarg
);
3123 default_parallel
= 0;
3124 if (strncmp(optarg
, "mon:", 4) == 0) {
3125 default_monitor
= 0;
3128 case QEMU_OPTION_debugcon
:
3129 add_device_config(DEV_DEBUGCON
, optarg
);
3131 case QEMU_OPTION_loadvm
:
3134 case QEMU_OPTION_full_screen
:
3138 case QEMU_OPTION_no_frame
:
3141 case QEMU_OPTION_alt_grab
:
3144 case QEMU_OPTION_ctrl_grab
:
3147 case QEMU_OPTION_no_quit
:
3150 case QEMU_OPTION_sdl
:
3151 display_type
= DT_SDL
;
3154 case QEMU_OPTION_no_frame
:
3155 case QEMU_OPTION_alt_grab
:
3156 case QEMU_OPTION_ctrl_grab
:
3157 case QEMU_OPTION_no_quit
:
3158 case QEMU_OPTION_sdl
:
3159 fprintf(stderr
, "SDL support is disabled\n");
3162 case QEMU_OPTION_pidfile
:
3165 case QEMU_OPTION_win2k_hack
:
3166 win2k_install_hack
= 1;
3168 case QEMU_OPTION_rtc_td_hack
: {
3169 static GlobalProperty slew_lost_ticks
[] = {
3171 .driver
= "mc146818rtc",
3172 .property
= "lost_tick_policy",
3175 { /* end of list */ }
3178 qdev_prop_register_global_list(slew_lost_ticks
);
3181 case QEMU_OPTION_acpitable
:
3182 do_acpitable_option(optarg
);
3184 case QEMU_OPTION_smbios
:
3185 do_smbios_option(optarg
);
3187 case QEMU_OPTION_enable_kvm
:
3188 olist
= qemu_find_opts("machine");
3189 qemu_opts_parse(olist
, "accel=kvm", 0);
3191 case QEMU_OPTION_machine
:
3192 olist
= qemu_find_opts("machine");
3193 opts
= qemu_opts_parse(olist
, optarg
, 1);
3195 fprintf(stderr
, "parse error: %s\n", optarg
);
3198 optarg
= qemu_opt_get(opts
, "type");
3200 machine
= machine_parse(optarg
);
3203 case QEMU_OPTION_no_kvm
:
3204 olist
= qemu_find_opts("machine");
3205 qemu_opts_parse(olist
, "accel=tcg", 0);
3207 case QEMU_OPTION_no_kvm_pit
: {
3208 fprintf(stderr
, "Warning: KVM PIT can no longer be disabled "
3212 case QEMU_OPTION_no_kvm_pit_reinjection
: {
3213 static GlobalProperty kvm_pit_lost_tick_policy
[] = {
3215 .driver
= "kvm-pit",
3216 .property
= "lost_tick_policy",
3219 { /* end of list */ }
3222 fprintf(stderr
, "Warning: option deprecated, use "
3223 "lost_tick_policy property of kvm-pit instead.\n");
3224 qdev_prop_register_global_list(kvm_pit_lost_tick_policy
);
3227 case QEMU_OPTION_usb
:
3228 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3230 qemu_opt_set_bool(machine_opts
, "usb", true);
3233 case QEMU_OPTION_usbdevice
:
3234 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3236 qemu_opt_set_bool(machine_opts
, "usb", true);
3238 add_device_config(DEV_USB
, optarg
);
3240 case QEMU_OPTION_device
:
3241 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
3245 case QEMU_OPTION_smp
:
3248 fprintf(stderr
, "Invalid number of CPUs\n");
3251 if (max_cpus
< smp_cpus
) {
3252 fprintf(stderr
, "maxcpus must be equal to or greater than "
3256 if (max_cpus
> 255) {
3257 fprintf(stderr
, "Unsupported number of maxcpus\n");
3261 case QEMU_OPTION_vnc
:
3264 vnc_display
= optarg
;
3266 fprintf(stderr
, "VNC support is disabled\n");
3270 case QEMU_OPTION_no_acpi
:
3273 case QEMU_OPTION_no_hpet
:
3276 case QEMU_OPTION_balloon
:
3277 if (balloon_parse(optarg
) < 0) {
3278 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
3282 case QEMU_OPTION_no_reboot
:
3285 case QEMU_OPTION_no_shutdown
:
3288 case QEMU_OPTION_show_cursor
:
3291 case QEMU_OPTION_uuid
:
3292 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
3293 fprintf(stderr
, "Fail to parse UUID string."
3294 " Wrong format.\n");
3298 case QEMU_OPTION_option_rom
:
3299 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
3300 fprintf(stderr
, "Too many option ROMs\n");
3303 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
3304 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
3305 option_rom
[nb_option_roms
].bootindex
=
3306 qemu_opt_get_number(opts
, "bootindex", -1);
3307 if (!option_rom
[nb_option_roms
].name
) {
3308 fprintf(stderr
, "Option ROM file is not specified\n");
3313 case QEMU_OPTION_semihosting
:
3314 semihosting_enabled
= 1;
3316 case QEMU_OPTION_tdf
:
3317 fprintf(stderr
, "Warning: user space PIT time drift fix "
3318 "is no longer supported.\n");
3320 case QEMU_OPTION_name
:
3321 qemu_name
= g_strdup(optarg
);
3323 char *p
= strchr(qemu_name
, ',');
3326 if (strncmp(p
, "process=", 8)) {
3327 fprintf(stderr
, "Unknown subargument %s to -name\n", p
);
3331 os_set_proc_name(p
);
3335 case QEMU_OPTION_prom_env
:
3336 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
3337 fprintf(stderr
, "Too many prom variables\n");
3340 prom_envs
[nb_prom_envs
] = optarg
;
3343 case QEMU_OPTION_old_param
:
3346 case QEMU_OPTION_clock
:
3347 configure_alarms(optarg
);
3349 case QEMU_OPTION_startdate
:
3350 configure_rtc_date_offset(optarg
, 1);
3352 case QEMU_OPTION_rtc
:
3353 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
3357 configure_rtc(opts
);
3359 case QEMU_OPTION_tb_size
:
3360 tcg_tb_size
= strtol(optarg
, NULL
, 0);
3361 if (tcg_tb_size
< 0) {
3365 case QEMU_OPTION_icount
:
3366 icount_option
= optarg
;
3368 case QEMU_OPTION_incoming
:
3370 runstate_set(RUN_STATE_INMIGRATE
);
3372 case QEMU_OPTION_nodefaults
:
3374 default_parallel
= 0;
3375 default_virtcon
= 0;
3376 default_monitor
= 0;
3383 case QEMU_OPTION_xen_domid
:
3384 if (!(xen_available())) {
3385 printf("Option %s not supported for this target\n", popt
->name
);
3388 xen_domid
= atoi(optarg
);
3390 case QEMU_OPTION_xen_create
:
3391 if (!(xen_available())) {
3392 printf("Option %s not supported for this target\n", popt
->name
);
3395 xen_mode
= XEN_CREATE
;
3397 case QEMU_OPTION_xen_attach
:
3398 if (!(xen_available())) {
3399 printf("Option %s not supported for this target\n", popt
->name
);
3402 xen_mode
= XEN_ATTACH
;
3404 case QEMU_OPTION_trace
:
3406 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
3410 trace_events
= qemu_opt_get(opts
, "events");
3411 trace_file
= qemu_opt_get(opts
, "file");
3414 case QEMU_OPTION_readconfig
:
3416 int ret
= qemu_read_config_file(optarg
);
3418 fprintf(stderr
, "read config %s: %s\n", optarg
,
3424 case QEMU_OPTION_spice
:
3425 olist
= qemu_find_opts("spice");
3427 fprintf(stderr
, "spice is not supported by this qemu build.\n");
3430 opts
= qemu_opts_parse(olist
, optarg
, 0);
3432 fprintf(stderr
, "parse error: %s\n", optarg
);
3436 case QEMU_OPTION_writeconfig
:
3439 if (strcmp(optarg
, "-") == 0) {
3442 fp
= fopen(optarg
, "w");
3444 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
3448 qemu_config_write(fp
);
3452 case QEMU_OPTION_qtest
:
3453 qtest_chrdev
= optarg
;
3455 case QEMU_OPTION_qtest_log
:
3458 case QEMU_OPTION_sandbox
:
3459 opts
= qemu_opts_parse(qemu_find_opts("sandbox"), optarg
, 1);
3464 case QEMU_OPTION_add_fd
:
3466 opts
= qemu_opts_parse(qemu_find_opts("add-fd"), optarg
, 0);
3471 error_report("File descriptor passing is disabled on this "
3477 os_parse_cmd_args(popt
->index
, optarg
);
3483 if (qemu_init_main_loop()) {
3484 fprintf(stderr
, "qemu_init_main_loop failed\n");
3488 if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox
, NULL
, 0)) {
3493 if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd
, NULL
, 1)) {
3497 if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd
, NULL
, 1)) {
3502 if (machine
== NULL
) {
3503 fprintf(stderr
, "No machine found.\n");
3507 if (machine
->hw_version
) {
3508 qemu_set_version(machine
->hw_version
);
3511 /* Init CPU def lists, based on config
3512 * - Must be called after all the qemu_read_config_file() calls
3513 * - Must be called before list_cpus()
3514 * - Must be called before machine->init()
3518 if (cpu_model
&& is_help_option(cpu_model
)) {
3519 list_cpus(stdout
, &fprintf
, cpu_model
);
3523 /* Open the logfile at this point, if necessary. We can't open the logfile
3524 * when encountering either of the logging options (-d or -D) because the
3525 * other one may be encountered later on the command line, changing the
3526 * location or level of logging.
3530 set_cpu_log_filename(log_file
);
3532 set_cpu_log(log_mask
);
3535 if (!trace_backend_init(trace_events
, trace_file
)) {
3539 /* If no data_dir is specified then try to find it relative to the
3542 data_dir
= os_find_datadir(argv
[0]);
3544 /* If all else fails use the install path specified when building. */
3546 data_dir
= CONFIG_QEMU_DATADIR
;
3550 * Default to max_cpus = smp_cpus, in case the user doesn't
3551 * specify a max_cpus value.
3554 max_cpus
= smp_cpus
;
3556 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
3557 if (smp_cpus
> machine
->max_cpus
) {
3558 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
3559 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
3565 * Get the default machine options from the machine if it is not already
3566 * specified either by the configuration file or by the command line.
3568 if (machine
->default_machine_opts
) {
3569 qemu_opts_set_defaults(qemu_find_opts("machine"),
3570 machine
->default_machine_opts
, 0);
3573 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
3574 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
3576 if (machine
->no_serial
) {
3579 if (machine
->no_parallel
) {
3580 default_parallel
= 0;
3582 if (!machine
->use_virtcon
) {
3583 default_virtcon
= 0;
3585 if (machine
->no_floppy
) {
3588 if (machine
->no_cdrom
) {
3591 if (machine
->no_sdcard
) {
3595 if (display_type
== DT_NOGRAPHIC
) {
3596 if (default_parallel
)
3597 add_device_config(DEV_PARALLEL
, "null");
3598 if (default_serial
&& default_monitor
) {
3599 add_device_config(DEV_SERIAL
, "mon:stdio");
3600 } else if (default_virtcon
&& default_monitor
) {
3601 add_device_config(DEV_VIRTCON
, "mon:stdio");
3604 add_device_config(DEV_SERIAL
, "stdio");
3605 if (default_virtcon
)
3606 add_device_config(DEV_VIRTCON
, "stdio");
3607 if (default_monitor
)
3608 monitor_parse("stdio", "readline");
3612 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
3613 if (default_parallel
)
3614 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
3615 if (default_monitor
)
3616 monitor_parse("vc:80Cx24C", "readline");
3617 if (default_virtcon
)
3618 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
3623 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
3625 #ifdef CONFIG_VIRTFS
3626 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
3633 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
3638 /* init the memory */
3639 if (ram_size
== 0) {
3640 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
3643 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0)
3648 configure_accelerator();
3650 machine_opts
= qemu_opts_find(qemu_find_opts("machine"), 0);
3652 kernel_filename
= qemu_opt_get(machine_opts
, "kernel");
3653 initrd_filename
= qemu_opt_get(machine_opts
, "initrd");
3654 kernel_cmdline
= qemu_opt_get(machine_opts
, "append");
3656 kernel_filename
= initrd_filename
= kernel_cmdline
= NULL
;
3659 if (!kernel_cmdline
) {
3660 kernel_cmdline
= "";
3663 linux_boot
= (kernel_filename
!= NULL
);
3665 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
3666 fprintf(stderr
, "-append only allowed with -kernel option\n");
3670 if (!linux_boot
&& initrd_filename
!= NULL
) {
3671 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
3675 if (!linux_boot
&& machine_opts
&& qemu_opt_get(machine_opts
, "dtb")) {
3676 fprintf(stderr
, "-dtb only allowed with -kernel option\n");
3680 os_set_line_buffering();
3682 qemu_init_cpu_loop();
3683 qemu_mutex_lock_iothread();
3686 /* spice needs the timers to be initialized by this point */
3690 if (icount_option
&& (kvm_enabled() || xen_enabled())) {
3691 fprintf(stderr
, "-icount is not allowed with kvm or xen\n");
3694 configure_icount(icount_option
);
3696 if (net_init_clients() < 0) {
3700 /* init the bluetooth world */
3701 if (foreach_device_config(DEV_BT
, bt_parse
))
3704 if (!xen_enabled()) {
3705 /* On 32-bit hosts, QEMU is limited by virtual address space */
3706 if (ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
3707 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
3712 cpu_exec_init_all();
3714 bdrv_init_with_whitelist();
3718 /* open the virtual block devices */
3720 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
3721 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
3724 default_drive(default_cdrom
, snapshot
, machine
->use_scsi
,
3725 IF_DEFAULT
, 2, CDROM_OPTS
);
3726 default_drive(default_floppy
, snapshot
, machine
->use_scsi
,
3727 IF_FLOPPY
, 0, FD_OPTS
);
3728 default_drive(default_sdcard
, snapshot
, machine
->use_scsi
,
3731 register_savevm_live(NULL
, "ram", 0, 4, &savevm_ram_handlers
, NULL
);
3733 if (nb_numa_nodes
> 0) {
3736 if (nb_numa_nodes
> MAX_NODES
) {
3737 nb_numa_nodes
= MAX_NODES
;
3740 /* If no memory size if given for any node, assume the default case
3741 * and distribute the available memory equally across all nodes
3743 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3744 if (node_mem
[i
] != 0)
3747 if (i
== nb_numa_nodes
) {
3748 uint64_t usedmem
= 0;
3750 /* On Linux, the each node's border has to be 8MB aligned,
3751 * the final node gets the rest.
3753 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
3754 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
3755 usedmem
+= node_mem
[i
];
3757 node_mem
[i
] = ram_size
- usedmem
;
3760 for (i
= 0; i
< nb_numa_nodes
; i
++) {
3761 if (!bitmap_empty(node_cpumask
[i
], MAX_CPUMASK_BITS
)) {
3765 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3766 * must cope with this anyway, because there are BIOSes out there in
3767 * real machines which also use this scheme.
3769 if (i
== nb_numa_nodes
) {
3770 for (i
= 0; i
< max_cpus
; i
++) {
3771 set_bit(i
, node_cpumask
[i
% nb_numa_nodes
]);
3776 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
3780 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
3782 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
3784 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
3786 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
3789 /* If no default VGA is requested, the default is "none". */
3791 if (cirrus_vga_available()) {
3792 vga_model
= "cirrus";
3793 } else if (vga_available()) {
3797 select_vgahw(vga_model
);
3800 i
= select_watchdog(watchdog
);
3802 exit (i
== 1 ? 1 : 0);
3805 if (machine
->compat_props
) {
3806 qdev_prop_register_global_list(machine
->compat_props
);
3810 qdev_machine_init();
3812 QEMUMachineInitArgs args
= { .ram_size
= ram_size
,
3813 .boot_device
= boot_devices
,
3814 .kernel_filename
= kernel_filename
,
3815 .kernel_cmdline
= kernel_cmdline
,
3816 .initrd_filename
= initrd_filename
,
3817 .cpu_model
= cpu_model
};
3818 machine
->init(&args
);
3820 cpu_synchronize_all_post_init();
3824 current_machine
= machine
;
3826 /* init USB devices */
3827 if (usb_enabled(false)) {
3828 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3832 /* init generic devices */
3833 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3836 net_check_clients();
3838 /* just use the first displaystate for the moment */
3839 ds
= get_displaystate();
3843 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3844 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3845 display_type
= DT_SDL
;
3846 #elif defined(CONFIG_VNC)
3847 vnc_display
= "localhost:0,to=99";
3850 display_type
= DT_NONE
;
3855 /* init local displays */
3856 switch (display_type
) {
3859 #if defined(CONFIG_CURSES)
3861 if (!is_daemonized()) {
3862 curses_display_init(ds
, full_screen
);
3866 #if defined(CONFIG_SDL)
3868 sdl_display_init(ds
, full_screen
, no_frame
);
3870 #elif defined(CONFIG_COCOA)
3872 cocoa_display_init(ds
, full_screen
);
3879 /* must be after terminal init, SDL library changes signal handlers */
3880 os_setup_signal_handling();
3883 /* init remote displays */
3885 Error
*local_err
= NULL
;
3886 vnc_display_init(ds
);
3887 vnc_display_open(ds
, vnc_display
, &local_err
);
3888 if (local_err
!= NULL
) {
3889 fprintf(stderr
, "Failed to start VNC server on `%s': %s\n",
3890 vnc_display
, error_get_pretty(local_err
));
3891 error_free(local_err
);
3895 if (show_vnc_port
) {
3896 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3901 if (using_spice
&& !qxl_enabled
) {
3902 qemu_spice_display_init(ds
);
3907 text_consoles_set_display(ds
);
3909 if (foreach_device_config(DEV_GDB
, gdbserver_start
) < 0) {
3913 qdev_machine_creation_done();
3915 if (rom_load_all() != 0) {
3916 fprintf(stderr
, "rom loading failed\n");
3920 /* TODO: once all bus devices are qdevified, this should be done
3921 * when bus is created by qdev.c */
3922 qemu_register_reset(qbus_reset_all_fn
, sysbus_get_default());
3923 qemu_run_machine_init_done_notifiers();
3925 qemu_system_reset(VMRESET_SILENT
);
3927 if (load_vmstate(loadvm
) < 0) {
3933 Error
*local_err
= NULL
;
3934 qemu_start_incoming_migration(incoming
, &local_err
);
3936 fprintf(stderr
, "-incoming %s: %s\n", incoming
, error_get_pretty(local_err
));
3937 error_free(local_err
);
3940 } else if (autostart
) {