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>
52 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
54 #include <sys/sysctl.h>
63 #include <linux/ppdev.h>
64 #include <linux/parport.h>
68 #include <sys/ethernet.h>
69 #include <sys/sockio.h>
70 #include <netinet/arp.h>
71 #include <netinet/in_systm.h>
72 #include <netinet/ip.h>
73 #include <netinet/ip_icmp.h> // must come after ip.h
74 #include <netinet/udp.h>
75 #include <netinet/tcp.h>
79 /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
80 discussion about Solaris header problems */
81 extern int madvise(caddr_t
, size_t, int);
86 #if defined(__OpenBSD__)
90 #if defined(CONFIG_VDE)
91 #include <libvdeplug.h>
99 #if defined(__APPLE__) || defined(main)
101 int qemu_main(int argc
, char **argv
, char **envp
);
102 int main(int argc
, char **argv
)
104 return qemu_main(argc
, argv
, NULL
);
107 #define main qemu_main
109 #endif /* CONFIG_SDL */
113 #define main qemu_main
114 #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"
140 #include "blockdev.h"
141 #include "block-migration.h"
143 #include "audio/audio.h"
144 #include "migration.h"
146 #include "qemu-option.h"
147 #include "qemu-config.h"
148 #include "qemu-objects.h"
149 #include "qemu-options.h"
150 #include "hw/device-assignment.h"
152 #include "fsdev/qemu-fsdev.h"
157 #include "qemu_socket.h"
159 #include "slirp/libslirp.h"
161 #include "qemu-queue.h"
163 #include "arch_init.h"
166 //#define DEBUG_SLIRP
168 #define DEFAULT_RAM_SIZE 128
170 #define MAX_VIRTIO_CONSOLES 1
172 static const char *data_dir
;
173 const char *bios_name
= NULL
;
174 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
175 DisplayType display_type
= DT_DEFAULT
;
176 const char* keyboard_layout
= NULL
;
178 const char *mem_path
= NULL
;
180 int mem_prealloc
= 0; /* force preallocation of physical target memory */
183 NICInfo nd_table
[MAX_NICS
];
186 int incoming_expected
; /* Started with -incoming and waiting for incoming */
187 static int rtc_utc
= 1;
188 static int rtc_date_offset
= -1; /* -1 means no change */
189 QEMUClock
*rtc_clock
;
190 int vga_interface_type
= VGA_NONE
;
191 static int full_screen
= 0;
193 static int no_frame
= 0;
196 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
197 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
198 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
199 int win2k_install_hack
= 0;
203 const char *assigned_devices
[MAX_DEV_ASSIGN_CMDLINE
];
204 int assigned_devices_index
;
209 const char *vnc_display
;
210 int acpi_enabled
= 1;
216 int graphic_rotate
= 0;
217 uint8_t irq0override
= 1;
218 const char *watchdog
;
219 const char *option_rom
[MAX_OPTION_ROMS
];
221 int semihosting_enabled
= 0;
222 int time_drift_fix
= 0;
223 unsigned int kvm_shadow_memory
= 0;
225 const char *qemu_name
;
228 unsigned int nb_prom_envs
= 0;
229 const char *prom_envs
[MAX_PROM_ENVS
];
230 const char *nvram
= NULL
;
234 uint64_t node_mem
[MAX_NODES
];
235 uint64_t node_cpumask
[MAX_NODES
];
237 static QEMUTimer
*nographic_timer
;
239 uint8_t qemu_uuid
[16];
241 static QEMUBootSetHandler
*boot_set_handler
;
242 static void *boot_set_opaque
;
244 static NotifierList exit_notifiers
=
245 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
249 enum xen_mode xen_mode
= XEN_EMULATE
;
251 static int default_serial
= 1;
252 static int default_parallel
= 1;
253 static int default_virtcon
= 1;
254 static int default_monitor
= 1;
255 static int default_vga
= 1;
256 static int default_floppy
= 1;
257 static int default_cdrom
= 1;
258 static int default_sdcard
= 1;
264 { .driver
= "isa-serial", .flag
= &default_serial
},
265 { .driver
= "isa-parallel", .flag
= &default_parallel
},
266 { .driver
= "isa-fdc", .flag
= &default_floppy
},
267 { .driver
= "ide-drive", .flag
= &default_cdrom
},
268 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
269 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
270 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
271 { .driver
= "VGA", .flag
= &default_vga
},
272 { .driver
= "cirrus-vga", .flag
= &default_vga
},
273 { .driver
= "vmware-svga", .flag
= &default_vga
},
276 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
278 const char *driver
= qemu_opt_get(opts
, "driver");
283 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
284 if (strcmp(default_list
[i
].driver
, driver
) != 0)
286 *(default_list
[i
].flag
) = 0;
291 /***********************************************************/
292 /* real time host monotonic timer */
294 /* compute with 96 bit intermediate result: (a*b)/c */
295 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
300 #ifdef HOST_WORDS_BIGENDIAN
310 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
311 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
314 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
318 /***********************************************************/
319 /* host time/date access */
320 void qemu_get_timedate(struct tm
*tm
, int offset
)
327 if (rtc_date_offset
== -1) {
331 ret
= localtime(&ti
);
333 ti
-= rtc_date_offset
;
337 memcpy(tm
, ret
, sizeof(struct tm
));
340 int qemu_timedate_diff(struct tm
*tm
)
344 if (rtc_date_offset
== -1)
346 seconds
= mktimegm(tm
);
348 seconds
= mktime(tm
);
350 seconds
= mktimegm(tm
) + rtc_date_offset
;
352 return seconds
- time(NULL
);
355 void rtc_change_mon_event(struct tm
*tm
)
359 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
360 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
361 qobject_decref(data
);
364 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
366 time_t rtc_start_date
;
369 if (!strcmp(startdate
, "now") && legacy
) {
370 rtc_date_offset
= -1;
372 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
380 } else if (sscanf(startdate
, "%d-%d-%d",
392 rtc_start_date
= mktimegm(&tm
);
393 if (rtc_start_date
== -1) {
395 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
396 "'2006-06-17T16:01:21' or '2006-06-17'\n");
399 rtc_date_offset
= time(NULL
) - rtc_start_date
;
403 static void configure_rtc(QemuOpts
*opts
)
407 value
= qemu_opt_get(opts
, "base");
409 if (!strcmp(value
, "utc")) {
411 } else if (!strcmp(value
, "localtime")) {
414 configure_rtc_date_offset(value
, 0);
417 value
= qemu_opt_get(opts
, "clock");
419 if (!strcmp(value
, "host")) {
420 rtc_clock
= host_clock
;
421 } else if (!strcmp(value
, "vm")) {
422 rtc_clock
= vm_clock
;
424 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
428 value
= qemu_opt_get(opts
, "driftfix");
430 if (!strcmp(value
, "slew")) {
432 } else if (!strcmp(value
, "none")) {
435 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
441 /***********************************************************/
442 /* Bluetooth support */
445 static struct HCIInfo
*hci_table
[MAX_NICS
];
447 static struct bt_vlan_s
{
448 struct bt_scatternet_s net
;
450 struct bt_vlan_s
*next
;
453 /* find or alloc a new bluetooth "VLAN" */
454 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
456 struct bt_vlan_s
**pvlan
, *vlan
;
457 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
461 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
463 pvlan
= &first_bt_vlan
;
464 while (*pvlan
!= NULL
)
465 pvlan
= &(*pvlan
)->next
;
470 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
474 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
479 static struct HCIInfo null_hci
= {
480 .cmd_send
= null_hci_send
,
481 .sco_send
= null_hci_send
,
482 .acl_send
= null_hci_send
,
483 .bdaddr_set
= null_hci_addr_set
,
486 struct HCIInfo
*qemu_next_hci(void)
488 if (cur_hci
== nb_hcis
)
491 return hci_table
[cur_hci
++];
494 static struct HCIInfo
*hci_init(const char *str
)
497 struct bt_scatternet_s
*vlan
= 0;
499 if (!strcmp(str
, "null"))
502 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
504 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
505 else if (!strncmp(str
, "hci", 3)) {
508 if (!strncmp(str
+ 3, ",vlan=", 6)) {
509 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
514 vlan
= qemu_find_bt_vlan(0);
516 return bt_new_hci(vlan
);
519 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
524 static int bt_hci_parse(const char *str
)
529 if (nb_hcis
>= MAX_NICS
) {
530 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
543 bdaddr
.b
[5] = 0x56 + nb_hcis
;
544 hci
->bdaddr_set(hci
, bdaddr
.b
);
546 hci_table
[nb_hcis
++] = hci
;
551 static void bt_vhci_add(int vlan_id
)
553 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
556 fprintf(stderr
, "qemu: warning: adding a VHCI to "
557 "an empty scatternet %i\n", vlan_id
);
559 bt_vhci_init(bt_new_hci(vlan
));
562 static struct bt_device_s
*bt_device_add(const char *opt
)
564 struct bt_scatternet_s
*vlan
;
566 char *endp
= strstr(opt
, ",vlan=");
567 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
570 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
573 vlan_id
= strtol(endp
+ 6, &endp
, 0);
575 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
580 vlan
= qemu_find_bt_vlan(vlan_id
);
583 fprintf(stderr
, "qemu: warning: adding a slave device to "
584 "an empty scatternet %i\n", vlan_id
);
586 if (!strcmp(devname
, "keyboard"))
587 return bt_keyboard_init(vlan
);
589 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
593 static int bt_parse(const char *opt
)
595 const char *endp
, *p
;
598 if (strstart(opt
, "hci", &endp
)) {
599 if (!*endp
|| *endp
== ',') {
601 if (!strstart(endp
, ",vlan=", 0))
604 return bt_hci_parse(opt
);
606 } else if (strstart(opt
, "vhci", &endp
)) {
607 if (!*endp
|| *endp
== ',') {
609 if (strstart(endp
, ",vlan=", &p
)) {
610 vlan
= strtol(p
, (char **) &endp
, 0);
612 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
616 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
625 } else if (strstart(opt
, "device:", &endp
))
626 return !bt_device_add(endp
);
628 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
632 /***********************************************************/
633 /* QEMU Block devices */
635 #define HD_ALIAS "index=%d,media=disk"
636 #define CDROM_ALIAS "index=2,media=cdrom"
637 #define FD_ALIAS "index=%d,if=floppy"
638 #define PFLASH_ALIAS "if=pflash"
639 #define MTD_ALIAS "if=mtd"
640 #define SD_ALIAS "index=0,if=sd"
642 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
644 int *use_scsi
= opaque
;
647 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
654 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
656 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
657 qemu_opt_set(opts
, "snapshot", "on");
662 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
664 boot_set_handler
= func
;
665 boot_set_opaque
= opaque
;
668 int qemu_boot_set(const char *boot_devices
)
670 if (!boot_set_handler
) {
673 return boot_set_handler(boot_set_opaque
, boot_devices
);
676 static void validate_bootdevices(char *devices
)
678 /* We just do some generic consistency checks */
682 for (p
= devices
; *p
!= '\0'; p
++) {
683 /* Allowed boot devices are:
684 * a-b: floppy disk drives
685 * c-f: IDE disk drives
686 * g-m: machine implementation dependant drives
687 * n-p: network devices
688 * It's up to each machine implementation to check if the given boot
689 * devices match the actual hardware implementation and firmware
692 if (*p
< 'a' || *p
> 'p') {
693 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
696 if (bitmap
& (1 << (*p
- 'a'))) {
697 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
700 bitmap
|= 1 << (*p
- 'a');
704 static void restore_boot_devices(void *opaque
)
706 char *standard_boot_devices
= opaque
;
707 static int first
= 1;
709 /* Restore boot order and remove ourselves after the first boot */
715 qemu_boot_set(standard_boot_devices
);
717 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
718 qemu_free(standard_boot_devices
);
721 static void numa_add(const char *optarg
)
725 unsigned long long value
, endvalue
;
728 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
729 if (!strcmp(option
, "node")) {
730 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
731 nodenr
= nb_numa_nodes
;
733 nodenr
= strtoull(option
, NULL
, 10);
736 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
737 node_mem
[nodenr
] = 0;
739 value
= strtoull(option
, &endptr
, 0);
741 case 0: case 'M': case 'm':
748 node_mem
[nodenr
] = value
;
750 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
751 node_cpumask
[nodenr
] = 0;
753 value
= strtoull(option
, &endptr
, 10);
756 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
758 if (*endptr
== '-') {
759 endvalue
= strtoull(endptr
+1, &endptr
, 10);
760 if (endvalue
>= 63) {
763 "only 63 CPUs in NUMA mode supported.\n");
765 value
= (2ULL << endvalue
) - (1ULL << value
);
767 value
= 1ULL << value
;
770 node_cpumask
[nodenr
] = value
;
777 static void smp_parse(const char *optarg
)
779 int smp
, sockets
= 0, threads
= 0, cores
= 0;
783 smp
= strtoul(optarg
, &endptr
, 10);
784 if (endptr
!= optarg
) {
785 if (*endptr
== ',') {
789 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
790 sockets
= strtoull(option
, NULL
, 10);
791 if (get_param_value(option
, 128, "cores", endptr
) != 0)
792 cores
= strtoull(option
, NULL
, 10);
793 if (get_param_value(option
, 128, "threads", endptr
) != 0)
794 threads
= strtoull(option
, NULL
, 10);
795 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
796 max_cpus
= strtoull(option
, NULL
, 10);
798 /* compute missing values, prefer sockets over cores over threads */
799 if (smp
== 0 || sockets
== 0) {
800 sockets
= sockets
> 0 ? sockets
: 1;
801 cores
= cores
> 0 ? cores
: 1;
802 threads
= threads
> 0 ? threads
: 1;
804 smp
= cores
* threads
* sockets
;
808 threads
= threads
> 0 ? threads
: 1;
809 cores
= smp
/ (sockets
* threads
);
811 threads
= smp
/ (cores
* sockets
);
815 smp_cores
= cores
> 0 ? cores
: 1;
816 smp_threads
= threads
> 0 ? threads
: 1;
821 /***********************************************************/
824 static int usb_device_add(const char *devname
)
827 USBDevice
*dev
= NULL
;
832 /* drivers with .usbdevice_name entry in USBDeviceInfo */
833 dev
= usbdevice_create(devname
);
838 if (strstart(devname
, "host:", &p
)) {
839 dev
= usb_host_device_open(p
);
840 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
841 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
842 bt_new_hci(qemu_find_bt_vlan(0)));
853 static int usb_device_del(const char *devname
)
858 if (strstart(devname
, "host:", &p
))
859 return usb_host_device_close(p
);
864 p
= strchr(devname
, '.');
867 bus_num
= strtoul(devname
, NULL
, 0);
868 addr
= strtoul(p
+ 1, NULL
, 0);
870 return usb_device_delete_addr(bus_num
, addr
);
873 static int usb_parse(const char *cmdline
)
876 r
= usb_device_add(cmdline
);
878 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
883 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
885 const char *devname
= qdict_get_str(qdict
, "devname");
886 if (usb_device_add(devname
) < 0) {
887 error_report("could not add USB device '%s'", devname
);
891 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
893 const char *devname
= qdict_get_str(qdict
, "devname");
894 if (usb_device_del(devname
) < 0) {
895 error_report("could not delete USB device '%s'", devname
);
899 /***********************************************************/
902 static struct pcmcia_socket_entry_s
{
903 PCMCIASocket
*socket
;
904 struct pcmcia_socket_entry_s
*next
;
905 } *pcmcia_sockets
= 0;
907 void pcmcia_socket_register(PCMCIASocket
*socket
)
909 struct pcmcia_socket_entry_s
*entry
;
911 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
912 entry
->socket
= socket
;
913 entry
->next
= pcmcia_sockets
;
914 pcmcia_sockets
= entry
;
917 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
919 struct pcmcia_socket_entry_s
*entry
, **ptr
;
921 ptr
= &pcmcia_sockets
;
922 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
923 if (entry
->socket
== socket
) {
929 void pcmcia_info(Monitor
*mon
)
931 struct pcmcia_socket_entry_s
*iter
;
934 monitor_printf(mon
, "No PCMCIA sockets\n");
936 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
937 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
938 iter
->socket
->attached
? iter
->socket
->card_string
:
942 /***********************************************************/
945 typedef struct IOHandlerRecord
{
947 IOCanReadHandler
*fd_read_poll
;
954 QLIST_ENTRY(IOHandlerRecord
) next
;
957 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
958 QLIST_HEAD_INITIALIZER(io_handlers
);
961 /* XXX: fd_read_poll should be suppressed, but an API change is
962 necessary in the character devices to suppress fd_can_read(). */
963 int qemu_set_fd_handler2(int fd
,
964 IOCanReadHandler
*fd_read_poll
,
969 IOHandlerRecord
*ioh
;
971 if (!fd_read
&& !fd_write
) {
972 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
979 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
983 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
984 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
987 ioh
->fd_read_poll
= fd_read_poll
;
988 ioh
->fd_read
= fd_read
;
989 ioh
->fd_write
= fd_write
;
990 ioh
->opaque
= opaque
;
997 int qemu_set_fd_handler(int fd
,
1002 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1005 /***********************************************************/
1006 /* machine registration */
1008 static QEMUMachine
*first_machine
= NULL
;
1009 QEMUMachine
*current_machine
= NULL
;
1011 int qemu_register_machine(QEMUMachine
*m
)
1014 pm
= &first_machine
;
1022 static QEMUMachine
*find_machine(const char *name
)
1026 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1027 if (!strcmp(m
->name
, name
))
1029 if (m
->alias
&& !strcmp(m
->alias
, name
))
1035 static QEMUMachine
*find_default_machine(void)
1039 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1040 if (m
->is_default
) {
1047 /***********************************************************/
1048 /* main execution loop */
1050 static void gui_update(void *opaque
)
1052 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1053 DisplayState
*ds
= opaque
;
1054 DisplayChangeListener
*dcl
= ds
->listeners
;
1056 qemu_flush_coalesced_mmio_buffer();
1059 while (dcl
!= NULL
) {
1060 if (dcl
->gui_timer_interval
&&
1061 dcl
->gui_timer_interval
< interval
)
1062 interval
= dcl
->gui_timer_interval
;
1065 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1068 static void nographic_update(void *opaque
)
1070 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1072 qemu_flush_coalesced_mmio_buffer();
1073 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1076 struct vm_change_state_entry
{
1077 VMChangeStateHandler
*cb
;
1079 QLIST_ENTRY (vm_change_state_entry
) entries
;
1082 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1084 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1087 VMChangeStateEntry
*e
;
1089 e
= qemu_mallocz(sizeof (*e
));
1093 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1097 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1099 QLIST_REMOVE (e
, entries
);
1103 void vm_state_notify(int running
, int reason
)
1105 VMChangeStateEntry
*e
;
1107 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1108 e
->cb(e
->opaque
, running
, reason
);
1117 vm_state_notify(1, 0);
1119 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1123 /* reset/shutdown handler */
1125 typedef struct QEMUResetEntry
{
1126 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1127 QEMUResetHandler
*func
;
1131 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1132 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1133 static int reset_requested
;
1134 static int shutdown_requested
;
1135 static int powerdown_requested
;
1136 int debug_requested
;
1137 int vmstop_requested
;
1139 int qemu_no_shutdown(void)
1141 int r
= no_shutdown
;
1146 int qemu_shutdown_requested(void)
1148 int r
= shutdown_requested
;
1149 shutdown_requested
= 0;
1153 int qemu_reset_requested(void)
1155 int r
= reset_requested
;
1156 reset_requested
= 0;
1160 int qemu_powerdown_requested(void)
1162 int r
= powerdown_requested
;
1163 powerdown_requested
= 0;
1167 static int qemu_debug_requested(void)
1169 int r
= debug_requested
;
1170 debug_requested
= 0;
1174 static int qemu_vmstop_requested(void)
1176 int r
= vmstop_requested
;
1177 vmstop_requested
= 0;
1181 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1183 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1186 re
->opaque
= opaque
;
1187 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1190 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1194 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1195 if (re
->func
== func
&& re
->opaque
== opaque
) {
1196 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1203 void qemu_system_reset(void)
1205 QEMUResetEntry
*re
, *nre
;
1207 /* reset all devices */
1208 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1209 re
->func(re
->opaque
);
1211 monitor_protocol_event(QEVENT_RESET
, NULL
);
1212 cpu_synchronize_all_post_reset();
1215 void qemu_system_reset_request(void)
1218 shutdown_requested
= 1;
1220 reset_requested
= 1;
1222 if (cpu_single_env
) {
1223 cpu_single_env
->stopped
= 1;
1224 cpu_exit(cpu_single_env
);
1226 qemu_notify_event();
1229 void qemu_system_shutdown_request(void)
1231 shutdown_requested
= 1;
1232 qemu_notify_event();
1235 void qemu_system_powerdown_request(void)
1237 powerdown_requested
= 1;
1238 qemu_notify_event();
1241 void main_loop_wait(int nonblocking
)
1243 IOHandlerRecord
*ioh
;
1244 fd_set rfds
, wfds
, xfds
;
1252 timeout
= qemu_calculate_timeout();
1253 qemu_bh_update_timeout(&timeout
);
1256 os_host_main_loop_wait(&timeout
);
1258 /* poll any events */
1259 /* XXX: separate device handlers from system ones */
1264 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1268 (!ioh
->fd_read_poll
||
1269 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1270 FD_SET(ioh
->fd
, &rfds
);
1274 if (ioh
->fd_write
) {
1275 FD_SET(ioh
->fd
, &wfds
);
1281 tv
.tv_sec
= timeout
/ 1000;
1282 tv
.tv_usec
= (timeout
% 1000) * 1000;
1284 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1286 qemu_mutex_unlock_iothread();
1287 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1288 qemu_mutex_lock_iothread();
1290 IOHandlerRecord
*pioh
;
1292 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1294 QLIST_REMOVE(ioh
, next
);
1298 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1299 ioh
->fd_read(ioh
->opaque
);
1300 if (!(ioh
->fd_read_poll
&& ioh
->fd_read_poll(ioh
->opaque
)))
1301 FD_CLR(ioh
->fd
, &rfds
);
1303 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1304 ioh
->fd_write(ioh
->opaque
);
1309 slirp_select_poll(&rfds
, &wfds
, &xfds
, (ret
< 0));
1311 qemu_run_all_timers();
1313 /* Check bottom-halves last in case any of the earlier events triggered
1319 static int vm_can_run(void)
1321 if (powerdown_requested
)
1323 if (reset_requested
)
1325 if (shutdown_requested
)
1327 if (debug_requested
)
1332 qemu_irq qemu_system_powerdown
;
1334 static void main_loop(void)
1338 if (kvm_enabled()) {
1340 cpu_disable_ticks();
1344 qemu_main_loop_start();
1348 bool nonblocking
= false;
1349 #ifdef CONFIG_PROFILER
1352 #ifndef CONFIG_IOTHREAD
1353 nonblocking
= cpu_exec_all();
1355 #ifdef CONFIG_PROFILER
1356 ti
= profile_getclock();
1358 main_loop_wait(nonblocking
);
1359 #ifdef CONFIG_PROFILER
1360 dev_time
+= profile_getclock() - ti
;
1362 } while (vm_can_run());
1364 if ((r
= qemu_debug_requested())) {
1367 if (qemu_shutdown_requested()) {
1368 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1375 if (qemu_reset_requested()) {
1377 qemu_system_reset();
1380 if (qemu_powerdown_requested()) {
1381 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1382 qemu_irq_raise(qemu_system_powerdown
);
1384 if ((r
= qemu_vmstop_requested())) {
1392 static void version(void)
1394 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1397 static void help(int exitcode
)
1399 const char *options_help
=
1400 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1402 #define DEFHEADING(text) stringify(text) "\n"
1403 #include "qemu-options.def"
1409 printf("usage: %s [options] [disk_image]\n"
1411 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1414 "During emulation, the following keys are useful:\n"
1415 "ctrl-alt-f toggle full screen\n"
1416 "ctrl-alt-n switch to virtual console 'n'\n"
1417 "ctrl-alt toggle mouse and keyboard grab\n"
1419 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1425 #define HAS_ARG 0x0001
1427 typedef struct QEMUOption
{
1434 static const QEMUOption qemu_options
[] = {
1435 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1436 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1437 { option, opt_arg, opt_enum, arch_mask },
1438 #define DEFHEADING(text)
1439 #include "qemu-options.def"
1445 static void select_vgahw (const char *p
)
1450 vga_interface_type
= VGA_NONE
;
1451 if (strstart(p
, "std", &opts
)) {
1452 vga_interface_type
= VGA_STD
;
1453 } else if (strstart(p
, "cirrus", &opts
)) {
1454 vga_interface_type
= VGA_CIRRUS
;
1455 } else if (strstart(p
, "vmware", &opts
)) {
1456 vga_interface_type
= VGA_VMWARE
;
1457 } else if (strstart(p
, "xenfb", &opts
)) {
1458 vga_interface_type
= VGA_XENFB
;
1459 } else if (!strstart(p
, "none", &opts
)) {
1461 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1465 const char *nextopt
;
1467 if (strstart(opts
, ",retrace=", &nextopt
)) {
1469 if (strstart(opts
, "dumb", &nextopt
))
1470 vga_retrace_method
= VGA_RETRACE_DUMB
;
1471 else if (strstart(opts
, "precise", &nextopt
))
1472 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1473 else goto invalid_vga
;
1474 } else goto invalid_vga
;
1479 static int balloon_parse(const char *arg
)
1483 if (strcmp(arg
, "none") == 0) {
1487 if (!strncmp(arg
, "virtio", 6)) {
1488 if (arg
[6] == ',') {
1489 /* have params -> parse them */
1490 opts
= qemu_opts_parse(&qemu_device_opts
, arg
+7, 0);
1494 /* create empty opts */
1495 opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1497 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1504 char *qemu_find_file(int type
, const char *name
)
1510 /* If name contains path separators then try it as a straight path. */
1511 if ((strchr(name
, '/') || strchr(name
, '\\'))
1512 && access(name
, R_OK
) == 0) {
1513 return qemu_strdup(name
);
1516 case QEMU_FILE_TYPE_BIOS
:
1519 case QEMU_FILE_TYPE_KEYMAP
:
1520 subdir
= "keymaps/";
1525 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1526 buf
= qemu_mallocz(len
);
1527 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1528 if (access(buf
, R_OK
)) {
1535 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1537 return qdev_device_help(opts
);
1540 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1544 dev
= qdev_device_add(opts
);
1550 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1552 CharDriverState
*chr
;
1554 chr
= qemu_chr_open_opts(opts
, NULL
);
1560 #ifdef CONFIG_VIRTFS
1561 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1564 ret
= qemu_fsdev_add(opts
);
1570 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1572 CharDriverState
*chr
;
1573 const char *chardev
;
1577 mode
= qemu_opt_get(opts
, "mode");
1581 if (strcmp(mode
, "readline") == 0) {
1582 flags
= MONITOR_USE_READLINE
;
1583 } else if (strcmp(mode
, "control") == 0) {
1584 flags
= MONITOR_USE_CONTROL
;
1586 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1590 if (qemu_opt_get_bool(opts
, "default", 0))
1591 flags
|= MONITOR_IS_DEFAULT
;
1593 chardev
= qemu_opt_get(opts
, "chardev");
1594 chr
= qemu_chr_find(chardev
);
1596 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1600 monitor_init(chr
, flags
);
1604 static void monitor_parse(const char *optarg
, const char *mode
)
1606 static int monitor_device_index
= 0;
1612 if (strstart(optarg
, "chardev:", &p
)) {
1613 snprintf(label
, sizeof(label
), "%s", p
);
1615 snprintf(label
, sizeof(label
), "compat_monitor%d",
1616 monitor_device_index
);
1617 if (monitor_device_index
== 0) {
1620 opts
= qemu_chr_parse_compat(label
, optarg
);
1622 fprintf(stderr
, "parse error: %s\n", optarg
);
1627 opts
= qemu_opts_create(&qemu_mon_opts
, label
, 1);
1629 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1632 qemu_opt_set(opts
, "mode", mode
);
1633 qemu_opt_set(opts
, "chardev", label
);
1635 qemu_opt_set(opts
, "default", "on");
1636 monitor_device_index
++;
1639 struct device_config
{
1641 DEV_USB
, /* -usbdevice */
1643 DEV_SERIAL
, /* -serial */
1644 DEV_PARALLEL
, /* -parallel */
1645 DEV_VIRTCON
, /* -virtioconsole */
1646 DEV_DEBUGCON
, /* -debugcon */
1648 const char *cmdline
;
1649 QTAILQ_ENTRY(device_config
) next
;
1651 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1653 static void add_device_config(int type
, const char *cmdline
)
1655 struct device_config
*conf
;
1657 conf
= qemu_mallocz(sizeof(*conf
));
1659 conf
->cmdline
= cmdline
;
1660 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1663 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1665 struct device_config
*conf
;
1668 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1669 if (conf
->type
!= type
)
1671 rc
= func(conf
->cmdline
);
1678 static int serial_parse(const char *devname
)
1680 static int index
= 0;
1683 if (strcmp(devname
, "none") == 0)
1685 if (index
== MAX_SERIAL_PORTS
) {
1686 fprintf(stderr
, "qemu: too many serial ports\n");
1689 snprintf(label
, sizeof(label
), "serial%d", index
);
1690 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1691 if (!serial_hds
[index
]) {
1692 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1693 devname
, strerror(errno
));
1700 static int parallel_parse(const char *devname
)
1702 static int index
= 0;
1705 if (strcmp(devname
, "none") == 0)
1707 if (index
== MAX_PARALLEL_PORTS
) {
1708 fprintf(stderr
, "qemu: too many parallel ports\n");
1711 snprintf(label
, sizeof(label
), "parallel%d", index
);
1712 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1713 if (!parallel_hds
[index
]) {
1714 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1715 devname
, strerror(errno
));
1722 static int virtcon_parse(const char *devname
)
1724 static int index
= 0;
1726 QemuOpts
*bus_opts
, *dev_opts
;
1728 if (strcmp(devname
, "none") == 0)
1730 if (index
== MAX_VIRTIO_CONSOLES
) {
1731 fprintf(stderr
, "qemu: too many virtio consoles\n");
1735 bus_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1736 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1738 dev_opts
= qemu_opts_create(&qemu_device_opts
, NULL
, 0);
1739 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1741 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1742 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1743 if (!virtcon_hds
[index
]) {
1744 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1745 devname
, strerror(errno
));
1748 qemu_opt_set(dev_opts
, "chardev", label
);
1754 static int debugcon_parse(const char *devname
)
1758 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1761 opts
= qemu_opts_create(&qemu_device_opts
, "debugcon", 1);
1763 fprintf(stderr
, "qemu: already have a debugcon device\n");
1766 qemu_opt_set(opts
, "driver", "isa-debugcon");
1767 qemu_opt_set(opts
, "chardev", "debugcon");
1771 void qemu_add_exit_notifier(Notifier
*notify
)
1773 notifier_list_add(&exit_notifiers
, notify
);
1776 void qemu_remove_exit_notifier(Notifier
*notify
)
1778 notifier_list_remove(&exit_notifiers
, notify
);
1781 static void qemu_run_exit_notifiers(void)
1783 notifier_list_notify(&exit_notifiers
);
1786 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1787 const char **poptarg
, int *poptind
)
1789 const QEMUOption
*popt
;
1790 int optind
= *poptind
;
1791 char *r
= argv
[optind
];
1794 loc_set_cmdline(argv
, optind
, 1);
1796 /* Treat --foo the same as -foo. */
1799 popt
= qemu_options
;
1802 error_report("invalid option");
1805 if (!strcmp(popt
->name
, r
+ 1))
1809 if (popt
->flags
& HAS_ARG
) {
1810 if (optind
>= argc
) {
1811 error_report("requires an argument");
1814 optarg
= argv
[optind
++];
1815 loc_set_cmdline(argv
, optind
- 2, 2);
1826 int main(int argc
, char **argv
, char **envp
)
1828 const char *gdbstub_dev
= NULL
;
1830 int snapshot
, linux_boot
;
1831 const char *icount_option
= NULL
;
1832 const char *initrd_filename
;
1833 const char *kernel_filename
, *kernel_cmdline
;
1834 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1836 DisplayChangeListener
*dcl
;
1837 int cyls
, heads
, secs
, translation
;
1838 QemuOpts
*hda_opts
= NULL
, *opts
;
1841 const char *loadvm
= NULL
;
1842 QEMUMachine
*machine
;
1843 const char *cpu_model
;
1845 const char *pid_file
= NULL
;
1846 const char *incoming
= NULL
;
1847 int show_vnc_port
= 0;
1850 atexit(qemu_run_exit_notifiers
);
1851 error_set_progname(argv
[0]);
1855 qemu_cache_utils_init(envp
);
1857 QLIST_INIT (&vm_change_state_head
);
1858 os_setup_early_signal_handling();
1860 module_call_init(MODULE_INIT_MACHINE
);
1861 machine
= find_default_machine();
1863 initrd_filename
= NULL
;
1866 kernel_filename
= NULL
;
1867 kernel_cmdline
= "";
1868 cyls
= heads
= secs
= 0;
1869 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1871 for (i
= 0; i
< MAX_NODES
; i
++) {
1873 node_cpumask
[i
] = 0;
1876 assigned_devices_index
= 0;
1884 /* first pass of option parsing */
1886 while (optind
< argc
) {
1887 if (argv
[optind
][0] != '-') {
1892 const QEMUOption
*popt
;
1894 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1895 switch (popt
->index
) {
1896 case QEMU_OPTION_nodefconfig
:
1906 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1907 if (ret
< 0 && ret
!= -ENOENT
) {
1911 ret
= qemu_read_config_file(arch_config_name
);
1912 if (ret
< 0 && ret
!= -ENOENT
) {
1918 /* second pass of option parsing */
1923 if (argv
[optind
][0] != '-') {
1924 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1926 const QEMUOption
*popt
;
1928 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1929 if (!(popt
->arch_mask
& arch_type
)) {
1930 printf("Option %s not supported for this target\n", popt
->name
);
1933 switch(popt
->index
) {
1935 machine
= find_machine(optarg
);
1938 printf("Supported machines are:\n");
1939 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1941 printf("%-10s %s (alias of %s)\n",
1942 m
->alias
, m
->desc
, m
->name
);
1943 printf("%-10s %s%s\n",
1945 m
->is_default
? " (default)" : "");
1947 exit(*optarg
!= '?');
1950 case QEMU_OPTION_cpu
:
1951 /* hw initialization will check this */
1952 if (*optarg
== '?') {
1953 list_cpus(stdout
, &fprintf
, optarg
);
1959 case QEMU_OPTION_initrd
:
1960 initrd_filename
= optarg
;
1962 case QEMU_OPTION_hda
:
1964 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1966 hda_opts
= drive_add(optarg
, HD_ALIAS
1967 ",cyls=%d,heads=%d,secs=%d%s",
1968 0, cyls
, heads
, secs
,
1969 translation
== BIOS_ATA_TRANSLATION_LBA
?
1971 translation
== BIOS_ATA_TRANSLATION_NONE
?
1972 ",trans=none" : "");
1974 case QEMU_OPTION_hdb
:
1975 case QEMU_OPTION_hdc
:
1976 case QEMU_OPTION_hdd
:
1977 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1979 case QEMU_OPTION_drive
:
1980 drive_add(NULL
, "%s", optarg
);
1982 case QEMU_OPTION_set
:
1983 if (qemu_set_option(optarg
) != 0)
1986 case QEMU_OPTION_global
:
1987 if (qemu_global_option(optarg
) != 0)
1990 case QEMU_OPTION_mtdblock
:
1991 drive_add(optarg
, MTD_ALIAS
);
1993 case QEMU_OPTION_sd
:
1994 drive_add(optarg
, SD_ALIAS
);
1996 case QEMU_OPTION_pflash
:
1997 drive_add(optarg
, PFLASH_ALIAS
);
1999 case QEMU_OPTION_snapshot
:
2002 case QEMU_OPTION_hdachs
:
2006 cyls
= strtol(p
, (char **)&p
, 0);
2007 if (cyls
< 1 || cyls
> 16383)
2012 heads
= strtol(p
, (char **)&p
, 0);
2013 if (heads
< 1 || heads
> 16)
2018 secs
= strtol(p
, (char **)&p
, 0);
2019 if (secs
< 1 || secs
> 63)
2023 if (!strcmp(p
, "none"))
2024 translation
= BIOS_ATA_TRANSLATION_NONE
;
2025 else if (!strcmp(p
, "lba"))
2026 translation
= BIOS_ATA_TRANSLATION_LBA
;
2027 else if (!strcmp(p
, "auto"))
2028 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2031 } else if (*p
!= '\0') {
2033 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2036 if (hda_opts
!= NULL
) {
2038 snprintf(num
, sizeof(num
), "%d", cyls
);
2039 qemu_opt_set(hda_opts
, "cyls", num
);
2040 snprintf(num
, sizeof(num
), "%d", heads
);
2041 qemu_opt_set(hda_opts
, "heads", num
);
2042 snprintf(num
, sizeof(num
), "%d", secs
);
2043 qemu_opt_set(hda_opts
, "secs", num
);
2044 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2045 qemu_opt_set(hda_opts
, "trans", "lba");
2046 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2047 qemu_opt_set(hda_opts
, "trans", "none");
2051 case QEMU_OPTION_numa
:
2052 if (nb_numa_nodes
>= MAX_NODES
) {
2053 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2058 case QEMU_OPTION_nographic
:
2059 display_type
= DT_NOGRAPHIC
;
2061 #ifdef CONFIG_CURSES
2062 case QEMU_OPTION_curses
:
2063 display_type
= DT_CURSES
;
2066 case QEMU_OPTION_portrait
:
2069 case QEMU_OPTION_kernel
:
2070 kernel_filename
= optarg
;
2072 case QEMU_OPTION_append
:
2073 kernel_cmdline
= optarg
;
2075 case QEMU_OPTION_cdrom
:
2076 drive_add(optarg
, CDROM_ALIAS
);
2078 case QEMU_OPTION_boot
:
2080 static const char * const params
[] = {
2081 "order", "once", "menu", NULL
2083 char buf
[sizeof(boot_devices
)];
2084 char *standard_boot_devices
;
2087 if (!strchr(optarg
, '=')) {
2089 pstrcpy(buf
, sizeof(buf
), optarg
);
2090 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2092 "qemu: unknown boot parameter '%s' in '%s'\n",
2098 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2099 validate_bootdevices(buf
);
2100 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2103 if (get_param_value(buf
, sizeof(buf
),
2105 validate_bootdevices(buf
);
2106 standard_boot_devices
= qemu_strdup(boot_devices
);
2107 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2108 qemu_register_reset(restore_boot_devices
,
2109 standard_boot_devices
);
2111 if (get_param_value(buf
, sizeof(buf
),
2113 if (!strcmp(buf
, "on")) {
2115 } else if (!strcmp(buf
, "off")) {
2119 "qemu: invalid option value '%s'\n",
2127 case QEMU_OPTION_fda
:
2128 case QEMU_OPTION_fdb
:
2129 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2131 case QEMU_OPTION_no_fd_bootchk
:
2134 case QEMU_OPTION_netdev
:
2135 if (net_client_parse(&qemu_netdev_opts
, optarg
) == -1) {
2139 case QEMU_OPTION_net
:
2140 if (net_client_parse(&qemu_net_opts
, optarg
) == -1) {
2145 case QEMU_OPTION_tftp
:
2146 legacy_tftp_prefix
= optarg
;
2148 case QEMU_OPTION_bootp
:
2149 legacy_bootp_filename
= optarg
;
2151 case QEMU_OPTION_redir
:
2152 if (net_slirp_redir(optarg
) < 0)
2156 case QEMU_OPTION_bt
:
2157 add_device_config(DEV_BT
, optarg
);
2159 case QEMU_OPTION_audio_help
:
2160 if (!(audio_available())) {
2161 printf("Option %s not supported for this target\n", popt
->name
);
2167 case QEMU_OPTION_soundhw
:
2168 if (!(audio_available())) {
2169 printf("Option %s not supported for this target\n", popt
->name
);
2172 select_soundhw (optarg
);
2177 case QEMU_OPTION_version
:
2181 case QEMU_OPTION_m
: {
2185 value
= strtoul(optarg
, &ptr
, 10);
2187 case 0: case 'M': case 'm':
2194 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2198 /* On 32-bit hosts, QEMU is limited by virtual address space */
2199 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2200 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2203 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2204 fprintf(stderr
, "qemu: ram size too large\n");
2210 case QEMU_OPTION_mempath
:
2214 case QEMU_OPTION_mem_prealloc
:
2219 set_cpu_log(optarg
);
2222 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2224 case QEMU_OPTION_gdb
:
2225 gdbstub_dev
= optarg
;
2230 case QEMU_OPTION_bios
:
2233 case QEMU_OPTION_singlestep
:
2240 keyboard_layout
= optarg
;
2242 case QEMU_OPTION_localtime
:
2245 case QEMU_OPTION_vga
:
2246 select_vgahw (optarg
);
2253 w
= strtol(p
, (char **)&p
, 10);
2256 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2262 h
= strtol(p
, (char **)&p
, 10);
2267 depth
= strtol(p
, (char **)&p
, 10);
2268 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2269 depth
!= 24 && depth
!= 32)
2271 } else if (*p
== '\0') {
2272 depth
= graphic_depth
;
2279 graphic_depth
= depth
;
2282 case QEMU_OPTION_echr
:
2285 term_escape_char
= strtol(optarg
, &r
, 0);
2287 printf("Bad argument to echr\n");
2290 case QEMU_OPTION_monitor
:
2291 monitor_parse(optarg
, "readline");
2292 default_monitor
= 0;
2294 case QEMU_OPTION_qmp
:
2295 monitor_parse(optarg
, "control");
2296 default_monitor
= 0;
2298 case QEMU_OPTION_mon
:
2299 opts
= qemu_opts_parse(&qemu_mon_opts
, optarg
, 1);
2303 default_monitor
= 0;
2305 case QEMU_OPTION_chardev
:
2306 opts
= qemu_opts_parse(&qemu_chardev_opts
, optarg
, 1);
2311 #ifdef CONFIG_VIRTFS
2312 case QEMU_OPTION_fsdev
:
2313 opts
= qemu_opts_parse(&qemu_fsdev_opts
, optarg
, 1);
2315 fprintf(stderr
, "parse error: %s\n", optarg
);
2319 case QEMU_OPTION_virtfs
: {
2320 char *arg_fsdev
= NULL
;
2321 char *arg_9p
= NULL
;
2324 opts
= qemu_opts_parse(&qemu_virtfs_opts
, optarg
, 1);
2326 fprintf(stderr
, "parse error: %s\n", optarg
);
2330 if (qemu_opt_get(opts
, "fstype") == NULL
||
2331 qemu_opt_get(opts
, "mount_tag") == NULL
||
2332 qemu_opt_get(opts
, "path") == NULL
||
2333 qemu_opt_get(opts
, "security_model") == NULL
) {
2334 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2335 "security_model=[mapped|passthrough],"
2340 len
= strlen(",id=,path=,security_model=");
2341 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2342 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2343 len
+= strlen(qemu_opt_get(opts
, "path"));
2344 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2345 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2348 fprintf(stderr
, "No memory to parse -fsdev for %s\n",
2353 sprintf(arg_fsdev
, "%s,id=%s,path=%s,security_model=%s",
2354 qemu_opt_get(opts
, "fstype"),
2355 qemu_opt_get(opts
, "mount_tag"),
2356 qemu_opt_get(opts
, "path"),
2357 qemu_opt_get(opts
, "security_model"));
2359 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2360 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2361 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2364 fprintf(stderr
, "No memory to parse -device for %s\n",
2369 sprintf(arg_9p
, "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2370 qemu_opt_get(opts
, "mount_tag"),
2371 qemu_opt_get(opts
, "mount_tag"));
2373 if (!qemu_opts_parse(&qemu_fsdev_opts
, arg_fsdev
, 1)) {
2374 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2378 if (!qemu_opts_parse(&qemu_device_opts
, arg_9p
, 1)) {
2379 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2383 qemu_free(arg_fsdev
);
2388 case QEMU_OPTION_serial
:
2389 add_device_config(DEV_SERIAL
, optarg
);
2391 if (strncmp(optarg
, "mon:", 4) == 0) {
2392 default_monitor
= 0;
2395 case QEMU_OPTION_watchdog
:
2398 "qemu: only one watchdog option may be given\n");
2403 case QEMU_OPTION_watchdog_action
:
2404 if (select_watchdog_action(optarg
) == -1) {
2405 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2409 case QEMU_OPTION_virtiocon
:
2410 add_device_config(DEV_VIRTCON
, optarg
);
2411 default_virtcon
= 0;
2412 if (strncmp(optarg
, "mon:", 4) == 0) {
2413 default_monitor
= 0;
2416 case QEMU_OPTION_parallel
:
2417 add_device_config(DEV_PARALLEL
, optarg
);
2418 default_parallel
= 0;
2419 if (strncmp(optarg
, "mon:", 4) == 0) {
2420 default_monitor
= 0;
2423 case QEMU_OPTION_debugcon
:
2424 add_device_config(DEV_DEBUGCON
, optarg
);
2426 case QEMU_OPTION_loadvm
:
2429 case QEMU_OPTION_full_screen
:
2433 case QEMU_OPTION_no_frame
:
2436 case QEMU_OPTION_alt_grab
:
2439 case QEMU_OPTION_ctrl_grab
:
2442 case QEMU_OPTION_no_quit
:
2445 case QEMU_OPTION_sdl
:
2446 display_type
= DT_SDL
;
2449 case QEMU_OPTION_pidfile
:
2452 case QEMU_OPTION_win2k_hack
:
2453 win2k_install_hack
= 1;
2455 case QEMU_OPTION_rtc_td_hack
:
2458 case QEMU_OPTION_acpitable
:
2459 do_acpitable_option(optarg
);
2461 case QEMU_OPTION_smbios
:
2462 do_smbios_option(optarg
);
2465 case QEMU_OPTION_enable_kvm
:
2469 case QEMU_OPTION_no_kvm
:
2473 case QEMU_OPTION_no_kvm_irqchip
: {
2478 case QEMU_OPTION_no_kvm_pit
: {
2482 case QEMU_OPTION_no_kvm_pit_reinjection
: {
2483 kvm_pit_reinject
= 0;
2486 case QEMU_OPTION_enable_nesting
: {
2491 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
2492 case QEMU_OPTION_pcidevice
:
2493 if (assigned_devices_index
>= MAX_DEV_ASSIGN_CMDLINE
) {
2494 fprintf(stderr
, "Too many assigned devices\n");
2497 assigned_devices
[assigned_devices_index
] = optarg
;
2498 assigned_devices_index
++;
2501 case QEMU_OPTION_usb
:
2504 case QEMU_OPTION_usbdevice
:
2506 add_device_config(DEV_USB
, optarg
);
2508 case QEMU_OPTION_device
:
2509 if (!qemu_opts_parse(&qemu_device_opts
, optarg
, 1)) {
2513 case QEMU_OPTION_smp
:
2516 fprintf(stderr
, "Invalid number of CPUs\n");
2519 if (max_cpus
< smp_cpus
) {
2520 fprintf(stderr
, "maxcpus must be equal to or greater than "
2524 if (max_cpus
> 255) {
2525 fprintf(stderr
, "Unsupported number of maxcpus\n");
2529 case QEMU_OPTION_vnc
:
2530 display_type
= DT_VNC
;
2531 vnc_display
= optarg
;
2533 case QEMU_OPTION_no_acpi
:
2536 case QEMU_OPTION_no_hpet
:
2539 case QEMU_OPTION_balloon
:
2540 if (balloon_parse(optarg
) < 0) {
2541 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2545 case QEMU_OPTION_no_reboot
:
2548 case QEMU_OPTION_no_shutdown
:
2551 case QEMU_OPTION_show_cursor
:
2554 case QEMU_OPTION_uuid
:
2555 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2556 fprintf(stderr
, "Fail to parse UUID string."
2557 " Wrong format.\n");
2561 case QEMU_OPTION_option_rom
:
2562 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2563 fprintf(stderr
, "Too many option ROMs\n");
2566 option_rom
[nb_option_roms
] = optarg
;
2569 case QEMU_OPTION_semihosting
:
2570 semihosting_enabled
= 1;
2572 case QEMU_OPTION_tdf
:
2575 case QEMU_OPTION_kvm_shadow_memory
:
2576 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2578 case QEMU_OPTION_name
:
2579 qemu_name
= qemu_strdup(optarg
);
2581 char *p
= strchr(qemu_name
, ',');
2584 if (strncmp(p
, "process=", 8)) {
2585 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2589 os_set_proc_name(p
);
2593 case QEMU_OPTION_prom_env
:
2594 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2595 fprintf(stderr
, "Too many prom variables\n");
2598 prom_envs
[nb_prom_envs
] = optarg
;
2601 case QEMU_OPTION_old_param
:
2604 case QEMU_OPTION_clock
:
2605 configure_alarms(optarg
);
2607 case QEMU_OPTION_startdate
:
2608 configure_rtc_date_offset(optarg
, 1);
2610 case QEMU_OPTION_rtc
:
2611 opts
= qemu_opts_parse(&qemu_rtc_opts
, optarg
, 0);
2615 configure_rtc(opts
);
2617 case QEMU_OPTION_tb_size
:
2618 tb_size
= strtol(optarg
, NULL
, 0);
2622 case QEMU_OPTION_icount
:
2623 icount_option
= optarg
;
2625 case QEMU_OPTION_incoming
:
2627 incoming_expected
= true;
2629 case QEMU_OPTION_nodefaults
:
2631 default_parallel
= 0;
2632 default_virtcon
= 0;
2633 default_monitor
= 0;
2641 case QEMU_OPTION_nvram
:
2645 case QEMU_OPTION_xen_domid
:
2646 if (!(xen_available())) {
2647 printf("Option %s not supported for this target\n", popt
->name
);
2650 xen_domid
= atoi(optarg
);
2652 case QEMU_OPTION_xen_create
:
2653 if (!(xen_available())) {
2654 printf("Option %s not supported for this target\n", popt
->name
);
2657 xen_mode
= XEN_CREATE
;
2659 case QEMU_OPTION_xen_attach
:
2660 if (!(xen_available())) {
2661 printf("Option %s not supported for this target\n", popt
->name
);
2664 xen_mode
= XEN_ATTACH
;
2666 case QEMU_OPTION_readconfig
:
2668 int ret
= qemu_read_config_file(optarg
);
2670 fprintf(stderr
, "read config %s: %s\n", optarg
,
2676 case QEMU_OPTION_writeconfig
:
2679 if (strcmp(optarg
, "-") == 0) {
2682 fp
= fopen(optarg
, "w");
2684 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2688 qemu_config_write(fp
);
2693 os_parse_cmd_args(popt
->index
, optarg
);
2699 /* If no data_dir is specified then try to find it relative to the
2702 data_dir
= os_find_datadir(argv
[0]);
2704 /* If all else fails use the install patch specified when building. */
2706 data_dir
= CONFIG_QEMU_DATADIR
;
2710 * Default to max_cpus = smp_cpus, in case the user doesn't
2711 * specify a max_cpus value.
2714 max_cpus
= smp_cpus
;
2716 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2717 if (smp_cpus
> machine
->max_cpus
) {
2718 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2719 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2724 qemu_opts_foreach(&qemu_device_opts
, default_driver_check
, NULL
, 0);
2725 qemu_opts_foreach(&qemu_global_opts
, default_driver_check
, NULL
, 0);
2727 if (machine
->no_serial
) {
2730 if (machine
->no_parallel
) {
2731 default_parallel
= 0;
2733 if (!machine
->use_virtcon
) {
2734 default_virtcon
= 0;
2736 if (machine
->no_vga
) {
2739 if (machine
->no_floppy
) {
2742 if (machine
->no_cdrom
) {
2745 if (machine
->no_sdcard
) {
2749 if (display_type
== DT_NOGRAPHIC
) {
2750 if (default_parallel
)
2751 add_device_config(DEV_PARALLEL
, "null");
2752 if (default_serial
&& default_monitor
) {
2753 add_device_config(DEV_SERIAL
, "mon:stdio");
2754 } else if (default_virtcon
&& default_monitor
) {
2755 add_device_config(DEV_VIRTCON
, "mon:stdio");
2758 add_device_config(DEV_SERIAL
, "stdio");
2759 if (default_virtcon
)
2760 add_device_config(DEV_VIRTCON
, "stdio");
2761 if (default_monitor
)
2762 monitor_parse("stdio", "readline");
2766 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2767 if (default_parallel
)
2768 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2769 if (default_monitor
)
2770 monitor_parse("vc:80Cx24C", "readline");
2771 if (default_virtcon
)
2772 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2775 vga_interface_type
= VGA_CIRRUS
;
2779 if (qemu_opts_foreach(&qemu_chardev_opts
, chardev_init_func
, NULL
, 1) != 0)
2781 #ifdef CONFIG_VIRTFS
2782 if (qemu_opts_foreach(&qemu_fsdev_opts
, fsdev_init_func
, NULL
, 1) != 0) {
2789 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2795 int ret
= kvm_init(smp_cpus
);
2797 #if defined(KVM_UPSTREAM) || defined(CONFIG_NO_CPU_EMULATION)
2798 if (!kvm_available()) {
2799 printf("KVM not supported for this target\n");
2801 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2806 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2812 if (qemu_init_main_loop()) {
2813 fprintf(stderr
, "qemu_init_main_loop failed\n");
2816 linux_boot
= (kernel_filename
!= NULL
);
2818 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2819 fprintf(stderr
, "-append only allowed with -kernel option\n");
2823 if (!linux_boot
&& initrd_filename
!= NULL
) {
2824 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2828 os_set_line_buffering();
2830 if (init_timer_alarm() < 0) {
2831 fprintf(stderr
, "could not initialize alarm timer\n");
2834 configure_icount(icount_option
);
2836 if (net_init_clients() < 0) {
2840 /* init the bluetooth world */
2841 if (foreach_device_config(DEV_BT
, bt_parse
))
2844 /* init the memory */
2846 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2848 /* init the dynamic translator */
2849 cpu_exec_init_all(tb_size
* 1024 * 1024);
2851 bdrv_init_with_whitelist();
2855 if (default_cdrom
) {
2856 /* we always create the cdrom drive, even if no disk is there */
2857 drive_add(NULL
, CDROM_ALIAS
);
2860 if (default_floppy
) {
2861 /* we always create at least one floppy */
2862 drive_add(NULL
, FD_ALIAS
, 0);
2865 if (default_sdcard
) {
2866 /* we always create one sd slot, even if no card is in it */
2867 drive_add(NULL
, SD_ALIAS
);
2870 /* open the virtual block devices */
2872 qemu_opts_foreach(&qemu_drive_opts
, drive_enable_snapshot
, NULL
, 0);
2873 if (qemu_opts_foreach(&qemu_drive_opts
, drive_init_func
, &machine
->use_scsi
, 1) != 0)
2876 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2879 if (nb_numa_nodes
> 0) {
2882 if (nb_numa_nodes
> smp_cpus
) {
2883 nb_numa_nodes
= smp_cpus
;
2886 /* If no memory size if given for any node, assume the default case
2887 * and distribute the available memory equally across all nodes
2889 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2890 if (node_mem
[i
] != 0)
2893 if (i
== nb_numa_nodes
) {
2894 uint64_t usedmem
= 0;
2896 /* On Linux, the each node's border has to be 8MB aligned,
2897 * the final node gets the rest.
2899 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2900 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2901 usedmem
+= node_mem
[i
];
2903 node_mem
[i
] = ram_size
- usedmem
;
2906 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2907 if (node_cpumask
[i
] != 0)
2910 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2911 * must cope with this anyway, because there are BIOSes out there in
2912 * real machines which also use this scheme.
2914 if (i
== nb_numa_nodes
) {
2915 for (i
= 0; i
< smp_cpus
; i
++) {
2916 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2921 if (qemu_opts_foreach(&qemu_mon_opts
, mon_init_func
, NULL
, 1) != 0) {
2925 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2927 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2929 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2931 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2934 module_call_init(MODULE_INIT_DEVICE
);
2936 if (qemu_opts_foreach(&qemu_device_opts
, device_help_func
, NULL
, 0) != 0)
2940 i
= select_watchdog(watchdog
);
2942 exit (i
== 1 ? 1 : 0);
2945 if (machine
->compat_props
) {
2946 qdev_prop_register_global_list(machine
->compat_props
);
2950 machine
->init(ram_size
, boot_devices
,
2951 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2953 cpu_synchronize_all_post_init();
2955 /* must be after terminal init, SDL library changes signal handlers */
2956 os_setup_signal_handling();
2960 current_machine
= machine
;
2962 /* init USB devices */
2964 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2968 /* init generic devices */
2969 if (qemu_opts_foreach(&qemu_device_opts
, device_init_func
, NULL
, 1) != 0)
2972 net_check_clients();
2974 /* just use the first displaystate for the moment */
2975 ds
= get_displaystate();
2977 if (display_type
== DT_DEFAULT
) {
2978 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2979 display_type
= DT_SDL
;
2981 display_type
= DT_VNC
;
2982 vnc_display
= "localhost:0,to=99";
2988 switch (display_type
) {
2991 #if defined(CONFIG_CURSES)
2993 curses_display_init(ds
, full_screen
);
2996 #if defined(CONFIG_SDL)
2998 sdl_display_init(ds
, full_screen
, no_frame
);
3000 #elif defined(CONFIG_COCOA)
3002 cocoa_display_init(ds
, full_screen
);
3006 vnc_display_init(ds
);
3007 if (vnc_display_open(ds
, vnc_display
) < 0)
3010 if (show_vnc_port
) {
3011 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3019 dcl
= ds
->listeners
;
3020 while (dcl
!= NULL
) {
3021 if (dcl
->dpy_refresh
!= NULL
) {
3022 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3023 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3029 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
3030 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3031 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3034 text_consoles_set_display(ds
);
3036 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3037 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3042 qdev_machine_creation_done();
3044 if (rom_load_all() != 0) {
3045 fprintf(stderr
, "rom loading failed\n");
3049 qemu_system_reset();
3051 if (load_vmstate(loadvm
) < 0) {
3057 int ret
= qemu_start_incoming_migration(incoming
);
3059 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3063 } else if (autostart
) {