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>
83 /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
84 discussion about Solaris header problems */
85 extern int madvise(caddr_t
, size_t, int);
90 #if defined(__OpenBSD__)
94 #if defined(CONFIG_VDE)
95 #include <libvdeplug.h>
103 #if defined(__APPLE__) || defined(main)
105 int qemu_main(int argc
, char **argv
, char **envp
);
106 int main(int argc
, char **argv
)
108 return qemu_main(argc
, argv
, NULL
);
111 #define main qemu_main
113 #endif /* CONFIG_SDL */
117 #define main qemu_main
118 #endif /* CONFIG_COCOA */
121 #include "hw/boards.h"
123 #include "hw/pcmcia.h"
128 #include "hw/watchdog.h"
129 #include "hw/smbios.h"
132 #include "hw/loader.h"
135 #include "net/slirp.h"
140 #include "qemu-timer.h"
141 #include "qemu-char.h"
142 #include "cache-utils.h"
144 #include "blockdev.h"
145 #include "block-migration.h"
147 #include "audio/audio.h"
148 #include "migration.h"
150 #include "qemu-option.h"
151 #include "qemu-config.h"
152 #include "qemu-objects.h"
153 #include "qemu-options.h"
154 #include "hw/device-assignment.h"
156 #include "fsdev/qemu-fsdev.h"
161 #include "qemu_socket.h"
163 #include "slirp/libslirp.h"
165 #include "qemu-queue.h"
167 #include "arch_init.h"
170 //#define DEBUG_SLIRP
172 #define DEFAULT_RAM_SIZE 128
174 #define MAX_VIRTIO_CONSOLES 1
176 static const char *data_dir
;
177 const char *bios_name
= NULL
;
178 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
179 DisplayType display_type
= DT_DEFAULT
;
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;
207 const char *assigned_devices
[MAX_DEV_ASSIGN_CMDLINE
];
208 int assigned_devices_index
;
213 const char *vnc_display
;
214 int acpi_enabled
= 1;
220 int graphic_rotate
= 0;
221 uint8_t irq0override
= 1;
222 const char *watchdog
;
223 const char *option_rom
[MAX_OPTION_ROMS
];
225 int semihosting_enabled
= 0;
226 int time_drift_fix
= 0;
227 unsigned int kvm_shadow_memory
= 0;
229 const char *qemu_name
;
232 unsigned int nb_prom_envs
= 0;
233 const char *prom_envs
[MAX_PROM_ENVS
];
234 const char *nvram
= NULL
;
238 uint64_t node_mem
[MAX_NODES
];
239 uint64_t node_cpumask
[MAX_NODES
];
241 static QEMUTimer
*nographic_timer
;
243 uint8_t qemu_uuid
[16];
245 static QEMUBootSetHandler
*boot_set_handler
;
246 static void *boot_set_opaque
;
248 static NotifierList exit_notifiers
=
249 NOTIFIER_LIST_INITIALIZER(exit_notifiers
);
253 enum xen_mode xen_mode
= XEN_EMULATE
;
255 static int default_serial
= 1;
256 static int default_parallel
= 1;
257 static int default_virtcon
= 1;
258 static int default_monitor
= 1;
259 static int default_vga
= 1;
260 static int default_floppy
= 1;
261 static int default_cdrom
= 1;
262 static int default_sdcard
= 1;
268 { .driver
= "isa-serial", .flag
= &default_serial
},
269 { .driver
= "isa-parallel", .flag
= &default_parallel
},
270 { .driver
= "isa-fdc", .flag
= &default_floppy
},
271 { .driver
= "ide-drive", .flag
= &default_cdrom
},
272 { .driver
= "virtio-serial-pci", .flag
= &default_virtcon
},
273 { .driver
= "virtio-serial-s390", .flag
= &default_virtcon
},
274 { .driver
= "virtio-serial", .flag
= &default_virtcon
},
275 { .driver
= "VGA", .flag
= &default_vga
},
276 { .driver
= "cirrus-vga", .flag
= &default_vga
},
277 { .driver
= "vmware-svga", .flag
= &default_vga
},
280 static int default_driver_check(QemuOpts
*opts
, void *opaque
)
282 const char *driver
= qemu_opt_get(opts
, "driver");
287 for (i
= 0; i
< ARRAY_SIZE(default_list
); i
++) {
288 if (strcmp(default_list
[i
].driver
, driver
) != 0)
290 *(default_list
[i
].flag
) = 0;
295 /***********************************************************/
296 /* real time host monotonic timer */
298 /* compute with 96 bit intermediate result: (a*b)/c */
299 uint64_t muldiv64(uint64_t a
, uint32_t b
, uint32_t c
)
304 #ifdef HOST_WORDS_BIGENDIAN
314 rl
= (uint64_t)u
.l
.low
* (uint64_t)b
;
315 rh
= (uint64_t)u
.l
.high
* (uint64_t)b
;
318 res
.l
.low
= (((rh
% c
) << 32) + (rl
& 0xffffffff)) / c
;
322 /***********************************************************/
323 /* host time/date access */
324 void qemu_get_timedate(struct tm
*tm
, int offset
)
331 if (rtc_date_offset
== -1) {
335 ret
= localtime(&ti
);
337 ti
-= rtc_date_offset
;
341 memcpy(tm
, ret
, sizeof(struct tm
));
344 int qemu_timedate_diff(struct tm
*tm
)
348 if (rtc_date_offset
== -1)
350 seconds
= mktimegm(tm
);
352 seconds
= mktime(tm
);
354 seconds
= mktimegm(tm
) + rtc_date_offset
;
356 return seconds
- time(NULL
);
359 void rtc_change_mon_event(struct tm
*tm
)
363 data
= qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm
));
364 monitor_protocol_event(QEVENT_RTC_CHANGE
, data
);
365 qobject_decref(data
);
368 static void configure_rtc_date_offset(const char *startdate
, int legacy
)
370 time_t rtc_start_date
;
373 if (!strcmp(startdate
, "now") && legacy
) {
374 rtc_date_offset
= -1;
376 if (sscanf(startdate
, "%d-%d-%dT%d:%d:%d",
384 } else if (sscanf(startdate
, "%d-%d-%d",
396 rtc_start_date
= mktimegm(&tm
);
397 if (rtc_start_date
== -1) {
399 fprintf(stderr
, "Invalid date format. Valid formats are:\n"
400 "'2006-06-17T16:01:21' or '2006-06-17'\n");
403 rtc_date_offset
= time(NULL
) - rtc_start_date
;
407 static void configure_rtc(QemuOpts
*opts
)
411 value
= qemu_opt_get(opts
, "base");
413 if (!strcmp(value
, "utc")) {
415 } else if (!strcmp(value
, "localtime")) {
418 configure_rtc_date_offset(value
, 0);
421 value
= qemu_opt_get(opts
, "clock");
423 if (!strcmp(value
, "host")) {
424 rtc_clock
= host_clock
;
425 } else if (!strcmp(value
, "vm")) {
426 rtc_clock
= vm_clock
;
428 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
432 value
= qemu_opt_get(opts
, "driftfix");
434 if (!strcmp(value
, "slew")) {
436 } else if (!strcmp(value
, "none")) {
439 fprintf(stderr
, "qemu: invalid option value '%s'\n", value
);
445 /***********************************************************/
446 /* Bluetooth support */
449 static struct HCIInfo
*hci_table
[MAX_NICS
];
451 static struct bt_vlan_s
{
452 struct bt_scatternet_s net
;
454 struct bt_vlan_s
*next
;
457 /* find or alloc a new bluetooth "VLAN" */
458 static struct bt_scatternet_s
*qemu_find_bt_vlan(int id
)
460 struct bt_vlan_s
**pvlan
, *vlan
;
461 for (vlan
= first_bt_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
465 vlan
= qemu_mallocz(sizeof(struct bt_vlan_s
));
467 pvlan
= &first_bt_vlan
;
468 while (*pvlan
!= NULL
)
469 pvlan
= &(*pvlan
)->next
;
474 static void null_hci_send(struct HCIInfo
*hci
, const uint8_t *data
, int len
)
478 static int null_hci_addr_set(struct HCIInfo
*hci
, const uint8_t *bd_addr
)
483 static struct HCIInfo null_hci
= {
484 .cmd_send
= null_hci_send
,
485 .sco_send
= null_hci_send
,
486 .acl_send
= null_hci_send
,
487 .bdaddr_set
= null_hci_addr_set
,
490 struct HCIInfo
*qemu_next_hci(void)
492 if (cur_hci
== nb_hcis
)
495 return hci_table
[cur_hci
++];
498 static struct HCIInfo
*hci_init(const char *str
)
501 struct bt_scatternet_s
*vlan
= 0;
503 if (!strcmp(str
, "null"))
506 else if (!strncmp(str
, "host", 4) && (str
[4] == '\0' || str
[4] == ':'))
508 return bt_host_hci(str
[4] ? str
+ 5 : "hci0");
509 else if (!strncmp(str
, "hci", 3)) {
512 if (!strncmp(str
+ 3, ",vlan=", 6)) {
513 vlan
= qemu_find_bt_vlan(strtol(str
+ 9, &endp
, 0));
518 vlan
= qemu_find_bt_vlan(0);
520 return bt_new_hci(vlan
);
523 fprintf(stderr
, "qemu: Unknown bluetooth HCI `%s'.\n", str
);
528 static int bt_hci_parse(const char *str
)
533 if (nb_hcis
>= MAX_NICS
) {
534 fprintf(stderr
, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS
);
547 bdaddr
.b
[5] = 0x56 + nb_hcis
;
548 hci
->bdaddr_set(hci
, bdaddr
.b
);
550 hci_table
[nb_hcis
++] = hci
;
555 static void bt_vhci_add(int vlan_id
)
557 struct bt_scatternet_s
*vlan
= qemu_find_bt_vlan(vlan_id
);
560 fprintf(stderr
, "qemu: warning: adding a VHCI to "
561 "an empty scatternet %i\n", vlan_id
);
563 bt_vhci_init(bt_new_hci(vlan
));
566 static struct bt_device_s
*bt_device_add(const char *opt
)
568 struct bt_scatternet_s
*vlan
;
570 char *endp
= strstr(opt
, ",vlan=");
571 int len
= (endp
? endp
- opt
: strlen(opt
)) + 1;
574 pstrcpy(devname
, MIN(sizeof(devname
), len
), opt
);
577 vlan_id
= strtol(endp
+ 6, &endp
, 0);
579 fprintf(stderr
, "qemu: unrecognised bluetooth vlan Id\n");
584 vlan
= qemu_find_bt_vlan(vlan_id
);
587 fprintf(stderr
, "qemu: warning: adding a slave device to "
588 "an empty scatternet %i\n", vlan_id
);
590 if (!strcmp(devname
, "keyboard"))
591 return bt_keyboard_init(vlan
);
593 fprintf(stderr
, "qemu: unsupported bluetooth device `%s'\n", devname
);
597 static int bt_parse(const char *opt
)
599 const char *endp
, *p
;
602 if (strstart(opt
, "hci", &endp
)) {
603 if (!*endp
|| *endp
== ',') {
605 if (!strstart(endp
, ",vlan=", 0))
608 return bt_hci_parse(opt
);
610 } else if (strstart(opt
, "vhci", &endp
)) {
611 if (!*endp
|| *endp
== ',') {
613 if (strstart(endp
, ",vlan=", &p
)) {
614 vlan
= strtol(p
, (char **) &endp
, 0);
616 fprintf(stderr
, "qemu: bad scatternet '%s'\n", p
);
620 fprintf(stderr
, "qemu: bad parameter '%s'\n", endp
+ 1);
629 } else if (strstart(opt
, "device:", &endp
))
630 return !bt_device_add(endp
);
632 fprintf(stderr
, "qemu: bad bluetooth parameter '%s'\n", opt
);
636 /***********************************************************/
637 /* QEMU Block devices */
639 #define HD_ALIAS "index=%d,media=disk"
640 #define CDROM_ALIAS "index=2,media=cdrom"
641 #define FD_ALIAS "index=%d,if=floppy"
642 #define PFLASH_ALIAS "if=pflash"
643 #define MTD_ALIAS "if=mtd"
644 #define SD_ALIAS "index=0,if=sd"
646 static int drive_init_func(QemuOpts
*opts
, void *opaque
)
648 int *use_scsi
= opaque
;
651 if (drive_init(opts
, *use_scsi
, &fatal_error
) == NULL
) {
658 static int drive_enable_snapshot(QemuOpts
*opts
, void *opaque
)
660 if (NULL
== qemu_opt_get(opts
, "snapshot")) {
661 qemu_opt_set(opts
, "snapshot", "on");
666 void qemu_register_boot_set(QEMUBootSetHandler
*func
, void *opaque
)
668 boot_set_handler
= func
;
669 boot_set_opaque
= opaque
;
672 int qemu_boot_set(const char *boot_devices
)
674 if (!boot_set_handler
) {
677 return boot_set_handler(boot_set_opaque
, boot_devices
);
680 static void validate_bootdevices(char *devices
)
682 /* We just do some generic consistency checks */
686 for (p
= devices
; *p
!= '\0'; p
++) {
687 /* Allowed boot devices are:
688 * a-b: floppy disk drives
689 * c-f: IDE disk drives
690 * g-m: machine implementation dependant drives
691 * n-p: network devices
692 * It's up to each machine implementation to check if the given boot
693 * devices match the actual hardware implementation and firmware
696 if (*p
< 'a' || *p
> 'p') {
697 fprintf(stderr
, "Invalid boot device '%c'\n", *p
);
700 if (bitmap
& (1 << (*p
- 'a'))) {
701 fprintf(stderr
, "Boot device '%c' was given twice\n", *p
);
704 bitmap
|= 1 << (*p
- 'a');
708 static void restore_boot_devices(void *opaque
)
710 char *standard_boot_devices
= opaque
;
711 static int first
= 1;
713 /* Restore boot order and remove ourselves after the first boot */
719 qemu_boot_set(standard_boot_devices
);
721 qemu_unregister_reset(restore_boot_devices
, standard_boot_devices
);
722 qemu_free(standard_boot_devices
);
725 static void numa_add(const char *optarg
)
729 unsigned long long value
, endvalue
;
732 optarg
= get_opt_name(option
, 128, optarg
, ',') + 1;
733 if (!strcmp(option
, "node")) {
734 if (get_param_value(option
, 128, "nodeid", optarg
) == 0) {
735 nodenr
= nb_numa_nodes
;
737 nodenr
= strtoull(option
, NULL
, 10);
740 if (get_param_value(option
, 128, "mem", optarg
) == 0) {
741 node_mem
[nodenr
] = 0;
743 value
= strtoull(option
, &endptr
, 0);
745 case 0: case 'M': case 'm':
752 node_mem
[nodenr
] = value
;
754 if (get_param_value(option
, 128, "cpus", optarg
) == 0) {
755 node_cpumask
[nodenr
] = 0;
757 value
= strtoull(option
, &endptr
, 10);
760 fprintf(stderr
, "only 64 CPUs in NUMA mode supported.\n");
762 if (*endptr
== '-') {
763 endvalue
= strtoull(endptr
+1, &endptr
, 10);
764 if (endvalue
>= 63) {
767 "only 63 CPUs in NUMA mode supported.\n");
769 value
= (2ULL << endvalue
) - (1ULL << value
);
771 value
= 1ULL << value
;
774 node_cpumask
[nodenr
] = value
;
781 static void smp_parse(const char *optarg
)
783 int smp
, sockets
= 0, threads
= 0, cores
= 0;
787 smp
= strtoul(optarg
, &endptr
, 10);
788 if (endptr
!= optarg
) {
789 if (*endptr
== ',') {
793 if (get_param_value(option
, 128, "sockets", endptr
) != 0)
794 sockets
= strtoull(option
, NULL
, 10);
795 if (get_param_value(option
, 128, "cores", endptr
) != 0)
796 cores
= strtoull(option
, NULL
, 10);
797 if (get_param_value(option
, 128, "threads", endptr
) != 0)
798 threads
= strtoull(option
, NULL
, 10);
799 if (get_param_value(option
, 128, "maxcpus", endptr
) != 0)
800 max_cpus
= strtoull(option
, NULL
, 10);
802 /* compute missing values, prefer sockets over cores over threads */
803 if (smp
== 0 || sockets
== 0) {
804 sockets
= sockets
> 0 ? sockets
: 1;
805 cores
= cores
> 0 ? cores
: 1;
806 threads
= threads
> 0 ? threads
: 1;
808 smp
= cores
* threads
* sockets
;
812 threads
= threads
> 0 ? threads
: 1;
813 cores
= smp
/ (sockets
* threads
);
815 threads
= smp
/ (cores
* sockets
);
819 smp_cores
= cores
> 0 ? cores
: 1;
820 smp_threads
= threads
> 0 ? threads
: 1;
825 /***********************************************************/
828 static int usb_device_add(const char *devname
)
831 USBDevice
*dev
= NULL
;
836 /* drivers with .usbdevice_name entry in USBDeviceInfo */
837 dev
= usbdevice_create(devname
);
842 if (strstart(devname
, "host:", &p
)) {
843 dev
= usb_host_device_open(p
);
844 } else if (!strcmp(devname
, "bt") || strstart(devname
, "bt:", &p
)) {
845 dev
= usb_bt_init(devname
[2] ? hci_init(p
) :
846 bt_new_hci(qemu_find_bt_vlan(0)));
857 static int usb_device_del(const char *devname
)
862 if (strstart(devname
, "host:", &p
))
863 return usb_host_device_close(p
);
868 p
= strchr(devname
, '.');
871 bus_num
= strtoul(devname
, NULL
, 0);
872 addr
= strtoul(p
+ 1, NULL
, 0);
874 return usb_device_delete_addr(bus_num
, addr
);
877 static int usb_parse(const char *cmdline
)
880 r
= usb_device_add(cmdline
);
882 fprintf(stderr
, "qemu: could not add USB device '%s'\n", cmdline
);
887 void do_usb_add(Monitor
*mon
, const QDict
*qdict
)
889 const char *devname
= qdict_get_str(qdict
, "devname");
890 if (usb_device_add(devname
) < 0) {
891 error_report("could not add USB device '%s'", devname
);
895 void do_usb_del(Monitor
*mon
, const QDict
*qdict
)
897 const char *devname
= qdict_get_str(qdict
, "devname");
898 if (usb_device_del(devname
) < 0) {
899 error_report("could not delete USB device '%s'", devname
);
903 /***********************************************************/
906 static struct pcmcia_socket_entry_s
{
907 PCMCIASocket
*socket
;
908 struct pcmcia_socket_entry_s
*next
;
909 } *pcmcia_sockets
= 0;
911 void pcmcia_socket_register(PCMCIASocket
*socket
)
913 struct pcmcia_socket_entry_s
*entry
;
915 entry
= qemu_malloc(sizeof(struct pcmcia_socket_entry_s
));
916 entry
->socket
= socket
;
917 entry
->next
= pcmcia_sockets
;
918 pcmcia_sockets
= entry
;
921 void pcmcia_socket_unregister(PCMCIASocket
*socket
)
923 struct pcmcia_socket_entry_s
*entry
, **ptr
;
925 ptr
= &pcmcia_sockets
;
926 for (entry
= *ptr
; entry
; ptr
= &entry
->next
, entry
= *ptr
)
927 if (entry
->socket
== socket
) {
933 void pcmcia_info(Monitor
*mon
)
935 struct pcmcia_socket_entry_s
*iter
;
938 monitor_printf(mon
, "No PCMCIA sockets\n");
940 for (iter
= pcmcia_sockets
; iter
; iter
= iter
->next
)
941 monitor_printf(mon
, "%s: %s\n", iter
->socket
->slot_string
,
942 iter
->socket
->attached
? iter
->socket
->card_string
:
946 /***********************************************************/
949 typedef struct IOHandlerRecord
{
951 IOCanReadHandler
*fd_read_poll
;
958 QLIST_ENTRY(IOHandlerRecord
) next
;
961 static QLIST_HEAD(, IOHandlerRecord
) io_handlers
=
962 QLIST_HEAD_INITIALIZER(io_handlers
);
965 /* XXX: fd_read_poll should be suppressed, but an API change is
966 necessary in the character devices to suppress fd_can_read(). */
967 int qemu_set_fd_handler2(int fd
,
968 IOCanReadHandler
*fd_read_poll
,
973 IOHandlerRecord
*ioh
;
975 if (!fd_read
&& !fd_write
) {
976 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
983 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
987 ioh
= qemu_mallocz(sizeof(IOHandlerRecord
));
988 QLIST_INSERT_HEAD(&io_handlers
, ioh
, next
);
991 ioh
->fd_read_poll
= fd_read_poll
;
992 ioh
->fd_read
= fd_read
;
993 ioh
->fd_write
= fd_write
;
994 ioh
->opaque
= opaque
;
1001 int qemu_set_fd_handler(int fd
,
1003 IOHandler
*fd_write
,
1006 return qemu_set_fd_handler2(fd
, NULL
, fd_read
, fd_write
, opaque
);
1009 /***********************************************************/
1010 /* machine registration */
1012 static QEMUMachine
*first_machine
= NULL
;
1013 QEMUMachine
*current_machine
= NULL
;
1015 int qemu_register_machine(QEMUMachine
*m
)
1018 pm
= &first_machine
;
1026 static QEMUMachine
*find_machine(const char *name
)
1030 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1031 if (!strcmp(m
->name
, name
))
1033 if (m
->alias
&& !strcmp(m
->alias
, name
))
1039 static QEMUMachine
*find_default_machine(void)
1043 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1044 if (m
->is_default
) {
1051 /***********************************************************/
1052 /* main execution loop */
1054 static void gui_update(void *opaque
)
1056 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1057 DisplayState
*ds
= opaque
;
1058 DisplayChangeListener
*dcl
= ds
->listeners
;
1060 qemu_flush_coalesced_mmio_buffer();
1063 while (dcl
!= NULL
) {
1064 if (dcl
->gui_timer_interval
&&
1065 dcl
->gui_timer_interval
< interval
)
1066 interval
= dcl
->gui_timer_interval
;
1069 qemu_mod_timer(ds
->gui_timer
, interval
+ qemu_get_clock(rt_clock
));
1072 static void nographic_update(void *opaque
)
1074 uint64_t interval
= GUI_REFRESH_INTERVAL
;
1076 qemu_flush_coalesced_mmio_buffer();
1077 qemu_mod_timer(nographic_timer
, interval
+ qemu_get_clock(rt_clock
));
1080 struct vm_change_state_entry
{
1081 VMChangeStateHandler
*cb
;
1083 QLIST_ENTRY (vm_change_state_entry
) entries
;
1086 static QLIST_HEAD(vm_change_state_head
, vm_change_state_entry
) vm_change_state_head
;
1088 VMChangeStateEntry
*qemu_add_vm_change_state_handler(VMChangeStateHandler
*cb
,
1091 VMChangeStateEntry
*e
;
1093 e
= qemu_mallocz(sizeof (*e
));
1097 QLIST_INSERT_HEAD(&vm_change_state_head
, e
, entries
);
1101 void qemu_del_vm_change_state_handler(VMChangeStateEntry
*e
)
1103 QLIST_REMOVE (e
, entries
);
1107 void vm_state_notify(int running
, int reason
)
1109 VMChangeStateEntry
*e
;
1111 for (e
= vm_change_state_head
.lh_first
; e
; e
= e
->entries
.le_next
) {
1112 e
->cb(e
->opaque
, running
, reason
);
1121 vm_state_notify(1, 0);
1123 monitor_protocol_event(QEVENT_RESUME
, NULL
);
1127 /* reset/shutdown handler */
1129 typedef struct QEMUResetEntry
{
1130 QTAILQ_ENTRY(QEMUResetEntry
) entry
;
1131 QEMUResetHandler
*func
;
1135 static QTAILQ_HEAD(reset_handlers
, QEMUResetEntry
) reset_handlers
=
1136 QTAILQ_HEAD_INITIALIZER(reset_handlers
);
1137 static int reset_requested
;
1138 static int shutdown_requested
;
1139 static int powerdown_requested
;
1140 int debug_requested
;
1141 int vmstop_requested
;
1143 int qemu_no_shutdown(void)
1145 int r
= no_shutdown
;
1150 int qemu_shutdown_requested(void)
1152 int r
= shutdown_requested
;
1153 shutdown_requested
= 0;
1157 int qemu_reset_requested(void)
1159 int r
= reset_requested
;
1160 reset_requested
= 0;
1164 int qemu_powerdown_requested(void)
1166 int r
= powerdown_requested
;
1167 powerdown_requested
= 0;
1171 static int qemu_debug_requested(void)
1173 int r
= debug_requested
;
1174 debug_requested
= 0;
1178 static int qemu_vmstop_requested(void)
1180 int r
= vmstop_requested
;
1181 vmstop_requested
= 0;
1185 void qemu_register_reset(QEMUResetHandler
*func
, void *opaque
)
1187 QEMUResetEntry
*re
= qemu_mallocz(sizeof(QEMUResetEntry
));
1190 re
->opaque
= opaque
;
1191 QTAILQ_INSERT_TAIL(&reset_handlers
, re
, entry
);
1194 void qemu_unregister_reset(QEMUResetHandler
*func
, void *opaque
)
1198 QTAILQ_FOREACH(re
, &reset_handlers
, entry
) {
1199 if (re
->func
== func
&& re
->opaque
== opaque
) {
1200 QTAILQ_REMOVE(&reset_handlers
, re
, entry
);
1207 void qemu_system_reset(void)
1209 QEMUResetEntry
*re
, *nre
;
1211 /* reset all devices */
1212 QTAILQ_FOREACH_SAFE(re
, &reset_handlers
, entry
, nre
) {
1213 re
->func(re
->opaque
);
1215 monitor_protocol_event(QEVENT_RESET
, NULL
);
1216 cpu_synchronize_all_post_reset();
1219 void qemu_system_reset_request(void)
1222 shutdown_requested
= 1;
1224 reset_requested
= 1;
1226 if (cpu_single_env
) {
1227 cpu_single_env
->stopped
= 1;
1228 cpu_exit(cpu_single_env
);
1230 qemu_notify_event();
1233 void qemu_system_shutdown_request(void)
1235 shutdown_requested
= 1;
1236 qemu_notify_event();
1239 void qemu_system_powerdown_request(void)
1241 powerdown_requested
= 1;
1242 qemu_notify_event();
1245 void main_loop_wait(int nonblocking
)
1247 IOHandlerRecord
*ioh
;
1248 fd_set rfds
, wfds
, xfds
;
1256 timeout
= qemu_calculate_timeout();
1257 qemu_bh_update_timeout(&timeout
);
1260 os_host_main_loop_wait(&timeout
);
1262 /* poll any events */
1263 /* XXX: separate device handlers from system ones */
1268 QLIST_FOREACH(ioh
, &io_handlers
, next
) {
1272 (!ioh
->fd_read_poll
||
1273 ioh
->fd_read_poll(ioh
->opaque
) != 0)) {
1274 FD_SET(ioh
->fd
, &rfds
);
1278 if (ioh
->fd_write
) {
1279 FD_SET(ioh
->fd
, &wfds
);
1285 tv
.tv_sec
= timeout
/ 1000;
1286 tv
.tv_usec
= (timeout
% 1000) * 1000;
1288 slirp_select_fill(&nfds
, &rfds
, &wfds
, &xfds
);
1290 qemu_mutex_unlock_iothread();
1291 ret
= select(nfds
+ 1, &rfds
, &wfds
, &xfds
, &tv
);
1292 qemu_mutex_lock_iothread();
1294 IOHandlerRecord
*pioh
;
1296 QLIST_FOREACH_SAFE(ioh
, &io_handlers
, next
, pioh
) {
1298 QLIST_REMOVE(ioh
, next
);
1302 if (ioh
->fd_read
&& FD_ISSET(ioh
->fd
, &rfds
)) {
1303 ioh
->fd_read(ioh
->opaque
);
1304 if (!(ioh
->fd_read_poll
&& ioh
->fd_read_poll(ioh
->opaque
)))
1305 FD_CLR(ioh
->fd
, &rfds
);
1307 if (ioh
->fd_write
&& FD_ISSET(ioh
->fd
, &wfds
)) {
1308 ioh
->fd_write(ioh
->opaque
);
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 if (kvm_enabled()) {
1344 cpu_disable_ticks();
1348 qemu_main_loop_start();
1352 bool nonblocking
= false;
1353 #ifdef CONFIG_PROFILER
1356 #ifndef CONFIG_IOTHREAD
1357 nonblocking
= cpu_exec_all();
1359 #ifdef CONFIG_PROFILER
1360 ti
= profile_getclock();
1362 main_loop_wait(nonblocking
);
1363 #ifdef CONFIG_PROFILER
1364 dev_time
+= profile_getclock() - ti
;
1366 } while (vm_can_run());
1368 if ((r
= qemu_debug_requested())) {
1371 if (qemu_shutdown_requested()) {
1372 monitor_protocol_event(QEVENT_SHUTDOWN
, NULL
);
1379 if (qemu_reset_requested()) {
1381 qemu_system_reset();
1384 if (qemu_powerdown_requested()) {
1385 monitor_protocol_event(QEVENT_POWERDOWN
, NULL
);
1386 qemu_irq_raise(qemu_system_powerdown
);
1388 if ((r
= qemu_vmstop_requested())) {
1396 static void version(void)
1398 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION
", Copyright (c) 2003-2008 Fabrice Bellard\n");
1401 static void help(int exitcode
)
1403 const char *options_help
=
1404 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1406 #define DEFHEADING(text) stringify(text) "\n"
1407 #include "qemu-options.def"
1413 printf("usage: %s [options] [disk_image]\n"
1415 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1418 "During emulation, the following keys are useful:\n"
1419 "ctrl-alt-f toggle full screen\n"
1420 "ctrl-alt-n switch to virtual console 'n'\n"
1421 "ctrl-alt toggle mouse and keyboard grab\n"
1423 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1429 #define HAS_ARG 0x0001
1431 typedef struct QEMUOption
{
1438 static const QEMUOption qemu_options
[] = {
1439 { "h", 0, QEMU_OPTION_h
, QEMU_ARCH_ALL
},
1440 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1441 { option, opt_arg, opt_enum, arch_mask },
1442 #define DEFHEADING(text)
1443 #include "qemu-options.def"
1449 static void select_vgahw (const char *p
)
1454 vga_interface_type
= VGA_NONE
;
1455 if (strstart(p
, "std", &opts
)) {
1456 vga_interface_type
= VGA_STD
;
1457 } else if (strstart(p
, "cirrus", &opts
)) {
1458 vga_interface_type
= VGA_CIRRUS
;
1459 } else if (strstart(p
, "vmware", &opts
)) {
1460 vga_interface_type
= VGA_VMWARE
;
1461 } else if (strstart(p
, "xenfb", &opts
)) {
1462 vga_interface_type
= VGA_XENFB
;
1463 } else if (!strstart(p
, "none", &opts
)) {
1465 fprintf(stderr
, "Unknown vga type: %s\n", p
);
1469 const char *nextopt
;
1471 if (strstart(opts
, ",retrace=", &nextopt
)) {
1473 if (strstart(opts
, "dumb", &nextopt
))
1474 vga_retrace_method
= VGA_RETRACE_DUMB
;
1475 else if (strstart(opts
, "precise", &nextopt
))
1476 vga_retrace_method
= VGA_RETRACE_PRECISE
;
1477 else goto invalid_vga
;
1478 } else goto invalid_vga
;
1483 static int balloon_parse(const char *arg
)
1487 if (strcmp(arg
, "none") == 0) {
1491 if (!strncmp(arg
, "virtio", 6)) {
1492 if (arg
[6] == ',') {
1493 /* have params -> parse them */
1494 opts
= qemu_opts_parse(qemu_find_opts("device"), arg
+7, 0);
1498 /* create empty opts */
1499 opts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0);
1501 qemu_opt_set(opts
, "driver", "virtio-balloon-pci");
1508 char *qemu_find_file(int type
, const char *name
)
1514 /* If name contains path separators then try it as a straight path. */
1515 if ((strchr(name
, '/') || strchr(name
, '\\'))
1516 && access(name
, R_OK
) == 0) {
1517 return qemu_strdup(name
);
1520 case QEMU_FILE_TYPE_BIOS
:
1523 case QEMU_FILE_TYPE_KEYMAP
:
1524 subdir
= "keymaps/";
1529 len
= strlen(data_dir
) + strlen(name
) + strlen(subdir
) + 2;
1530 buf
= qemu_mallocz(len
);
1531 snprintf(buf
, len
, "%s/%s%s", data_dir
, subdir
, name
);
1532 if (access(buf
, R_OK
)) {
1539 static int device_help_func(QemuOpts
*opts
, void *opaque
)
1541 return qdev_device_help(opts
);
1544 static int device_init_func(QemuOpts
*opts
, void *opaque
)
1548 dev
= qdev_device_add(opts
);
1554 static int chardev_init_func(QemuOpts
*opts
, void *opaque
)
1556 CharDriverState
*chr
;
1558 chr
= qemu_chr_open_opts(opts
, NULL
);
1564 #ifdef CONFIG_VIRTFS
1565 static int fsdev_init_func(QemuOpts
*opts
, void *opaque
)
1568 ret
= qemu_fsdev_add(opts
);
1574 static int mon_init_func(QemuOpts
*opts
, void *opaque
)
1576 CharDriverState
*chr
;
1577 const char *chardev
;
1581 mode
= qemu_opt_get(opts
, "mode");
1585 if (strcmp(mode
, "readline") == 0) {
1586 flags
= MONITOR_USE_READLINE
;
1587 } else if (strcmp(mode
, "control") == 0) {
1588 flags
= MONITOR_USE_CONTROL
;
1590 fprintf(stderr
, "unknown monitor mode \"%s\"\n", mode
);
1594 if (qemu_opt_get_bool(opts
, "default", 0))
1595 flags
|= MONITOR_IS_DEFAULT
;
1597 chardev
= qemu_opt_get(opts
, "chardev");
1598 chr
= qemu_chr_find(chardev
);
1600 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1604 monitor_init(chr
, flags
);
1608 static void monitor_parse(const char *optarg
, const char *mode
)
1610 static int monitor_device_index
= 0;
1616 if (strstart(optarg
, "chardev:", &p
)) {
1617 snprintf(label
, sizeof(label
), "%s", p
);
1619 snprintf(label
, sizeof(label
), "compat_monitor%d",
1620 monitor_device_index
);
1621 if (monitor_device_index
== 0) {
1624 opts
= qemu_chr_parse_compat(label
, optarg
);
1626 fprintf(stderr
, "parse error: %s\n", optarg
);
1631 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1633 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1636 qemu_opt_set(opts
, "mode", mode
);
1637 qemu_opt_set(opts
, "chardev", label
);
1639 qemu_opt_set(opts
, "default", "on");
1640 monitor_device_index
++;
1643 struct device_config
{
1645 DEV_USB
, /* -usbdevice */
1647 DEV_SERIAL
, /* -serial */
1648 DEV_PARALLEL
, /* -parallel */
1649 DEV_VIRTCON
, /* -virtioconsole */
1650 DEV_DEBUGCON
, /* -debugcon */
1652 const char *cmdline
;
1653 QTAILQ_ENTRY(device_config
) next
;
1655 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1657 static void add_device_config(int type
, const char *cmdline
)
1659 struct device_config
*conf
;
1661 conf
= qemu_mallocz(sizeof(*conf
));
1663 conf
->cmdline
= cmdline
;
1664 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1667 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1669 struct device_config
*conf
;
1672 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1673 if (conf
->type
!= type
)
1675 rc
= func(conf
->cmdline
);
1682 static int serial_parse(const char *devname
)
1684 static int index
= 0;
1687 if (strcmp(devname
, "none") == 0)
1689 if (index
== MAX_SERIAL_PORTS
) {
1690 fprintf(stderr
, "qemu: too many serial ports\n");
1693 snprintf(label
, sizeof(label
), "serial%d", index
);
1694 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1695 if (!serial_hds
[index
]) {
1696 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1697 devname
, strerror(errno
));
1704 static int parallel_parse(const char *devname
)
1706 static int index
= 0;
1709 if (strcmp(devname
, "none") == 0)
1711 if (index
== MAX_PARALLEL_PORTS
) {
1712 fprintf(stderr
, "qemu: too many parallel ports\n");
1715 snprintf(label
, sizeof(label
), "parallel%d", index
);
1716 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1717 if (!parallel_hds
[index
]) {
1718 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1719 devname
, strerror(errno
));
1726 static int virtcon_parse(const char *devname
)
1728 QemuOptsList
*device
= qemu_find_opts("device");
1729 static int index
= 0;
1731 QemuOpts
*bus_opts
, *dev_opts
;
1733 if (strcmp(devname
, "none") == 0)
1735 if (index
== MAX_VIRTIO_CONSOLES
) {
1736 fprintf(stderr
, "qemu: too many virtio consoles\n");
1740 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1741 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1743 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1744 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1746 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1747 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1748 if (!virtcon_hds
[index
]) {
1749 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1750 devname
, strerror(errno
));
1753 qemu_opt_set(dev_opts
, "chardev", label
);
1759 static int debugcon_parse(const char *devname
)
1763 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1766 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1768 fprintf(stderr
, "qemu: already have a debugcon device\n");
1771 qemu_opt_set(opts
, "driver", "isa-debugcon");
1772 qemu_opt_set(opts
, "chardev", "debugcon");
1776 void qemu_add_exit_notifier(Notifier
*notify
)
1778 notifier_list_add(&exit_notifiers
, notify
);
1781 void qemu_remove_exit_notifier(Notifier
*notify
)
1783 notifier_list_remove(&exit_notifiers
, notify
);
1786 static void qemu_run_exit_notifiers(void)
1788 notifier_list_notify(&exit_notifiers
);
1791 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1792 const char **poptarg
, int *poptind
)
1794 const QEMUOption
*popt
;
1795 int optind
= *poptind
;
1796 char *r
= argv
[optind
];
1799 loc_set_cmdline(argv
, optind
, 1);
1801 /* Treat --foo the same as -foo. */
1804 popt
= qemu_options
;
1807 error_report("invalid option");
1810 if (!strcmp(popt
->name
, r
+ 1))
1814 if (popt
->flags
& HAS_ARG
) {
1815 if (optind
>= argc
) {
1816 error_report("requires an argument");
1819 optarg
= argv
[optind
++];
1820 loc_set_cmdline(argv
, optind
- 2, 2);
1831 int main(int argc
, char **argv
, char **envp
)
1833 const char *gdbstub_dev
= NULL
;
1835 int snapshot
, linux_boot
;
1836 const char *icount_option
= NULL
;
1837 const char *initrd_filename
;
1838 const char *kernel_filename
, *kernel_cmdline
;
1839 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1841 DisplayChangeListener
*dcl
;
1842 int cyls
, heads
, secs
, translation
;
1843 QemuOpts
*hda_opts
= NULL
, *opts
;
1844 QemuOptsList
*olist
;
1847 const char *loadvm
= NULL
;
1848 QEMUMachine
*machine
;
1849 const char *cpu_model
;
1851 const char *pid_file
= NULL
;
1852 const char *incoming
= NULL
;
1853 int show_vnc_port
= 0;
1856 #ifdef CONFIG_SIMPLE_TRACE
1857 const char *trace_file
= NULL
;
1859 atexit(qemu_run_exit_notifiers
);
1860 error_set_progname(argv
[0]);
1864 qemu_cache_utils_init(envp
);
1866 QLIST_INIT (&vm_change_state_head
);
1867 os_setup_early_signal_handling();
1869 module_call_init(MODULE_INIT_MACHINE
);
1870 machine
= find_default_machine();
1872 initrd_filename
= NULL
;
1875 kernel_filename
= NULL
;
1876 kernel_cmdline
= "";
1877 cyls
= heads
= secs
= 0;
1878 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1880 for (i
= 0; i
< MAX_NODES
; i
++) {
1882 node_cpumask
[i
] = 0;
1885 assigned_devices_index
= 0;
1893 #ifdef CONFIG_VIRTFS
1894 qemu_add_opts(&qemu_fsdev_opts
);
1895 qemu_add_opts(&qemu_virtfs_opts
);
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
: {
2199 value
= strtoul(optarg
, &ptr
, 10);
2201 case 0: case 'M': case 'm':
2208 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2212 /* On 32-bit hosts, QEMU is limited by virtual address space */
2213 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2214 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2217 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2218 fprintf(stderr
, "qemu: ram size too large\n");
2224 case QEMU_OPTION_mempath
:
2228 case QEMU_OPTION_mem_prealloc
:
2233 set_cpu_log(optarg
);
2236 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2238 case QEMU_OPTION_gdb
:
2239 gdbstub_dev
= optarg
;
2244 case QEMU_OPTION_bios
:
2247 case QEMU_OPTION_singlestep
:
2254 keyboard_layout
= optarg
;
2256 case QEMU_OPTION_localtime
:
2259 case QEMU_OPTION_vga
:
2260 select_vgahw (optarg
);
2267 w
= strtol(p
, (char **)&p
, 10);
2270 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2276 h
= strtol(p
, (char **)&p
, 10);
2281 depth
= strtol(p
, (char **)&p
, 10);
2282 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2283 depth
!= 24 && depth
!= 32)
2285 } else if (*p
== '\0') {
2286 depth
= graphic_depth
;
2293 graphic_depth
= depth
;
2296 case QEMU_OPTION_echr
:
2299 term_escape_char
= strtol(optarg
, &r
, 0);
2301 printf("Bad argument to echr\n");
2304 case QEMU_OPTION_monitor
:
2305 monitor_parse(optarg
, "readline");
2306 default_monitor
= 0;
2308 case QEMU_OPTION_qmp
:
2309 monitor_parse(optarg
, "control");
2310 default_monitor
= 0;
2312 case QEMU_OPTION_mon
:
2313 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2317 default_monitor
= 0;
2319 case QEMU_OPTION_chardev
:
2320 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2325 case QEMU_OPTION_fsdev
:
2326 olist
= qemu_find_opts("fsdev");
2328 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2331 opts
= qemu_opts_parse(olist
, optarg
, 1);
2333 fprintf(stderr
, "parse error: %s\n", optarg
);
2337 case QEMU_OPTION_virtfs
: {
2338 char *arg_fsdev
= NULL
;
2339 char *arg_9p
= NULL
;
2342 olist
= qemu_find_opts("virtfs");
2344 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2347 opts
= qemu_opts_parse(olist
, optarg
, 1);
2349 fprintf(stderr
, "parse error: %s\n", optarg
);
2353 if (qemu_opt_get(opts
, "fstype") == NULL
||
2354 qemu_opt_get(opts
, "mount_tag") == NULL
||
2355 qemu_opt_get(opts
, "path") == NULL
||
2356 qemu_opt_get(opts
, "security_model") == NULL
) {
2357 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2358 "security_model=[mapped|passthrough|none],"
2363 len
= strlen(",id=,path=,security_model=");
2364 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2365 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2366 len
+= strlen(qemu_opt_get(opts
, "path"));
2367 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2368 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2370 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2371 "%s,id=%s,path=%s,security_model=%s",
2372 qemu_opt_get(opts
, "fstype"),
2373 qemu_opt_get(opts
, "mount_tag"),
2374 qemu_opt_get(opts
, "path"),
2375 qemu_opt_get(opts
, "security_model"));
2377 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2378 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2379 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2381 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2382 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2383 qemu_opt_get(opts
, "mount_tag"),
2384 qemu_opt_get(opts
, "mount_tag"));
2386 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2387 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2391 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2392 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2396 qemu_free(arg_fsdev
);
2400 case QEMU_OPTION_serial
:
2401 add_device_config(DEV_SERIAL
, optarg
);
2403 if (strncmp(optarg
, "mon:", 4) == 0) {
2404 default_monitor
= 0;
2407 case QEMU_OPTION_watchdog
:
2410 "qemu: only one watchdog option may be given\n");
2415 case QEMU_OPTION_watchdog_action
:
2416 if (select_watchdog_action(optarg
) == -1) {
2417 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2421 case QEMU_OPTION_virtiocon
:
2422 add_device_config(DEV_VIRTCON
, optarg
);
2423 default_virtcon
= 0;
2424 if (strncmp(optarg
, "mon:", 4) == 0) {
2425 default_monitor
= 0;
2428 case QEMU_OPTION_parallel
:
2429 add_device_config(DEV_PARALLEL
, optarg
);
2430 default_parallel
= 0;
2431 if (strncmp(optarg
, "mon:", 4) == 0) {
2432 default_monitor
= 0;
2435 case QEMU_OPTION_debugcon
:
2436 add_device_config(DEV_DEBUGCON
, optarg
);
2438 case QEMU_OPTION_loadvm
:
2441 case QEMU_OPTION_full_screen
:
2445 case QEMU_OPTION_no_frame
:
2448 case QEMU_OPTION_alt_grab
:
2451 case QEMU_OPTION_ctrl_grab
:
2454 case QEMU_OPTION_no_quit
:
2457 case QEMU_OPTION_sdl
:
2458 display_type
= DT_SDL
;
2461 case QEMU_OPTION_pidfile
:
2464 case QEMU_OPTION_win2k_hack
:
2465 win2k_install_hack
= 1;
2467 case QEMU_OPTION_rtc_td_hack
:
2470 case QEMU_OPTION_acpitable
:
2471 do_acpitable_option(optarg
);
2473 case QEMU_OPTION_smbios
:
2474 do_smbios_option(optarg
);
2476 #ifdef OBSOLETE_KVM_IMPL
2477 case QEMU_OPTION_enable_kvm
:
2481 case QEMU_OPTION_no_kvm
:
2483 #ifdef CONFIG_NO_CPU_EMULATION
2484 fprintf(stderr
, "cpu emulation not configured\n");
2489 case QEMU_OPTION_no_kvm_irqchip
: {
2494 case QEMU_OPTION_no_kvm_pit
: {
2498 case QEMU_OPTION_no_kvm_pit_reinjection
: {
2499 kvm_pit_reinject
= 0;
2502 case QEMU_OPTION_enable_nesting
: {
2507 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
2508 case QEMU_OPTION_pcidevice
:
2509 if (assigned_devices_index
>= MAX_DEV_ASSIGN_CMDLINE
) {
2510 fprintf(stderr
, "Too many assigned devices\n");
2513 assigned_devices
[assigned_devices_index
] = optarg
;
2514 assigned_devices_index
++;
2517 case QEMU_OPTION_usb
:
2520 case QEMU_OPTION_usbdevice
:
2522 add_device_config(DEV_USB
, optarg
);
2524 case QEMU_OPTION_device
:
2525 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2529 case QEMU_OPTION_smp
:
2532 fprintf(stderr
, "Invalid number of CPUs\n");
2535 if (max_cpus
< smp_cpus
) {
2536 fprintf(stderr
, "maxcpus must be equal to or greater than "
2540 if (max_cpus
> 255) {
2541 fprintf(stderr
, "Unsupported number of maxcpus\n");
2545 case QEMU_OPTION_vnc
:
2546 display_type
= DT_VNC
;
2547 vnc_display
= optarg
;
2549 case QEMU_OPTION_no_acpi
:
2552 case QEMU_OPTION_no_hpet
:
2555 case QEMU_OPTION_balloon
:
2556 if (balloon_parse(optarg
) < 0) {
2557 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2561 case QEMU_OPTION_no_reboot
:
2564 case QEMU_OPTION_no_shutdown
:
2567 case QEMU_OPTION_show_cursor
:
2570 case QEMU_OPTION_uuid
:
2571 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2572 fprintf(stderr
, "Fail to parse UUID string."
2573 " Wrong format.\n");
2577 case QEMU_OPTION_option_rom
:
2578 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2579 fprintf(stderr
, "Too many option ROMs\n");
2582 option_rom
[nb_option_roms
] = optarg
;
2585 case QEMU_OPTION_semihosting
:
2586 semihosting_enabled
= 1;
2588 case QEMU_OPTION_tdf
:
2591 case QEMU_OPTION_kvm_shadow_memory
:
2592 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2594 case QEMU_OPTION_name
:
2595 qemu_name
= qemu_strdup(optarg
);
2597 char *p
= strchr(qemu_name
, ',');
2600 if (strncmp(p
, "process=", 8)) {
2601 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2605 os_set_proc_name(p
);
2609 case QEMU_OPTION_prom_env
:
2610 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2611 fprintf(stderr
, "Too many prom variables\n");
2614 prom_envs
[nb_prom_envs
] = optarg
;
2617 case QEMU_OPTION_old_param
:
2620 case QEMU_OPTION_clock
:
2621 configure_alarms(optarg
);
2623 case QEMU_OPTION_startdate
:
2624 configure_rtc_date_offset(optarg
, 1);
2626 case QEMU_OPTION_rtc
:
2627 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2631 configure_rtc(opts
);
2633 case QEMU_OPTION_tb_size
:
2634 tb_size
= strtol(optarg
, NULL
, 0);
2638 case QEMU_OPTION_icount
:
2639 icount_option
= optarg
;
2641 case QEMU_OPTION_incoming
:
2643 incoming_expected
= true;
2645 case QEMU_OPTION_nodefaults
:
2647 default_parallel
= 0;
2648 default_virtcon
= 0;
2649 default_monitor
= 0;
2657 case QEMU_OPTION_nvram
:
2661 case QEMU_OPTION_xen_domid
:
2662 if (!(xen_available())) {
2663 printf("Option %s not supported for this target\n", popt
->name
);
2666 xen_domid
= atoi(optarg
);
2668 case QEMU_OPTION_xen_create
:
2669 if (!(xen_available())) {
2670 printf("Option %s not supported for this target\n", popt
->name
);
2673 xen_mode
= XEN_CREATE
;
2675 case QEMU_OPTION_xen_attach
:
2676 if (!(xen_available())) {
2677 printf("Option %s not supported for this target\n", popt
->name
);
2680 xen_mode
= XEN_ATTACH
;
2682 #ifdef CONFIG_SIMPLE_TRACE
2683 case QEMU_OPTION_trace
:
2684 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2686 trace_file
= qemu_opt_get(opts
, "file");
2690 case QEMU_OPTION_readconfig
:
2692 int ret
= qemu_read_config_file(optarg
);
2694 fprintf(stderr
, "read config %s: %s\n", optarg
,
2700 case QEMU_OPTION_writeconfig
:
2703 if (strcmp(optarg
, "-") == 0) {
2706 fp
= fopen(optarg
, "w");
2708 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2712 qemu_config_write(fp
);
2717 os_parse_cmd_args(popt
->index
, optarg
);
2723 /* If no data_dir is specified then try to find it relative to the
2726 data_dir
= os_find_datadir(argv
[0]);
2728 /* If all else fails use the install patch specified when building. */
2730 data_dir
= CONFIG_QEMU_DATADIR
;
2733 #ifdef CONFIG_SIMPLE_TRACE
2735 * Set the trace file name, if specified.
2737 st_set_trace_file(trace_file
);
2740 * Default to max_cpus = smp_cpus, in case the user doesn't
2741 * specify a max_cpus value.
2744 max_cpus
= smp_cpus
;
2746 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2747 if (smp_cpus
> machine
->max_cpus
) {
2748 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2749 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2754 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2755 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2757 if (machine
->no_serial
) {
2760 if (machine
->no_parallel
) {
2761 default_parallel
= 0;
2763 if (!machine
->use_virtcon
) {
2764 default_virtcon
= 0;
2766 if (machine
->no_vga
) {
2769 if (machine
->no_floppy
) {
2772 if (machine
->no_cdrom
) {
2775 if (machine
->no_sdcard
) {
2779 if (display_type
== DT_NOGRAPHIC
) {
2780 if (default_parallel
)
2781 add_device_config(DEV_PARALLEL
, "null");
2782 if (default_serial
&& default_monitor
) {
2783 add_device_config(DEV_SERIAL
, "mon:stdio");
2784 } else if (default_virtcon
&& default_monitor
) {
2785 add_device_config(DEV_VIRTCON
, "mon:stdio");
2788 add_device_config(DEV_SERIAL
, "stdio");
2789 if (default_virtcon
)
2790 add_device_config(DEV_VIRTCON
, "stdio");
2791 if (default_monitor
)
2792 monitor_parse("stdio", "readline");
2796 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2797 if (default_parallel
)
2798 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2799 if (default_monitor
)
2800 monitor_parse("vc:80Cx24C", "readline");
2801 if (default_virtcon
)
2802 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2805 vga_interface_type
= VGA_CIRRUS
;
2809 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2811 #ifdef CONFIG_VIRTFS
2812 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2819 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2825 int ret
= kvm_init(smp_cpus
);
2827 #if defined(OBSOLETE_KVM_IMPL) || defined(CONFIG_NO_CPU_EMULATION)
2828 if (!kvm_available()) {
2829 printf("KVM not supported for this target\n");
2831 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2836 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2842 if (qemu_init_main_loop()) {
2843 fprintf(stderr
, "qemu_init_main_loop failed\n");
2846 linux_boot
= (kernel_filename
!= NULL
);
2848 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2849 fprintf(stderr
, "-append only allowed with -kernel option\n");
2853 if (!linux_boot
&& initrd_filename
!= NULL
) {
2854 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2858 os_set_line_buffering();
2860 if (init_timer_alarm() < 0) {
2861 fprintf(stderr
, "could not initialize alarm timer\n");
2864 configure_icount(icount_option
);
2866 if (net_init_clients() < 0) {
2870 /* init the bluetooth world */
2871 if (foreach_device_config(DEV_BT
, bt_parse
))
2874 /* init the memory */
2876 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2878 /* init the dynamic translator */
2879 cpu_exec_init_all(tb_size
* 1024 * 1024);
2881 bdrv_init_with_whitelist();
2885 if (default_cdrom
) {
2886 /* we always create the cdrom drive, even if no disk is there */
2887 drive_add(NULL
, CDROM_ALIAS
);
2890 if (default_floppy
) {
2891 /* we always create at least one floppy */
2892 drive_add(NULL
, FD_ALIAS
, 0);
2895 if (default_sdcard
) {
2896 /* we always create one sd slot, even if no card is in it */
2897 drive_add(NULL
, SD_ALIAS
);
2900 /* open the virtual block devices */
2902 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2903 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2906 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2909 if (nb_numa_nodes
> 0) {
2912 if (nb_numa_nodes
> smp_cpus
) {
2913 nb_numa_nodes
= smp_cpus
;
2916 /* If no memory size if given for any node, assume the default case
2917 * and distribute the available memory equally across all nodes
2919 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2920 if (node_mem
[i
] != 0)
2923 if (i
== nb_numa_nodes
) {
2924 uint64_t usedmem
= 0;
2926 /* On Linux, the each node's border has to be 8MB aligned,
2927 * the final node gets the rest.
2929 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2930 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2931 usedmem
+= node_mem
[i
];
2933 node_mem
[i
] = ram_size
- usedmem
;
2936 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2937 if (node_cpumask
[i
] != 0)
2940 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2941 * must cope with this anyway, because there are BIOSes out there in
2942 * real machines which also use this scheme.
2944 if (i
== nb_numa_nodes
) {
2945 for (i
= 0; i
< smp_cpus
; i
++) {
2946 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2951 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2955 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2957 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2959 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2961 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2964 module_call_init(MODULE_INIT_DEVICE
);
2966 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2970 i
= select_watchdog(watchdog
);
2972 exit (i
== 1 ? 1 : 0);
2975 if (machine
->compat_props
) {
2976 qdev_prop_register_global_list(machine
->compat_props
);
2980 machine
->init(ram_size
, boot_devices
,
2981 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2983 cpu_synchronize_all_post_init();
2985 /* must be after terminal init, SDL library changes signal handlers */
2986 os_setup_signal_handling();
2990 current_machine
= machine
;
2992 /* init USB devices */
2994 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
2998 /* init generic devices */
2999 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3002 net_check_clients();
3004 /* just use the first displaystate for the moment */
3005 ds
= get_displaystate();
3007 if (display_type
== DT_DEFAULT
) {
3008 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3009 display_type
= DT_SDL
;
3011 display_type
= DT_VNC
;
3012 vnc_display
= "localhost:0,to=99";
3018 switch (display_type
) {
3021 #if defined(CONFIG_CURSES)
3023 curses_display_init(ds
, full_screen
);
3026 #if defined(CONFIG_SDL)
3028 sdl_display_init(ds
, full_screen
, no_frame
);
3030 #elif defined(CONFIG_COCOA)
3032 cocoa_display_init(ds
, full_screen
);
3036 vnc_display_init(ds
);
3037 if (vnc_display_open(ds
, vnc_display
) < 0)
3040 if (show_vnc_port
) {
3041 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3049 dcl
= ds
->listeners
;
3050 while (dcl
!= NULL
) {
3051 if (dcl
->dpy_refresh
!= NULL
) {
3052 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3053 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3059 if (display_type
== DT_NOGRAPHIC
|| display_type
== DT_VNC
) {
3060 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3061 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3064 text_consoles_set_display(ds
);
3066 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3067 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3072 qdev_machine_creation_done();
3074 if (rom_load_all() != 0) {
3075 fprintf(stderr
, "rom loading failed\n");
3079 qemu_system_reset();
3081 if (load_vmstate(loadvm
) < 0) {
3087 int ret
= qemu_start_incoming_migration(incoming
);
3089 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3093 } else if (autostart
) {