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
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc
, char **argv
, char **envp
);
103 int main(int argc
, char **argv
)
105 return qemu_main(argc
, argv
, NULL
);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
162 #include "qemu-queue.h"
164 #include "arch_init.h"
166 #include "ui/qemu-spice.h"
169 //#define DEBUG_SLIRP
171 #define DEFAULT_RAM_SIZE 128
173 #define MAX_VIRTIO_CONSOLES 1
175 static const char *data_dir
;
176 const char *bios_name
= NULL
;
177 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
178 DisplayType display_type
= DT_DEFAULT
;
179 int display_remote
= 0;
180 const char* keyboard_layout
= NULL
;
182 const char *mem_path
= NULL
;
184 int mem_prealloc
= 0; /* force preallocation of physical target memory */
187 NICInfo nd_table
[MAX_NICS
];
190 int incoming_expected
; /* Started with -incoming and waiting for incoming */
191 static int rtc_utc
= 1;
192 static int rtc_date_offset
= -1; /* -1 means no change */
193 QEMUClock
*rtc_clock
;
194 int vga_interface_type
= VGA_NONE
;
195 static int full_screen
= 0;
197 static int no_frame
= 0;
200 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
201 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
202 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
203 int win2k_install_hack
= 0;
211 const char *vnc_display
;
212 int acpi_enabled
= 1;
218 int graphic_rotate
= 0;
219 uint8_t irq0override
= 1;
220 const char *watchdog
;
221 QEMUOptionRom option_rom
[MAX_OPTION_ROMS
];
223 int semihosting_enabled
= 0;
225 const char *qemu_name
;
228 unsigned int nb_prom_envs
= 0;
229 const char *prom_envs
[MAX_PROM_ENVS
];
232 typedef struct FWBootEntry FWBootEntry
;
235 QTAILQ_ENTRY(FWBootEntry
) link
;
241 QTAILQ_HEAD(, FWBootEntry
) fw_boot_order
= QTAILQ_HEAD_INITIALIZER(fw_boot_order
);
244 uint64_t node_mem
[MAX_NODES
];
245 uint64_t node_cpumask
[MAX_NODES
];
247 static QEMUTimer
*nographic_timer
;
249 uint8_t qemu_uuid
[16];
251 static QEMUBootSetHandler
*boot_set_handler
;
252 static void *boot_set_opaque
;
254 static NotifierList exit_notifiers
=
255 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
257 static NotifierList machine_init_done_notifiers
=
258 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
262 enum xen_mode xen_mode
= XEN_EMULATE
;
264 static int default_serial
= 1;
265 static int default_parallel
= 1;
266 static int default_virtcon
= 1;
267 static int default_monitor
= 1;
268 static int default_vga
= 1;
269 static int default_floppy
= 1;
270 static int default_cdrom
= 1;
271 static int default_sdcard
= 1;
277 { .driver
= "isa-serial", .flag
= &default_serial
},
278 { .driver
= "isa-parallel", .flag
= &default_parallel
},
279 { .driver
= "isa-fdc", .flag
= &default_floppy
},
280 { .driver
= "ide-drive", .flag
= &default_cdrom
},
281 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
282 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
283 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
284 { .driver
= "VGA", .flag
= &default_vga
},
285 { .driver
= "cirrus-vga", .flag
= &default_vga
},
286 { .driver
= "vmware-svga", .flag
= &default_vga
},
289 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
291 const char *driver
= qemu_opt_get(opts
, "driver");
296 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
297 if (strcmp(default_list
[i
].driver
, driver
) != 0)
299 *(default_list
[i
].flag
) = 0;
304 /***********************************************************/
305 /* real time host monotonic timer */
307 /***********************************************************/
308 /* host time/date access */
309 void qemu_get_timedate(struct tm
*tm
, int offset
)
316 if (rtc_date_offset
== -1) {
320 ret
= localtime(&ti
);
322 ti
-= rtc_date_offset
;
326 memcpy(tm
, ret
, sizeof(struct tm
));
329 int qemu_timedate_diff(struct tm
*tm
)
333 if (rtc_date_offset
== -1)
335 seconds
= mktimegm(tm
);
337 seconds
= mktime(tm
);
339 seconds
= mktimegm(tm
) + rtc_date_offset
;
341 return seconds
- time(NULL
);
344 void rtc_change_mon_event(struct tm
*tm
)
348 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
349 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
350 qobject_decref(data
);
353 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
355 time_t rtc_start_date
;
358 if (!strcmp(startdate
, "now") && legacy
) {
359 rtc_date_offset
= -1;
361 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
369 } else if (sscanf(startdate
, "%d-%d-%d",
381 rtc_start_date
= mktimegm(&tm
);
382 if (rtc_start_date
== -1) {
384 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
385 "'2006-06-17T16:01:21' or '2006-06-17'\n");
388 rtc_date_offset
= time(NULL
) - rtc_start_date
;
392 static void configure_rtc(QemuOpts
*opts
)
396 value
= qemu_opt_get(opts
, "base");
398 if (!strcmp(value
, "utc")) {
400 } else if (!strcmp(value
, "localtime")) {
403 configure_rtc_date_offset(value
, 0);
406 value
= qemu_opt_get(opts
, "clock");
408 if (!strcmp(value
, "host")) {
409 rtc_clock
= host_clock
;
410 } else if (!strcmp(value
, "vm")) {
411 rtc_clock
= vm_clock
;
413 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
417 value
= qemu_opt_get(opts
, "driftfix");
419 if (!strcmp(value
, "slew")) {
421 } else if (!strcmp(value
, "none")) {
424 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
430 /***********************************************************/
431 /* Bluetooth support */
434 static struct HCIInfo
*hci_table
[MAX_NICS
];
436 static struct bt_vlan_s
{
437 struct bt_scatternet_s net
;
439 struct bt_vlan_s
*next
;
442 /* find or alloc a new bluetooth "VLAN" */
443 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
445 struct bt_vlan_s
**pvlan
, *vlan
;
446 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
450 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
452 pvlan
= &first_bt_vlan
;
453 while (*pvlan
!= NULL
)
454 pvlan
= &(*pvlan
)->next
;
459 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
463 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
468 static struct HCIInfo null_hci
= {
469 .cmd_send
= null_hci_send
,
470 .sco_send
= null_hci_send
,
471 .acl_send
= null_hci_send
,
472 .bdaddr_set
= null_hci_addr_set
,
475 struct HCIInfo
*qemu_next_hci(void)
477 if (cur_hci
== nb_hcis
)
480 return hci_table
[cur_hci
++];
483 static struct HCIInfo
*hci_init(const char *str
)
486 struct bt_scatternet_s
*vlan
= 0;
488 if (!strcmp(str
, "null"))
491 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
493 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
494 else if (!strncmp(str
, "hci", 3)) {
497 if (!strncmp(str
+ 3, ",vlan=", 6)) {
498 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
503 vlan
= qemu_find_bt_vlan(0);
505 return bt_new_hci(vlan
);
508 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
513 static int bt_hci_parse(const char *str
)
518 if (nb_hcis
>= MAX_NICS
) {
519 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
532 bdaddr
.b
[5] = 0x56 + nb_hcis
;
533 hci
->bdaddr_set(hci
, bdaddr
.b
);
535 hci_table
[nb_hcis
++] = hci
;
540 static void bt_vhci_add(int vlan_id
)
542 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
545 fprintf(stderr
, "qemu: warning: adding a VHCI to "
546 "an empty scatternet %i\n", vlan_id
);
548 bt_vhci_init(bt_new_hci(vlan
));
551 static struct bt_device_s
*bt_device_add(const char *opt
)
553 struct bt_scatternet_s
*vlan
;
555 char *endp
= strstr(opt
, ",vlan=");
556 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
559 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
562 vlan_id
= strtol(endp
+ 6, &endp
, 0);
564 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
569 vlan
= qemu_find_bt_vlan(vlan_id
);
572 fprintf(stderr
, "qemu: warning: adding a slave device to "
573 "an empty scatternet %i\n", vlan_id
);
575 if (!strcmp(devname
, "keyboard"))
576 return bt_keyboard_init(vlan
);
578 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
582 static int bt_parse(const char *opt
)
584 const char *endp
, *p
;
587 if (strstart(opt
, "hci", &endp
)) {
588 if (!*endp
|| *endp
== ',') {
590 if (!strstart(endp
, ",vlan=", 0))
593 return bt_hci_parse(opt
);
595 } else if (strstart(opt
, "vhci", &endp
)) {
596 if (!*endp
|| *endp
== ',') {
598 if (strstart(endp
, ",vlan=", &p
)) {
599 vlan
= strtol(p
, (char **) &endp
, 0);
601 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
605 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
614 } else if (strstart(opt
, "device:", &endp
))
615 return !bt_device_add(endp
);
617 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
621 /***********************************************************/
622 /* QEMU Block devices */
624 #define HD_ALIAS "index=%d,media=disk"
625 #define CDROM_ALIAS "index=2,media=cdrom"
626 #define FD_ALIAS "index=%d,if=floppy"
627 #define PFLASH_ALIAS "if=pflash"
628 #define MTD_ALIAS "if=mtd"
629 #define SD_ALIAS "index=0,if=sd"
631 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
633 int *use_scsi
= opaque
;
636 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
643 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
645 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
646 qemu_opt_set(opts
, "snapshot", "on");
651 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
653 boot_set_handler
= func
;
654 boot_set_opaque
= opaque
;
657 int qemu_boot_set(const char *boot_devices
)
659 if (!boot_set_handler
) {
662 return boot_set_handler(boot_set_opaque
, boot_devices
);
665 static void validate_bootdevices(char *devices
)
667 /* We just do some generic consistency checks */
671 for (p
= devices
; *p
!= '\0'; p
++) {
672 /* Allowed boot devices are:
673 * a-b: floppy disk drives
674 * c-f: IDE disk drives
675 * g-m: machine implementation dependant drives
676 * n-p: network devices
677 * It's up to each machine implementation to check if the given boot
678 * devices match the actual hardware implementation and firmware
681 if (*p
< 'a' || *p
> 'p') {
682 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
685 if (bitmap
& (1 << (*p
- 'a'))) {
686 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
689 bitmap
|= 1 << (*p
- 'a');
693 static void restore_boot_devices(void *opaque
)
695 char *standard_boot_devices
= opaque
;
696 static int first
= 1;
698 /* Restore boot order and remove ourselves after the first boot */
704 qemu_boot_set(standard_boot_devices
);
706 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
707 qemu_free(standard_boot_devices
);
710 void add_boot_device_path(int32_t bootindex
, DeviceState
*dev
,
713 FWBootEntry
*node
, *i
;
719 assert(dev
!= NULL
|| suffix
!= NULL
);
721 node
= qemu_mallocz(sizeof(FWBootEntry
));
722 node
->bootindex
= bootindex
;
723 node
->suffix
= strdup(suffix
);
726 QTAILQ_FOREACH(i
, &fw_boot_order
, link
) {
727 if (i
->bootindex
== bootindex
) {
728 fprintf(stderr
, "Two devices with same boot index %d\n", bootindex
);
730 } else if (i
->bootindex
< bootindex
) {
733 QTAILQ_INSERT_BEFORE(i
, node
, link
);
736 QTAILQ_INSERT_TAIL(&fw_boot_order
, node
, link
);
739 static void numa_add(const char *optarg
)
743 unsigned long long value
, endvalue
;
746 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
747 if (!strcmp(option
, "node")) {
748 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
749 nodenr
= nb_numa_nodes
;
751 nodenr
= strtoull(option
, NULL
, 10);
754 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
755 node_mem
[nodenr
] = 0;
758 sval
= strtosz(option
, NULL
);
760 fprintf(stderr
, "qemu: invalid numa mem size: %s\n", optarg
);
763 node_mem
[nodenr
] = sval
;
765 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
766 node_cpumask
[nodenr
] = 0;
768 value
= strtoull(option
, &endptr
, 10);
771 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
773 if (*endptr
== '-') {
774 endvalue
= strtoull(endptr
+1, &endptr
, 10);
775 if (endvalue
>= 63) {
778 "only 63 CPUs in NUMA mode supported.\n");
780 value
= (2ULL << endvalue
) - (1ULL << value
);
782 value
= 1ULL << value
;
785 node_cpumask
[nodenr
] = value
;
792 static void smp_parse(const char *optarg
)
794 int smp
, sockets
= 0, threads
= 0, cores
= 0;
798 smp
= strtoul(optarg
, &endptr
, 10);
799 if (endptr
!= optarg
) {
800 if (*endptr
== ',') {
804 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
805 sockets
= strtoull(option
, NULL
, 10);
806 if (get_param_value(option
, 128, "cores", endptr
) != 0)
807 cores
= strtoull(option
, NULL
, 10);
808 if (get_param_value(option
, 128, "threads", endptr
) != 0)
809 threads
= strtoull(option
, NULL
, 10);
810 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
811 max_cpus
= strtoull(option
, NULL
, 10);
813 /* compute missing values, prefer sockets over cores over threads */
814 if (smp
== 0 || sockets
== 0) {
815 sockets
= sockets
> 0 ? sockets
: 1;
816 cores
= cores
> 0 ? cores
: 1;
817 threads
= threads
> 0 ? threads
: 1;
819 smp
= cores
* threads
* sockets
;
823 threads
= threads
> 0 ? threads
: 1;
824 cores
= smp
/ (sockets
* threads
);
826 threads
= smp
/ (cores
* sockets
);
830 smp_cores
= cores
> 0 ? cores
: 1;
831 smp_threads
= threads
> 0 ? threads
: 1;
836 /***********************************************************/
839 static int usb_device_add(const char *devname
)
842 USBDevice
*dev
= NULL
;
847 /* drivers with .usbdevice_name entry in USBDeviceInfo */
848 dev
= usbdevice_create(devname
);
853 if (strstart(devname
, "host:", &p
)) {
854 dev
= usb_host_device_open(p
);
855 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
856 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
857 bt_new_hci(qemu_find_bt_vlan(0)));
868 static int usb_device_del(const char *devname
)
873 if (strstart(devname
, "host:", &p
))
874 return usb_host_device_close(p
);
879 p
= strchr(devname
, '.');
882 bus_num
= strtoul(devname
, NULL
, 0);
883 addr
= strtoul(p
+ 1, NULL
, 0);
885 return usb_device_delete_addr(bus_num
, addr
);
888 static int usb_parse(const char *cmdline
)
891 r
= usb_device_add(cmdline
);
893 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
898 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
900 const char *devname
= qdict_get_str(qdict
, "devname");
901 if (usb_device_add(devname
) < 0) {
902 error_report("could not add USB device '%s'", devname
);
906 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
908 const char *devname
= qdict_get_str(qdict
, "devname");
909 if (usb_device_del(devname
) < 0) {
910 error_report("could not delete USB device '%s'", devname
);
914 /***********************************************************/
917 static struct pcmcia_socket_entry_s
{
918 PCMCIASocket
*socket
;
919 struct pcmcia_socket_entry_s
*next
;
920 } *pcmcia_sockets
= 0;
922 void pcmcia_socket_register(PCMCIASocket
*socket
)
924 struct pcmcia_socket_entry_s
*entry
;
926 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
927 entry
->socket
= socket
;
928 entry
->next
= pcmcia_sockets
;
929 pcmcia_sockets
= entry
;
932 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
934 struct pcmcia_socket_entry_s
*entry
, **ptr
;
936 ptr
= &pcmcia_sockets
;
937 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
938 if (entry
->socket
== socket
) {
944 void pcmcia_info(Monitor
*mon
)
946 struct pcmcia_socket_entry_s
*iter
;
949 monitor_printf(mon
, "No PCMCIA sockets\n");
951 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
952 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
953 iter
->socket
->attached
? iter
->socket
->card_string
:
957 /***********************************************************/
960 typedef struct IOHandlerRecord
{
962 IOCanReadHandler
*fd_read_poll
;
969 QLIST_ENTRY(IOHandlerRecord
) next
;
972 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
973 QLIST_HEAD_INITIALIZER(io_handlers
);
976 /* XXX: fd_read_poll should be suppressed, but an API change is
977 necessary in the character devices to suppress fd_can_read(). */
978 int qemu_set_fd_handler2(int fd
,
979 IOCanReadHandler
*fd_read_poll
,
984 IOHandlerRecord
*ioh
;
986 if (!fd_read
&& !fd_write
) {
987 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
994 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
998 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
999 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
1002 ioh
->fd_read_poll
= fd_read_poll
;
1003 ioh
->fd_read
= fd_read
;
1004 ioh
->fd_write
= fd_write
;
1005 ioh
->opaque
= opaque
;
1011 int qemu_set_fd_handler(int fd
,
1013 IOHandler
*fd_write
,
1016 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1019 /***********************************************************/
1020 /* machine registration */
1022 static QEMUMachine
*first_machine
= NULL
;
1023 QEMUMachine
*current_machine
= NULL
;
1025 int qemu_register_machine(QEMUMachine
*m
)
1028 pm
= &first_machine
;
1036 static QEMUMachine
*find_machine(const char *name
)
1040 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1041 if (!strcmp(m
->name
, name
))
1043 if (m
->alias
&& !strcmp(m
->alias
, name
))
1049 static QEMUMachine
*find_default_machine(void)
1053 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1054 if (m
->is_default
) {
1061 /***********************************************************/
1062 /* main execution loop */
1064 static void gui_update(void *opaque
)
1066 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1067 DisplayState
*ds
= opaque
;
1068 DisplayChangeListener
*dcl
= ds
->listeners
;
1070 qemu_flush_coalesced_mmio_buffer();
1073 while (dcl
!= NULL
) {
1074 if (dcl
->gui_timer_interval
&&
1075 dcl
->gui_timer_interval
< interval
)
1076 interval
= dcl
->gui_timer_interval
;
1079 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1082 static void nographic_update(void *opaque
)
1084 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1086 qemu_flush_coalesced_mmio_buffer();
1087 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1090 struct vm_change_state_entry
{
1091 VMChangeStateHandler
*cb
;
1093 QLIST_ENTRY (vm_change_state_entry
) entries
;
1096 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1098 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1101 VMChangeStateEntry
*e
;
1103 e
= qemu_mallocz(sizeof (*e
));
1107 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1111 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1113 QLIST_REMOVE (e
, entries
);
1117 void vm_state_notify(int running
, int reason
)
1119 VMChangeStateEntry
*e
;
1121 trace_vm_state_notify(running
, reason
);
1123 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1124 e
->cb(e
->opaque
, running
, reason
);
1133 vm_state_notify(1, 0);
1135 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1139 /* reset/shutdown handler */
1141 typedef struct QEMUResetEntry
{
1142 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1143 QEMUResetHandler
*func
;
1147 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1148 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1149 static int reset_requested
;
1150 static int shutdown_requested
;
1151 static int powerdown_requested
;
1152 int debug_requested
;
1153 int vmstop_requested
;
1155 int qemu_shutdown_requested(void)
1157 int r
= shutdown_requested
;
1158 shutdown_requested
= 0;
1162 int qemu_reset_requested(void)
1164 int r
= reset_requested
;
1165 reset_requested
= 0;
1169 int qemu_powerdown_requested(void)
1171 int r
= powerdown_requested
;
1172 powerdown_requested
= 0;
1176 static int qemu_debug_requested(void)
1178 int r
= debug_requested
;
1179 debug_requested
= 0;
1183 static int qemu_vmstop_requested(void)
1185 int r
= vmstop_requested
;
1186 vmstop_requested
= 0;
1190 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1192 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1195 re
->opaque
= opaque
;
1196 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1199 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1203 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1204 if (re
->func
== func
&& re
->opaque
== opaque
) {
1205 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1212 void qemu_system_reset(void)
1214 QEMUResetEntry
*re
, *nre
;
1216 /* reset all devices */
1217 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1218 re
->func(re
->opaque
);
1220 monitor_protocol_event(QEVENT_RESET
, NULL
);
1221 cpu_synchronize_all_post_reset();
1224 void qemu_system_reset_request(void)
1227 shutdown_requested
= 1;
1229 reset_requested
= 1;
1231 qemu_notify_event();
1234 void qemu_system_shutdown_request(void)
1236 shutdown_requested
= 1;
1237 qemu_notify_event();
1240 void qemu_system_powerdown_request(void)
1242 powerdown_requested
= 1;
1243 qemu_notify_event();
1246 void main_loop_wait(int nonblocking
)
1248 IOHandlerRecord
*ioh
;
1249 fd_set rfds
, wfds
, xfds
;
1257 timeout
= qemu_calculate_timeout();
1258 qemu_bh_update_timeout(&timeout
);
1261 os_host_main_loop_wait(&timeout
);
1263 /* poll any events */
1264 /* XXX: separate device handlers from system ones */
1269 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1273 (!ioh
->fd_read_poll
||
1274 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1275 FD_SET(ioh
->fd
, &rfds
);
1279 if (ioh
->fd_write
) {
1280 FD_SET(ioh
->fd
, &wfds
);
1286 tv
.tv_sec
= timeout
/ 1000;
1287 tv
.tv_usec
= (timeout
% 1000) * 1000;
1289 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1291 qemu_mutex_unlock_iothread();
1292 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1293 qemu_mutex_lock_iothread();
1295 IOHandlerRecord
*pioh
;
1297 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1298 if (!ioh
->deleted
&& ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1299 ioh
->fd_read(ioh
->opaque
);
1301 if (!ioh
->deleted
&& ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1302 ioh
->fd_write(ioh
->opaque
);
1305 /* Do this last in case read/write handlers marked it for deletion */
1307 QLIST_REMOVE(ioh
, next
);
1313 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1315 qemu_run_all_timers();
1317 /* Check bottom-halves last in case any of the earlier events triggered
1323 static int vm_can_run(void)
1325 if (powerdown_requested
)
1327 if (reset_requested
)
1329 if (shutdown_requested
)
1331 if (debug_requested
)
1336 qemu_irq qemu_system_powerdown
;
1338 static void main_loop(void)
1342 qemu_main_loop_start();
1346 bool nonblocking
= false;
1347 #ifdef CONFIG_PROFILER
1350 #ifndef CONFIG_IOTHREAD
1351 nonblocking
= cpu_exec_all();
1353 #ifdef CONFIG_PROFILER
1354 ti
= profile_getclock();
1356 main_loop_wait(nonblocking
);
1357 #ifdef CONFIG_PROFILER
1358 dev_time
+= profile_getclock() - ti
;
1360 } while (vm_can_run());
1362 if ((r
= qemu_debug_requested())) {
1365 if (qemu_shutdown_requested()) {
1366 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1373 if (qemu_reset_requested()) {
1375 qemu_system_reset();
1378 if (qemu_powerdown_requested()) {
1379 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1380 qemu_irq_raise(qemu_system_powerdown
);
1382 if ((r
= qemu_vmstop_requested())) {
1390 static void version(void)
1392 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1395 static void help(int exitcode
)
1397 const char *options_help
=
1398 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1400 #define DEFHEADING(text) stringify(text) "\n"
1401 #include "qemu-options.def"
1407 printf("usage: %s [options] [disk_image]\n"
1409 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1412 "During emulation, the following keys are useful:\n"
1413 "ctrl-alt-f toggle full screen\n"
1414 "ctrl-alt-n switch to virtual console 'n'\n"
1415 "ctrl-alt toggle mouse and keyboard grab\n"
1417 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1423 #define HAS_ARG 0x0001
1425 typedef struct QEMUOption
{
1432 static const QEMUOption qemu_options
[] = {
1433 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1434 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1435 { option, opt_arg, opt_enum, arch_mask },
1436 #define DEFHEADING(text)
1437 #include "qemu-options.def"
1443 static void select_vgahw (const char *p
)
1448 vga_interface_type
= VGA_NONE
;
1449 if (strstart(p
, "std", &opts
)) {
1450 vga_interface_type
= VGA_STD
;
1451 } else if (strstart(p
, "cirrus", &opts
)) {
1452 vga_interface_type
= VGA_CIRRUS
;
1453 } else if (strstart(p
, "vmware", &opts
)) {
1454 vga_interface_type
= VGA_VMWARE
;
1455 } else if (strstart(p
, "xenfb", &opts
)) {
1456 vga_interface_type
= VGA_XENFB
;
1457 } else if (!strstart(p
, "none", &opts
)) {
1459 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1463 const char *nextopt
;
1465 if (strstart(opts
, ",retrace=", &nextopt
)) {
1467 if (strstart(opts
, "dumb", &nextopt
))
1468 vga_retrace_method
= VGA_RETRACE_DUMB
;
1469 else if (strstart(opts
, "precise", &nextopt
))
1470 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1471 else goto invalid_vga
;
1472 } else goto invalid_vga
;
1477 static int balloon_parse(const char *arg
)
1481 if (strcmp(arg
, "none") == 0) {
1485 if (!strncmp(arg
, "virtio", 6)) {
1486 if (arg
[6] == ',') {
1487 /* have params -> parse them */
1488 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1492 /* create empty opts */
1493 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1495 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1502 char *qemu_find_file(int type
, const char *name
)
1508 /* If name contains path separators then try it as a straight path. */
1509 if ((strchr(name
, '/') || strchr(name
, '\\'))
1510 && access(name
, R_OK
) == 0) {
1511 return qemu_strdup(name
);
1514 case QEMU_FILE_TYPE_BIOS
:
1517 case QEMU_FILE_TYPE_KEYMAP
:
1518 subdir
= "keymaps/";
1523 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1524 buf
= qemu_mallocz(len
);
1525 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1526 if (access(buf
, R_OK
)) {
1533 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1535 return qdev_device_help(opts
);
1538 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1542 dev
= qdev_device_add(opts
);
1548 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1550 CharDriverState
*chr
;
1552 chr
= qemu_chr_open_opts(opts
, NULL
);
1558 #ifdef CONFIG_VIRTFS
1559 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1562 ret
= qemu_fsdev_add(opts
);
1568 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1570 CharDriverState
*chr
;
1571 const char *chardev
;
1575 mode
= qemu_opt_get(opts
, "mode");
1579 if (strcmp(mode
, "readline") == 0) {
1580 flags
= MONITOR_USE_READLINE
;
1581 } else if (strcmp(mode
, "control") == 0) {
1582 flags
= MONITOR_USE_CONTROL
;
1584 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1588 if (qemu_opt_get_bool(opts
, "pretty", 0))
1589 flags
|= MONITOR_USE_PRETTY
;
1591 if (qemu_opt_get_bool(opts
, "default", 0))
1592 flags
|= MONITOR_IS_DEFAULT
;
1594 chardev
= qemu_opt_get(opts
, "chardev");
1595 chr
= qemu_chr_find(chardev
);
1597 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1601 monitor_init(chr
, flags
);
1605 static void monitor_parse(const char *optarg
, const char *mode
)
1607 static int monitor_device_index
= 0;
1613 if (strstart(optarg
, "chardev:", &p
)) {
1614 snprintf(label
, sizeof(label
), "%s", p
);
1616 snprintf(label
, sizeof(label
), "compat_monitor%d",
1617 monitor_device_index
);
1618 if (monitor_device_index
== 0) {
1621 opts
= qemu_chr_parse_compat(label
, optarg
);
1623 fprintf(stderr
, "parse error: %s\n", optarg
);
1628 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1630 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1633 qemu_opt_set(opts
, "mode", mode
);
1634 qemu_opt_set(opts
, "chardev", label
);
1636 qemu_opt_set(opts
, "default", "on");
1637 monitor_device_index
++;
1640 struct device_config
{
1642 DEV_USB
, /* -usbdevice */
1644 DEV_SERIAL
, /* -serial */
1645 DEV_PARALLEL
, /* -parallel */
1646 DEV_VIRTCON
, /* -virtioconsole */
1647 DEV_DEBUGCON
, /* -debugcon */
1649 const char *cmdline
;
1650 QTAILQ_ENTRY(device_config
) next
;
1652 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1654 static void add_device_config(int type
, const char *cmdline
)
1656 struct device_config
*conf
;
1658 conf
= qemu_mallocz(sizeof(*conf
));
1660 conf
->cmdline
= cmdline
;
1661 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1664 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1666 struct device_config
*conf
;
1669 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1670 if (conf
->type
!= type
)
1672 rc
= func(conf
->cmdline
);
1679 static int serial_parse(const char *devname
)
1681 static int index
= 0;
1684 if (strcmp(devname
, "none") == 0)
1686 if (index
== MAX_SERIAL_PORTS
) {
1687 fprintf(stderr
, "qemu: too many serial ports\n");
1690 snprintf(label
, sizeof(label
), "serial%d", index
);
1691 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1692 if (!serial_hds
[index
]) {
1693 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1694 devname
, strerror(errno
));
1701 static int parallel_parse(const char *devname
)
1703 static int index
= 0;
1706 if (strcmp(devname
, "none") == 0)
1708 if (index
== MAX_PARALLEL_PORTS
) {
1709 fprintf(stderr
, "qemu: too many parallel ports\n");
1712 snprintf(label
, sizeof(label
), "parallel%d", index
);
1713 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1714 if (!parallel_hds
[index
]) {
1715 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1716 devname
, strerror(errno
));
1723 static int virtcon_parse(const char *devname
)
1725 QemuOptsList
*device
= qemu_find_opts("device");
1726 static int index
= 0;
1728 QemuOpts
*bus_opts
, *dev_opts
;
1730 if (strcmp(devname
, "none") == 0)
1732 if (index
== MAX_VIRTIO_CONSOLES
) {
1733 fprintf(stderr
, "qemu: too many virtio consoles\n");
1737 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1738 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1740 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1741 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1743 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1744 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1745 if (!virtcon_hds
[index
]) {
1746 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1747 devname
, strerror(errno
));
1750 qemu_opt_set(dev_opts
, "chardev", label
);
1756 static int debugcon_parse(const char *devname
)
1760 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1763 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1765 fprintf(stderr
, "qemu: already have a debugcon device\n");
1768 qemu_opt_set(opts
, "driver", "isa-debugcon");
1769 qemu_opt_set(opts
, "chardev", "debugcon");
1773 void qemu_add_exit_notifier(Notifier
*notify
)
1775 notifier_list_add(&exit_notifiers
, notify
);
1778 void qemu_remove_exit_notifier(Notifier
*notify
)
1780 notifier_list_remove(&exit_notifiers
, notify
);
1783 static void qemu_run_exit_notifiers(void)
1785 notifier_list_notify(&exit_notifiers
);
1788 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1790 notifier_list_add(&machine_init_done_notifiers
, notify
);
1793 static void qemu_run_machine_init_done_notifiers(void)
1795 notifier_list_notify(&machine_init_done_notifiers
);
1798 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1799 const char **poptarg
, int *poptind
)
1801 const QEMUOption
*popt
;
1802 int optind
= *poptind
;
1803 char *r
= argv
[optind
];
1806 loc_set_cmdline(argv
, optind
, 1);
1808 /* Treat --foo the same as -foo. */
1811 popt
= qemu_options
;
1814 error_report("invalid option");
1817 if (!strcmp(popt
->name
, r
+ 1))
1821 if (popt
->flags
& HAS_ARG
) {
1822 if (optind
>= argc
) {
1823 error_report("requires an argument");
1826 optarg
= argv
[optind
++];
1827 loc_set_cmdline(argv
, optind
- 2, 2);
1838 int main(int argc
, char **argv
, char **envp
)
1840 const char *gdbstub_dev
= NULL
;
1842 int snapshot
, linux_boot
;
1843 const char *icount_option
= NULL
;
1844 const char *initrd_filename
;
1845 const char *kernel_filename
, *kernel_cmdline
;
1846 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1848 DisplayChangeListener
*dcl
;
1849 int cyls
, heads
, secs
, translation
;
1850 QemuOpts
*hda_opts
= NULL
, *opts
;
1851 QemuOptsList
*olist
;
1854 const char *loadvm
= NULL
;
1855 QEMUMachine
*machine
;
1856 const char *cpu_model
;
1858 const char *pid_file
= NULL
;
1859 const char *incoming
= NULL
;
1860 int show_vnc_port
= 0;
1863 #ifdef CONFIG_SIMPLE_TRACE
1864 const char *trace_file
= NULL
;
1866 atexit(qemu_run_exit_notifiers
);
1867 error_set_progname(argv
[0]);
1871 qemu_cache_utils_init(envp
);
1873 QLIST_INIT (&vm_change_state_head
);
1874 os_setup_early_signal_handling();
1876 module_call_init(MODULE_INIT_MACHINE
);
1877 machine
= find_default_machine();
1879 initrd_filename
= NULL
;
1882 kernel_filename
= NULL
;
1883 kernel_cmdline
= "";
1884 cyls
= heads
= secs
= 0;
1885 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1887 for (i
= 0; i
< MAX_NODES
; i
++) {
1889 node_cpumask
[i
] = 0;
1898 /* first pass of option parsing */
1900 while (optind
< argc
) {
1901 if (argv
[optind
][0] != '-') {
1906 const QEMUOption
*popt
;
1908 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1909 switch (popt
->index
) {
1910 case QEMU_OPTION_nodefconfig
:
1920 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1921 if (ret
< 0 && ret
!= -ENOENT
) {
1925 ret
= qemu_read_config_file(arch_config_name
);
1926 if (ret
< 0 && ret
!= -ENOENT
) {
1932 /* second pass of option parsing */
1937 if (argv
[optind
][0] != '-') {
1938 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1940 const QEMUOption
*popt
;
1942 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1943 if (!(popt
->arch_mask
& arch_type
)) {
1944 printf("Option %s not supported for this target\n", popt
->name
);
1947 switch(popt
->index
) {
1949 machine
= find_machine(optarg
);
1952 printf("Supported machines are:\n");
1953 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1955 printf("%-10s %s (alias of %s)\n",
1956 m
->alias
, m
->desc
, m
->name
);
1957 printf("%-10s %s%s\n",
1959 m
->is_default
? " (default)" : "");
1961 exit(*optarg
!= '?');
1964 case QEMU_OPTION_cpu
:
1965 /* hw initialization will check this */
1966 if (*optarg
== '?') {
1967 list_cpus(stdout
, &fprintf
, optarg
);
1973 case QEMU_OPTION_initrd
:
1974 initrd_filename
= optarg
;
1976 case QEMU_OPTION_hda
:
1978 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1980 hda_opts
= drive_add(optarg
, HD_ALIAS
1981 ",cyls=%d,heads=%d,secs=%d%s",
1982 0, cyls
, heads
, secs
,
1983 translation
== BIOS_ATA_TRANSLATION_LBA
?
1985 translation
== BIOS_ATA_TRANSLATION_NONE
?
1986 ",trans=none" : "");
1988 case QEMU_OPTION_hdb
:
1989 case QEMU_OPTION_hdc
:
1990 case QEMU_OPTION_hdd
:
1991 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1993 case QEMU_OPTION_drive
:
1994 drive_add(NULL
, "%s", optarg
);
1996 case QEMU_OPTION_set
:
1997 if (qemu_set_option(optarg
) != 0)
2000 case QEMU_OPTION_global
:
2001 if (qemu_global_option(optarg
) != 0)
2004 case QEMU_OPTION_mtdblock
:
2005 drive_add(optarg
, MTD_ALIAS
);
2007 case QEMU_OPTION_sd
:
2008 drive_add(optarg
, SD_ALIAS
);
2010 case QEMU_OPTION_pflash
:
2011 drive_add(optarg
, PFLASH_ALIAS
);
2013 case QEMU_OPTION_snapshot
:
2016 case QEMU_OPTION_hdachs
:
2020 cyls
= strtol(p
, (char **)&p
, 0);
2021 if (cyls
< 1 || cyls
> 16383)
2026 heads
= strtol(p
, (char **)&p
, 0);
2027 if (heads
< 1 || heads
> 16)
2032 secs
= strtol(p
, (char **)&p
, 0);
2033 if (secs
< 1 || secs
> 63)
2037 if (!strcmp(p
, "none"))
2038 translation
= BIOS_ATA_TRANSLATION_NONE
;
2039 else if (!strcmp(p
, "lba"))
2040 translation
= BIOS_ATA_TRANSLATION_LBA
;
2041 else if (!strcmp(p
, "auto"))
2042 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2045 } else if (*p
!= '\0') {
2047 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2050 if (hda_opts
!= NULL
) {
2052 snprintf(num
, sizeof(num
), "%d", cyls
);
2053 qemu_opt_set(hda_opts
, "cyls", num
);
2054 snprintf(num
, sizeof(num
), "%d", heads
);
2055 qemu_opt_set(hda_opts
, "heads", num
);
2056 snprintf(num
, sizeof(num
), "%d", secs
);
2057 qemu_opt_set(hda_opts
, "secs", num
);
2058 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2059 qemu_opt_set(hda_opts
, "trans", "lba");
2060 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2061 qemu_opt_set(hda_opts
, "trans", "none");
2065 case QEMU_OPTION_numa
:
2066 if (nb_numa_nodes
>= MAX_NODES
) {
2067 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2072 case QEMU_OPTION_nographic
:
2073 display_type
= DT_NOGRAPHIC
;
2075 #ifdef CONFIG_CURSES
2076 case QEMU_OPTION_curses
:
2077 display_type
= DT_CURSES
;
2080 case QEMU_OPTION_portrait
:
2083 case QEMU_OPTION_kernel
:
2084 kernel_filename
= optarg
;
2086 case QEMU_OPTION_append
:
2087 kernel_cmdline
= optarg
;
2089 case QEMU_OPTION_cdrom
:
2090 drive_add(optarg
, CDROM_ALIAS
);
2092 case QEMU_OPTION_boot
:
2094 static const char * const params
[] = {
2095 "order", "once", "menu", NULL
2097 char buf
[sizeof(boot_devices
)];
2098 char *standard_boot_devices
;
2101 if (!strchr(optarg
, '=')) {
2103 pstrcpy(buf
, sizeof(buf
), optarg
);
2104 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2106 "qemu: unknown boot parameter '%s' in '%s'\n",
2112 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2113 validate_bootdevices(buf
);
2114 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2117 if (get_param_value(buf
, sizeof(buf
),
2119 validate_bootdevices(buf
);
2120 standard_boot_devices
= qemu_strdup(boot_devices
);
2121 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2122 qemu_register_reset(restore_boot_devices
,
2123 standard_boot_devices
);
2125 if (get_param_value(buf
, sizeof(buf
),
2127 if (!strcmp(buf
, "on")) {
2129 } else if (!strcmp(buf
, "off")) {
2133 "qemu: invalid option value '%s'\n",
2141 case QEMU_OPTION_fda
:
2142 case QEMU_OPTION_fdb
:
2143 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2145 case QEMU_OPTION_no_fd_bootchk
:
2148 case QEMU_OPTION_netdev
:
2149 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2153 case QEMU_OPTION_net
:
2154 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2159 case QEMU_OPTION_tftp
:
2160 legacy_tftp_prefix
= optarg
;
2162 case QEMU_OPTION_bootp
:
2163 legacy_bootp_filename
= optarg
;
2165 case QEMU_OPTION_redir
:
2166 if (net_slirp_redir(optarg
) < 0)
2170 case QEMU_OPTION_bt
:
2171 add_device_config(DEV_BT
, optarg
);
2173 case QEMU_OPTION_audio_help
:
2174 if (!(audio_available())) {
2175 printf("Option %s not supported for this target\n", popt
->name
);
2181 case QEMU_OPTION_soundhw
:
2182 if (!(audio_available())) {
2183 printf("Option %s not supported for this target\n", popt
->name
);
2186 select_soundhw (optarg
);
2191 case QEMU_OPTION_version
:
2195 case QEMU_OPTION_m
: {
2198 value
= strtosz(optarg
, NULL
);
2200 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2204 /* On 32-bit hosts, QEMU is limited by virtual address space */
2205 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2206 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2209 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2210 fprintf(stderr
, "qemu: ram size too large\n");
2216 case QEMU_OPTION_mempath
:
2220 case QEMU_OPTION_mem_prealloc
:
2225 set_cpu_log(optarg
);
2228 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2230 case QEMU_OPTION_gdb
:
2231 gdbstub_dev
= optarg
;
2236 case QEMU_OPTION_bios
:
2239 case QEMU_OPTION_singlestep
:
2246 keyboard_layout
= optarg
;
2248 case QEMU_OPTION_localtime
:
2251 case QEMU_OPTION_vga
:
2252 select_vgahw (optarg
);
2259 w
= strtol(p
, (char **)&p
, 10);
2262 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2268 h
= strtol(p
, (char **)&p
, 10);
2273 depth
= strtol(p
, (char **)&p
, 10);
2274 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2275 depth
!= 24 && depth
!= 32)
2277 } else if (*p
== '\0') {
2278 depth
= graphic_depth
;
2285 graphic_depth
= depth
;
2288 case QEMU_OPTION_echr
:
2291 term_escape_char
= strtol(optarg
, &r
, 0);
2293 printf("Bad argument to echr\n");
2296 case QEMU_OPTION_monitor
:
2297 monitor_parse(optarg
, "readline");
2298 default_monitor
= 0;
2300 case QEMU_OPTION_qmp
:
2301 monitor_parse(optarg
, "control");
2302 default_monitor
= 0;
2304 case QEMU_OPTION_mon
:
2305 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2309 default_monitor
= 0;
2311 case QEMU_OPTION_chardev
:
2312 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2317 case QEMU_OPTION_fsdev
:
2318 olist
= qemu_find_opts("fsdev");
2320 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2323 opts
= qemu_opts_parse(olist
, optarg
, 1);
2325 fprintf(stderr
, "parse error: %s\n", optarg
);
2329 case QEMU_OPTION_virtfs
: {
2330 char *arg_fsdev
= NULL
;
2331 char *arg_9p
= NULL
;
2334 olist
= qemu_find_opts("virtfs");
2336 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2339 opts
= qemu_opts_parse(olist
, optarg
, 1);
2341 fprintf(stderr
, "parse error: %s\n", optarg
);
2345 if (qemu_opt_get(opts
, "fstype") == NULL
||
2346 qemu_opt_get(opts
, "mount_tag") == NULL
||
2347 qemu_opt_get(opts
, "path") == NULL
||
2348 qemu_opt_get(opts
, "security_model") == NULL
) {
2349 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2350 "security_model=[mapped|passthrough|none],"
2355 len
= strlen(",id=,path=,security_model=");
2356 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2357 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2358 len
+= strlen(qemu_opt_get(opts
, "path"));
2359 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2360 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2362 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2363 "%s,id=%s,path=%s,security_model=%s",
2364 qemu_opt_get(opts
, "fstype"),
2365 qemu_opt_get(opts
, "mount_tag"),
2366 qemu_opt_get(opts
, "path"),
2367 qemu_opt_get(opts
, "security_model"));
2369 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2370 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2371 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2373 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2374 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2375 qemu_opt_get(opts
, "mount_tag"),
2376 qemu_opt_get(opts
, "mount_tag"));
2378 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2379 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2383 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2384 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2388 qemu_free(arg_fsdev
);
2392 case QEMU_OPTION_serial
:
2393 add_device_config(DEV_SERIAL
, optarg
);
2395 if (strncmp(optarg
, "mon:", 4) == 0) {
2396 default_monitor
= 0;
2399 case QEMU_OPTION_watchdog
:
2402 "qemu: only one watchdog option may be given\n");
2407 case QEMU_OPTION_watchdog_action
:
2408 if (select_watchdog_action(optarg
) == -1) {
2409 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2413 case QEMU_OPTION_virtiocon
:
2414 add_device_config(DEV_VIRTCON
, optarg
);
2415 default_virtcon
= 0;
2416 if (strncmp(optarg
, "mon:", 4) == 0) {
2417 default_monitor
= 0;
2420 case QEMU_OPTION_parallel
:
2421 add_device_config(DEV_PARALLEL
, optarg
);
2422 default_parallel
= 0;
2423 if (strncmp(optarg
, "mon:", 4) == 0) {
2424 default_monitor
= 0;
2427 case QEMU_OPTION_debugcon
:
2428 add_device_config(DEV_DEBUGCON
, optarg
);
2430 case QEMU_OPTION_loadvm
:
2433 case QEMU_OPTION_full_screen
:
2437 case QEMU_OPTION_no_frame
:
2440 case QEMU_OPTION_alt_grab
:
2443 case QEMU_OPTION_ctrl_grab
:
2446 case QEMU_OPTION_no_quit
:
2449 case QEMU_OPTION_sdl
:
2450 display_type
= DT_SDL
;
2453 case QEMU_OPTION_pidfile
:
2456 case QEMU_OPTION_win2k_hack
:
2457 win2k_install_hack
= 1;
2459 case QEMU_OPTION_rtc_td_hack
:
2462 case QEMU_OPTION_acpitable
:
2463 do_acpitable_option(optarg
);
2465 case QEMU_OPTION_smbios
:
2466 do_smbios_option(optarg
);
2468 case QEMU_OPTION_enable_kvm
:
2471 case QEMU_OPTION_usb
:
2474 case QEMU_OPTION_usbdevice
:
2476 add_device_config(DEV_USB
, optarg
);
2478 case QEMU_OPTION_device
:
2479 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2483 case QEMU_OPTION_smp
:
2486 fprintf(stderr
, "Invalid number of CPUs\n");
2489 if (max_cpus
< smp_cpus
) {
2490 fprintf(stderr
, "maxcpus must be equal to or greater than "
2494 if (max_cpus
> 255) {
2495 fprintf(stderr
, "Unsupported number of maxcpus\n");
2499 case QEMU_OPTION_vnc
:
2501 vnc_display
= optarg
;
2503 case QEMU_OPTION_no_acpi
:
2506 case QEMU_OPTION_no_hpet
:
2509 case QEMU_OPTION_balloon
:
2510 if (balloon_parse(optarg
) < 0) {
2511 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2515 case QEMU_OPTION_no_reboot
:
2518 case QEMU_OPTION_no_shutdown
:
2521 case QEMU_OPTION_show_cursor
:
2524 case QEMU_OPTION_uuid
:
2525 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2526 fprintf(stderr
, "Fail to parse UUID string."
2527 " Wrong format.\n");
2531 case QEMU_OPTION_option_rom
:
2532 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2533 fprintf(stderr
, "Too many option ROMs\n");
2536 opts
= qemu_opts_parse(qemu_find_opts("option-rom"), optarg
, 1);
2537 option_rom
[nb_option_roms
].name
= qemu_opt_get(opts
, "romfile");
2538 option_rom
[nb_option_roms
].bootindex
=
2539 qemu_opt_get_number(opts
, "bootindex", -1);
2540 if (!option_rom
[nb_option_roms
].name
) {
2541 fprintf(stderr
, "Option ROM file is not specified\n");
2546 case QEMU_OPTION_semihosting
:
2547 semihosting_enabled
= 1;
2549 case QEMU_OPTION_name
:
2550 qemu_name
= qemu_strdup(optarg
);
2552 char *p
= strchr(qemu_name
, ',');
2555 if (strncmp(p
, "process=", 8)) {
2556 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2560 os_set_proc_name(p
);
2564 case QEMU_OPTION_prom_env
:
2565 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2566 fprintf(stderr
, "Too many prom variables\n");
2569 prom_envs
[nb_prom_envs
] = optarg
;
2572 case QEMU_OPTION_old_param
:
2575 case QEMU_OPTION_clock
:
2576 configure_alarms(optarg
);
2578 case QEMU_OPTION_startdate
:
2579 configure_rtc_date_offset(optarg
, 1);
2581 case QEMU_OPTION_rtc
:
2582 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2586 configure_rtc(opts
);
2588 case QEMU_OPTION_tb_size
:
2589 tb_size
= strtol(optarg
, NULL
, 0);
2593 case QEMU_OPTION_icount
:
2594 icount_option
= optarg
;
2596 case QEMU_OPTION_incoming
:
2598 incoming_expected
= true;
2600 case QEMU_OPTION_nodefaults
:
2602 default_parallel
= 0;
2603 default_virtcon
= 0;
2604 default_monitor
= 0;
2611 case QEMU_OPTION_xen_domid
:
2612 if (!(xen_available())) {
2613 printf("Option %s not supported for this target\n", popt
->name
);
2616 xen_domid
= atoi(optarg
);
2618 case QEMU_OPTION_xen_create
:
2619 if (!(xen_available())) {
2620 printf("Option %s not supported for this target\n", popt
->name
);
2623 xen_mode
= XEN_CREATE
;
2625 case QEMU_OPTION_xen_attach
:
2626 if (!(xen_available())) {
2627 printf("Option %s not supported for this target\n", popt
->name
);
2630 xen_mode
= XEN_ATTACH
;
2632 #ifdef CONFIG_SIMPLE_TRACE
2633 case QEMU_OPTION_trace
:
2634 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2636 trace_file
= qemu_opt_get(opts
, "file");
2640 case QEMU_OPTION_readconfig
:
2642 int ret
= qemu_read_config_file(optarg
);
2644 fprintf(stderr
, "read config %s: %s\n", optarg
,
2650 case QEMU_OPTION_spice
:
2651 olist
= qemu_find_opts("spice");
2653 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2656 opts
= qemu_opts_parse(olist
, optarg
, 0);
2658 fprintf(stderr
, "parse error: %s\n", optarg
);
2662 case QEMU_OPTION_writeconfig
:
2665 if (strcmp(optarg
, "-") == 0) {
2668 fp
= fopen(optarg
, "w");
2670 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2674 qemu_config_write(fp
);
2679 os_parse_cmd_args(popt
->index
, optarg
);
2685 /* If no data_dir is specified then try to find it relative to the
2688 data_dir
= os_find_datadir(argv
[0]);
2690 /* If all else fails use the install patch specified when building. */
2692 data_dir
= CONFIG_QEMU_DATADIR
;
2695 #ifdef CONFIG_SIMPLE_TRACE
2697 * Set the trace file name, if specified.
2699 st_set_trace_file(trace_file
);
2702 * Default to max_cpus = smp_cpus, in case the user doesn't
2703 * specify a max_cpus value.
2706 max_cpus
= smp_cpus
;
2708 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2709 if (smp_cpus
> machine
->max_cpus
) {
2710 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2711 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2716 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2717 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2719 if (machine
->no_serial
) {
2722 if (machine
->no_parallel
) {
2723 default_parallel
= 0;
2725 if (!machine
->use_virtcon
) {
2726 default_virtcon
= 0;
2728 if (machine
->no_vga
) {
2731 if (machine
->no_floppy
) {
2734 if (machine
->no_cdrom
) {
2737 if (machine
->no_sdcard
) {
2741 if (display_type
== DT_NOGRAPHIC
) {
2742 if (default_parallel
)
2743 add_device_config(DEV_PARALLEL
, "null");
2744 if (default_serial
&& default_monitor
) {
2745 add_device_config(DEV_SERIAL
, "mon:stdio");
2746 } else if (default_virtcon
&& default_monitor
) {
2747 add_device_config(DEV_VIRTCON
, "mon:stdio");
2750 add_device_config(DEV_SERIAL
, "stdio");
2751 if (default_virtcon
)
2752 add_device_config(DEV_VIRTCON
, "stdio");
2753 if (default_monitor
)
2754 monitor_parse("stdio", "readline");
2758 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2759 if (default_parallel
)
2760 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2761 if (default_monitor
)
2762 monitor_parse("vc:80Cx24C", "readline");
2763 if (default_virtcon
)
2764 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2767 vga_interface_type
= VGA_CIRRUS
;
2771 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2773 #ifdef CONFIG_VIRTFS
2774 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2781 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2787 int ret
= kvm_init(smp_cpus
);
2789 if (!kvm_available()) {
2790 printf("KVM not supported for this target\n");
2792 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2798 if (qemu_init_main_loop()) {
2799 fprintf(stderr
, "qemu_init_main_loop failed\n");
2802 linux_boot
= (kernel_filename
!= NULL
);
2804 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2805 fprintf(stderr
, "-append only allowed with -kernel option\n");
2809 if (!linux_boot
&& initrd_filename
!= NULL
) {
2810 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2814 os_set_line_buffering();
2816 if (init_timer_alarm() < 0) {
2817 fprintf(stderr
, "could not initialize alarm timer\n");
2820 configure_icount(icount_option
);
2822 if (net_init_clients() < 0) {
2826 /* init the bluetooth world */
2827 if (foreach_device_config(DEV_BT
, bt_parse
))
2830 /* init the memory */
2832 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2834 /* init the dynamic translator */
2835 cpu_exec_init_all(tb_size
* 1024 * 1024);
2837 bdrv_init_with_whitelist();
2841 if (default_cdrom
) {
2842 /* we always create the cdrom drive, even if no disk is there */
2843 drive_add(NULL
, CDROM_ALIAS
);
2846 if (default_floppy
) {
2847 /* we always create at least one floppy */
2848 drive_add(NULL
, FD_ALIAS
, 0);
2851 if (default_sdcard
) {
2852 /* we always create one sd slot, even if no card is in it */
2853 drive_add(NULL
, SD_ALIAS
);
2856 /* open the virtual block devices */
2858 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2859 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2862 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2865 if (nb_numa_nodes
> 0) {
2868 if (nb_numa_nodes
> smp_cpus
) {
2869 nb_numa_nodes
= smp_cpus
;
2872 /* If no memory size if given for any node, assume the default case
2873 * and distribute the available memory equally across all nodes
2875 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2876 if (node_mem
[i
] != 0)
2879 if (i
== nb_numa_nodes
) {
2880 uint64_t usedmem
= 0;
2882 /* On Linux, the each node's border has to be 8MB aligned,
2883 * the final node gets the rest.
2885 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2886 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2887 usedmem
+= node_mem
[i
];
2889 node_mem
[i
] = ram_size
- usedmem
;
2892 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2893 if (node_cpumask
[i
] != 0)
2896 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2897 * must cope with this anyway, because there are BIOSes out there in
2898 * real machines which also use this scheme.
2900 if (i
== nb_numa_nodes
) {
2901 for (i
= 0; i
< smp_cpus
; i
++) {
2902 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2907 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2911 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2913 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2915 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2917 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2920 module_call_init(MODULE_INIT_DEVICE
);
2922 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2926 i
= select_watchdog(watchdog
);
2928 exit (i
== 1 ? 1 : 0);
2931 if (machine
->compat_props
) {
2932 qdev_prop_register_global_list(machine
->compat_props
);
2936 machine
->init(ram_size
, boot_devices
,
2937 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2939 cpu_synchronize_all_post_init();
2941 /* must be after terminal init, SDL library changes signal handlers */
2942 os_setup_signal_handling();
2946 current_machine
= machine
;
2948 /* init USB devices */
2950 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2954 /* init generic devices */
2955 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
2958 net_check_clients();
2960 /* just use the first displaystate for the moment */
2961 ds
= get_displaystate();
2965 if (display_type
== DT_DEFAULT
&& !display_remote
) {
2966 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2967 display_type
= DT_SDL
;
2969 vnc_display
= "localhost:0,to=99";
2975 /* init local displays */
2976 switch (display_type
) {
2979 #if defined(CONFIG_CURSES)
2981 curses_display_init(ds
, full_screen
);
2984 #if defined(CONFIG_SDL)
2986 sdl_display_init(ds
, full_screen
, no_frame
);
2988 #elif defined(CONFIG_COCOA)
2990 cocoa_display_init(ds
, full_screen
);
2997 /* init remote displays */
2999 vnc_display_init(ds
);
3000 if (vnc_display_open(ds
, vnc_display
) < 0)
3003 if (show_vnc_port
) {
3004 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3009 qemu_spice_display_init(ds
);
3015 dcl
= ds
->listeners
;
3016 while (dcl
!= NULL
) {
3017 if (dcl
->dpy_refresh
!= NULL
) {
3018 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3019 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3024 if (ds
->gui_timer
== NULL
) {
3025 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3026 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3028 text_consoles_set_display(ds
);
3030 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3031 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3036 qdev_machine_creation_done();
3038 if (rom_load_all() != 0) {
3039 fprintf(stderr
, "rom loading failed\n");
3043 qemu_register_reset((void *)qbus_reset_all
, sysbus_get_default());
3044 qemu_run_machine_init_done_notifiers();
3046 qemu_system_reset();
3048 if (load_vmstate(loadvm
) < 0) {
3054 int ret
= qemu_start_incoming_migration(incoming
);
3056 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3060 } else if (autostart
) {