4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 /* Needed early for CONFIG_BSD etc. */
33 #include "config-host.h"
37 #include <sys/times.h>
41 #include <sys/ioctl.h>
42 #include <sys/resource.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
46 #include <arpa/inet.h>
49 #include <sys/select.h>
50 #ifdef CONFIG_SIMPLE_TRACE
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
58 #include <sys/sysctl.h>
67 #include <linux/ppdev.h>
68 #include <linux/parport.h>
72 #include <sys/ethernet.h>
73 #include <sys/sockio.h>
74 #include <netinet/arp.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/ip_icmp.h> // must come after ip.h
78 #include <netinet/udp.h>
79 #include <netinet/tcp.h>
87 #if defined(__OpenBSD__)
91 #if defined(CONFIG_VDE)
92 #include <libvdeplug.h>
100 #if defined(__APPLE__) || defined(main)
102 int qemu_main(int argc
, char **argv
, char **envp
);
103 int main(int argc
, char **argv
)
105 return qemu_main(argc
, argv
, NULL
);
108 #define main qemu_main
110 #endif /* CONFIG_SDL */
114 #define main qemu_main
115 #endif /* CONFIG_COCOA */
118 #include "hw/boards.h"
120 #include "hw/pcmcia.h"
125 #include "hw/watchdog.h"
126 #include "hw/smbios.h"
129 #include "hw/loader.h"
132 #include "net/slirp.h"
137 #include "qemu-timer.h"
138 #include "qemu-char.h"
139 #include "cache-utils.h"
141 #include "blockdev.h"
142 #include "block-migration.h"
144 #include "audio/audio.h"
145 #include "migration.h"
147 #include "qemu-option.h"
148 #include "qemu-config.h"
149 #include "qemu-objects.h"
150 #include "qemu-options.h"
151 #include "hw/device-assignment.h"
153 #include "fsdev/qemu-fsdev.h"
158 #include "qemu_socket.h"
160 #include "slirp/libslirp.h"
162 #include "qemu-queue.h"
164 #include "arch_init.h"
166 #include "ui/qemu-spice.h"
169 //#define DEBUG_SLIRP
171 #define DEFAULT_RAM_SIZE 128
173 #define MAX_VIRTIO_CONSOLES 1
175 static const char *data_dir
;
176 const char *bios_name
= NULL
;
177 enum vga_retrace_method vga_retrace_method
= VGA_RETRACE_DUMB
;
178 DisplayType display_type
= DT_DEFAULT
;
179 int display_remote
= 0;
180 const char* keyboard_layout
= NULL
;
182 const char *mem_path
= NULL
;
184 int mem_prealloc
= 0; /* force preallocation of physical target memory */
187 NICInfo nd_table
[MAX_NICS
];
190 int incoming_expected
; /* Started with -incoming and waiting for incoming */
191 static int rtc_utc
= 1;
192 static int rtc_date_offset
= -1; /* -1 means no change */
193 QEMUClock
*rtc_clock
;
194 int vga_interface_type
= VGA_NONE
;
195 static int full_screen
= 0;
197 static int no_frame
= 0;
200 CharDriverState
*serial_hds
[MAX_SERIAL_PORTS
];
201 CharDriverState
*parallel_hds
[MAX_PARALLEL_PORTS
];
202 CharDriverState
*virtcon_hds
[MAX_VIRTIO_CONSOLES
];
203 int win2k_install_hack
= 0;
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
, "pretty", 0))
1595 flags
|= MONITOR_USE_PRETTY
;
1597 if (qemu_opt_get_bool(opts
, "default", 0))
1598 flags
|= MONITOR_IS_DEFAULT
;
1600 chardev
= qemu_opt_get(opts
, "chardev");
1601 chr
= qemu_chr_find(chardev
);
1603 fprintf(stderr
, "chardev \"%s\" not found\n", chardev
);
1607 monitor_init(chr
, flags
);
1611 static void monitor_parse(const char *optarg
, const char *mode
)
1613 static int monitor_device_index
= 0;
1619 if (strstart(optarg
, "chardev:", &p
)) {
1620 snprintf(label
, sizeof(label
), "%s", p
);
1622 snprintf(label
, sizeof(label
), "compat_monitor%d",
1623 monitor_device_index
);
1624 if (monitor_device_index
== 0) {
1627 opts
= qemu_chr_parse_compat(label
, optarg
);
1629 fprintf(stderr
, "parse error: %s\n", optarg
);
1634 opts
= qemu_opts_create(qemu_find_opts("mon"), label
, 1);
1636 fprintf(stderr
, "duplicate chardev: %s\n", label
);
1639 qemu_opt_set(opts
, "mode", mode
);
1640 qemu_opt_set(opts
, "chardev", label
);
1642 qemu_opt_set(opts
, "default", "on");
1643 monitor_device_index
++;
1646 struct device_config
{
1648 DEV_USB
, /* -usbdevice */
1650 DEV_SERIAL
, /* -serial */
1651 DEV_PARALLEL
, /* -parallel */
1652 DEV_VIRTCON
, /* -virtioconsole */
1653 DEV_DEBUGCON
, /* -debugcon */
1655 const char *cmdline
;
1656 QTAILQ_ENTRY(device_config
) next
;
1658 QTAILQ_HEAD(, device_config
) device_configs
= QTAILQ_HEAD_INITIALIZER(device_configs
);
1660 static void add_device_config(int type
, const char *cmdline
)
1662 struct device_config
*conf
;
1664 conf
= qemu_mallocz(sizeof(*conf
));
1666 conf
->cmdline
= cmdline
;
1667 QTAILQ_INSERT_TAIL(&device_configs
, conf
, next
);
1670 static int foreach_device_config(int type
, int (*func
)(const char *cmdline
))
1672 struct device_config
*conf
;
1675 QTAILQ_FOREACH(conf
, &device_configs
, next
) {
1676 if (conf
->type
!= type
)
1678 rc
= func(conf
->cmdline
);
1685 static int serial_parse(const char *devname
)
1687 static int index
= 0;
1690 if (strcmp(devname
, "none") == 0)
1692 if (index
== MAX_SERIAL_PORTS
) {
1693 fprintf(stderr
, "qemu: too many serial ports\n");
1696 snprintf(label
, sizeof(label
), "serial%d", index
);
1697 serial_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1698 if (!serial_hds
[index
]) {
1699 fprintf(stderr
, "qemu: could not open serial device '%s': %s\n",
1700 devname
, strerror(errno
));
1707 static int parallel_parse(const char *devname
)
1709 static int index
= 0;
1712 if (strcmp(devname
, "none") == 0)
1714 if (index
== MAX_PARALLEL_PORTS
) {
1715 fprintf(stderr
, "qemu: too many parallel ports\n");
1718 snprintf(label
, sizeof(label
), "parallel%d", index
);
1719 parallel_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1720 if (!parallel_hds
[index
]) {
1721 fprintf(stderr
, "qemu: could not open parallel device '%s': %s\n",
1722 devname
, strerror(errno
));
1729 static int virtcon_parse(const char *devname
)
1731 QemuOptsList
*device
= qemu_find_opts("device");
1732 static int index
= 0;
1734 QemuOpts
*bus_opts
, *dev_opts
;
1736 if (strcmp(devname
, "none") == 0)
1738 if (index
== MAX_VIRTIO_CONSOLES
) {
1739 fprintf(stderr
, "qemu: too many virtio consoles\n");
1743 bus_opts
= qemu_opts_create(device
, NULL
, 0);
1744 qemu_opt_set(bus_opts
, "driver", "virtio-serial");
1746 dev_opts
= qemu_opts_create(device
, NULL
, 0);
1747 qemu_opt_set(dev_opts
, "driver", "virtconsole");
1749 snprintf(label
, sizeof(label
), "virtcon%d", index
);
1750 virtcon_hds
[index
] = qemu_chr_open(label
, devname
, NULL
);
1751 if (!virtcon_hds
[index
]) {
1752 fprintf(stderr
, "qemu: could not open virtio console '%s': %s\n",
1753 devname
, strerror(errno
));
1756 qemu_opt_set(dev_opts
, "chardev", label
);
1762 static int debugcon_parse(const char *devname
)
1766 if (!qemu_chr_open("debugcon", devname
, NULL
)) {
1769 opts
= qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1771 fprintf(stderr
, "qemu: already have a debugcon device\n");
1774 qemu_opt_set(opts
, "driver", "isa-debugcon");
1775 qemu_opt_set(opts
, "chardev", "debugcon");
1779 void qemu_add_exit_notifier(Notifier
*notify
)
1781 notifier_list_add(&exit_notifiers
, notify
);
1784 void qemu_remove_exit_notifier(Notifier
*notify
)
1786 notifier_list_remove(&exit_notifiers
, notify
);
1789 static void qemu_run_exit_notifiers(void)
1791 notifier_list_notify(&exit_notifiers
);
1794 static const QEMUOption
*lookup_opt(int argc
, char **argv
,
1795 const char **poptarg
, int *poptind
)
1797 const QEMUOption
*popt
;
1798 int optind
= *poptind
;
1799 char *r
= argv
[optind
];
1802 loc_set_cmdline(argv
, optind
, 1);
1804 /* Treat --foo the same as -foo. */
1807 popt
= qemu_options
;
1810 error_report("invalid option");
1813 if (!strcmp(popt
->name
, r
+ 1))
1817 if (popt
->flags
& HAS_ARG
) {
1818 if (optind
>= argc
) {
1819 error_report("requires an argument");
1822 optarg
= argv
[optind
++];
1823 loc_set_cmdline(argv
, optind
- 2, 2);
1834 int main(int argc
, char **argv
, char **envp
)
1836 const char *gdbstub_dev
= NULL
;
1838 int snapshot
, linux_boot
;
1839 const char *icount_option
= NULL
;
1840 const char *initrd_filename
;
1841 const char *kernel_filename
, *kernel_cmdline
;
1842 char boot_devices
[33] = "cad"; /* default to HD->floppy->CD-ROM */
1844 DisplayChangeListener
*dcl
;
1845 int cyls
, heads
, secs
, translation
;
1846 QemuOpts
*hda_opts
= NULL
, *opts
;
1847 QemuOptsList
*olist
;
1850 const char *loadvm
= NULL
;
1851 QEMUMachine
*machine
;
1852 const char *cpu_model
;
1854 const char *pid_file
= NULL
;
1855 const char *incoming
= NULL
;
1856 int show_vnc_port
= 0;
1859 #ifdef CONFIG_SIMPLE_TRACE
1860 const char *trace_file
= NULL
;
1862 atexit(qemu_run_exit_notifiers
);
1863 error_set_progname(argv
[0]);
1867 qemu_cache_utils_init(envp
);
1869 QLIST_INIT (&vm_change_state_head
);
1870 os_setup_early_signal_handling();
1872 module_call_init(MODULE_INIT_MACHINE
);
1873 machine
= find_default_machine();
1875 initrd_filename
= NULL
;
1878 kernel_filename
= NULL
;
1879 kernel_cmdline
= "";
1880 cyls
= heads
= secs
= 0;
1881 translation
= BIOS_ATA_TRANSLATION_AUTO
;
1883 for (i
= 0; i
< MAX_NODES
; i
++) {
1885 node_cpumask
[i
] = 0;
1888 assigned_devices_index
= 0;
1896 /* first pass of option parsing */
1898 while (optind
< argc
) {
1899 if (argv
[optind
][0] != '-') {
1904 const QEMUOption
*popt
;
1906 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1907 switch (popt
->index
) {
1908 case QEMU_OPTION_nodefconfig
:
1918 ret
= qemu_read_config_file(CONFIG_QEMU_CONFDIR
"/qemu.conf");
1919 if (ret
< 0 && ret
!= -ENOENT
) {
1923 ret
= qemu_read_config_file(arch_config_name
);
1924 if (ret
< 0 && ret
!= -ENOENT
) {
1930 /* second pass of option parsing */
1935 if (argv
[optind
][0] != '-') {
1936 hda_opts
= drive_add(argv
[optind
++], HD_ALIAS
, 0);
1938 const QEMUOption
*popt
;
1940 popt
= lookup_opt(argc
, argv
, &optarg
, &optind
);
1941 if (!(popt
->arch_mask
& arch_type
)) {
1942 printf("Option %s not supported for this target\n", popt
->name
);
1945 switch(popt
->index
) {
1947 machine
= find_machine(optarg
);
1950 printf("Supported machines are:\n");
1951 for(m
= first_machine
; m
!= NULL
; m
= m
->next
) {
1953 printf("%-10s %s (alias of %s)\n",
1954 m
->alias
, m
->desc
, m
->name
);
1955 printf("%-10s %s%s\n",
1957 m
->is_default
? " (default)" : "");
1959 exit(*optarg
!= '?');
1962 case QEMU_OPTION_cpu
:
1963 /* hw initialization will check this */
1964 if (*optarg
== '?') {
1965 list_cpus(stdout
, &fprintf
, optarg
);
1971 case QEMU_OPTION_initrd
:
1972 initrd_filename
= optarg
;
1974 case QEMU_OPTION_hda
:
1976 hda_opts
= drive_add(optarg
, HD_ALIAS
, 0);
1978 hda_opts
= drive_add(optarg
, HD_ALIAS
1979 ",cyls=%d,heads=%d,secs=%d%s",
1980 0, cyls
, heads
, secs
,
1981 translation
== BIOS_ATA_TRANSLATION_LBA
?
1983 translation
== BIOS_ATA_TRANSLATION_NONE
?
1984 ",trans=none" : "");
1986 case QEMU_OPTION_hdb
:
1987 case QEMU_OPTION_hdc
:
1988 case QEMU_OPTION_hdd
:
1989 drive_add(optarg
, HD_ALIAS
, popt
->index
- QEMU_OPTION_hda
);
1991 case QEMU_OPTION_drive
:
1992 drive_add(NULL
, "%s", optarg
);
1994 case QEMU_OPTION_set
:
1995 if (qemu_set_option(optarg
) != 0)
1998 case QEMU_OPTION_global
:
1999 if (qemu_global_option(optarg
) != 0)
2002 case QEMU_OPTION_mtdblock
:
2003 drive_add(optarg
, MTD_ALIAS
);
2005 case QEMU_OPTION_sd
:
2006 drive_add(optarg
, SD_ALIAS
);
2008 case QEMU_OPTION_pflash
:
2009 drive_add(optarg
, PFLASH_ALIAS
);
2011 case QEMU_OPTION_snapshot
:
2014 case QEMU_OPTION_hdachs
:
2018 cyls
= strtol(p
, (char **)&p
, 0);
2019 if (cyls
< 1 || cyls
> 16383)
2024 heads
= strtol(p
, (char **)&p
, 0);
2025 if (heads
< 1 || heads
> 16)
2030 secs
= strtol(p
, (char **)&p
, 0);
2031 if (secs
< 1 || secs
> 63)
2035 if (!strcmp(p
, "none"))
2036 translation
= BIOS_ATA_TRANSLATION_NONE
;
2037 else if (!strcmp(p
, "lba"))
2038 translation
= BIOS_ATA_TRANSLATION_LBA
;
2039 else if (!strcmp(p
, "auto"))
2040 translation
= BIOS_ATA_TRANSLATION_AUTO
;
2043 } else if (*p
!= '\0') {
2045 fprintf(stderr
, "qemu: invalid physical CHS format\n");
2048 if (hda_opts
!= NULL
) {
2050 snprintf(num
, sizeof(num
), "%d", cyls
);
2051 qemu_opt_set(hda_opts
, "cyls", num
);
2052 snprintf(num
, sizeof(num
), "%d", heads
);
2053 qemu_opt_set(hda_opts
, "heads", num
);
2054 snprintf(num
, sizeof(num
), "%d", secs
);
2055 qemu_opt_set(hda_opts
, "secs", num
);
2056 if (translation
== BIOS_ATA_TRANSLATION_LBA
)
2057 qemu_opt_set(hda_opts
, "trans", "lba");
2058 if (translation
== BIOS_ATA_TRANSLATION_NONE
)
2059 qemu_opt_set(hda_opts
, "trans", "none");
2063 case QEMU_OPTION_numa
:
2064 if (nb_numa_nodes
>= MAX_NODES
) {
2065 fprintf(stderr
, "qemu: too many NUMA nodes\n");
2070 case QEMU_OPTION_nographic
:
2071 display_type
= DT_NOGRAPHIC
;
2073 #ifdef CONFIG_CURSES
2074 case QEMU_OPTION_curses
:
2075 display_type
= DT_CURSES
;
2078 case QEMU_OPTION_portrait
:
2081 case QEMU_OPTION_kernel
:
2082 kernel_filename
= optarg
;
2084 case QEMU_OPTION_append
:
2085 kernel_cmdline
= optarg
;
2087 case QEMU_OPTION_cdrom
:
2088 drive_add(optarg
, CDROM_ALIAS
);
2090 case QEMU_OPTION_boot
:
2092 static const char * const params
[] = {
2093 "order", "once", "menu", NULL
2095 char buf
[sizeof(boot_devices
)];
2096 char *standard_boot_devices
;
2099 if (!strchr(optarg
, '=')) {
2101 pstrcpy(buf
, sizeof(buf
), optarg
);
2102 } else if (check_params(buf
, sizeof(buf
), params
, optarg
) < 0) {
2104 "qemu: unknown boot parameter '%s' in '%s'\n",
2110 get_param_value(buf
, sizeof(buf
), "order", optarg
)) {
2111 validate_bootdevices(buf
);
2112 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2115 if (get_param_value(buf
, sizeof(buf
),
2117 validate_bootdevices(buf
);
2118 standard_boot_devices
= qemu_strdup(boot_devices
);
2119 pstrcpy(boot_devices
, sizeof(boot_devices
), buf
);
2120 qemu_register_reset(restore_boot_devices
,
2121 standard_boot_devices
);
2123 if (get_param_value(buf
, sizeof(buf
),
2125 if (!strcmp(buf
, "on")) {
2127 } else if (!strcmp(buf
, "off")) {
2131 "qemu: invalid option value '%s'\n",
2139 case QEMU_OPTION_fda
:
2140 case QEMU_OPTION_fdb
:
2141 drive_add(optarg
, FD_ALIAS
, popt
->index
- QEMU_OPTION_fda
);
2143 case QEMU_OPTION_no_fd_bootchk
:
2146 case QEMU_OPTION_netdev
:
2147 if (net_client_parse(qemu_find_opts("netdev"), optarg
) == -1) {
2151 case QEMU_OPTION_net
:
2152 if (net_client_parse(qemu_find_opts("net"), optarg
) == -1) {
2157 case QEMU_OPTION_tftp
:
2158 legacy_tftp_prefix
= optarg
;
2160 case QEMU_OPTION_bootp
:
2161 legacy_bootp_filename
= optarg
;
2163 case QEMU_OPTION_redir
:
2164 if (net_slirp_redir(optarg
) < 0)
2168 case QEMU_OPTION_bt
:
2169 add_device_config(DEV_BT
, optarg
);
2171 case QEMU_OPTION_audio_help
:
2172 if (!(audio_available())) {
2173 printf("Option %s not supported for this target\n", popt
->name
);
2179 case QEMU_OPTION_soundhw
:
2180 if (!(audio_available())) {
2181 printf("Option %s not supported for this target\n", popt
->name
);
2184 select_soundhw (optarg
);
2189 case QEMU_OPTION_version
:
2193 case QEMU_OPTION_m
: {
2197 value
= strtoul(optarg
, &ptr
, 10);
2199 case 0: case 'M': case 'm':
2206 fprintf(stderr
, "qemu: invalid ram size: %s\n", optarg
);
2210 /* On 32-bit hosts, QEMU is limited by virtual address space */
2211 if (value
> (2047 << 20) && HOST_LONG_BITS
== 32) {
2212 fprintf(stderr
, "qemu: at most 2047 MB RAM can be simulated\n");
2215 if (value
!= (uint64_t)(ram_addr_t
)value
) {
2216 fprintf(stderr
, "qemu: ram size too large\n");
2222 case QEMU_OPTION_mempath
:
2226 case QEMU_OPTION_mem_prealloc
:
2231 set_cpu_log(optarg
);
2234 gdbstub_dev
= "tcp::" DEFAULT_GDBSTUB_PORT
;
2236 case QEMU_OPTION_gdb
:
2237 gdbstub_dev
= optarg
;
2242 case QEMU_OPTION_bios
:
2245 case QEMU_OPTION_singlestep
:
2252 keyboard_layout
= optarg
;
2254 case QEMU_OPTION_localtime
:
2257 case QEMU_OPTION_vga
:
2258 select_vgahw (optarg
);
2265 w
= strtol(p
, (char **)&p
, 10);
2268 fprintf(stderr
, "qemu: invalid resolution or depth\n");
2274 h
= strtol(p
, (char **)&p
, 10);
2279 depth
= strtol(p
, (char **)&p
, 10);
2280 if (depth
!= 8 && depth
!= 15 && depth
!= 16 &&
2281 depth
!= 24 && depth
!= 32)
2283 } else if (*p
== '\0') {
2284 depth
= graphic_depth
;
2291 graphic_depth
= depth
;
2294 case QEMU_OPTION_echr
:
2297 term_escape_char
= strtol(optarg
, &r
, 0);
2299 printf("Bad argument to echr\n");
2302 case QEMU_OPTION_monitor
:
2303 monitor_parse(optarg
, "readline");
2304 default_monitor
= 0;
2306 case QEMU_OPTION_qmp
:
2307 monitor_parse(optarg
, "control");
2308 default_monitor
= 0;
2310 case QEMU_OPTION_mon
:
2311 opts
= qemu_opts_parse(qemu_find_opts("mon"), optarg
, 1);
2315 default_monitor
= 0;
2317 case QEMU_OPTION_chardev
:
2318 opts
= qemu_opts_parse(qemu_find_opts("chardev"), optarg
, 1);
2323 case QEMU_OPTION_fsdev
:
2324 olist
= qemu_find_opts("fsdev");
2326 fprintf(stderr
, "fsdev is not supported by this qemu build.\n");
2329 opts
= qemu_opts_parse(olist
, optarg
, 1);
2331 fprintf(stderr
, "parse error: %s\n", optarg
);
2335 case QEMU_OPTION_virtfs
: {
2336 char *arg_fsdev
= NULL
;
2337 char *arg_9p
= NULL
;
2340 olist
= qemu_find_opts("virtfs");
2342 fprintf(stderr
, "virtfs is not supported by this qemu build.\n");
2345 opts
= qemu_opts_parse(olist
, optarg
, 1);
2347 fprintf(stderr
, "parse error: %s\n", optarg
);
2351 if (qemu_opt_get(opts
, "fstype") == NULL
||
2352 qemu_opt_get(opts
, "mount_tag") == NULL
||
2353 qemu_opt_get(opts
, "path") == NULL
||
2354 qemu_opt_get(opts
, "security_model") == NULL
) {
2355 fprintf(stderr
, "Usage: -virtfs fstype,path=/share_path/,"
2356 "security_model=[mapped|passthrough|none],"
2361 len
= strlen(",id=,path=,security_model=");
2362 len
+= strlen(qemu_opt_get(opts
, "fstype"));
2363 len
+= strlen(qemu_opt_get(opts
, "mount_tag"));
2364 len
+= strlen(qemu_opt_get(opts
, "path"));
2365 len
+= strlen(qemu_opt_get(opts
, "security_model"));
2366 arg_fsdev
= qemu_malloc((len
+ 1) * sizeof(*arg_fsdev
));
2368 snprintf(arg_fsdev
, (len
+ 1) * sizeof(*arg_fsdev
),
2369 "%s,id=%s,path=%s,security_model=%s",
2370 qemu_opt_get(opts
, "fstype"),
2371 qemu_opt_get(opts
, "mount_tag"),
2372 qemu_opt_get(opts
, "path"),
2373 qemu_opt_get(opts
, "security_model"));
2375 len
= strlen("virtio-9p-pci,fsdev=,mount_tag=");
2376 len
+= 2*strlen(qemu_opt_get(opts
, "mount_tag"));
2377 arg_9p
= qemu_malloc((len
+ 1) * sizeof(*arg_9p
));
2379 snprintf(arg_9p
, (len
+ 1) * sizeof(*arg_9p
),
2380 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2381 qemu_opt_get(opts
, "mount_tag"),
2382 qemu_opt_get(opts
, "mount_tag"));
2384 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev
, 1)) {
2385 fprintf(stderr
, "parse error [fsdev]: %s\n", optarg
);
2389 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p
, 1)) {
2390 fprintf(stderr
, "parse error [device]: %s\n", optarg
);
2394 qemu_free(arg_fsdev
);
2398 case QEMU_OPTION_serial
:
2399 add_device_config(DEV_SERIAL
, optarg
);
2401 if (strncmp(optarg
, "mon:", 4) == 0) {
2402 default_monitor
= 0;
2405 case QEMU_OPTION_watchdog
:
2408 "qemu: only one watchdog option may be given\n");
2413 case QEMU_OPTION_watchdog_action
:
2414 if (select_watchdog_action(optarg
) == -1) {
2415 fprintf(stderr
, "Unknown -watchdog-action parameter\n");
2419 case QEMU_OPTION_virtiocon
:
2420 add_device_config(DEV_VIRTCON
, optarg
);
2421 default_virtcon
= 0;
2422 if (strncmp(optarg
, "mon:", 4) == 0) {
2423 default_monitor
= 0;
2426 case QEMU_OPTION_parallel
:
2427 add_device_config(DEV_PARALLEL
, optarg
);
2428 default_parallel
= 0;
2429 if (strncmp(optarg
, "mon:", 4) == 0) {
2430 default_monitor
= 0;
2433 case QEMU_OPTION_debugcon
:
2434 add_device_config(DEV_DEBUGCON
, optarg
);
2436 case QEMU_OPTION_loadvm
:
2439 case QEMU_OPTION_full_screen
:
2443 case QEMU_OPTION_no_frame
:
2446 case QEMU_OPTION_alt_grab
:
2449 case QEMU_OPTION_ctrl_grab
:
2452 case QEMU_OPTION_no_quit
:
2455 case QEMU_OPTION_sdl
:
2456 display_type
= DT_SDL
;
2459 case QEMU_OPTION_pidfile
:
2462 case QEMU_OPTION_win2k_hack
:
2463 win2k_install_hack
= 1;
2465 case QEMU_OPTION_rtc_td_hack
:
2468 case QEMU_OPTION_acpitable
:
2469 do_acpitable_option(optarg
);
2471 case QEMU_OPTION_smbios
:
2472 do_smbios_option(optarg
);
2474 #ifdef OBSOLETE_KVM_IMPL
2475 case QEMU_OPTION_enable_kvm
:
2479 case QEMU_OPTION_no_kvm
:
2481 #ifdef CONFIG_NO_CPU_EMULATION
2482 fprintf(stderr
, "cpu emulation not configured\n");
2487 case QEMU_OPTION_no_kvm_irqchip
: {
2492 case QEMU_OPTION_no_kvm_pit
: {
2496 case QEMU_OPTION_no_kvm_pit_reinjection
: {
2497 kvm_pit_reinject
= 0;
2500 case QEMU_OPTION_enable_nesting
: {
2505 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
2506 case QEMU_OPTION_pcidevice
:
2507 if (assigned_devices_index
>= MAX_DEV_ASSIGN_CMDLINE
) {
2508 fprintf(stderr
, "Too many assigned devices\n");
2511 assigned_devices
[assigned_devices_index
] = optarg
;
2512 assigned_devices_index
++;
2515 case QEMU_OPTION_usb
:
2518 case QEMU_OPTION_usbdevice
:
2520 add_device_config(DEV_USB
, optarg
);
2522 case QEMU_OPTION_device
:
2523 if (!qemu_opts_parse(qemu_find_opts("device"), optarg
, 1)) {
2527 case QEMU_OPTION_smp
:
2530 fprintf(stderr
, "Invalid number of CPUs\n");
2533 if (max_cpus
< smp_cpus
) {
2534 fprintf(stderr
, "maxcpus must be equal to or greater than "
2538 if (max_cpus
> 255) {
2539 fprintf(stderr
, "Unsupported number of maxcpus\n");
2543 case QEMU_OPTION_vnc
:
2545 vnc_display
= optarg
;
2547 case QEMU_OPTION_no_acpi
:
2550 case QEMU_OPTION_no_hpet
:
2553 case QEMU_OPTION_balloon
:
2554 if (balloon_parse(optarg
) < 0) {
2555 fprintf(stderr
, "Unknown -balloon argument %s\n", optarg
);
2559 case QEMU_OPTION_no_reboot
:
2562 case QEMU_OPTION_no_shutdown
:
2565 case QEMU_OPTION_show_cursor
:
2568 case QEMU_OPTION_uuid
:
2569 if(qemu_uuid_parse(optarg
, qemu_uuid
) < 0) {
2570 fprintf(stderr
, "Fail to parse UUID string."
2571 " Wrong format.\n");
2575 case QEMU_OPTION_option_rom
:
2576 if (nb_option_roms
>= MAX_OPTION_ROMS
) {
2577 fprintf(stderr
, "Too many option ROMs\n");
2580 option_rom
[nb_option_roms
] = optarg
;
2583 case QEMU_OPTION_semihosting
:
2584 semihosting_enabled
= 1;
2586 case QEMU_OPTION_tdf
:
2589 case QEMU_OPTION_kvm_shadow_memory
:
2590 kvm_shadow_memory
= (int64_t)atoi(optarg
) * 1024 * 1024 / 4096;
2592 case QEMU_OPTION_name
:
2593 qemu_name
= qemu_strdup(optarg
);
2595 char *p
= strchr(qemu_name
, ',');
2598 if (strncmp(p
, "process=", 8)) {
2599 fprintf(stderr
, "Unknown subargument %s to -name", p
);
2603 os_set_proc_name(p
);
2607 case QEMU_OPTION_prom_env
:
2608 if (nb_prom_envs
>= MAX_PROM_ENVS
) {
2609 fprintf(stderr
, "Too many prom variables\n");
2612 prom_envs
[nb_prom_envs
] = optarg
;
2615 case QEMU_OPTION_old_param
:
2618 case QEMU_OPTION_clock
:
2619 configure_alarms(optarg
);
2621 case QEMU_OPTION_startdate
:
2622 configure_rtc_date_offset(optarg
, 1);
2624 case QEMU_OPTION_rtc
:
2625 opts
= qemu_opts_parse(qemu_find_opts("rtc"), optarg
, 0);
2629 configure_rtc(opts
);
2631 case QEMU_OPTION_tb_size
:
2632 tb_size
= strtol(optarg
, NULL
, 0);
2636 case QEMU_OPTION_icount
:
2637 icount_option
= optarg
;
2639 case QEMU_OPTION_incoming
:
2641 incoming_expected
= true;
2643 case QEMU_OPTION_nodefaults
:
2645 default_parallel
= 0;
2646 default_virtcon
= 0;
2647 default_monitor
= 0;
2655 case QEMU_OPTION_nvram
:
2659 case QEMU_OPTION_xen_domid
:
2660 if (!(xen_available())) {
2661 printf("Option %s not supported for this target\n", popt
->name
);
2664 xen_domid
= atoi(optarg
);
2666 case QEMU_OPTION_xen_create
:
2667 if (!(xen_available())) {
2668 printf("Option %s not supported for this target\n", popt
->name
);
2671 xen_mode
= XEN_CREATE
;
2673 case QEMU_OPTION_xen_attach
:
2674 if (!(xen_available())) {
2675 printf("Option %s not supported for this target\n", popt
->name
);
2678 xen_mode
= XEN_ATTACH
;
2680 #ifdef CONFIG_SIMPLE_TRACE
2681 case QEMU_OPTION_trace
:
2682 opts
= qemu_opts_parse(qemu_find_opts("trace"), optarg
, 0);
2684 trace_file
= qemu_opt_get(opts
, "file");
2688 case QEMU_OPTION_readconfig
:
2690 int ret
= qemu_read_config_file(optarg
);
2692 fprintf(stderr
, "read config %s: %s\n", optarg
,
2698 case QEMU_OPTION_spice
:
2699 olist
= qemu_find_opts("spice");
2701 fprintf(stderr
, "spice is not supported by this qemu build.\n");
2704 opts
= qemu_opts_parse(olist
, optarg
, 0);
2706 fprintf(stderr
, "parse error: %s\n", optarg
);
2710 case QEMU_OPTION_writeconfig
:
2713 if (strcmp(optarg
, "-") == 0) {
2716 fp
= fopen(optarg
, "w");
2718 fprintf(stderr
, "open %s: %s\n", optarg
, strerror(errno
));
2722 qemu_config_write(fp
);
2727 os_parse_cmd_args(popt
->index
, optarg
);
2733 /* If no data_dir is specified then try to find it relative to the
2736 data_dir
= os_find_datadir(argv
[0]);
2738 /* If all else fails use the install patch specified when building. */
2740 data_dir
= CONFIG_QEMU_DATADIR
;
2743 #ifdef CONFIG_SIMPLE_TRACE
2745 * Set the trace file name, if specified.
2747 st_set_trace_file(trace_file
);
2750 * Default to max_cpus = smp_cpus, in case the user doesn't
2751 * specify a max_cpus value.
2754 max_cpus
= smp_cpus
;
2756 machine
->max_cpus
= machine
->max_cpus
?: 1; /* Default to UP */
2757 if (smp_cpus
> machine
->max_cpus
) {
2758 fprintf(stderr
, "Number of SMP cpus requested (%d), exceeds max cpus "
2759 "supported by machine `%s' (%d)\n", smp_cpus
, machine
->name
,
2764 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check
, NULL
, 0);
2765 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check
, NULL
, 0);
2767 if (machine
->no_serial
) {
2770 if (machine
->no_parallel
) {
2771 default_parallel
= 0;
2773 if (!machine
->use_virtcon
) {
2774 default_virtcon
= 0;
2776 if (machine
->no_vga
) {
2779 if (machine
->no_floppy
) {
2782 if (machine
->no_cdrom
) {
2785 if (machine
->no_sdcard
) {
2789 if (display_type
== DT_NOGRAPHIC
) {
2790 if (default_parallel
)
2791 add_device_config(DEV_PARALLEL
, "null");
2792 if (default_serial
&& default_monitor
) {
2793 add_device_config(DEV_SERIAL
, "mon:stdio");
2794 } else if (default_virtcon
&& default_monitor
) {
2795 add_device_config(DEV_VIRTCON
, "mon:stdio");
2798 add_device_config(DEV_SERIAL
, "stdio");
2799 if (default_virtcon
)
2800 add_device_config(DEV_VIRTCON
, "stdio");
2801 if (default_monitor
)
2802 monitor_parse("stdio", "readline");
2806 add_device_config(DEV_SERIAL
, "vc:80Cx24C");
2807 if (default_parallel
)
2808 add_device_config(DEV_PARALLEL
, "vc:80Cx24C");
2809 if (default_monitor
)
2810 monitor_parse("vc:80Cx24C", "readline");
2811 if (default_virtcon
)
2812 add_device_config(DEV_VIRTCON
, "vc:80Cx24C");
2815 vga_interface_type
= VGA_CIRRUS
;
2819 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func
, NULL
, 1) != 0)
2821 #ifdef CONFIG_VIRTFS
2822 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func
, NULL
, 1) != 0) {
2829 if (pid_file
&& qemu_create_pidfile(pid_file
) != 0) {
2835 int ret
= kvm_init(smp_cpus
);
2837 #if defined(OBSOLETE_KVM_IMPL) || defined(CONFIG_NO_CPU_EMULATION)
2838 if (!kvm_available()) {
2839 printf("KVM not supported for this target\n");
2841 fprintf(stderr
, "failed to initialize KVM: %s\n", strerror(-ret
));
2846 fprintf(stderr
, "Could not initialize KVM, will disable KVM support\n");
2852 if (qemu_init_main_loop()) {
2853 fprintf(stderr
, "qemu_init_main_loop failed\n");
2856 linux_boot
= (kernel_filename
!= NULL
);
2858 if (!linux_boot
&& *kernel_cmdline
!= '\0') {
2859 fprintf(stderr
, "-append only allowed with -kernel option\n");
2863 if (!linux_boot
&& initrd_filename
!= NULL
) {
2864 fprintf(stderr
, "-initrd only allowed with -kernel option\n");
2868 os_set_line_buffering();
2870 if (init_timer_alarm() < 0) {
2871 fprintf(stderr
, "could not initialize alarm timer\n");
2874 configure_icount(icount_option
);
2876 if (net_init_clients() < 0) {
2880 /* init the bluetooth world */
2881 if (foreach_device_config(DEV_BT
, bt_parse
))
2884 /* init the memory */
2886 ram_size
= DEFAULT_RAM_SIZE
* 1024 * 1024;
2888 /* init the dynamic translator */
2889 cpu_exec_init_all(tb_size
* 1024 * 1024);
2891 bdrv_init_with_whitelist();
2895 if (default_cdrom
) {
2896 /* we always create the cdrom drive, even if no disk is there */
2897 drive_add(NULL
, CDROM_ALIAS
);
2900 if (default_floppy
) {
2901 /* we always create at least one floppy */
2902 drive_add(NULL
, FD_ALIAS
, 0);
2905 if (default_sdcard
) {
2906 /* we always create one sd slot, even if no card is in it */
2907 drive_add(NULL
, SD_ALIAS
);
2910 /* open the virtual block devices */
2912 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot
, NULL
, 0);
2913 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func
, &machine
->use_scsi
, 1) != 0)
2916 register_savevm_live(NULL
, "ram", 0, 4, NULL
, ram_save_live
, NULL
,
2919 if (nb_numa_nodes
> 0) {
2922 if (nb_numa_nodes
> smp_cpus
) {
2923 nb_numa_nodes
= smp_cpus
;
2926 /* If no memory size if given for any node, assume the default case
2927 * and distribute the available memory equally across all nodes
2929 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2930 if (node_mem
[i
] != 0)
2933 if (i
== nb_numa_nodes
) {
2934 uint64_t usedmem
= 0;
2936 /* On Linux, the each node's border has to be 8MB aligned,
2937 * the final node gets the rest.
2939 for (i
= 0; i
< nb_numa_nodes
- 1; i
++) {
2940 node_mem
[i
] = (ram_size
/ nb_numa_nodes
) & ~((1 << 23UL) - 1);
2941 usedmem
+= node_mem
[i
];
2943 node_mem
[i
] = ram_size
- usedmem
;
2946 for (i
= 0; i
< nb_numa_nodes
; i
++) {
2947 if (node_cpumask
[i
] != 0)
2950 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2951 * must cope with this anyway, because there are BIOSes out there in
2952 * real machines which also use this scheme.
2954 if (i
== nb_numa_nodes
) {
2955 for (i
= 0; i
< smp_cpus
; i
++) {
2956 node_cpumask
[i
% nb_numa_nodes
] |= 1 << i
;
2961 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func
, NULL
, 1) != 0) {
2965 if (foreach_device_config(DEV_SERIAL
, serial_parse
) < 0)
2967 if (foreach_device_config(DEV_PARALLEL
, parallel_parse
) < 0)
2969 if (foreach_device_config(DEV_VIRTCON
, virtcon_parse
) < 0)
2971 if (foreach_device_config(DEV_DEBUGCON
, debugcon_parse
) < 0)
2974 module_call_init(MODULE_INIT_DEVICE
);
2976 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func
, NULL
, 0) != 0)
2980 i
= select_watchdog(watchdog
);
2982 exit (i
== 1 ? 1 : 0);
2985 if (machine
->compat_props
) {
2986 qdev_prop_register_global_list(machine
->compat_props
);
2990 machine
->init(ram_size
, boot_devices
,
2991 kernel_filename
, kernel_cmdline
, initrd_filename
, cpu_model
);
2993 cpu_synchronize_all_post_init();
2995 /* must be after terminal init, SDL library changes signal handlers */
2996 os_setup_signal_handling();
3000 current_machine
= machine
;
3002 /* init USB devices */
3004 if (foreach_device_config(DEV_USB
, usb_parse
) < 0)
3008 /* init generic devices */
3009 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func
, NULL
, 1) != 0)
3012 net_check_clients();
3014 /* just use the first displaystate for the moment */
3015 ds
= get_displaystate();
3019 if (display_type
== DT_DEFAULT
&& !display_remote
) {
3020 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3021 display_type
= DT_SDL
;
3023 vnc_display
= "localhost:0,to=99";
3029 /* init local displays */
3030 switch (display_type
) {
3033 #if defined(CONFIG_CURSES)
3035 curses_display_init(ds
, full_screen
);
3038 #if defined(CONFIG_SDL)
3040 sdl_display_init(ds
, full_screen
, no_frame
);
3042 #elif defined(CONFIG_COCOA)
3044 cocoa_display_init(ds
, full_screen
);
3051 /* init remote displays */
3053 vnc_display_init(ds
);
3054 if (vnc_display_open(ds
, vnc_display
) < 0)
3057 if (show_vnc_port
) {
3058 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds
));
3063 qemu_spice_display_init(ds
);
3069 dcl
= ds
->listeners
;
3070 while (dcl
!= NULL
) {
3071 if (dcl
->dpy_refresh
!= NULL
) {
3072 ds
->gui_timer
= qemu_new_timer(rt_clock
, gui_update
, ds
);
3073 qemu_mod_timer(ds
->gui_timer
, qemu_get_clock(rt_clock
));
3078 if (ds
->gui_timer
== NULL
) {
3079 nographic_timer
= qemu_new_timer(rt_clock
, nographic_update
, NULL
);
3080 qemu_mod_timer(nographic_timer
, qemu_get_clock(rt_clock
));
3082 text_consoles_set_display(ds
);
3084 if (gdbstub_dev
&& gdbserver_start(gdbstub_dev
) < 0) {
3085 fprintf(stderr
, "qemu: could not open gdbserver on device '%s'\n",
3090 qdev_machine_creation_done();
3092 if (rom_load_all() != 0) {
3093 fprintf(stderr
, "rom loading failed\n");
3097 qemu_system_reset();
3099 if (load_vmstate(loadvm
) < 0) {
3105 int ret
= qemu_start_incoming_migration(incoming
);
3107 fprintf(stderr
, "Migration failed. Exit code %s(%d), exiting.\n",
3111 } else if (autostart
) {