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>
53
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
55
#include <sys/sysctl.h>
64
#include <linux/ppdev.h>
65
#include <linux/parport.h>
69
#include <sys/ethernet.h>
70
#include <sys/sockio.h>
71
#include <netinet/arp.h>
72
#include <netinet/in_systm.h>
73
#include <netinet/ip.h>
74
#include <netinet/ip_icmp.h> // must come after ip.h
75
#include <netinet/udp.h>
76
#include <netinet/tcp.h>
84
#if defined(__OpenBSD__)
88
#if defined(CONFIG_VDE)
89
#include <libvdeplug.h>
97
#if defined(__APPLE__) || defined(main)
99
int qemu_main(int argc, char **argv, char **envp);
100
int main(int argc, char **argv)
102
return qemu_main(argc, argv, NULL);
105
#define main qemu_main
107
#endif /* CONFIG_SDL */
111
#define main qemu_main
112
#endif /* CONFIG_COCOA */
115
#include "hw/boards.h"
117
#include "hw/pcmcia.h"
122
#include "hw/watchdog.h"
123
#include "hw/smbios.h"
126
#include "hw/loader.h"
129
#include "net/slirp.h"
134
#include "qemu-timer.h"
135
#include "qemu-char.h"
136
#include "cache-utils.h"
138
#include "blockdev.h"
139
#include "block-migration.h"
141
#include "audio/audio.h"
142
#include "migration.h"
144
#include "qemu-option.h"
145
#include "qemu-config.h"
146
#include "qemu-objects.h"
147
#include "qemu-options.h"
150
#include "fsdev/qemu-fsdev.h"
155
#include "qemu_socket.h"
157
#include "slirp/libslirp.h"
160
#include "simpletrace.h"
161
#include "qemu-queue.h"
163
#include "arch_init.h"
165
#include "ui/qemu-spice.h"
168
//#define DEBUG_SLIRP
170
#define DEFAULT_RAM_SIZE 128
172
#define MAX_VIRTIO_CONSOLES 1
174
static const char *data_dir;
175
const char *bios_name = NULL;
176
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
177
DisplayType display_type = DT_DEFAULT;
178
int display_remote = 0;
179
const char* keyboard_layout = NULL;
181
const char *mem_path = NULL;
183
int mem_prealloc = 0; /* force preallocation of physical target memory */
186
NICInfo nd_table[MAX_NICS];
189
int incoming_expected; /* Started with -incoming and waiting for incoming */
190
static int rtc_utc = 1;
191
static int rtc_date_offset = -1; /* -1 means no change */
192
QEMUClock *rtc_clock;
193
int vga_interface_type = VGA_NONE;
194
static int full_screen = 0;
196
static int no_frame = 0;
199
CharDriverState *serial_hds[MAX_SERIAL_PORTS];
200
CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
201
CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
202
int win2k_install_hack = 0;
211
const char *vnc_display;
213
int acpi_enabled = 1;
219
int graphic_rotate = 0;
220
const char *watchdog;
221
QEMUOptionRom option_rom[MAX_OPTION_ROMS];
223
int semihosting_enabled = 0;
224
int time_drift_fix = 0;
225
unsigned int kvm_shadow_memory = 0;
227
const char *qemu_name;
230
unsigned int nb_prom_envs = 0;
231
const char *prom_envs[MAX_PROM_ENVS];
232
const char *nvram = NULL;
235
typedef struct FWBootEntry FWBootEntry;
238
QTAILQ_ENTRY(FWBootEntry) link;
244
QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
247
uint64_t node_mem[MAX_NODES];
248
uint64_t node_cpumask[MAX_NODES];
250
static QEMUTimer *nographic_timer;
252
uint8_t qemu_uuid[16];
254
static QEMUBootSetHandler *boot_set_handler;
255
static void *boot_set_opaque;
257
static NotifierList exit_notifiers =
258
NOTIFIER_LIST_INITIALIZER(exit_notifiers);
260
static NotifierList machine_init_done_notifiers =
261
NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
263
static int tcg_allowed = 1;
267
enum xen_mode xen_mode = XEN_EMULATE;
269
static int default_serial = 1;
270
static int default_parallel = 1;
271
static int default_virtcon = 1;
272
static int default_monitor = 1;
273
static int default_vga = 1;
274
static int default_floppy = 1;
275
static int default_cdrom = 1;
276
static int default_sdcard = 1;
282
{ .driver = "isa-serial", .flag = &default_serial },
283
{ .driver = "isa-parallel", .flag = &default_parallel },
284
{ .driver = "isa-fdc", .flag = &default_floppy },
285
{ .driver = "ide-cd", .flag = &default_cdrom },
286
{ .driver = "ide-hd", .flag = &default_cdrom },
287
{ .driver = "ide-drive", .flag = &default_cdrom },
288
{ .driver = "scsi-cd", .flag = &default_cdrom },
289
{ .driver = "virtio-serial-pci", .flag = &default_virtcon },
290
{ .driver = "virtio-serial-s390", .flag = &default_virtcon },
291
{ .driver = "virtio-serial", .flag = &default_virtcon },
292
{ .driver = "VGA", .flag = &default_vga },
293
{ .driver = "cirrus-vga", .flag = &default_vga },
294
{ .driver = "vmware-svga", .flag = &default_vga },
295
{ .driver = "isa-vga", .flag = &default_vga },
296
{ .driver = "qxl-vga", .flag = &default_vga },
299
static int default_driver_check(QemuOpts *opts, void *opaque)
301
const char *driver = qemu_opt_get(opts, "driver");
306
for (i = 0; i < ARRAY_SIZE(default_list); i++) {
307
if (strcmp(default_list[i].driver, driver) != 0)
309
*(default_list[i].flag) = 0;
314
/***********************************************************/
315
/* real time host monotonic timer */
317
/***********************************************************/
318
/* host time/date access */
319
void qemu_get_timedate(struct tm *tm, int offset)
326
if (rtc_date_offset == -1) {
330
ret = localtime(&ti);
332
ti -= rtc_date_offset;
336
memcpy(tm, ret, sizeof(struct tm));
339
int qemu_timedate_diff(struct tm *tm)
343
if (rtc_date_offset == -1)
345
seconds = mktimegm(tm);
347
seconds = mktime(tm);
349
seconds = mktimegm(tm) + rtc_date_offset;
351
return seconds - time(NULL);
354
void rtc_change_mon_event(struct tm *tm)
358
data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
359
monitor_protocol_event(QEVENT_RTC_CHANGE, data);
360
qobject_decref(data);
363
static void configure_rtc_date_offset(const char *startdate, int legacy)
365
time_t rtc_start_date;
368
if (!strcmp(startdate, "now") && legacy) {
369
rtc_date_offset = -1;
371
if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
379
} else if (sscanf(startdate, "%d-%d-%d",
391
rtc_start_date = mktimegm(&tm);
392
if (rtc_start_date == -1) {
394
fprintf(stderr, "Invalid date format. Valid formats are:\n"
395
"'2006-06-17T16:01:21' or '2006-06-17'\n");
398
rtc_date_offset = time(NULL) - rtc_start_date;
402
static void configure_rtc(QemuOpts *opts)
406
value = qemu_opt_get(opts, "base");
408
if (!strcmp(value, "utc")) {
410
} else if (!strcmp(value, "localtime")) {
413
configure_rtc_date_offset(value, 0);
416
value = qemu_opt_get(opts, "clock");
418
if (!strcmp(value, "host")) {
419
rtc_clock = host_clock;
420
} else if (!strcmp(value, "vm")) {
421
rtc_clock = vm_clock;
423
fprintf(stderr, "qemu: invalid option value '%s'\n", value);
427
value = qemu_opt_get(opts, "driftfix");
429
if (!strcmp(value, "slew")) {
431
} else if (!strcmp(value, "none")) {
434
fprintf(stderr, "qemu: invalid option value '%s'\n", value);
440
/***********************************************************/
441
/* Bluetooth support */
444
static struct HCIInfo *hci_table[MAX_NICS];
446
static struct bt_vlan_s {
447
struct bt_scatternet_s net;
449
struct bt_vlan_s *next;
452
/* find or alloc a new bluetooth "VLAN" */
453
static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
455
struct bt_vlan_s **pvlan, *vlan;
456
for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
460
vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
462
pvlan = &first_bt_vlan;
463
while (*pvlan != NULL)
464
pvlan = &(*pvlan)->next;
469
static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
473
static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
478
static struct HCIInfo null_hci = {
479
.cmd_send = null_hci_send,
480
.sco_send = null_hci_send,
481
.acl_send = null_hci_send,
482
.bdaddr_set = null_hci_addr_set,
485
struct HCIInfo *qemu_next_hci(void)
487
if (cur_hci == nb_hcis)
490
return hci_table[cur_hci++];
493
static struct HCIInfo *hci_init(const char *str)
496
struct bt_scatternet_s *vlan = 0;
498
if (!strcmp(str, "null"))
501
else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
503
return bt_host_hci(str[4] ? str + 5 : "hci0");
504
else if (!strncmp(str, "hci", 3)) {
507
if (!strncmp(str + 3, ",vlan=", 6)) {
508
vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
513
vlan = qemu_find_bt_vlan(0);
515
return bt_new_hci(vlan);
518
fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
523
static int bt_hci_parse(const char *str)
528
if (nb_hcis >= MAX_NICS) {
529
fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
542
bdaddr.b[5] = 0x56 + nb_hcis;
543
hci->bdaddr_set(hci, bdaddr.b);
545
hci_table[nb_hcis++] = hci;
550
static void bt_vhci_add(int vlan_id)
552
struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
555
fprintf(stderr, "qemu: warning: adding a VHCI to "
556
"an empty scatternet %i\n", vlan_id);
558
bt_vhci_init(bt_new_hci(vlan));
561
static struct bt_device_s *bt_device_add(const char *opt)
563
struct bt_scatternet_s *vlan;
565
char *endp = strstr(opt, ",vlan=");
566
int len = (endp ? endp - opt : strlen(opt)) + 1;
569
pstrcpy(devname, MIN(sizeof(devname), len), opt);
572
vlan_id = strtol(endp + 6, &endp, 0);
574
fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
579
vlan = qemu_find_bt_vlan(vlan_id);
582
fprintf(stderr, "qemu: warning: adding a slave device to "
583
"an empty scatternet %i\n", vlan_id);
585
if (!strcmp(devname, "keyboard"))
586
return bt_keyboard_init(vlan);
588
fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
592
static int bt_parse(const char *opt)
594
const char *endp, *p;
597
if (strstart(opt, "hci", &endp)) {
598
if (!*endp || *endp == ',') {
600
if (!strstart(endp, ",vlan=", 0))
603
return bt_hci_parse(opt);
605
} else if (strstart(opt, "vhci", &endp)) {
606
if (!*endp || *endp == ',') {
608
if (strstart(endp, ",vlan=", &p)) {
609
vlan = strtol(p, (char **) &endp, 0);
611
fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
615
fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
624
} else if (strstart(opt, "device:", &endp))
625
return !bt_device_add(endp);
627
fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
631
/***********************************************************/
632
/* QEMU Block devices */
634
#define HD_OPTS "media=disk"
635
#define CDROM_OPTS "media=cdrom"
637
#define PFLASH_OPTS ""
641
static int drive_init_func(QemuOpts *opts, void *opaque)
643
int *use_scsi = opaque;
645
return drive_init(opts, *use_scsi) == NULL;
648
static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
650
if (NULL == qemu_opt_get(opts, "snapshot")) {
651
qemu_opt_set(opts, "snapshot", "on");
656
static void default_drive(int enable, int snapshot, int use_scsi,
657
BlockInterfaceType type, int index,
662
if (type == IF_DEFAULT) {
663
type = use_scsi ? IF_SCSI : IF_IDE;
666
if (!enable || drive_get_by_index(type, index)) {
670
opts = drive_add(type, index, NULL, optstr);
672
drive_enable_snapshot(opts, NULL);
674
if (!drive_init(opts, use_scsi)) {
679
void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
681
boot_set_handler = func;
682
boot_set_opaque = opaque;
685
int qemu_boot_set(const char *boot_devices)
687
if (!boot_set_handler) {
690
return boot_set_handler(boot_set_opaque, boot_devices);
693
static void validate_bootdevices(char *devices)
695
/* We just do some generic consistency checks */
699
for (p = devices; *p != '\0'; p++) {
700
/* Allowed boot devices are:
701
* a-b: floppy disk drives
702
* c-f: IDE disk drives
703
* g-m: machine implementation dependant drives
704
* n-p: network devices
705
* It's up to each machine implementation to check if the given boot
706
* devices match the actual hardware implementation and firmware
709
if (*p < 'a' || *p > 'p') {
710
fprintf(stderr, "Invalid boot device '%c'\n", *p);
713
if (bitmap & (1 << (*p - 'a'))) {
714
fprintf(stderr, "Boot device '%c' was given twice\n", *p);
717
bitmap |= 1 << (*p - 'a');
721
static void restore_boot_devices(void *opaque)
723
char *standard_boot_devices = opaque;
724
static int first = 1;
726
/* Restore boot order and remove ourselves after the first boot */
732
qemu_boot_set(standard_boot_devices);
734
qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
735
qemu_free(standard_boot_devices);
738
void add_boot_device_path(int32_t bootindex, DeviceState *dev,
741
FWBootEntry *node, *i;
747
assert(dev != NULL || suffix != NULL);
749
node = qemu_mallocz(sizeof(FWBootEntry));
750
node->bootindex = bootindex;
751
node->suffix = suffix ? qemu_strdup(suffix) : NULL;
754
QTAILQ_FOREACH(i, &fw_boot_order, link) {
755
if (i->bootindex == bootindex) {
756
fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
758
} else if (i->bootindex < bootindex) {
761
QTAILQ_INSERT_BEFORE(i, node, link);
764
QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
768
* This function returns null terminated string that consist of new line
769
* separated device paths.
771
* memory pointed by "size" is assigned total length of the array in bytes
774
char *get_boot_devices_list(uint32_t *size)
780
QTAILQ_FOREACH(i, &fw_boot_order, link) {
781
char *devpath = NULL, *bootpath;
785
devpath = qdev_get_fw_dev_path(i->dev);
789
if (i->suffix && devpath) {
790
size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
792
bootpath = qemu_malloc(bootpathlen);
793
snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
795
} else if (devpath) {
798
bootpath = qemu_strdup(i->suffix);
803
list[total-1] = '\n';
805
len = strlen(bootpath) + 1;
806
list = qemu_realloc(list, total + len);
807
memcpy(&list[total], bootpath, len);
817
static void numa_add(const char *optarg)
821
unsigned long long value, endvalue;
824
optarg = get_opt_name(option, 128, optarg, ',') + 1;
825
if (!strcmp(option, "node")) {
826
if (get_param_value(option, 128, "nodeid", optarg) == 0) {
827
nodenr = nb_numa_nodes;
829
nodenr = strtoull(option, NULL, 10);
832
if (get_param_value(option, 128, "mem", optarg) == 0) {
833
node_mem[nodenr] = 0;
836
sval = strtosz(option, NULL);
838
fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
841
node_mem[nodenr] = sval;
843
if (get_param_value(option, 128, "cpus", optarg) == 0) {
844
node_cpumask[nodenr] = 0;
846
value = strtoull(option, &endptr, 10);
849
fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
851
if (*endptr == '-') {
852
endvalue = strtoull(endptr+1, &endptr, 10);
853
if (endvalue >= 63) {
856
"only 63 CPUs in NUMA mode supported.\n");
858
value = (2ULL << endvalue) - (1ULL << value);
860
value = 1ULL << value;
863
node_cpumask[nodenr] = value;
870
static void smp_parse(const char *optarg)
872
int smp, sockets = 0, threads = 0, cores = 0;
876
smp = strtoul(optarg, &endptr, 10);
877
if (endptr != optarg) {
878
if (*endptr == ',') {
882
if (get_param_value(option, 128, "sockets", endptr) != 0)
883
sockets = strtoull(option, NULL, 10);
884
if (get_param_value(option, 128, "cores", endptr) != 0)
885
cores = strtoull(option, NULL, 10);
886
if (get_param_value(option, 128, "threads", endptr) != 0)
887
threads = strtoull(option, NULL, 10);
888
if (get_param_value(option, 128, "maxcpus", endptr) != 0)
889
max_cpus = strtoull(option, NULL, 10);
891
/* compute missing values, prefer sockets over cores over threads */
892
if (smp == 0 || sockets == 0) {
893
sockets = sockets > 0 ? sockets : 1;
894
cores = cores > 0 ? cores : 1;
895
threads = threads > 0 ? threads : 1;
897
smp = cores * threads * sockets;
901
threads = threads > 0 ? threads : 1;
902
cores = smp / (sockets * threads);
904
threads = smp / (cores * sockets);
908
smp_cores = cores > 0 ? cores : 1;
909
smp_threads = threads > 0 ? threads : 1;
914
/***********************************************************/
917
static int usb_device_add(const char *devname)
920
USBDevice *dev = NULL;
925
/* drivers with .usbdevice_name entry in USBDeviceInfo */
926
dev = usbdevice_create(devname);
932
/* only the linux version is qdev-ified, usb-bsd still needs this */
933
if (strstart(devname, "host:", &p)) {
934
dev = usb_host_device_open(p);
937
if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
938
dev = usb_bt_init(devname[2] ? hci_init(p) :
939
bt_new_hci(qemu_find_bt_vlan(0)));
950
static int usb_device_del(const char *devname)
955
if (strstart(devname, "host:", &p))
956
return usb_host_device_close(p);
961
p = strchr(devname, '.');
964
bus_num = strtoul(devname, NULL, 0);
965
addr = strtoul(p + 1, NULL, 0);
967
return usb_device_delete_addr(bus_num, addr);
970
static int usb_parse(const char *cmdline)
973
r = usb_device_add(cmdline);
975
fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
980
void do_usb_add(Monitor *mon, const QDict *qdict)
982
const char *devname = qdict_get_str(qdict, "devname");
983
if (usb_device_add(devname) < 0) {
984
error_report("could not add USB device '%s'", devname);
988
void do_usb_del(Monitor *mon, const QDict *qdict)
990
const char *devname = qdict_get_str(qdict, "devname");
991
if (usb_device_del(devname) < 0) {
992
error_report("could not delete USB device '%s'", devname);
996
/***********************************************************/
999
static struct pcmcia_socket_entry_s {
1000
PCMCIASocket *socket;
1001
struct pcmcia_socket_entry_s *next;
1002
} *pcmcia_sockets = 0;
1004
void pcmcia_socket_register(PCMCIASocket *socket)
1006
struct pcmcia_socket_entry_s *entry;
1008
entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
1009
entry->socket = socket;
1010
entry->next = pcmcia_sockets;
1011
pcmcia_sockets = entry;
1014
void pcmcia_socket_unregister(PCMCIASocket *socket)
1016
struct pcmcia_socket_entry_s *entry, **ptr;
1018
ptr = &pcmcia_sockets;
1019
for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1020
if (entry->socket == socket) {
1026
void pcmcia_info(Monitor *mon)
1028
struct pcmcia_socket_entry_s *iter;
1030
if (!pcmcia_sockets)
1031
monitor_printf(mon, "No PCMCIA sockets\n");
1033
for (iter = pcmcia_sockets; iter; iter = iter->next)
1034
monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1035
iter->socket->attached ? iter->socket->card_string :
1039
/***********************************************************/
1040
/* machine registration */
1042
static QEMUMachine *first_machine = NULL;
1043
QEMUMachine *current_machine = NULL;
1045
int qemu_register_machine(QEMUMachine *m)
1048
pm = &first_machine;
1056
static QEMUMachine *find_machine(const char *name)
1060
for(m = first_machine; m != NULL; m = m->next) {
1061
if (!strcmp(m->name, name))
1063
if (m->alias && !strcmp(m->alias, name))
1069
static QEMUMachine *find_default_machine(void)
1073
for(m = first_machine; m != NULL; m = m->next) {
1074
if (m->is_default) {
1081
/***********************************************************/
1082
/* main execution loop */
1084
static void gui_update(void *opaque)
1086
uint64_t interval = GUI_REFRESH_INTERVAL;
1087
DisplayState *ds = opaque;
1088
DisplayChangeListener *dcl = ds->listeners;
1090
qemu_flush_coalesced_mmio_buffer();
1093
while (dcl != NULL) {
1094
if (dcl->gui_timer_interval &&
1095
dcl->gui_timer_interval < interval)
1096
interval = dcl->gui_timer_interval;
1099
qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
1102
static void nographic_update(void *opaque)
1104
uint64_t interval = GUI_REFRESH_INTERVAL;
1106
qemu_flush_coalesced_mmio_buffer();
1107
qemu_mod_timer(nographic_timer, interval + qemu_get_clock_ms(rt_clock));
1110
struct vm_change_state_entry {
1111
VMChangeStateHandler *cb;
1113
QLIST_ENTRY (vm_change_state_entry) entries;
1116
static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
1118
VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1121
VMChangeStateEntry *e;
1123
e = qemu_mallocz(sizeof (*e));
1127
QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
1131
void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1133
QLIST_REMOVE (e, entries);
1137
void vm_state_notify(int running, int reason)
1139
VMChangeStateEntry *e;
1141
trace_vm_state_notify(running, reason);
1143
for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1144
e->cb(e->opaque, running, reason);
1153
vm_state_notify(1, 0);
1155
monitor_protocol_event(QEVENT_RESUME, NULL);
1159
/* reset/shutdown handler */
1161
typedef struct QEMUResetEntry {
1162
QTAILQ_ENTRY(QEMUResetEntry) entry;
1163
QEMUResetHandler *func;
1167
static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1168
QTAILQ_HEAD_INITIALIZER(reset_handlers);
1169
static int reset_requested;
1170
static int shutdown_requested, shutdown_signal = -1;
1171
static pid_t shutdown_pid;
1172
static int powerdown_requested;
1173
static int debug_requested;
1174
static int vmstop_requested;
1176
int qemu_shutdown_requested_get(void)
1178
return shutdown_requested;
1181
int qemu_reset_requested_get(void)
1183
return reset_requested;
1186
int qemu_shutdown_requested(void)
1188
int r = shutdown_requested;
1189
shutdown_requested = 0;
1193
void qemu_kill_report(void)
1195
if (shutdown_signal != -1) {
1196
fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1197
if (shutdown_pid == 0) {
1198
/* This happens for eg ^C at the terminal, so it's worth
1199
* avoiding printing an odd message in that case.
1201
fputc('\n', stderr);
1203
fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
1205
shutdown_signal = -1;
1209
int qemu_reset_requested(void)
1211
int r = reset_requested;
1212
reset_requested = 0;
1216
int qemu_powerdown_requested(void)
1218
int r = powerdown_requested;
1219
powerdown_requested = 0;
1223
static int qemu_debug_requested(void)
1225
int r = debug_requested;
1226
debug_requested = 0;
1230
static int qemu_vmstop_requested(void)
1232
int r = vmstop_requested;
1233
vmstop_requested = 0;
1237
void qemu_register_reset(QEMUResetHandler *func, void *opaque)
1239
QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
1242
re->opaque = opaque;
1243
QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
1246
void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
1250
QTAILQ_FOREACH(re, &reset_handlers, entry) {
1251
if (re->func == func && re->opaque == opaque) {
1252
QTAILQ_REMOVE(&reset_handlers, re, entry);
1259
void qemu_system_reset(bool report)
1261
QEMUResetEntry *re, *nre;
1263
/* reset all devices */
1264
QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
1265
re->func(re->opaque);
1268
monitor_protocol_event(QEVENT_RESET, NULL);
1270
cpu_synchronize_all_post_reset();
1273
void qemu_system_reset_request(void)
1276
shutdown_requested = 1;
1278
reset_requested = 1;
1281
qemu_notify_event();
1284
void qemu_system_killed(int signal, pid_t pid)
1286
shutdown_signal = signal;
1288
qemu_system_shutdown_request();
1291
void qemu_system_shutdown_request(void)
1293
shutdown_requested = 1;
1294
qemu_notify_event();
1297
void qemu_system_powerdown_request(void)
1299
powerdown_requested = 1;
1300
qemu_notify_event();
1303
void qemu_system_debug_request(void)
1305
debug_requested = 1;
1306
qemu_notify_event();
1309
void qemu_system_vmstop_request(int reason)
1311
vmstop_requested = reason;
1312
qemu_notify_event();
1315
void main_loop_wait(int nonblocking)
1317
fd_set rfds, wfds, xfds;
1325
timeout = qemu_calculate_timeout();
1326
qemu_bh_update_timeout(&timeout);
1329
os_host_main_loop_wait(&timeout);
1331
tv.tv_sec = timeout / 1000;
1332
tv.tv_usec = (timeout % 1000) * 1000;
1334
/* poll any events */
1335
/* XXX: separate device handlers from system ones */
1340
qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
1341
slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1343
qemu_mutex_unlock_iothread();
1344
ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
1345
qemu_mutex_lock_iothread();
1347
qemu_iohandler_poll(&rfds, &wfds, &xfds, ret);
1348
slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
1350
qemu_run_all_timers();
1352
/* Check bottom-halves last in case any of the earlier events triggered
1358
#ifndef CONFIG_IOTHREAD
1359
static int vm_request_pending(void)
1361
return powerdown_requested ||
1363
shutdown_requested ||
1369
qemu_irq qemu_system_powerdown;
1371
static void main_loop(void)
1373
bool nonblocking = false;
1374
#ifdef CONFIG_PROFILER
1379
qemu_main_loop_start();
1382
#ifndef CONFIG_IOTHREAD
1383
nonblocking = cpu_exec_all();
1384
if (vm_request_pending()) {
1388
#ifdef CONFIG_PROFILER
1389
ti = profile_getclock();
1391
main_loop_wait(nonblocking);
1392
#ifdef CONFIG_PROFILER
1393
dev_time += profile_getclock() - ti;
1396
if (qemu_debug_requested()) {
1397
vm_stop(VMSTOP_DEBUG);
1399
if (qemu_shutdown_requested()) {
1401
monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1403
vm_stop(VMSTOP_SHUTDOWN);
1407
if (qemu_reset_requested()) {
1409
cpu_synchronize_all_states();
1410
qemu_system_reset(VMRESET_REPORT);
1413
if (qemu_powerdown_requested()) {
1414
monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1415
qemu_irq_raise(qemu_system_powerdown);
1417
if ((r = qemu_vmstop_requested())) {
1425
static void version(void)
1427
printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
1430
static void help(int exitcode)
1432
const char *options_help =
1433
#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1435
#define DEFHEADING(text) stringify(text) "\n"
1436
#include "qemu-options.def"
1442
printf("usage: %s [options] [disk_image]\n"
1444
"'disk_image' is a raw hard disk image for IDE hard disk 0\n"
1447
"During emulation, the following keys are useful:\n"
1448
"ctrl-alt-f toggle full screen\n"
1449
"ctrl-alt-n switch to virtual console 'n'\n"
1450
"ctrl-alt toggle mouse and keyboard grab\n"
1452
"When using -nographic, press 'ctrl-a h' to get some help.\n",
1458
#define HAS_ARG 0x0001
1460
typedef struct QEMUOption {
1467
static const QEMUOption qemu_options[] = {
1468
{ "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1469
#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1470
{ option, opt_arg, opt_enum, arch_mask },
1471
#define DEFHEADING(text)
1472
#include "qemu-options.def"
1478
static void select_vgahw (const char *p)
1483
vga_interface_type = VGA_NONE;
1484
if (strstart(p, "std", &opts)) {
1485
vga_interface_type = VGA_STD;
1486
} else if (strstart(p, "cirrus", &opts)) {
1487
vga_interface_type = VGA_CIRRUS;
1488
} else if (strstart(p, "vmware", &opts)) {
1489
vga_interface_type = VGA_VMWARE;
1490
} else if (strstart(p, "xenfb", &opts)) {
1491
vga_interface_type = VGA_XENFB;
1492
} else if (strstart(p, "qxl", &opts)) {
1493
vga_interface_type = VGA_QXL;
1494
} else if (!strstart(p, "none", &opts)) {
1496
fprintf(stderr, "Unknown vga type: %s\n", p);
1500
const char *nextopt;
1502
if (strstart(opts, ",retrace=", &nextopt)) {
1504
if (strstart(opts, "dumb", &nextopt))
1505
vga_retrace_method = VGA_RETRACE_DUMB;
1506
else if (strstart(opts, "precise", &nextopt))
1507
vga_retrace_method = VGA_RETRACE_PRECISE;
1508
else goto invalid_vga;
1509
} else goto invalid_vga;
1514
static DisplayType select_display(const char *p)
1517
DisplayType display = DT_DEFAULT;
1519
if (strstart(p, "sdl", &opts)) {
1523
const char *nextopt;
1525
if (strstart(opts, ",frame=", &nextopt)) {
1527
if (strstart(opts, "on", &nextopt)) {
1529
} else if (strstart(opts, "off", &nextopt)) {
1532
goto invalid_sdl_args;
1534
} else if (strstart(opts, ",alt_grab=", &nextopt)) {
1536
if (strstart(opts, "on", &nextopt)) {
1538
} else if (strstart(opts, "off", &nextopt)) {
1541
goto invalid_sdl_args;
1543
} else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1545
if (strstart(opts, "on", &nextopt)) {
1547
} else if (strstart(opts, "off", &nextopt)) {
1550
goto invalid_sdl_args;
1552
} else if (strstart(opts, ",window_close=", &nextopt)) {
1554
if (strstart(opts, "on", &nextopt)) {
1556
} else if (strstart(opts, "off", &nextopt)) {
1559
goto invalid_sdl_args;
1563
fprintf(stderr, "Invalid SDL option string: %s\n", p);
1569
fprintf(stderr, "SDL support is disabled\n");
1572
} else if (strstart(p, "vnc", &opts)) {
1577
const char *nextopt;
1579
if (strstart(opts, "=", &nextopt)) {
1580
vnc_display = nextopt;
1584
fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1588
fprintf(stderr, "VNC support is disabled\n");
1591
} else if (strstart(p, "curses", &opts)) {
1592
#ifdef CONFIG_CURSES
1593
display = DT_CURSES;
1595
fprintf(stderr, "Curses support is disabled\n");
1598
} else if (strstart(p, "none", &opts)) {
1601
fprintf(stderr, "Unknown display type: %s\n", p);
1608
static int balloon_parse(const char *arg)
1612
if (strcmp(arg, "none") == 0) {
1616
if (!strncmp(arg, "virtio", 6)) {
1617
if (arg[6] == ',') {
1618
/* have params -> parse them */
1619
opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
1623
/* create empty opts */
1624
opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
1626
qemu_opt_set(opts, "driver", "virtio-balloon");
1633
char *qemu_find_file(int type, const char *name)
1639
/* If name contains path separators then try it as a straight path. */
1640
if ((strchr(name, '/') || strchr(name, '\\'))
1641
&& access(name, R_OK) == 0) {
1642
return qemu_strdup(name);
1645
case QEMU_FILE_TYPE_BIOS:
1648
case QEMU_FILE_TYPE_KEYMAP:
1649
subdir = "keymaps/";
1654
len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1655
buf = qemu_mallocz(len);
1656
snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
1657
if (access(buf, R_OK)) {
1664
static int device_help_func(QemuOpts *opts, void *opaque)
1666
return qdev_device_help(opts);
1669
static int device_init_func(QemuOpts *opts, void *opaque)
1673
dev = qdev_device_add(opts);
1679
static int chardev_init_func(QemuOpts *opts, void *opaque)
1681
CharDriverState *chr;
1683
chr = qemu_chr_open_opts(opts, NULL);
1689
#ifdef CONFIG_VIRTFS
1690
static int fsdev_init_func(QemuOpts *opts, void *opaque)
1693
ret = qemu_fsdev_add(opts);
1699
static int mon_init_func(QemuOpts *opts, void *opaque)
1701
CharDriverState *chr;
1702
const char *chardev;
1706
mode = qemu_opt_get(opts, "mode");
1710
if (strcmp(mode, "readline") == 0) {
1711
flags = MONITOR_USE_READLINE;
1712
} else if (strcmp(mode, "control") == 0) {
1713
flags = MONITOR_USE_CONTROL;
1715
fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1719
if (qemu_opt_get_bool(opts, "pretty", 0))
1720
flags |= MONITOR_USE_PRETTY;
1722
if (qemu_opt_get_bool(opts, "default", 0))
1723
flags |= MONITOR_IS_DEFAULT;
1725
chardev = qemu_opt_get(opts, "chardev");
1726
chr = qemu_chr_find(chardev);
1728
fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1732
monitor_init(chr, flags);
1736
static void monitor_parse(const char *optarg, const char *mode)
1738
static int monitor_device_index = 0;
1744
if (strstart(optarg, "chardev:", &p)) {
1745
snprintf(label, sizeof(label), "%s", p);
1747
snprintf(label, sizeof(label), "compat_monitor%d",
1748
monitor_device_index);
1749
if (monitor_device_index == 0) {
1752
opts = qemu_chr_parse_compat(label, optarg);
1754
fprintf(stderr, "parse error: %s\n", optarg);
1759
opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
1761
fprintf(stderr, "duplicate chardev: %s\n", label);
1764
qemu_opt_set(opts, "mode", mode);
1765
qemu_opt_set(opts, "chardev", label);
1767
qemu_opt_set(opts, "default", "on");
1768
monitor_device_index++;
1771
struct device_config {
1773
DEV_USB, /* -usbdevice */
1775
DEV_SERIAL, /* -serial */
1776
DEV_PARALLEL, /* -parallel */
1777
DEV_VIRTCON, /* -virtioconsole */
1778
DEV_DEBUGCON, /* -debugcon */
1780
const char *cmdline;
1781
QTAILQ_ENTRY(device_config) next;
1783
QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
1785
static void add_device_config(int type, const char *cmdline)
1787
struct device_config *conf;
1789
conf = qemu_mallocz(sizeof(*conf));
1791
conf->cmdline = cmdline;
1792
QTAILQ_INSERT_TAIL(&device_configs, conf, next);
1795
static int foreach_device_config(int type, int (*func)(const char *cmdline))
1797
struct device_config *conf;
1800
QTAILQ_FOREACH(conf, &device_configs, next) {
1801
if (conf->type != type)
1803
rc = func(conf->cmdline);
1810
static int serial_parse(const char *devname)
1812
static int index = 0;
1815
if (strcmp(devname, "none") == 0)
1817
if (index == MAX_SERIAL_PORTS) {
1818
fprintf(stderr, "qemu: too many serial ports\n");
1821
snprintf(label, sizeof(label), "serial%d", index);
1822
serial_hds[index] = qemu_chr_open(label, devname, NULL);
1823
if (!serial_hds[index]) {
1824
fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1825
devname, strerror(errno));
1832
static int parallel_parse(const char *devname)
1834
static int index = 0;
1837
if (strcmp(devname, "none") == 0)
1839
if (index == MAX_PARALLEL_PORTS) {
1840
fprintf(stderr, "qemu: too many parallel ports\n");
1843
snprintf(label, sizeof(label), "parallel%d", index);
1844
parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1845
if (!parallel_hds[index]) {
1846
fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1847
devname, strerror(errno));
1854
static int virtcon_parse(const char *devname)
1856
QemuOptsList *device = qemu_find_opts("device");
1857
static int index = 0;
1859
QemuOpts *bus_opts, *dev_opts;
1861
if (strcmp(devname, "none") == 0)
1863
if (index == MAX_VIRTIO_CONSOLES) {
1864
fprintf(stderr, "qemu: too many virtio consoles\n");
1868
bus_opts = qemu_opts_create(device, NULL, 0);
1869
qemu_opt_set(bus_opts, "driver", "virtio-serial");
1871
dev_opts = qemu_opts_create(device, NULL, 0);
1872
qemu_opt_set(dev_opts, "driver", "virtconsole");
1874
snprintf(label, sizeof(label), "virtcon%d", index);
1875
virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1876
if (!virtcon_hds[index]) {
1877
fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1878
devname, strerror(errno));
1881
qemu_opt_set(dev_opts, "chardev", label);
1887
static int debugcon_parse(const char *devname)
1891
if (!qemu_chr_open("debugcon", devname, NULL)) {
1894
opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
1896
fprintf(stderr, "qemu: already have a debugcon device\n");
1899
qemu_opt_set(opts, "driver", "isa-debugcon");
1900
qemu_opt_set(opts, "chardev", "debugcon");
1904
static QEMUMachine *machine_parse(const char *name)
1906
QEMUMachine *m, *machine = NULL;
1909
machine = find_machine(name);
1914
printf("Supported machines are:\n");
1915
for (m = first_machine; m != NULL; m = m->next) {
1917
printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
1919
printf("%-10s %s%s\n", m->name, m->desc,
1920
m->is_default ? " (default)" : "");
1922
exit(!name || *name != '?');
1925
static int tcg_init(void)
1931
const char *opt_name;
1933
int (*available)(void);
1937
{ "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
1938
{ "xen", "Xen", xen_available, xen_init, &xen_allowed },
1939
{ "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
1942
static int configure_accelerator(void)
1944
const char *p = NULL;
1947
bool accel_initalised = 0;
1948
bool init_failed = 0;
1950
QemuOptsList *list = qemu_find_opts("machine");
1951
if (!QTAILQ_EMPTY(&list->head)) {
1952
p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
1957
/* Use the default "accelerator", kvm */
1960
/* Use the default "accelerator", tcg */
1965
while (!accel_initalised && *p != '\0') {
1969
p = get_opt_name(buf, sizeof (buf), p, ':');
1970
for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
1971
if (strcmp(accel_list[i].opt_name, buf) == 0) {
1972
*(accel_list[i].allowed) = 1;
1973
ret = accel_list[i].init();
1976
if (!accel_list[i].available()) {
1977
printf("%s not supported for this target\n",
1978
accel_list[i].name);
1980
fprintf(stderr, "failed to initialize %s: %s\n",
1984
*(accel_list[i].allowed) = 0;
1986
accel_initalised = 1;
1991
if (i == ARRAY_SIZE(accel_list)) {
1992
fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
1996
if (!accel_initalised) {
1997
fprintf(stderr, "No accelerator found!\n");
2002
fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2005
return !accel_initalised;
2008
void qemu_add_exit_notifier(Notifier *notify)
2010
notifier_list_add(&exit_notifiers, notify);
2013
void qemu_remove_exit_notifier(Notifier *notify)
2015
notifier_list_remove(&exit_notifiers, notify);
2018
static void qemu_run_exit_notifiers(void)
2020
notifier_list_notify(&exit_notifiers, NULL);
2023
void qemu_add_machine_init_done_notifier(Notifier *notify)
2025
notifier_list_add(&machine_init_done_notifiers, notify);
2028
static void qemu_run_machine_init_done_notifiers(void)
2030
notifier_list_notify(&machine_init_done_notifiers, NULL);
2033
static const QEMUOption *lookup_opt(int argc, char **argv,
2034
const char **poptarg, int *poptind)
2036
const QEMUOption *popt;
2037
int optind = *poptind;
2038
char *r = argv[optind];
2041
loc_set_cmdline(argv, optind, 1);
2043
/* Treat --foo the same as -foo. */
2046
popt = qemu_options;
2049
error_report("invalid option");
2052
if (!strcmp(popt->name, r + 1))
2056
if (popt->flags & HAS_ARG) {
2057
if (optind >= argc) {
2058
error_report("requires an argument");
2061
optarg = argv[optind++];
2062
loc_set_cmdline(argv, optind - 2, 2);
2073
int main(int argc, char **argv, char **envp)
2075
const char *gdbstub_dev = NULL;
2077
int snapshot, linux_boot;
2078
const char *icount_option = NULL;
2079
const char *initrd_filename;
2080
const char *kernel_filename, *kernel_cmdline;
2081
char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
2083
DisplayChangeListener *dcl;
2084
int cyls, heads, secs, translation;
2085
QemuOpts *hda_opts = NULL, *opts;
2086
QemuOptsList *olist;
2089
const char *loadvm = NULL;
2090
QEMUMachine *machine;
2091
const char *cpu_model;
2093
const char *pid_file = NULL;
2094
const char *incoming = NULL;
2096
int show_vnc_port = 0;
2099
const char *trace_file = NULL;
2100
const char *log_mask = NULL;
2101
const char *log_file = NULL;
2103
atexit(qemu_run_exit_notifiers);
2104
error_set_progname(argv[0]);
2108
qemu_cache_utils_init(envp);
2110
QLIST_INIT (&vm_change_state_head);
2111
os_setup_early_signal_handling();
2113
module_call_init(MODULE_INIT_MACHINE);
2114
machine = find_default_machine();
2116
initrd_filename = NULL;
2119
kernel_filename = NULL;
2120
kernel_cmdline = "";
2121
cyls = heads = secs = 0;
2122
translation = BIOS_ATA_TRANSLATION_AUTO;
2124
for (i = 0; i < MAX_NODES; i++) {
2126
node_cpumask[i] = 0;
2135
/* first pass of option parsing */
2137
while (optind < argc) {
2138
if (argv[optind][0] != '-') {
2143
const QEMUOption *popt;
2145
popt = lookup_opt(argc, argv, &optarg, &optind);
2146
switch (popt->index) {
2147
case QEMU_OPTION_nodefconfig:
2157
ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
2158
if (ret < 0 && ret != -ENOENT) {
2162
ret = qemu_read_config_file(arch_config_name);
2163
if (ret < 0 && ret != -ENOENT) {
2169
/* second pass of option parsing */
2174
if (argv[optind][0] != '-') {
2175
hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2177
const QEMUOption *popt;
2179
popt = lookup_opt(argc, argv, &optarg, &optind);
2180
if (!(popt->arch_mask & arch_type)) {
2181
printf("Option %s not supported for this target\n", popt->name);
2184
switch(popt->index) {
2186
machine = machine_parse(optarg);
2188
case QEMU_OPTION_cpu:
2189
/* hw initialization will check this */
2190
if (*optarg == '?') {
2191
list_cpus(stdout, &fprintf, optarg);
2197
case QEMU_OPTION_initrd:
2198
initrd_filename = optarg;
2200
case QEMU_OPTION_hda:
2204
snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2206
snprintf(buf, sizeof(buf),
2207
"%s,cyls=%d,heads=%d,secs=%d%s",
2208
HD_OPTS , cyls, heads, secs,
2209
translation == BIOS_ATA_TRANSLATION_LBA ?
2211
translation == BIOS_ATA_TRANSLATION_NONE ?
2212
",trans=none" : "");
2213
drive_add(IF_DEFAULT, 0, optarg, buf);
2216
case QEMU_OPTION_hdb:
2217
case QEMU_OPTION_hdc:
2218
case QEMU_OPTION_hdd:
2219
drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2222
case QEMU_OPTION_drive:
2223
if (drive_def(optarg) == NULL) {
2227
case QEMU_OPTION_set:
2228
if (qemu_set_option(optarg) != 0)
2231
case QEMU_OPTION_global:
2232
if (qemu_global_option(optarg) != 0)
2235
case QEMU_OPTION_mtdblock:
2236
drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2238
case QEMU_OPTION_sd:
2239
drive_add(IF_SD, 0, optarg, SD_OPTS);
2241
case QEMU_OPTION_pflash:
2242
drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2244
case QEMU_OPTION_snapshot:
2247
case QEMU_OPTION_hdachs:
2251
cyls = strtol(p, (char **)&p, 0);
2252
if (cyls < 1 || cyls > 16383)
2257
heads = strtol(p, (char **)&p, 0);
2258
if (heads < 1 || heads > 16)
2263
secs = strtol(p, (char **)&p, 0);
2264
if (secs < 1 || secs > 63)
2268
if (!strcmp(p, "none"))
2269
translation = BIOS_ATA_TRANSLATION_NONE;
2270
else if (!strcmp(p, "lba"))
2271
translation = BIOS_ATA_TRANSLATION_LBA;
2272
else if (!strcmp(p, "auto"))
2273
translation = BIOS_ATA_TRANSLATION_AUTO;
2276
} else if (*p != '\0') {
2278
fprintf(stderr, "qemu: invalid physical CHS format\n");
2281
if (hda_opts != NULL) {
2283
snprintf(num, sizeof(num), "%d", cyls);
2284
qemu_opt_set(hda_opts, "cyls", num);
2285
snprintf(num, sizeof(num), "%d", heads);
2286
qemu_opt_set(hda_opts, "heads", num);
2287
snprintf(num, sizeof(num), "%d", secs);
2288
qemu_opt_set(hda_opts, "secs", num);
2289
if (translation == BIOS_ATA_TRANSLATION_LBA)
2290
qemu_opt_set(hda_opts, "trans", "lba");
2291
if (translation == BIOS_ATA_TRANSLATION_NONE)
2292
qemu_opt_set(hda_opts, "trans", "none");
2296
case QEMU_OPTION_numa:
2297
if (nb_numa_nodes >= MAX_NODES) {
2298
fprintf(stderr, "qemu: too many NUMA nodes\n");
2303
case QEMU_OPTION_display:
2304
display_type = select_display(optarg);
2306
case QEMU_OPTION_nographic:
2307
display_type = DT_NOGRAPHIC;
2309
case QEMU_OPTION_curses:
2310
#ifdef CONFIG_CURSES
2311
display_type = DT_CURSES;
2313
fprintf(stderr, "Curses support is disabled\n");
2317
case QEMU_OPTION_portrait:
2318
graphic_rotate = 90;
2320
case QEMU_OPTION_rotate:
2321
graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2322
if (graphic_rotate != 0 && graphic_rotate != 90 &&
2323
graphic_rotate != 180 && graphic_rotate != 270) {
2325
"qemu: only 90, 180, 270 deg rotation is available\n");
2329
case QEMU_OPTION_kernel:
2330
kernel_filename = optarg;
2332
case QEMU_OPTION_append:
2333
kernel_cmdline = optarg;
2335
case QEMU_OPTION_cdrom:
2336
drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2338
case QEMU_OPTION_boot:
2340
static const char * const params[] = {
2341
"order", "once", "menu", NULL
2343
char buf[sizeof(boot_devices)];
2344
char *standard_boot_devices;
2347
if (!strchr(optarg, '=')) {
2349
pstrcpy(buf, sizeof(buf), optarg);
2350
} else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2352
"qemu: unknown boot parameter '%s' in '%s'\n",
2358
get_param_value(buf, sizeof(buf), "order", optarg)) {
2359
validate_bootdevices(buf);
2360
pstrcpy(boot_devices, sizeof(boot_devices), buf);
2363
if (get_param_value(buf, sizeof(buf),
2365
validate_bootdevices(buf);
2366
standard_boot_devices = qemu_strdup(boot_devices);
2367
pstrcpy(boot_devices, sizeof(boot_devices), buf);
2368
qemu_register_reset(restore_boot_devices,
2369
standard_boot_devices);
2371
if (get_param_value(buf, sizeof(buf),
2373
if (!strcmp(buf, "on")) {
2375
} else if (!strcmp(buf, "off")) {
2379
"qemu: invalid option value '%s'\n",
2387
case QEMU_OPTION_fda:
2388
case QEMU_OPTION_fdb:
2389
drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2392
case QEMU_OPTION_no_fd_bootchk:
2395
case QEMU_OPTION_netdev:
2396
if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2400
case QEMU_OPTION_net:
2401
if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2406
case QEMU_OPTION_tftp:
2407
legacy_tftp_prefix = optarg;
2409
case QEMU_OPTION_bootp:
2410
legacy_bootp_filename = optarg;
2412
case QEMU_OPTION_redir:
2413
if (net_slirp_redir(optarg) < 0)
2417
case QEMU_OPTION_bt:
2418
add_device_config(DEV_BT, optarg);
2420
case QEMU_OPTION_audio_help:
2421
if (!(audio_available())) {
2422
printf("Option %s not supported for this target\n", popt->name);
2428
case QEMU_OPTION_soundhw:
2429
if (!(audio_available())) {
2430
printf("Option %s not supported for this target\n", popt->name);
2433
select_soundhw (optarg);
2438
case QEMU_OPTION_version:
2442
case QEMU_OPTION_m: {
2445
value = strtosz(optarg, NULL);
2447
fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
2451
/* On 32-bit hosts, QEMU is limited by virtual address space */
2452
if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
2453
fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2456
if (value != (uint64_t)(ram_addr_t)value) {
2457
fprintf(stderr, "qemu: ram size too large\n");
2463
case QEMU_OPTION_mempath:
2467
case QEMU_OPTION_mem_prealloc:
2478
gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
2480
case QEMU_OPTION_gdb:
2481
gdbstub_dev = optarg;
2486
case QEMU_OPTION_bios:
2489
case QEMU_OPTION_singlestep:
2496
keyboard_layout = optarg;
2498
case QEMU_OPTION_localtime:
2501
case QEMU_OPTION_vga:
2502
select_vgahw (optarg);
2509
w = strtol(p, (char **)&p, 10);
2512
fprintf(stderr, "qemu: invalid resolution or depth\n");
2518
h = strtol(p, (char **)&p, 10);
2523
depth = strtol(p, (char **)&p, 10);
2524
if (depth != 8 && depth != 15 && depth != 16 &&
2525
depth != 24 && depth != 32)
2527
} else if (*p == '\0') {
2528
depth = graphic_depth;
2535
graphic_depth = depth;
2538
case QEMU_OPTION_echr:
2541
term_escape_char = strtol(optarg, &r, 0);
2543
printf("Bad argument to echr\n");
2546
case QEMU_OPTION_monitor:
2547
monitor_parse(optarg, "readline");
2548
default_monitor = 0;
2550
case QEMU_OPTION_qmp:
2551
monitor_parse(optarg, "control");
2552
default_monitor = 0;
2554
case QEMU_OPTION_mon:
2555
opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
2559
default_monitor = 0;
2561
case QEMU_OPTION_chardev:
2562
opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
2567
case QEMU_OPTION_fsdev:
2568
olist = qemu_find_opts("fsdev");
2570
fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2573
opts = qemu_opts_parse(olist, optarg, 1);
2575
fprintf(stderr, "parse error: %s\n", optarg);
2579
case QEMU_OPTION_virtfs: {
2583
olist = qemu_find_opts("virtfs");
2585
fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2588
opts = qemu_opts_parse(olist, optarg, 1);
2590
fprintf(stderr, "parse error: %s\n", optarg);
2594
if (qemu_opt_get(opts, "fstype") == NULL ||
2595
qemu_opt_get(opts, "mount_tag") == NULL ||
2596
qemu_opt_get(opts, "path") == NULL ||
2597
qemu_opt_get(opts, "security_model") == NULL) {
2598
fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
2599
"security_model=[mapped|passthrough|none],"
2600
"mount_tag=tag.\n");
2604
fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
2605
qemu_opt_get(opts, "mount_tag"), 1);
2607
fprintf(stderr, "duplicate fsdev id: %s\n",
2608
qemu_opt_get(opts, "mount_tag"));
2611
qemu_opt_set(fsdev, "fstype", qemu_opt_get(opts, "fstype"));
2612
qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
2613
qemu_opt_set(fsdev, "security_model",
2614
qemu_opt_get(opts, "security_model"));
2616
device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
2617
qemu_opt_set(device, "driver", "virtio-9p-pci");
2618
qemu_opt_set(device, "fsdev",
2619
qemu_opt_get(opts, "mount_tag"));
2620
qemu_opt_set(device, "mount_tag",
2621
qemu_opt_get(opts, "mount_tag"));
2624
case QEMU_OPTION_serial:
2625
add_device_config(DEV_SERIAL, optarg);
2627
if (strncmp(optarg, "mon:", 4) == 0) {
2628
default_monitor = 0;
2631
case QEMU_OPTION_watchdog:
2634
"qemu: only one watchdog option may be given\n");
2639
case QEMU_OPTION_watchdog_action:
2640
if (select_watchdog_action(optarg) == -1) {
2641
fprintf(stderr, "Unknown -watchdog-action parameter\n");
2645
case QEMU_OPTION_virtiocon:
2646
add_device_config(DEV_VIRTCON, optarg);
2647
default_virtcon = 0;
2648
if (strncmp(optarg, "mon:", 4) == 0) {
2649
default_monitor = 0;
2652
case QEMU_OPTION_parallel:
2653
add_device_config(DEV_PARALLEL, optarg);
2654
default_parallel = 0;
2655
if (strncmp(optarg, "mon:", 4) == 0) {
2656
default_monitor = 0;
2659
case QEMU_OPTION_debugcon:
2660
add_device_config(DEV_DEBUGCON, optarg);
2662
case QEMU_OPTION_loadvm:
2665
case QEMU_OPTION_full_screen:
2669
case QEMU_OPTION_no_frame:
2672
case QEMU_OPTION_alt_grab:
2675
case QEMU_OPTION_ctrl_grab:
2678
case QEMU_OPTION_no_quit:
2681
case QEMU_OPTION_sdl:
2682
display_type = DT_SDL;
2685
case QEMU_OPTION_no_frame:
2686
case QEMU_OPTION_alt_grab:
2687
case QEMU_OPTION_ctrl_grab:
2688
case QEMU_OPTION_no_quit:
2689
case QEMU_OPTION_sdl:
2690
fprintf(stderr, "SDL support is disabled\n");
2693
case QEMU_OPTION_pidfile:
2696
case QEMU_OPTION_win2k_hack:
2697
win2k_install_hack = 1;
2699
case QEMU_OPTION_rtc_td_hack:
2702
case QEMU_OPTION_acpitable:
2703
do_acpitable_option(optarg);
2705
case QEMU_OPTION_smbios:
2706
do_smbios_option(optarg);
2708
case QEMU_OPTION_enable_kvm:
2709
olist = qemu_find_opts("machine");
2710
qemu_opts_reset(olist);
2711
qemu_opts_parse(olist, "accel=kvm", 0);
2713
case QEMU_OPTION_machine:
2714
olist = qemu_find_opts("machine");
2715
qemu_opts_reset(olist);
2716
opts = qemu_opts_parse(olist, optarg, 1);
2718
fprintf(stderr, "parse error: %s\n", optarg);
2721
machine = machine_parse(qemu_opt_get(opts, "type"));
2723
case QEMU_OPTION_no_kvm:
2724
olist = qemu_find_opts("machine");
2725
qemu_opts_reset(olist);
2726
qemu_opts_parse(olist, "accel=tcg", 0);
2729
case QEMU_OPTION_no_kvm_irqchip: {
2734
case QEMU_OPTION_no_kvm_pit: {
2738
case QEMU_OPTION_no_kvm_pit_reinjection: {
2739
kvm_pit_reinject = 0;
2743
case QEMU_OPTION_usb:
2746
case QEMU_OPTION_usbdevice:
2748
add_device_config(DEV_USB, optarg);
2750
case QEMU_OPTION_device:
2751
if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
2755
case QEMU_OPTION_smp:
2758
fprintf(stderr, "Invalid number of CPUs\n");
2761
if (max_cpus < smp_cpus) {
2762
fprintf(stderr, "maxcpus must be equal to or greater than "
2766
if (max_cpus > 255) {
2767
fprintf(stderr, "Unsupported number of maxcpus\n");
2771
case QEMU_OPTION_vnc:
2774
vnc_display = optarg;
2776
fprintf(stderr, "VNC support is disabled\n");
2780
case QEMU_OPTION_no_acpi:
2783
case QEMU_OPTION_no_hpet:
2786
case QEMU_OPTION_balloon:
2787
if (balloon_parse(optarg) < 0) {
2788
fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2792
case QEMU_OPTION_no_reboot:
2795
case QEMU_OPTION_no_shutdown:
2798
case QEMU_OPTION_show_cursor:
2801
case QEMU_OPTION_uuid:
2802
if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2803
fprintf(stderr, "Fail to parse UUID string."
2804
" Wrong format.\n");
2808
case QEMU_OPTION_option_rom:
2809
if (nb_option_roms >= MAX_OPTION_ROMS) {
2810
fprintf(stderr, "Too many option ROMs\n");
2813
opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2814
option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2815
option_rom[nb_option_roms].bootindex =
2816
qemu_opt_get_number(opts, "bootindex", -1);
2817
if (!option_rom[nb_option_roms].name) {
2818
fprintf(stderr, "Option ROM file is not specified\n");
2823
case QEMU_OPTION_semihosting:
2824
semihosting_enabled = 1;
2826
case QEMU_OPTION_tdf:
2829
case QEMU_OPTION_kvm_shadow_memory:
2830
kvm_shadow_memory = (int64_t)atoi(optarg) * 1024 * 1024 / 4096;
2832
case QEMU_OPTION_name:
2833
qemu_name = qemu_strdup(optarg);
2835
char *p = strchr(qemu_name, ',');
2838
if (strncmp(p, "process=", 8)) {
2839
fprintf(stderr, "Unknown subargument %s to -name\n", p);
2843
os_set_proc_name(p);
2847
case QEMU_OPTION_prom_env:
2848
if (nb_prom_envs >= MAX_PROM_ENVS) {
2849
fprintf(stderr, "Too many prom variables\n");
2852
prom_envs[nb_prom_envs] = optarg;
2855
case QEMU_OPTION_old_param:
2858
case QEMU_OPTION_clock:
2859
configure_alarms(optarg);
2861
case QEMU_OPTION_startdate:
2862
configure_rtc_date_offset(optarg, 1);
2864
case QEMU_OPTION_rtc:
2865
opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
2869
configure_rtc(opts);
2871
case QEMU_OPTION_tb_size:
2872
tb_size = strtol(optarg, NULL, 0);
2876
case QEMU_OPTION_icount:
2877
icount_option = optarg;
2879
case QEMU_OPTION_incoming:
2881
incoming_expected = true;
2883
case QEMU_OPTION_nodefaults:
2885
default_parallel = 0;
2886
default_virtcon = 0;
2887
default_monitor = 0;
2895
case QEMU_OPTION_nvram:
2899
case QEMU_OPTION_xen_domid:
2900
if (!(xen_available())) {
2901
printf("Option %s not supported for this target\n", popt->name);
2904
xen_domid = atoi(optarg);
2906
case QEMU_OPTION_xen_create:
2907
if (!(xen_available())) {
2908
printf("Option %s not supported for this target\n", popt->name);
2911
xen_mode = XEN_CREATE;
2913
case QEMU_OPTION_xen_attach:
2914
if (!(xen_available())) {
2915
printf("Option %s not supported for this target\n", popt->name);
2918
xen_mode = XEN_ATTACH;
2920
#ifdef CONFIG_SIMPLE_TRACE
2921
case QEMU_OPTION_trace:
2922
opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2924
trace_file = qemu_opt_get(opts, "file");
2928
case QEMU_OPTION_readconfig:
2930
int ret = qemu_read_config_file(optarg);
2932
fprintf(stderr, "read config %s: %s\n", optarg,
2938
case QEMU_OPTION_spice:
2939
olist = qemu_find_opts("spice");
2941
fprintf(stderr, "spice is not supported by this qemu build.\n");
2944
opts = qemu_opts_parse(olist, optarg, 0);
2946
fprintf(stderr, "parse error: %s\n", optarg);
2950
case QEMU_OPTION_writeconfig:
2953
if (strcmp(optarg, "-") == 0) {
2956
fp = fopen(optarg, "w");
2958
fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2962
qemu_config_write(fp);
2967
os_parse_cmd_args(popt->index, optarg);
2973
/* Open the logfile at this point, if necessary. We can't open the logfile
2974
* when encountering either of the logging options (-d or -D) because the
2975
* other one may be encountered later on the command line, changing the
2976
* location or level of logging.
2980
set_cpu_log_filename(log_file);
2982
set_cpu_log(log_mask);
2985
if (!st_init(trace_file)) {
2986
fprintf(stderr, "warning: unable to initialize simple trace backend\n");
2989
/* If no data_dir is specified then try to find it relative to the
2992
data_dir = os_find_datadir(argv[0]);
2994
/* If all else fails use the install patch specified when building. */
2996
data_dir = CONFIG_QEMU_DATADIR;
3000
* Default to max_cpus = smp_cpus, in case the user doesn't
3001
* specify a max_cpus value.
3004
max_cpus = smp_cpus;
3006
machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
3007
if (smp_cpus > machine->max_cpus) {
3008
fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3009
"supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3015
* Get the default machine options from the machine if it is not already
3016
* specified either by the configuration file or by the command line.
3018
if (machine->default_machine_opts) {
3019
QemuOptsList *list = qemu_find_opts("machine");
3020
const char *p = NULL;
3022
if (!QTAILQ_EMPTY(&list->head)) {
3023
p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
3026
qemu_opts_reset(list);
3027
opts = qemu_opts_parse(list, machine->default_machine_opts, 0);
3029
fprintf(stderr, "parse error for machine %s: %s\n",
3030
machine->name, machine->default_machine_opts);
3036
qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3037
qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
3039
if (machine->no_serial) {
3042
if (machine->no_parallel) {
3043
default_parallel = 0;
3045
if (!machine->use_virtcon) {
3046
default_virtcon = 0;
3048
if (machine->no_vga) {
3051
if (machine->no_floppy) {
3054
if (machine->no_cdrom) {
3057
if (machine->no_sdcard) {
3061
if (display_type == DT_NOGRAPHIC) {
3062
if (default_parallel)
3063
add_device_config(DEV_PARALLEL, "null");
3064
if (default_serial && default_monitor) {
3065
add_device_config(DEV_SERIAL, "mon:stdio");
3066
} else if (default_virtcon && default_monitor) {
3067
add_device_config(DEV_VIRTCON, "mon:stdio");
3070
add_device_config(DEV_SERIAL, "stdio");
3071
if (default_virtcon)
3072
add_device_config(DEV_VIRTCON, "stdio");
3073
if (default_monitor)
3074
monitor_parse("stdio", "readline");
3078
add_device_config(DEV_SERIAL, "vc:80Cx24C");
3079
if (default_parallel)
3080
add_device_config(DEV_PARALLEL, "vc:80Cx24C");
3081
if (default_monitor)
3082
monitor_parse("vc:80Cx24C", "readline");
3083
if (default_virtcon)
3084
add_device_config(DEV_VIRTCON, "vc:80Cx24C");
3087
vga_interface_type = VGA_CIRRUS;
3091
if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
3093
#ifdef CONFIG_VIRTFS
3094
if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
3101
if (pid_file && qemu_create_pidfile(pid_file) != 0) {
3106
configure_accelerator();
3108
if (qemu_init_main_loop()) {
3109
fprintf(stderr, "qemu_init_main_loop failed\n");
3112
linux_boot = (kernel_filename != NULL);
3114
if (!linux_boot && *kernel_cmdline != '\0') {
3115
fprintf(stderr, "-append only allowed with -kernel option\n");
3119
if (!linux_boot && initrd_filename != NULL) {
3120
fprintf(stderr, "-initrd only allowed with -kernel option\n");
3124
os_set_line_buffering();
3126
if (init_timer_alarm() < 0) {
3127
fprintf(stderr, "could not initialize alarm timer\n");
3130
configure_icount(icount_option);
3132
if (net_init_clients() < 0) {
3136
/* init the bluetooth world */
3137
if (foreach_device_config(DEV_BT, bt_parse))
3140
/* init the memory */
3142
ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
3144
/* init the dynamic translator */
3145
cpu_exec_init_all(tb_size * 1024 * 1024);
3147
bdrv_init_with_whitelist();
3151
/* open the virtual block devices */
3153
qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
3154
if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
3157
default_drive(default_cdrom, snapshot, machine->use_scsi,
3158
IF_DEFAULT, 2, CDROM_OPTS);
3159
default_drive(default_floppy, snapshot, machine->use_scsi,
3160
IF_FLOPPY, 0, FD_OPTS);
3161
default_drive(default_sdcard, snapshot, machine->use_scsi,
3164
register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
3167
if (nb_numa_nodes > 0) {
3170
if (nb_numa_nodes > MAX_NODES) {
3171
nb_numa_nodes = MAX_NODES;
3174
/* If no memory size if given for any node, assume the default case
3175
* and distribute the available memory equally across all nodes
3177
for (i = 0; i < nb_numa_nodes; i++) {
3178
if (node_mem[i] != 0)
3181
if (i == nb_numa_nodes) {
3182
uint64_t usedmem = 0;
3184
/* On Linux, the each node's border has to be 8MB aligned,
3185
* the final node gets the rest.
3187
for (i = 0; i < nb_numa_nodes - 1; i++) {
3188
node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3189
usedmem += node_mem[i];
3191
node_mem[i] = ram_size - usedmem;
3194
for (i = 0; i < nb_numa_nodes; i++) {
3195
if (node_cpumask[i] != 0)
3198
/* assigning the VCPUs round-robin is easier to implement, guest OSes
3199
* must cope with this anyway, because there are BIOSes out there in
3200
* real machines which also use this scheme.
3202
if (i == nb_numa_nodes) {
3203
for (i = 0; i < smp_cpus; i++) {
3204
node_cpumask[i % nb_numa_nodes] |= 1 << i;
3209
if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
3213
if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3215
if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3217
if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3219
if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3222
module_call_init(MODULE_INIT_DEVICE);
3224
if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
3228
i = select_watchdog(watchdog);
3230
exit (i == 1 ? 1 : 0);
3233
if (machine->compat_props) {
3234
qdev_prop_register_global_list(machine->compat_props);
3238
machine->init(ram_size, boot_devices,
3239
kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3241
cpu_synchronize_all_post_init();
3245
current_machine = machine;
3247
/* init USB devices */
3249
if (foreach_device_config(DEV_USB, usb_parse) < 0)
3253
/* init generic devices */
3254
if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
3257
net_check_clients();
3259
/* just use the first displaystate for the moment */
3260
ds = get_displaystate();
3264
if (display_type == DT_DEFAULT && !display_remote) {
3265
#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3266
display_type = DT_SDL;
3267
#elif defined(CONFIG_VNC)
3268
vnc_display = "localhost:0,to=99";
3271
display_type = DT_NONE;
3276
/* init local displays */
3277
switch (display_type) {
3280
#if defined(CONFIG_CURSES)
3282
curses_display_init(ds, full_screen);
3285
#if defined(CONFIG_SDL)
3287
sdl_display_init(ds, full_screen, no_frame);
3289
#elif defined(CONFIG_COCOA)
3291
cocoa_display_init(ds, full_screen);
3298
/* must be after terminal init, SDL library changes signal handlers */
3299
os_setup_signal_handling();
3302
/* init remote displays */
3304
vnc_display_init(ds);
3305
if (vnc_display_open(ds, vnc_display) < 0)
3308
if (show_vnc_port) {
3309
printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
3314
if (using_spice && !qxl_enabled) {
3315
qemu_spice_display_init(ds);
3321
dcl = ds->listeners;
3322
while (dcl != NULL) {
3323
if (dcl->dpy_refresh != NULL) {
3324
ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3325
qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
3330
if (ds->gui_timer == NULL) {
3331
nographic_timer = qemu_new_timer_ms(rt_clock, nographic_update, NULL);
3332
qemu_mod_timer(nographic_timer, qemu_get_clock_ms(rt_clock));
3334
text_consoles_set_display(ds);
3336
if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3337
fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3342
qdev_machine_creation_done();
3344
if (rom_load_all() != 0) {
3345
fprintf(stderr, "rom loading failed\n");
3349
/* TODO: once all bus devices are qdevified, this should be done
3350
* when bus is created by qdev.c */
3351
qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
3352
qemu_run_machine_init_done_notifiers();
3354
qemu_system_reset(VMRESET_SILENT);
3356
if (load_vmstate(loadvm) < 0) {
3362
int ret = qemu_start_incoming_migration(incoming);
3364
fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3368
} else if (autostart) {