]> git.proxmox.com Git - qemu.git/blame - vl.c
Add notifier that will be called when machine is fully created.
[qemu.git] / vl.c
CommitLineData
0824d6fc 1/*
80cabfad 2 * QEMU System Emulator
5fafdf24 3 *
68d0f70e 4 * Copyright (c) 2003-2008 Fabrice Bellard
5fafdf24 5 *
1df912cf
FB
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
0824d6fc 23 */
0824d6fc 24#include <unistd.h>
0824d6fc
FB
25#include <fcntl.h>
26#include <signal.h>
27#include <time.h>
0824d6fc 28#include <errno.h>
67b915a5 29#include <sys/time.h>
c88676f8 30#include <zlib.h>
67b915a5 31
71e72a19 32/* Needed early for CONFIG_BSD etc. */
d40cdb10
BS
33#include "config-host.h"
34
67b915a5 35#ifndef _WIN32
5cea8590 36#include <libgen.h>
67b915a5 37#include <sys/times.h>
f1510b2c 38#include <sys/wait.h>
67b915a5 39#include <termios.h>
67b915a5 40#include <sys/mman.h>
f1510b2c 41#include <sys/ioctl.h>
24646c7e 42#include <sys/resource.h>
f1510b2c 43#include <sys/socket.h>
c94c8d64 44#include <netinet/in.h>
24646c7e 45#include <net/if.h>
24646c7e 46#include <arpa/inet.h>
9d728e8c 47#include <dirent.h>
7c9d8e07 48#include <netdb.h>
cb4b976b 49#include <sys/select.h>
ab6540d5
PS
50#ifdef CONFIG_SIMPLE_TRACE
51#include "trace.h"
52#endif
53
71e72a19 54#ifdef CONFIG_BSD
7d3505c5 55#include <sys/stat.h>
a167ba50 56#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
7d3505c5 57#include <libutil.h>
92c0e657 58#include <sys/sysctl.h>
24646c7e
BS
59#else
60#include <util.h>
128ab2ff 61#endif
bbe813a2 62#else
223f0d72 63#ifdef __linux__
7d3505c5
FB
64#include <pty.h>
65#include <malloc.h>
bd494f4c 66
e57a8c0e 67#include <linux/ppdev.h>
5867c88a 68#include <linux/parport.h>
223f0d72
BS
69#endif
70#ifdef __sun__
d5d10bc3
TS
71#include <sys/stat.h>
72#include <sys/ethernet.h>
73#include <sys/sockio.h>
d5d10bc3 74#include <netinet/arp.h>
d5d10bc3
TS
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>
80#include <net/if.h>
81#include <syslog.h>
82#include <stropts.h>
67b915a5 83#endif
7d3505c5 84#endif
ec530c81 85#endif
67b915a5 86
9892fbfb
BS
87#if defined(__OpenBSD__)
88#include <util.h>
89#endif
90
8a16d273
TS
91#if defined(CONFIG_VDE)
92#include <libvdeplug.h>
93#endif
94
67b915a5 95#ifdef _WIN32
49dc768d 96#include <windows.h>
67b915a5
FB
97#endif
98
73332e5c 99#ifdef CONFIG_SDL
59a36a2f 100#if defined(__APPLE__) || defined(main)
6693665a 101#include <SDL.h>
880fec5d 102int qemu_main(int argc, char **argv, char **envp);
103int main(int argc, char **argv)
104{
59a36a2f 105 return qemu_main(argc, argv, NULL);
880fec5d 106}
107#undef main
108#define main qemu_main
96bcd4f8 109#endif
73332e5c 110#endif /* CONFIG_SDL */
0824d6fc 111
5b0753e0
FB
112#ifdef CONFIG_COCOA
113#undef main
114#define main qemu_main
115#endif /* CONFIG_COCOA */
116
511d2b14
BS
117#include "hw/hw.h"
118#include "hw/boards.h"
119#include "hw/usb.h"
120#include "hw/pcmcia.h"
121#include "hw/pc.h"
511d2b14
BS
122#include "hw/isa.h"
123#include "hw/baum.h"
124#include "hw/bt.h"
9dd986cc 125#include "hw/watchdog.h"
b6f6e3d3 126#include "hw/smbios.h"
e37630ca 127#include "hw/xen.h"
bd3c948d 128#include "hw/qdev.h"
45a50b16 129#include "hw/loader.h"
5ef4efa4 130#include "bt-host.h"
511d2b14 131#include "net.h"
68ac40d2 132#include "net/slirp.h"
511d2b14
BS
133#include "monitor.h"
134#include "console.h"
135#include "sysemu.h"
136#include "gdbstub.h"
137#include "qemu-timer.h"
138#include "qemu-char.h"
139#include "cache-utils.h"
140#include "block.h"
666daa68 141#include "blockdev.h"
c163b5ca 142#include "block-migration.h"
a718acec 143#include "dma.h"
511d2b14
BS
144#include "audio/audio.h"
145#include "migration.h"
146#include "kvm.h"
d3f24367 147#include "qemu-option.h"
7282a033 148#include "qemu-config.h"
e78c48ec 149#include "qemu-objects.h"
59a5264b 150#include "qemu-options.h"
758e8e38 151#ifdef CONFIG_VIRTFS
74db920c
GS
152#include "fsdev/qemu-fsdev.h"
153#endif
511d2b14 154
0824d6fc 155#include "disas.h"
fc01f7e7 156
511d2b14
BS
157#include "qemu_socket.h"
158
d918f23e 159#include "slirp/libslirp.h"
511d2b14 160
94b0b5ff 161#include "trace.h"
72cf2d4f 162#include "qemu-queue.h"
296af7c9 163#include "cpus.h"
ad96090a 164#include "arch_init.h"
72cf2d4f 165
29b0040b
GH
166#include "ui/qemu-spice.h"
167
9dc63a1e
BS
168//#define DEBUG_NET
169//#define DEBUG_SLIRP
330d0414 170
1bfe856e 171#define DEFAULT_RAM_SIZE 128
313aa567 172
98b19252
AS
173#define MAX_VIRTIO_CONSOLES 1
174
5cea8590 175static const char *data_dir;
1192dad8 176const char *bios_name = NULL;
cb5a7aa8 177enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
993fbfdb 178DisplayType display_type = DT_DEFAULT;
6b62dc2d 179int display_remote = 0;
3d11d0eb 180const char* keyboard_layout = NULL;
c227f099 181ram_addr_t ram_size;
c902760f
MT
182const char *mem_path = NULL;
183#ifdef MAP_POPULATE
184int mem_prealloc = 0; /* force preallocation of physical target memory */
185#endif
c4b1fcc0 186int nb_nics;
7c9d8e07 187NICInfo nd_table[MAX_NICS];
8a7ddc38 188int vm_running;
d399f677 189int autostart;
8e84865e 190int incoming_expected; /* Started with -incoming and waiting for incoming */
f6503059
AZ
191static int rtc_utc = 1;
192static int rtc_date_offset = -1; /* -1 means no change */
6875204c 193QEMUClock *rtc_clock;
64465297 194int vga_interface_type = VGA_NONE;
dbed7e40 195static int full_screen = 0;
634a21f6 196#ifdef CONFIG_SDL
dbed7e40 197static int no_frame = 0;
634a21f6 198#endif
667accab 199int no_quit = 0;
8d11df9e 200CharDriverState *serial_hds[MAX_SERIAL_PORTS];
6508fe59 201CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
9ede2fde 202CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
a09db21f 203int win2k_install_hack = 0;
73822ec8 204int rtc_td_hack = 0;
bb36d470 205int usb_enabled = 0;
1b530a6d 206int singlestep = 0;
6a00d601 207int smp_cpus = 1;
6be68d7e 208int max_cpus = 0;
dc6b1c09
AP
209int smp_cores = 1;
210int smp_threads = 1;
73fc9742 211const char *vnc_display;
6515b203 212int acpi_enabled = 1;
16b29ae1 213int no_hpet = 0;
52ca8d6a 214int fd_bootchk = 1;
d1beab82 215int no_reboot = 0;
b2f76161 216int no_shutdown = 0;
9467cd46 217int cursor_hide = 1;
a171fe39 218int graphic_rotate = 0;
6b35e7bf 219uint8_t irq0override = 1;
09aaa160 220const char *watchdog;
2e55e842 221QEMUOptionRom option_rom[MAX_OPTION_ROMS];
9ae02555 222int nb_option_roms;
8e71621f 223int semihosting_enabled = 0;
2b8f2d41 224int old_param = 0;
c35734b2 225const char *qemu_name;
3780e197 226int alt_grab = 0;
0ca9f8a4 227int ctrl_grab = 0;
66508601
BS
228unsigned int nb_prom_envs = 0;
229const char *prom_envs[MAX_PROM_ENVS];
95387491 230int boot_menu;
0824d6fc 231
1ca4d09a
GN
232typedef struct FWBootEntry FWBootEntry;
233
234struct FWBootEntry {
235 QTAILQ_ENTRY(FWBootEntry) link;
236 int32_t bootindex;
237 DeviceState *dev;
238 char *suffix;
239};
240
241QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
242
268a362c
AL
243int nb_numa_nodes;
244uint64_t node_mem[MAX_NODES];
245uint64_t node_cpumask[MAX_NODES];
246
9043b62d 247static QEMUTimer *nographic_timer;
ee5605e5 248
8fcb1b90
BS
249uint8_t qemu_uuid[16];
250
76e30d0f
JK
251static QEMUBootSetHandler *boot_set_handler;
252static void *boot_set_opaque;
253
fd42deeb
GH
254static NotifierList exit_notifiers =
255 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
256
4cab946a
GN
257static NotifierList machine_init_done_notifiers =
258 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
259
d745bef8
BS
260int kvm_allowed = 0;
261uint32_t xen_domid;
262enum xen_mode xen_mode = XEN_EMULATE;
263
998bbd74 264static int default_serial = 1;
6a5e8b0e 265static int default_parallel = 1;
986c5f78 266static int default_virtcon = 1;
abdeed06 267static int default_monitor = 1;
64465297 268static int default_vga = 1;
ac33f8fa
GH
269static int default_floppy = 1;
270static int default_cdrom = 1;
271static int default_sdcard = 1;
998bbd74
GH
272
273static struct {
274 const char *driver;
275 int *flag;
276} default_list[] = {
6a5e8b0e
GH
277 { .driver = "isa-serial", .flag = &default_serial },
278 { .driver = "isa-parallel", .flag = &default_parallel },
d8bcbabf
GH
279 { .driver = "isa-fdc", .flag = &default_floppy },
280 { .driver = "ide-drive", .flag = &default_cdrom },
392ecf54
AS
281 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
282 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
283 { .driver = "virtio-serial", .flag = &default_virtcon },
64465297 284 { .driver = "VGA", .flag = &default_vga },
69fd02ee
GH
285 { .driver = "cirrus-vga", .flag = &default_vga },
286 { .driver = "vmware-svga", .flag = &default_vga },
998bbd74
GH
287};
288
289static int default_driver_check(QemuOpts *opts, void *opaque)
290{
291 const char *driver = qemu_opt_get(opts, "driver");
292 int i;
293
294 if (!driver)
295 return 0;
296 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
297 if (strcmp(default_list[i].driver, driver) != 0)
298 continue;
299 *(default_list[i].flag) = 0;
300 }
301 return 0;
302}
303
8f0056b7
PB
304/***********************************************************/
305/* real time host monotonic timer */
09b26c5e 306
f6503059
AZ
307/***********************************************************/
308/* host time/date access */
309void qemu_get_timedate(struct tm *tm, int offset)
310{
311 time_t ti;
312 struct tm *ret;
313
314 time(&ti);
315 ti += offset;
316 if (rtc_date_offset == -1) {
317 if (rtc_utc)
318 ret = gmtime(&ti);
319 else
320 ret = localtime(&ti);
321 } else {
322 ti -= rtc_date_offset;
323 ret = gmtime(&ti);
324 }
325
326 memcpy(tm, ret, sizeof(struct tm));
327}
328
329int qemu_timedate_diff(struct tm *tm)
330{
331 time_t seconds;
332
333 if (rtc_date_offset == -1)
334 if (rtc_utc)
335 seconds = mktimegm(tm);
336 else
337 seconds = mktime(tm);
338 else
339 seconds = mktimegm(tm) + rtc_date_offset;
340
341 return seconds - time(NULL);
342}
343
80cd3478
LC
344void rtc_change_mon_event(struct tm *tm)
345{
346 QObject *data;
347
348 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
349 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
350 qobject_decref(data);
351}
352
1ed2fc1f
JK
353static void configure_rtc_date_offset(const char *startdate, int legacy)
354{
355 time_t rtc_start_date;
356 struct tm tm;
357
358 if (!strcmp(startdate, "now") && legacy) {
359 rtc_date_offset = -1;
360 } else {
361 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
362 &tm.tm_year,
363 &tm.tm_mon,
364 &tm.tm_mday,
365 &tm.tm_hour,
366 &tm.tm_min,
367 &tm.tm_sec) == 6) {
368 /* OK */
369 } else if (sscanf(startdate, "%d-%d-%d",
370 &tm.tm_year,
371 &tm.tm_mon,
372 &tm.tm_mday) == 3) {
373 tm.tm_hour = 0;
374 tm.tm_min = 0;
375 tm.tm_sec = 0;
376 } else {
377 goto date_fail;
378 }
379 tm.tm_year -= 1900;
380 tm.tm_mon--;
381 rtc_start_date = mktimegm(&tm);
382 if (rtc_start_date == -1) {
383 date_fail:
384 fprintf(stderr, "Invalid date format. Valid formats are:\n"
385 "'2006-06-17T16:01:21' or '2006-06-17'\n");
386 exit(1);
387 }
388 rtc_date_offset = time(NULL) - rtc_start_date;
389 }
390}
391
392static void configure_rtc(QemuOpts *opts)
393{
394 const char *value;
395
396 value = qemu_opt_get(opts, "base");
397 if (value) {
398 if (!strcmp(value, "utc")) {
399 rtc_utc = 1;
400 } else if (!strcmp(value, "localtime")) {
401 rtc_utc = 0;
402 } else {
403 configure_rtc_date_offset(value, 0);
404 }
405 }
6875204c
JK
406 value = qemu_opt_get(opts, "clock");
407 if (value) {
408 if (!strcmp(value, "host")) {
409 rtc_clock = host_clock;
410 } else if (!strcmp(value, "vm")) {
411 rtc_clock = vm_clock;
412 } else {
413 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
414 exit(1);
415 }
416 }
1ed2fc1f
JK
417 value = qemu_opt_get(opts, "driftfix");
418 if (value) {
7e4c0336 419 if (!strcmp(value, "slew")) {
1ed2fc1f 420 rtc_td_hack = 1;
7e4c0336 421 } else if (!strcmp(value, "none")) {
1ed2fc1f
JK
422 rtc_td_hack = 0;
423 } else {
424 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
425 exit(1);
426 }
427 }
1ed2fc1f
JK
428}
429
1ae26a18
AZ
430/***********************************************************/
431/* Bluetooth support */
432static int nb_hcis;
433static int cur_hci;
434static struct HCIInfo *hci_table[MAX_NICS];
dc72ac14 435
1ae26a18
AZ
436static struct bt_vlan_s {
437 struct bt_scatternet_s net;
438 int id;
439 struct bt_vlan_s *next;
440} *first_bt_vlan;
441
442/* find or alloc a new bluetooth "VLAN" */
674bb261 443static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
1ae26a18
AZ
444{
445 struct bt_vlan_s **pvlan, *vlan;
446 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
447 if (vlan->id == id)
448 return &vlan->net;
449 }
450 vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
451 vlan->id = id;
452 pvlan = &first_bt_vlan;
453 while (*pvlan != NULL)
454 pvlan = &(*pvlan)->next;
455 *pvlan = vlan;
456 return &vlan->net;
457}
458
459static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
460{
461}
462
463static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
464{
465 return -ENOTSUP;
466}
467
468static struct HCIInfo null_hci = {
469 .cmd_send = null_hci_send,
470 .sco_send = null_hci_send,
471 .acl_send = null_hci_send,
472 .bdaddr_set = null_hci_addr_set,
473};
474
475struct HCIInfo *qemu_next_hci(void)
476{
477 if (cur_hci == nb_hcis)
478 return &null_hci;
479
480 return hci_table[cur_hci++];
481}
482
dc72ac14
AZ
483static struct HCIInfo *hci_init(const char *str)
484{
485 char *endp;
486 struct bt_scatternet_s *vlan = 0;
487
488 if (!strcmp(str, "null"))
489 /* null */
490 return &null_hci;
491 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
492 /* host[:hciN] */
493 return bt_host_hci(str[4] ? str + 5 : "hci0");
494 else if (!strncmp(str, "hci", 3)) {
495 /* hci[,vlan=n] */
496 if (str[3]) {
497 if (!strncmp(str + 3, ",vlan=", 6)) {
498 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
499 if (*endp)
500 vlan = 0;
501 }
502 } else
503 vlan = qemu_find_bt_vlan(0);
504 if (vlan)
505 return bt_new_hci(vlan);
506 }
507
508 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
509
510 return 0;
511}
512
513static int bt_hci_parse(const char *str)
514{
515 struct HCIInfo *hci;
c227f099 516 bdaddr_t bdaddr;
dc72ac14
AZ
517
518 if (nb_hcis >= MAX_NICS) {
519 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
520 return -1;
521 }
522
523 hci = hci_init(str);
524 if (!hci)
525 return -1;
526
527 bdaddr.b[0] = 0x52;
528 bdaddr.b[1] = 0x54;
529 bdaddr.b[2] = 0x00;
530 bdaddr.b[3] = 0x12;
531 bdaddr.b[4] = 0x34;
532 bdaddr.b[5] = 0x56 + nb_hcis;
533 hci->bdaddr_set(hci, bdaddr.b);
534
535 hci_table[nb_hcis++] = hci;
536
537 return 0;
538}
539
540static void bt_vhci_add(int vlan_id)
541{
542 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
543
544 if (!vlan->slave)
545 fprintf(stderr, "qemu: warning: adding a VHCI to "
546 "an empty scatternet %i\n", vlan_id);
547
548 bt_vhci_init(bt_new_hci(vlan));
549}
550
551static struct bt_device_s *bt_device_add(const char *opt)
552{
553 struct bt_scatternet_s *vlan;
554 int vlan_id = 0;
555 char *endp = strstr(opt, ",vlan=");
556 int len = (endp ? endp - opt : strlen(opt)) + 1;
557 char devname[10];
558
559 pstrcpy(devname, MIN(sizeof(devname), len), opt);
560
561 if (endp) {
562 vlan_id = strtol(endp + 6, &endp, 0);
563 if (*endp) {
564 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
565 return 0;
566 }
567 }
568
569 vlan = qemu_find_bt_vlan(vlan_id);
570
571 if (!vlan->slave)
572 fprintf(stderr, "qemu: warning: adding a slave device to "
573 "an empty scatternet %i\n", vlan_id);
574
575 if (!strcmp(devname, "keyboard"))
576 return bt_keyboard_init(vlan);
577
578 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
579 return 0;
580}
581
582static int bt_parse(const char *opt)
583{
584 const char *endp, *p;
585 int vlan;
586
587 if (strstart(opt, "hci", &endp)) {
588 if (!*endp || *endp == ',') {
589 if (*endp)
590 if (!strstart(endp, ",vlan=", 0))
591 opt = endp + 1;
592
593 return bt_hci_parse(opt);
594 }
595 } else if (strstart(opt, "vhci", &endp)) {
596 if (!*endp || *endp == ',') {
597 if (*endp) {
598 if (strstart(endp, ",vlan=", &p)) {
599 vlan = strtol(p, (char **) &endp, 0);
600 if (*endp) {
601 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
602 return 1;
603 }
604 } else {
605 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
606 return 1;
607 }
608 } else
609 vlan = 0;
610
611 bt_vhci_add(vlan);
612 return 0;
613 }
614 } else if (strstart(opt, "device:", &endp))
615 return !bt_device_add(endp);
616
617 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
618 return 1;
619}
620
1ae26a18
AZ
621/***********************************************************/
622/* QEMU Block devices */
623
609497ab 624#define HD_ALIAS "index=%d,media=disk"
e4bcb14c 625#define CDROM_ALIAS "index=2,media=cdrom"
e4bcb14c 626#define FD_ALIAS "index=%d,if=floppy"
609497ab
AZ
627#define PFLASH_ALIAS "if=pflash"
628#define MTD_ALIAS "if=mtd"
9d413d1d 629#define SD_ALIAS "index=0,if=sd"
e4bcb14c 630
9dfd7c7a
GH
631static int drive_init_func(QemuOpts *opts, void *opaque)
632{
a803cb8e 633 int *use_scsi = opaque;
9dfd7c7a
GH
634 int fatal_error = 0;
635
a803cb8e 636 if (drive_init(opts, *use_scsi, &fatal_error) == NULL) {
9dfd7c7a
GH
637 if (fatal_error)
638 return 1;
639 }
640 return 0;
641}
642
643static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
644{
645 if (NULL == qemu_opt_get(opts, "snapshot")) {
646 qemu_opt_set(opts, "snapshot", "on");
647 }
648 return 0;
649}
650
76e30d0f
JK
651void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
652{
653 boot_set_handler = func;
654 boot_set_opaque = opaque;
655}
656
657int qemu_boot_set(const char *boot_devices)
658{
659 if (!boot_set_handler) {
660 return -EINVAL;
661 }
662 return boot_set_handler(boot_set_opaque, boot_devices);
663}
664
4e9e9d6e 665static void validate_bootdevices(char *devices)
ef3adf68
JK
666{
667 /* We just do some generic consistency checks */
668 const char *p;
669 int bitmap = 0;
670
671 for (p = devices; *p != '\0'; p++) {
672 /* Allowed boot devices are:
673 * a-b: floppy disk drives
674 * c-f: IDE disk drives
675 * g-m: machine implementation dependant drives
676 * n-p: network devices
677 * It's up to each machine implementation to check if the given boot
678 * devices match the actual hardware implementation and firmware
679 * features.
680 */
681 if (*p < 'a' || *p > 'p') {
682 fprintf(stderr, "Invalid boot device '%c'\n", *p);
683 exit(1);
684 }
685 if (bitmap & (1 << (*p - 'a'))) {
686 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
687 exit(1);
688 }
689 bitmap |= 1 << (*p - 'a');
690 }
ef3adf68
JK
691}
692
e0f084bf
JK
693static void restore_boot_devices(void *opaque)
694{
695 char *standard_boot_devices = opaque;
37905d6a
AW
696 static int first = 1;
697
698 /* Restore boot order and remove ourselves after the first boot */
699 if (first) {
700 first = 0;
701 return;
702 }
e0f084bf
JK
703
704 qemu_boot_set(standard_boot_devices);
705
706 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
707 qemu_free(standard_boot_devices);
708}
709
1ca4d09a
GN
710void add_boot_device_path(int32_t bootindex, DeviceState *dev,
711 const char *suffix)
712{
713 FWBootEntry *node, *i;
714
715 if (bootindex < 0) {
716 return;
717 }
718
719 assert(dev != NULL || suffix != NULL);
720
721 node = qemu_mallocz(sizeof(FWBootEntry));
722 node->bootindex = bootindex;
723 node->suffix = strdup(suffix);
724 node->dev = dev;
725
726 QTAILQ_FOREACH(i, &fw_boot_order, link) {
727 if (i->bootindex == bootindex) {
728 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
729 exit(1);
730 } else if (i->bootindex < bootindex) {
731 continue;
732 }
733 QTAILQ_INSERT_BEFORE(i, node, link);
734 return;
735 }
736 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
737}
738
268a362c
AL
739static void numa_add(const char *optarg)
740{
741 char option[128];
742 char *endptr;
743 unsigned long long value, endvalue;
744 int nodenr;
745
746 optarg = get_opt_name(option, 128, optarg, ',') + 1;
747 if (!strcmp(option, "node")) {
748 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
749 nodenr = nb_numa_nodes;
750 } else {
751 nodenr = strtoull(option, NULL, 10);
752 }
753
754 if (get_param_value(option, 128, "mem", optarg) == 0) {
755 node_mem[nodenr] = 0;
756 } else {
9f9b17a4
JS
757 ssize_t sval;
758 sval = strtosz(option, NULL);
759 if (sval < 0) {
760 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
761 exit(1);
268a362c 762 }
9f9b17a4 763 node_mem[nodenr] = sval;
268a362c
AL
764 }
765 if (get_param_value(option, 128, "cpus", optarg) == 0) {
766 node_cpumask[nodenr] = 0;
767 } else {
768 value = strtoull(option, &endptr, 10);
769 if (value >= 64) {
770 value = 63;
771 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
772 } else {
773 if (*endptr == '-') {
774 endvalue = strtoull(endptr+1, &endptr, 10);
775 if (endvalue >= 63) {
776 endvalue = 62;
777 fprintf(stderr,
778 "only 63 CPUs in NUMA mode supported.\n");
779 }
0dfbd514 780 value = (2ULL << endvalue) - (1ULL << value);
268a362c 781 } else {
0dfbd514 782 value = 1ULL << value;
268a362c
AL
783 }
784 }
785 node_cpumask[nodenr] = value;
786 }
787 nb_numa_nodes++;
788 }
789 return;
790}
791
dc6b1c09
AP
792static void smp_parse(const char *optarg)
793{
794 int smp, sockets = 0, threads = 0, cores = 0;
795 char *endptr;
796 char option[128];
797
798 smp = strtoul(optarg, &endptr, 10);
799 if (endptr != optarg) {
800 if (*endptr == ',') {
801 endptr++;
802 }
803 }
804 if (get_param_value(option, 128, "sockets", endptr) != 0)
805 sockets = strtoull(option, NULL, 10);
806 if (get_param_value(option, 128, "cores", endptr) != 0)
807 cores = strtoull(option, NULL, 10);
808 if (get_param_value(option, 128, "threads", endptr) != 0)
809 threads = strtoull(option, NULL, 10);
810 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
811 max_cpus = strtoull(option, NULL, 10);
812
813 /* compute missing values, prefer sockets over cores over threads */
814 if (smp == 0 || sockets == 0) {
815 sockets = sockets > 0 ? sockets : 1;
816 cores = cores > 0 ? cores : 1;
817 threads = threads > 0 ? threads : 1;
818 if (smp == 0) {
819 smp = cores * threads * sockets;
dc6b1c09
AP
820 }
821 } else {
822 if (cores == 0) {
823 threads = threads > 0 ? threads : 1;
824 cores = smp / (sockets * threads);
825 } else {
dca98169 826 threads = smp / (cores * sockets);
dc6b1c09
AP
827 }
828 }
829 smp_cpus = smp;
830 smp_cores = cores > 0 ? cores : 1;
831 smp_threads = threads > 0 ? threads : 1;
832 if (max_cpus == 0)
833 max_cpus = smp_cpus;
834}
835
a594cfbf
FB
836/***********************************************************/
837/* USB devices */
838
fb08000c 839static int usb_device_add(const char *devname)
a594cfbf
FB
840{
841 const char *p;
a5d2f727 842 USBDevice *dev = NULL;
a594cfbf 843
a5d2f727 844 if (!usb_enabled)
a594cfbf
FB
845 return -1;
846
0958b4cc
GH
847 /* drivers with .usbdevice_name entry in USBDeviceInfo */
848 dev = usbdevice_create(devname);
849 if (dev)
850 goto done;
851
a5d2f727 852 /* the other ones */
a594cfbf
FB
853 if (strstart(devname, "host:", &p)) {
854 dev = usb_host_device_open(p);
dc72ac14
AZ
855 } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
856 dev = usb_bt_init(devname[2] ? hci_init(p) :
857 bt_new_hci(qemu_find_bt_vlan(0)));
a594cfbf
FB
858 } else {
859 return -1;
860 }
0d92ed30
PB
861 if (!dev)
862 return -1;
863
a5d2f727 864done:
a594cfbf
FB
865 return 0;
866}
867
1f3870ab
AL
868static int usb_device_del(const char *devname)
869{
870 int bus_num, addr;
871 const char *p;
872
5d0c5750
AL
873 if (strstart(devname, "host:", &p))
874 return usb_host_device_close(p);
875
a5d2f727 876 if (!usb_enabled)
1f3870ab
AL
877 return -1;
878
879 p = strchr(devname, '.');
880 if (!p)
881 return -1;
882 bus_num = strtoul(devname, NULL, 0);
883 addr = strtoul(p + 1, NULL, 0);
884
a5d2f727 885 return usb_device_delete_addr(bus_num, addr);
1f3870ab
AL
886}
887
bd3c948d
GH
888static int usb_parse(const char *cmdline)
889{
59d1c1c2 890 int r;
fb08000c 891 r = usb_device_add(cmdline);
59d1c1c2
ST
892 if (r < 0) {
893 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
894 }
895 return r;
bd3c948d
GH
896}
897
d54908a5 898void do_usb_add(Monitor *mon, const QDict *qdict)
a594cfbf 899{
59d1c1c2 900 const char *devname = qdict_get_str(qdict, "devname");
fb08000c 901 if (usb_device_add(devname) < 0) {
1ecda02b 902 error_report("could not add USB device '%s'", devname);
59d1c1c2 903 }
a594cfbf
FB
904}
905
d54908a5 906void do_usb_del(Monitor *mon, const QDict *qdict)
a594cfbf 907{
59d1c1c2
ST
908 const char *devname = qdict_get_str(qdict, "devname");
909 if (usb_device_del(devname) < 0) {
1ecda02b 910 error_report("could not delete USB device '%s'", devname);
59d1c1c2 911 }
a594cfbf
FB
912}
913
201a51fc
AZ
914/***********************************************************/
915/* PCMCIA/Cardbus */
916
917static struct pcmcia_socket_entry_s {
bc24a225 918 PCMCIASocket *socket;
201a51fc
AZ
919 struct pcmcia_socket_entry_s *next;
920} *pcmcia_sockets = 0;
921
bc24a225 922void pcmcia_socket_register(PCMCIASocket *socket)
201a51fc
AZ
923{
924 struct pcmcia_socket_entry_s *entry;
925
926 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
927 entry->socket = socket;
928 entry->next = pcmcia_sockets;
929 pcmcia_sockets = entry;
930}
931
bc24a225 932void pcmcia_socket_unregister(PCMCIASocket *socket)
201a51fc
AZ
933{
934 struct pcmcia_socket_entry_s *entry, **ptr;
935
936 ptr = &pcmcia_sockets;
937 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
938 if (entry->socket == socket) {
939 *ptr = entry->next;
940 qemu_free(entry);
941 }
942}
943
376253ec 944void pcmcia_info(Monitor *mon)
201a51fc
AZ
945{
946 struct pcmcia_socket_entry_s *iter;
376253ec 947
201a51fc 948 if (!pcmcia_sockets)
376253ec 949 monitor_printf(mon, "No PCMCIA sockets\n");
201a51fc
AZ
950
951 for (iter = pcmcia_sockets; iter; iter = iter->next)
376253ec
AL
952 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
953 iter->socket->attached ? iter->socket->card_string :
954 "Empty");
201a51fc
AZ
955}
956
2ff89790 957/***********************************************************/
8a7ddc38 958/* I/O handling */
0824d6fc 959
c4b1fcc0
FB
960typedef struct IOHandlerRecord {
961 int fd;
7b27a769 962 IOCanReadHandler *fd_read_poll;
7c9d8e07
FB
963 IOHandler *fd_read;
964 IOHandler *fd_write;
cafffd40 965 int deleted;
c4b1fcc0
FB
966 void *opaque;
967 /* temporary data */
968 struct pollfd *ufd;
31d4ee6c 969 QLIST_ENTRY(IOHandlerRecord) next;
c4b1fcc0
FB
970} IOHandlerRecord;
971
31d4ee6c
JQ
972static QLIST_HEAD(, IOHandlerRecord) io_handlers =
973 QLIST_HEAD_INITIALIZER(io_handlers);
974
c4b1fcc0 975
7c9d8e07
FB
976/* XXX: fd_read_poll should be suppressed, but an API change is
977 necessary in the character devices to suppress fd_can_read(). */
5fafdf24 978int qemu_set_fd_handler2(int fd,
7b27a769 979 IOCanReadHandler *fd_read_poll,
5fafdf24
TS
980 IOHandler *fd_read,
981 IOHandler *fd_write,
7c9d8e07 982 void *opaque)
c4b1fcc0 983{
31d4ee6c 984 IOHandlerRecord *ioh;
c4b1fcc0 985
7c9d8e07 986 if (!fd_read && !fd_write) {
31d4ee6c 987 QLIST_FOREACH(ioh, &io_handlers, next) {
7c9d8e07 988 if (ioh->fd == fd) {
cafffd40 989 ioh->deleted = 1;
7c9d8e07
FB
990 break;
991 }
7c9d8e07
FB
992 }
993 } else {
31d4ee6c 994 QLIST_FOREACH(ioh, &io_handlers, next) {
7c9d8e07
FB
995 if (ioh->fd == fd)
996 goto found;
997 }
998 ioh = qemu_mallocz(sizeof(IOHandlerRecord));
31d4ee6c 999 QLIST_INSERT_HEAD(&io_handlers, ioh, next);
7c9d8e07
FB
1000 found:
1001 ioh->fd = fd;
1002 ioh->fd_read_poll = fd_read_poll;
1003 ioh->fd_read = fd_read;
1004 ioh->fd_write = fd_write;
1005 ioh->opaque = opaque;
cafffd40 1006 ioh->deleted = 0;
7c9d8e07 1007 }
c4b1fcc0
FB
1008 return 0;
1009}
1010
5fafdf24
TS
1011int qemu_set_fd_handler(int fd,
1012 IOHandler *fd_read,
1013 IOHandler *fd_write,
7c9d8e07 1014 void *opaque)
8a7ddc38 1015{
7c9d8e07 1016 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
8a7ddc38
FB
1017}
1018
cc1daa40
FB
1019/***********************************************************/
1020/* machine registration */
1021
bdaf78e0 1022static QEMUMachine *first_machine = NULL;
6f338c34 1023QEMUMachine *current_machine = NULL;
cc1daa40
FB
1024
1025int qemu_register_machine(QEMUMachine *m)
1026{
1027 QEMUMachine **pm;
1028 pm = &first_machine;
1029 while (*pm != NULL)
1030 pm = &(*pm)->next;
1031 m->next = NULL;
1032 *pm = m;
1033 return 0;
1034}
1035
9596ebb7 1036static QEMUMachine *find_machine(const char *name)
cc1daa40
FB
1037{
1038 QEMUMachine *m;
1039
1040 for(m = first_machine; m != NULL; m = m->next) {
1041 if (!strcmp(m->name, name))
1042 return m;
3f6599e6
MM
1043 if (m->alias && !strcmp(m->alias, name))
1044 return m;
cc1daa40
FB
1045 }
1046 return NULL;
1047}
1048
0c257437
AL
1049static QEMUMachine *find_default_machine(void)
1050{
1051 QEMUMachine *m;
1052
1053 for(m = first_machine; m != NULL; m = m->next) {
1054 if (m->is_default) {
1055 return m;
1056 }
1057 }
1058 return NULL;
1059}
1060
8a7ddc38
FB
1061/***********************************************************/
1062/* main execution loop */
1063
9596ebb7 1064static void gui_update(void *opaque)
8a7ddc38 1065{
7d957bd8 1066 uint64_t interval = GUI_REFRESH_INTERVAL;
740733bb 1067 DisplayState *ds = opaque;
7d957bd8
AL
1068 DisplayChangeListener *dcl = ds->listeners;
1069
62a2744c 1070 qemu_flush_coalesced_mmio_buffer();
7d957bd8
AL
1071 dpy_refresh(ds);
1072
1073 while (dcl != NULL) {
1074 if (dcl->gui_timer_interval &&
1075 dcl->gui_timer_interval < interval)
1076 interval = dcl->gui_timer_interval;
1077 dcl = dcl->next;
1078 }
1079 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
8a7ddc38
FB
1080}
1081
9043b62d
BS
1082static void nographic_update(void *opaque)
1083{
1084 uint64_t interval = GUI_REFRESH_INTERVAL;
1085
62a2744c 1086 qemu_flush_coalesced_mmio_buffer();
9043b62d
BS
1087 qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
1088}
1089
0bd48850
FB
1090struct vm_change_state_entry {
1091 VMChangeStateHandler *cb;
1092 void *opaque;
72cf2d4f 1093 QLIST_ENTRY (vm_change_state_entry) entries;
0bd48850
FB
1094};
1095
72cf2d4f 1096static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
0bd48850
FB
1097
1098VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1099 void *opaque)
1100{
1101 VMChangeStateEntry *e;
1102
1103 e = qemu_mallocz(sizeof (*e));
0bd48850
FB
1104
1105 e->cb = cb;
1106 e->opaque = opaque;
72cf2d4f 1107 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
0bd48850
FB
1108 return e;
1109}
1110
1111void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1112{
72cf2d4f 1113 QLIST_REMOVE (e, entries);
0bd48850
FB
1114 qemu_free (e);
1115}
1116
296af7c9 1117void vm_state_notify(int running, int reason)
0bd48850
FB
1118{
1119 VMChangeStateEntry *e;
1120
94b0b5ff
SH
1121 trace_vm_state_notify(running, reason);
1122
0bd48850 1123 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
9781e040 1124 e->cb(e->opaque, running, reason);
0bd48850
FB
1125 }
1126}
1127
8a7ddc38
FB
1128void vm_start(void)
1129{
1130 if (!vm_running) {
1131 cpu_enable_ticks();
1132 vm_running = 1;
9781e040 1133 vm_state_notify(1, 0);
d6dc3d42 1134 resume_all_vcpus();
6ed2c484 1135 monitor_protocol_event(QEVENT_RESUME, NULL);
8a7ddc38
FB
1136 }
1137}
1138
bb0c6722
FB
1139/* reset/shutdown handler */
1140
1141typedef struct QEMUResetEntry {
72cf2d4f 1142 QTAILQ_ENTRY(QEMUResetEntry) entry;
bb0c6722
FB
1143 QEMUResetHandler *func;
1144 void *opaque;
bb0c6722
FB
1145} QEMUResetEntry;
1146
72cf2d4f
BS
1147static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1148 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bb0c6722
FB
1149static int reset_requested;
1150static int shutdown_requested;
3475187d 1151static int powerdown_requested;
296af7c9 1152int debug_requested;
7277e027 1153int vmstop_requested;
bb0c6722 1154
cf7a2fe2
AJ
1155int qemu_shutdown_requested(void)
1156{
1157 int r = shutdown_requested;
1158 shutdown_requested = 0;
1159 return r;
1160}
1161
1162int qemu_reset_requested(void)
1163{
1164 int r = reset_requested;
1165 reset_requested = 0;
1166 return r;
1167}
1168
1169int qemu_powerdown_requested(void)
1170{
1171 int r = powerdown_requested;
1172 powerdown_requested = 0;
1173 return r;
1174}
1175
e568902a
AL
1176static int qemu_debug_requested(void)
1177{
1178 int r = debug_requested;
1179 debug_requested = 0;
1180 return r;
1181}
1182
6e29f5da
AL
1183static int qemu_vmstop_requested(void)
1184{
1185 int r = vmstop_requested;
1186 vmstop_requested = 0;
1187 return r;
1188}
1189
a08d4367 1190void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bb0c6722 1191{
55ddfe8e 1192 QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
bb0c6722 1193
bb0c6722
FB
1194 re->func = func;
1195 re->opaque = opaque;
72cf2d4f 1196 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bb0c6722
FB
1197}
1198
dda9b29f 1199void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bb0c6722
FB
1200{
1201 QEMUResetEntry *re;
1202
72cf2d4f 1203 QTAILQ_FOREACH(re, &reset_handlers, entry) {
dda9b29f 1204 if (re->func == func && re->opaque == opaque) {
72cf2d4f 1205 QTAILQ_REMOVE(&reset_handlers, re, entry);
dda9b29f
JK
1206 qemu_free(re);
1207 return;
1208 }
1209 }
1210}
1211
1212void qemu_system_reset(void)
1213{
1214 QEMUResetEntry *re, *nre;
1215
1216 /* reset all devices */
72cf2d4f 1217 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bb0c6722
FB
1218 re->func(re->opaque);
1219 }
81d9b784 1220 monitor_protocol_event(QEVENT_RESET, NULL);
ea375f9a 1221 cpu_synchronize_all_post_reset();
bb0c6722
FB
1222}
1223
1224void qemu_system_reset_request(void)
1225{
d1beab82
FB
1226 if (no_reboot) {
1227 shutdown_requested = 1;
1228 } else {
1229 reset_requested = 1;
1230 }
d9f75a4e 1231 qemu_notify_event();
bb0c6722
FB
1232}
1233
1234void qemu_system_shutdown_request(void)
1235{
1236 shutdown_requested = 1;
d9f75a4e 1237 qemu_notify_event();
bb0c6722
FB
1238}
1239
3475187d
FB
1240void qemu_system_powerdown_request(void)
1241{
1242 powerdown_requested = 1;
d9f75a4e
AL
1243 qemu_notify_event();
1244}
1245
d6f4ade2 1246void main_loop_wait(int nonblocking)
56f3a5d0
AL
1247{
1248 IOHandlerRecord *ioh;
1249 fd_set rfds, wfds, xfds;
1250 int ret, nfds;
1251 struct timeval tv;
d6f4ade2 1252 int timeout;
56f3a5d0 1253
d6f4ade2
PB
1254 if (nonblocking)
1255 timeout = 0;
1256 else {
1257 timeout = qemu_calculate_timeout();
1258 qemu_bh_update_timeout(&timeout);
1259 }
56f3a5d0 1260
0d93ca7c 1261 os_host_main_loop_wait(&timeout);
56f3a5d0 1262
fd1dff4b
FB
1263 /* poll any events */
1264 /* XXX: separate device handlers from system ones */
6abfbd79 1265 nfds = -1;
fd1dff4b
FB
1266 FD_ZERO(&rfds);
1267 FD_ZERO(&wfds);
e035649e 1268 FD_ZERO(&xfds);
31d4ee6c 1269 QLIST_FOREACH(ioh, &io_handlers, next) {
cafffd40
TS
1270 if (ioh->deleted)
1271 continue;
fd1dff4b
FB
1272 if (ioh->fd_read &&
1273 (!ioh->fd_read_poll ||
1274 ioh->fd_read_poll(ioh->opaque) != 0)) {
1275 FD_SET(ioh->fd, &rfds);
1276 if (ioh->fd > nfds)
1277 nfds = ioh->fd;
1278 }
1279 if (ioh->fd_write) {
1280 FD_SET(ioh->fd, &wfds);
1281 if (ioh->fd > nfds)
1282 nfds = ioh->fd;
1283 }
1284 }
3b46e624 1285
56f3a5d0
AL
1286 tv.tv_sec = timeout / 1000;
1287 tv.tv_usec = (timeout % 1000) * 1000;
1288
d918f23e
JK
1289 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
1290
4870852c 1291 qemu_mutex_unlock_iothread();
e035649e 1292 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
4870852c 1293 qemu_mutex_lock_iothread();
fd1dff4b 1294 if (ret > 0) {
31d4ee6c 1295 IOHandlerRecord *pioh;
cafffd40 1296
31d4ee6c 1297 QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
0290b57b 1298 if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
4bed9837
JQ
1299 ioh->fd_read(ioh->opaque);
1300 }
0290b57b 1301 if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
4bed9837 1302 ioh->fd_write(ioh->opaque);
31d4ee6c 1303 }
0290b57b
SH
1304
1305 /* Do this last in case read/write handlers marked it for deletion */
1306 if (ioh->deleted) {
1307 QLIST_REMOVE(ioh, next);
1308 qemu_free(ioh);
1309 }
cafffd40 1310 }
fd1dff4b 1311 }
d918f23e
JK
1312
1313 slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
b4608c04 1314
b6964827 1315 qemu_run_all_timers();
21d5d12b 1316
423f0742
PB
1317 /* Check bottom-halves last in case any of the earlier events triggered
1318 them. */
1319 qemu_bh_poll();
3b46e624 1320
5905b2e5
FB
1321}
1322
43b96858
AL
1323static int vm_can_run(void)
1324{
1325 if (powerdown_requested)
1326 return 0;
1327 if (reset_requested)
1328 return 0;
1329 if (shutdown_requested)
1330 return 0;
e568902a
AL
1331 if (debug_requested)
1332 return 0;
43b96858
AL
1333 return 1;
1334}
1335
d9c32310
BS
1336qemu_irq qemu_system_powerdown;
1337
43b96858
AL
1338static void main_loop(void)
1339{
6e29f5da 1340 int r;
e6e35b1e 1341
7277e027 1342 qemu_main_loop_start();
d6dc3d42 1343
6e29f5da 1344 for (;;) {
43b96858 1345 do {
d6f4ade2 1346 bool nonblocking = false;
e6e35b1e
AL
1347#ifdef CONFIG_PROFILER
1348 int64_t ti;
1349#endif
d6dc3d42 1350#ifndef CONFIG_IOTHREAD
472fb0c4 1351 nonblocking = cpu_exec_all();
d6dc3d42 1352#endif
89bfc105 1353#ifdef CONFIG_PROFILER
43b96858 1354 ti = profile_getclock();
89bfc105 1355#endif
d6f4ade2 1356 main_loop_wait(nonblocking);
89bfc105 1357#ifdef CONFIG_PROFILER
43b96858 1358 dev_time += profile_getclock() - ti;
89bfc105 1359#endif
e568902a 1360 } while (vm_can_run());
43b96858 1361
54fc6ea9
BS
1362 if ((r = qemu_debug_requested())) {
1363 vm_stop(r);
b1a15e7e 1364 }
43b96858 1365 if (qemu_shutdown_requested()) {
242cd003 1366 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
43b96858
AL
1367 if (no_shutdown) {
1368 vm_stop(0);
1369 no_shutdown = 0;
1370 } else
1371 break;
1372 }
d6dc3d42
AL
1373 if (qemu_reset_requested()) {
1374 pause_all_vcpus();
43b96858 1375 qemu_system_reset();
d6dc3d42
AL
1376 resume_all_vcpus();
1377 }
d9c32310 1378 if (qemu_powerdown_requested()) {
242cd003 1379 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
d9c32310
BS
1380 qemu_irq_raise(qemu_system_powerdown);
1381 }
b1a15e7e 1382 if ((r = qemu_vmstop_requested())) {
6e29f5da 1383 vm_stop(r);
b1a15e7e 1384 }
b4608c04 1385 }
2bc93fed 1386 bdrv_close_all();
d6dc3d42 1387 pause_all_vcpus();
b4608c04
FB
1388}
1389
9bd7e6d9
PB
1390static void version(void)
1391{
f75ca1ae 1392 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
9bd7e6d9
PB
1393}
1394
15f82208 1395static void help(int exitcode)
0824d6fc 1396{
e8105ebb 1397 const char *options_help =
ad96090a
BS
1398#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1399 opt_help
5824d651 1400#define DEFHEADING(text) stringify(text) "\n"
9f16732a 1401#include "qemu-options.def"
5824d651
BS
1402#undef DEF
1403#undef DEFHEADING
1404#undef GEN_DOCS
e8105ebb
PB
1405 ;
1406 version();
1407 printf("usage: %s [options] [disk_image]\n"
1408 "\n"
f75ca1ae 1409 "'disk_image' is a raw hard disk image for IDE hard disk 0\n"
3f020d70 1410 "\n"
e8105ebb 1411 "%s\n"
3f020d70 1412 "During emulation, the following keys are useful:\n"
1413 "ctrl-alt-f toggle full screen\n"
1414 "ctrl-alt-n switch to virtual console 'n'\n"
1415 "ctrl-alt toggle mouse and keyboard grab\n"
1416 "\n"
e8105ebb
PB
1417 "When using -nographic, press 'ctrl-a h' to get some help.\n",
1418 "qemu",
1419 options_help);
15f82208 1420 exit(exitcode);
0824d6fc
FB
1421}
1422
cd6f1169
FB
1423#define HAS_ARG 0x0001
1424
cd6f1169
FB
1425typedef struct QEMUOption {
1426 const char *name;
1427 int flags;
1428 int index;
ad96090a 1429 uint32_t arch_mask;
cd6f1169
FB
1430} QEMUOption;
1431
dbed7e40 1432static const QEMUOption qemu_options[] = {
ad96090a
BS
1433 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
1434#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
1435 { option, opt_arg, opt_enum, arch_mask },
5824d651 1436#define DEFHEADING(text)
9f16732a 1437#include "qemu-options.def"
5824d651
BS
1438#undef DEF
1439#undef DEFHEADING
1440#undef GEN_DOCS
cd6f1169 1441 { NULL },
fc01f7e7 1442};
3893c124 1443static void select_vgahw (const char *p)
1444{
1445 const char *opts;
1446
64465297 1447 default_vga = 0;
86176759 1448 vga_interface_type = VGA_NONE;
3893c124 1449 if (strstart(p, "std", &opts)) {
86176759 1450 vga_interface_type = VGA_STD;
3893c124 1451 } else if (strstart(p, "cirrus", &opts)) {
86176759 1452 vga_interface_type = VGA_CIRRUS;
3893c124 1453 } else if (strstart(p, "vmware", &opts)) {
86176759 1454 vga_interface_type = VGA_VMWARE;
94909d9f 1455 } else if (strstart(p, "xenfb", &opts)) {
86176759 1456 vga_interface_type = VGA_XENFB;
28b85ed8 1457 } else if (!strstart(p, "none", &opts)) {
3893c124 1458 invalid_vga:
1459 fprintf(stderr, "Unknown vga type: %s\n", p);
1460 exit(1);
1461 }
cb5a7aa8 1462 while (*opts) {
1463 const char *nextopt;
1464
1465 if (strstart(opts, ",retrace=", &nextopt)) {
1466 opts = nextopt;
1467 if (strstart(opts, "dumb", &nextopt))
1468 vga_retrace_method = VGA_RETRACE_DUMB;
1469 else if (strstart(opts, "precise", &nextopt))
1470 vga_retrace_method = VGA_RETRACE_PRECISE;
1471 else goto invalid_vga;
1472 } else goto invalid_vga;
1473 opts = nextopt;
1474 }
3893c124 1475}
1476
7d4c3d53
MA
1477static int balloon_parse(const char *arg)
1478{
382f0743 1479 QemuOpts *opts;
7d4c3d53 1480
382f0743
GH
1481 if (strcmp(arg, "none") == 0) {
1482 return 0;
1483 }
1484
1485 if (!strncmp(arg, "virtio", 6)) {
1486 if (arg[6] == ',') {
1487 /* have params -> parse them */
3329f07b 1488 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
382f0743
GH
1489 if (!opts)
1490 return -1;
1491 } else {
1492 /* create empty opts */
3329f07b 1493 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
7d4c3d53 1494 }
382f0743
GH
1495 qemu_opt_set(opts, "driver", "virtio-balloon-pci");
1496 return 0;
7d4c3d53 1497 }
382f0743
GH
1498
1499 return -1;
7d4c3d53 1500}
7d4c3d53 1501
5cea8590
PB
1502char *qemu_find_file(int type, const char *name)
1503{
1504 int len;
1505 const char *subdir;
1506 char *buf;
1507
1508 /* If name contains path separators then try it as a straight path. */
1509 if ((strchr(name, '/') || strchr(name, '\\'))
1510 && access(name, R_OK) == 0) {
73ffc805 1511 return qemu_strdup(name);
5cea8590
PB
1512 }
1513 switch (type) {
1514 case QEMU_FILE_TYPE_BIOS:
1515 subdir = "";
1516 break;
1517 case QEMU_FILE_TYPE_KEYMAP:
1518 subdir = "keymaps/";
1519 break;
1520 default:
1521 abort();
1522 }
1523 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
1524 buf = qemu_mallocz(len);
3a41759d 1525 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
5cea8590
PB
1526 if (access(buf, R_OK)) {
1527 qemu_free(buf);
1528 return NULL;
1529 }
1530 return buf;
1531}
1532
ff952ba2
MA
1533static int device_help_func(QemuOpts *opts, void *opaque)
1534{
1535 return qdev_device_help(opts);
1536}
1537
f31d07d1
GH
1538static int device_init_func(QemuOpts *opts, void *opaque)
1539{
1540 DeviceState *dev;
1541
1542 dev = qdev_device_add(opts);
1543 if (!dev)
1544 return -1;
1545 return 0;
1546}
1547
1a688d3b
GH
1548static int chardev_init_func(QemuOpts *opts, void *opaque)
1549{
1550 CharDriverState *chr;
1551
1552 chr = qemu_chr_open_opts(opts, NULL);
1553 if (!chr)
1554 return -1;
1555 return 0;
1556}
1557
758e8e38 1558#ifdef CONFIG_VIRTFS
74db920c
GS
1559static int fsdev_init_func(QemuOpts *opts, void *opaque)
1560{
1561 int ret;
1562 ret = qemu_fsdev_add(opts);
1563
1564 return ret;
1565}
1566#endif
1567
88589343
GH
1568static int mon_init_func(QemuOpts *opts, void *opaque)
1569{
1570 CharDriverState *chr;
1571 const char *chardev;
1572 const char *mode;
1573 int flags;
1574
1575 mode = qemu_opt_get(opts, "mode");
1576 if (mode == NULL) {
1577 mode = "readline";
1578 }
1579 if (strcmp(mode, "readline") == 0) {
1580 flags = MONITOR_USE_READLINE;
1581 } else if (strcmp(mode, "control") == 0) {
1582 flags = MONITOR_USE_CONTROL;
1583 } else {
1584 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1585 exit(1);
1586 }
1587
39eaab9a
DB
1588 if (qemu_opt_get_bool(opts, "pretty", 0))
1589 flags |= MONITOR_USE_PRETTY;
1590
88589343
GH
1591 if (qemu_opt_get_bool(opts, "default", 0))
1592 flags |= MONITOR_IS_DEFAULT;
1593
1594 chardev = qemu_opt_get(opts, "chardev");
1595 chr = qemu_chr_find(chardev);
1596 if (chr == NULL) {
1597 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1598 exit(1);
1599 }
1600
1601 monitor_init(chr, flags);
1602 return 0;
1603}
1604
6ca5582d 1605static void monitor_parse(const char *optarg, const char *mode)
88589343
GH
1606{
1607 static int monitor_device_index = 0;
1608 QemuOpts *opts;
1609 const char *p;
1610 char label[32];
1611 int def = 0;
1612
1613 if (strstart(optarg, "chardev:", &p)) {
1614 snprintf(label, sizeof(label), "%s", p);
1615 } else {
140e065d
JK
1616 snprintf(label, sizeof(label), "compat_monitor%d",
1617 monitor_device_index);
1618 if (monitor_device_index == 0) {
88589343
GH
1619 def = 1;
1620 }
1621 opts = qemu_chr_parse_compat(label, optarg);
1622 if (!opts) {
1623 fprintf(stderr, "parse error: %s\n", optarg);
1624 exit(1);
1625 }
1626 }
1627
3329f07b 1628 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
88589343
GH
1629 if (!opts) {
1630 fprintf(stderr, "duplicate chardev: %s\n", label);
1631 exit(1);
1632 }
6ca5582d 1633 qemu_opt_set(opts, "mode", mode);
88589343
GH
1634 qemu_opt_set(opts, "chardev", label);
1635 if (def)
1636 qemu_opt_set(opts, "default", "on");
1637 monitor_device_index++;
1638}
1639
bd3c948d
GH
1640struct device_config {
1641 enum {
aee1b935
GH
1642 DEV_USB, /* -usbdevice */
1643 DEV_BT, /* -bt */
1644 DEV_SERIAL, /* -serial */
1645 DEV_PARALLEL, /* -parallel */
1646 DEV_VIRTCON, /* -virtioconsole */
c9f398e5 1647 DEV_DEBUGCON, /* -debugcon */
bd3c948d
GH
1648 } type;
1649 const char *cmdline;
72cf2d4f 1650 QTAILQ_ENTRY(device_config) next;
bd3c948d 1651};
72cf2d4f 1652QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
bd3c948d
GH
1653
1654static void add_device_config(int type, const char *cmdline)
1655{
1656 struct device_config *conf;
1657
1658 conf = qemu_mallocz(sizeof(*conf));
1659 conf->type = type;
1660 conf->cmdline = cmdline;
72cf2d4f 1661 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
bd3c948d
GH
1662}
1663
1664static int foreach_device_config(int type, int (*func)(const char *cmdline))
1665{
1666 struct device_config *conf;
1667 int rc;
1668
72cf2d4f 1669 QTAILQ_FOREACH(conf, &device_configs, next) {
bd3c948d
GH
1670 if (conf->type != type)
1671 continue;
1672 rc = func(conf->cmdline);
1673 if (0 != rc)
1674 return rc;
1675 }
1676 return 0;
1677}
1678
998bbd74
GH
1679static int serial_parse(const char *devname)
1680{
1681 static int index = 0;
1682 char label[32];
1683
1684 if (strcmp(devname, "none") == 0)
1685 return 0;
1686 if (index == MAX_SERIAL_PORTS) {
1687 fprintf(stderr, "qemu: too many serial ports\n");
1688 exit(1);
1689 }
1690 snprintf(label, sizeof(label), "serial%d", index);
1691 serial_hds[index] = qemu_chr_open(label, devname, NULL);
1692 if (!serial_hds[index]) {
1693 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1694 devname, strerror(errno));
1695 return -1;
1696 }
1697 index++;
1698 return 0;
1699}
1700
6a5e8b0e
GH
1701static int parallel_parse(const char *devname)
1702{
1703 static int index = 0;
1704 char label[32];
1705
1706 if (strcmp(devname, "none") == 0)
1707 return 0;
1708 if (index == MAX_PARALLEL_PORTS) {
1709 fprintf(stderr, "qemu: too many parallel ports\n");
1710 exit(1);
1711 }
1712 snprintf(label, sizeof(label), "parallel%d", index);
1713 parallel_hds[index] = qemu_chr_open(label, devname, NULL);
1714 if (!parallel_hds[index]) {
1715 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
1716 devname, strerror(errno));
1717 return -1;
1718 }
1719 index++;
1720 return 0;
1721}
1722
aee1b935
GH
1723static int virtcon_parse(const char *devname)
1724{
3329f07b 1725 QemuOptsList *device = qemu_find_opts("device");
aee1b935
GH
1726 static int index = 0;
1727 char label[32];
392ecf54 1728 QemuOpts *bus_opts, *dev_opts;
aee1b935
GH
1729
1730 if (strcmp(devname, "none") == 0)
1731 return 0;
1732 if (index == MAX_VIRTIO_CONSOLES) {
1733 fprintf(stderr, "qemu: too many virtio consoles\n");
1734 exit(1);
1735 }
392ecf54 1736
3329f07b 1737 bus_opts = qemu_opts_create(device, NULL, 0);
392ecf54
AS
1738 qemu_opt_set(bus_opts, "driver", "virtio-serial");
1739
3329f07b 1740 dev_opts = qemu_opts_create(device, NULL, 0);
392ecf54
AS
1741 qemu_opt_set(dev_opts, "driver", "virtconsole");
1742
aee1b935
GH
1743 snprintf(label, sizeof(label), "virtcon%d", index);
1744 virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
1745 if (!virtcon_hds[index]) {
1746 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
1747 devname, strerror(errno));
1748 return -1;
1749 }
392ecf54
AS
1750 qemu_opt_set(dev_opts, "chardev", label);
1751
aee1b935
GH
1752 index++;
1753 return 0;
1754}
1755
c9f398e5
PA
1756static int debugcon_parse(const char *devname)
1757{
1758 QemuOpts *opts;
1759
1760 if (!qemu_chr_open("debugcon", devname, NULL)) {
1761 exit(1);
1762 }
3329f07b 1763 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
c9f398e5
PA
1764 if (!opts) {
1765 fprintf(stderr, "qemu: already have a debugcon device\n");
1766 exit(1);
1767 }
1768 qemu_opt_set(opts, "driver", "isa-debugcon");
1769 qemu_opt_set(opts, "chardev", "debugcon");
1770 return 0;
1771}
1772
fd42deeb
GH
1773void qemu_add_exit_notifier(Notifier *notify)
1774{
1775 notifier_list_add(&exit_notifiers, notify);
1776}
1777
1778void qemu_remove_exit_notifier(Notifier *notify)
1779{
1780 notifier_list_remove(&exit_notifiers, notify);
1781}
1782
1783static void qemu_run_exit_notifiers(void)
1784{
1785 notifier_list_notify(&exit_notifiers);
1786}
1787
4cab946a
GN
1788void qemu_add_machine_init_done_notifier(Notifier *notify)
1789{
1790 notifier_list_add(&machine_init_done_notifiers, notify);
1791}
1792
1793static void qemu_run_machine_init_done_notifiers(void)
1794{
1795 notifier_list_notify(&machine_init_done_notifiers);
1796}
1797
6530a97b
AL
1798static const QEMUOption *lookup_opt(int argc, char **argv,
1799 const char **poptarg, int *poptind)
1800{
1801 const QEMUOption *popt;
1802 int optind = *poptind;
1803 char *r = argv[optind];
1804 const char *optarg;
1805
0f0bc3f1 1806 loc_set_cmdline(argv, optind, 1);
6530a97b
AL
1807 optind++;
1808 /* Treat --foo the same as -foo. */
1809 if (r[1] == '-')
1810 r++;
1811 popt = qemu_options;
1812 for(;;) {
1813 if (!popt->name) {
0f0bc3f1 1814 error_report("invalid option");
6530a97b
AL
1815 exit(1);
1816 }
1817 if (!strcmp(popt->name, r + 1))
1818 break;
1819 popt++;
1820 }
1821 if (popt->flags & HAS_ARG) {
1822 if (optind >= argc) {
0f0bc3f1 1823 error_report("requires an argument");
6530a97b
AL
1824 exit(1);
1825 }
1826 optarg = argv[optind++];
0f0bc3f1 1827 loc_set_cmdline(argv, optind - 2, 2);
6530a97b
AL
1828 } else {
1829 optarg = NULL;
1830 }
1831
1832 *poptarg = optarg;
1833 *poptind = optind;
1834
1835 return popt;
1836}
1837
902b3d5c 1838int main(int argc, char **argv, char **envp)
0824d6fc 1839{
59030a8c 1840 const char *gdbstub_dev = NULL;
e4bcb14c 1841 int i;
da1fcfda 1842 int snapshot, linux_boot;
4e3de9e9 1843 const char *icount_option = NULL;
7f7f9873 1844 const char *initrd_filename;
a20dd508 1845 const char *kernel_filename, *kernel_cmdline;
195325a4 1846 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
3023f332 1847 DisplayState *ds;
7d957bd8 1848 DisplayChangeListener *dcl;
46d4767d 1849 int cyls, heads, secs, translation;
f31d07d1 1850 QemuOpts *hda_opts = NULL, *opts;
03b0ba70 1851 QemuOptsList *olist;
cd6f1169 1852 int optind;
6530a97b 1853 const char *optarg;
d63d307f 1854 const char *loadvm = NULL;
cc1daa40 1855 QEMUMachine *machine;
94fc95cd 1856 const char *cpu_model;
26a5f13b 1857 int tb_size;
93815bc2 1858 const char *pid_file = NULL;
5bb7910a 1859 const char *incoming = NULL;
993fbfdb 1860 int show_vnc_port = 0;
292444cb 1861 int defconfig = 1;
0bd48850 1862
ab6540d5
PS
1863#ifdef CONFIG_SIMPLE_TRACE
1864 const char *trace_file = NULL;
1865#endif
fd42deeb 1866 atexit(qemu_run_exit_notifiers);
65abca0a
MA
1867 error_set_progname(argv[0]);
1868
6875204c
JK
1869 init_clocks();
1870
902b3d5c 1871 qemu_cache_utils_init(envp);
1872
72cf2d4f 1873 QLIST_INIT (&vm_change_state_head);
fe98ac14 1874 os_setup_early_signal_handling();
be995c27 1875
f80f9ec9 1876 module_call_init(MODULE_INIT_MACHINE);
0c257437 1877 machine = find_default_machine();
94fc95cd 1878 cpu_model = NULL;
fc01f7e7 1879 initrd_filename = NULL;
4fc5d071 1880 ram_size = 0;
33e3963e 1881 snapshot = 0;
a20dd508
FB
1882 kernel_filename = NULL;
1883 kernel_cmdline = "";
c4b1fcc0 1884 cyls = heads = secs = 0;
46d4767d 1885 translation = BIOS_ATA_TRANSLATION_AUTO;
c4b1fcc0 1886
268a362c
AL
1887 for (i = 0; i < MAX_NODES; i++) {
1888 node_mem[i] = 0;
1889 node_cpumask[i] = 0;
1890 }
1891
268a362c 1892 nb_numa_nodes = 0;
7c9d8e07 1893 nb_nics = 0;
3b46e624 1894
26a5f13b 1895 tb_size = 0;
41bd639b
BS
1896 autostart= 1;
1897
292444cb
AL
1898 /* first pass of option parsing */
1899 optind = 1;
1900 while (optind < argc) {
1901 if (argv[optind][0] != '-') {
1902 /* disk image */
28e68d68 1903 optind++;
292444cb
AL
1904 continue;
1905 } else {
1906 const QEMUOption *popt;
1907
1908 popt = lookup_opt(argc, argv, &optarg, &optind);
1909 switch (popt->index) {
1910 case QEMU_OPTION_nodefconfig:
1911 defconfig=0;
1912 break;
1913 }
1914 }
1915 }
1916
1917 if (defconfig) {
dcfb0939 1918 int ret;
cf5a65aa 1919
dcfb0939 1920 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
019e78ba 1921 if (ret < 0 && ret != -ENOENT) {
dcfb0939 1922 exit(1);
292444cb
AL
1923 }
1924
dcfb0939 1925 ret = qemu_read_config_file(arch_config_name);
019e78ba 1926 if (ret < 0 && ret != -ENOENT) {
dcfb0939 1927 exit(1);
292444cb
AL
1928 }
1929 }
de06f8d1 1930 cpudef_init();
292444cb
AL
1931
1932 /* second pass of option parsing */
cd6f1169 1933 optind = 1;
0824d6fc 1934 for(;;) {
cd6f1169 1935 if (optind >= argc)
0824d6fc 1936 break;
6530a97b 1937 if (argv[optind][0] != '-') {
9dfd7c7a 1938 hda_opts = drive_add(argv[optind++], HD_ALIAS, 0);
cd6f1169
FB
1939 } else {
1940 const QEMUOption *popt;
1941
6530a97b 1942 popt = lookup_opt(argc, argv, &optarg, &optind);
ad96090a
BS
1943 if (!(popt->arch_mask & arch_type)) {
1944 printf("Option %s not supported for this target\n", popt->name);
1945 exit(1);
1946 }
cd6f1169 1947 switch(popt->index) {
cc1daa40
FB
1948 case QEMU_OPTION_M:
1949 machine = find_machine(optarg);
1950 if (!machine) {
1951 QEMUMachine *m;
1952 printf("Supported machines are:\n");
1953 for(m = first_machine; m != NULL; m = m->next) {
3f6599e6
MM
1954 if (m->alias)
1955 printf("%-10s %s (alias of %s)\n",
1956 m->alias, m->desc, m->name);
cc1daa40 1957 printf("%-10s %s%s\n",
5fafdf24 1958 m->name, m->desc,
0c257437 1959 m->is_default ? " (default)" : "");
cc1daa40 1960 }
15f82208 1961 exit(*optarg != '?');
cc1daa40
FB
1962 }
1963 break;
94fc95cd
JM
1964 case QEMU_OPTION_cpu:
1965 /* hw initialization will check this */
15f82208 1966 if (*optarg == '?') {
262353cb 1967 list_cpus(stdout, &fprintf, optarg);
15f82208 1968 exit(0);
94fc95cd
JM
1969 } else {
1970 cpu_model = optarg;
1971 }
1972 break;
cd6f1169 1973 case QEMU_OPTION_initrd:
fc01f7e7
FB
1974 initrd_filename = optarg;
1975 break;
cd6f1169 1976 case QEMU_OPTION_hda:
e4bcb14c 1977 if (cyls == 0)
9dfd7c7a 1978 hda_opts = drive_add(optarg, HD_ALIAS, 0);
e4bcb14c 1979 else
9dfd7c7a 1980 hda_opts = drive_add(optarg, HD_ALIAS
e4bcb14c 1981 ",cyls=%d,heads=%d,secs=%d%s",
609497ab 1982 0, cyls, heads, secs,
e4bcb14c
TS
1983 translation == BIOS_ATA_TRANSLATION_LBA ?
1984 ",trans=lba" :
1985 translation == BIOS_ATA_TRANSLATION_NONE ?
1986 ",trans=none" : "");
1987 break;
cd6f1169 1988 case QEMU_OPTION_hdb:
cc1daa40
FB
1989 case QEMU_OPTION_hdc:
1990 case QEMU_OPTION_hdd:
609497ab 1991 drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda);
fc01f7e7 1992 break;
e4bcb14c 1993 case QEMU_OPTION_drive:
609497ab 1994 drive_add(NULL, "%s", optarg);
e4bcb14c 1995 break;
d058fe03
GH
1996 case QEMU_OPTION_set:
1997 if (qemu_set_option(optarg) != 0)
1998 exit(1);
1999 break;
d0fef6fb
GH
2000 case QEMU_OPTION_global:
2001 if (qemu_global_option(optarg) != 0)
2002 exit(1);
2003 break;
3e3d5815 2004 case QEMU_OPTION_mtdblock:
609497ab 2005 drive_add(optarg, MTD_ALIAS);
3e3d5815 2006 break;
a1bb27b1 2007 case QEMU_OPTION_sd:
609497ab 2008 drive_add(optarg, SD_ALIAS);
a1bb27b1 2009 break;
86f55663 2010 case QEMU_OPTION_pflash:
609497ab 2011 drive_add(optarg, PFLASH_ALIAS);
86f55663 2012 break;
cd6f1169 2013 case QEMU_OPTION_snapshot:
33e3963e
FB
2014 snapshot = 1;
2015 break;
cd6f1169 2016 case QEMU_OPTION_hdachs:
330d0414 2017 {
330d0414
FB
2018 const char *p;
2019 p = optarg;
2020 cyls = strtol(p, (char **)&p, 0);
46d4767d
FB
2021 if (cyls < 1 || cyls > 16383)
2022 goto chs_fail;
330d0414
FB
2023 if (*p != ',')
2024 goto chs_fail;
2025 p++;
2026 heads = strtol(p, (char **)&p, 0);
46d4767d
FB
2027 if (heads < 1 || heads > 16)
2028 goto chs_fail;
330d0414
FB
2029 if (*p != ',')
2030 goto chs_fail;
2031 p++;
2032 secs = strtol(p, (char **)&p, 0);
46d4767d
FB
2033 if (secs < 1 || secs > 63)
2034 goto chs_fail;
2035 if (*p == ',') {
2036 p++;
2037 if (!strcmp(p, "none"))
2038 translation = BIOS_ATA_TRANSLATION_NONE;
2039 else if (!strcmp(p, "lba"))
2040 translation = BIOS_ATA_TRANSLATION_LBA;
2041 else if (!strcmp(p, "auto"))
2042 translation = BIOS_ATA_TRANSLATION_AUTO;
2043 else
2044 goto chs_fail;
2045 } else if (*p != '\0') {
c4b1fcc0 2046 chs_fail:
46d4767d
FB
2047 fprintf(stderr, "qemu: invalid physical CHS format\n");
2048 exit(1);
c4b1fcc0 2049 }
9dfd7c7a
GH
2050 if (hda_opts != NULL) {
2051 char num[16];
2052 snprintf(num, sizeof(num), "%d", cyls);
2053 qemu_opt_set(hda_opts, "cyls", num);
2054 snprintf(num, sizeof(num), "%d", heads);
2055 qemu_opt_set(hda_opts, "heads", num);
2056 snprintf(num, sizeof(num), "%d", secs);
2057 qemu_opt_set(hda_opts, "secs", num);
2058 if (translation == BIOS_ATA_TRANSLATION_LBA)
2059 qemu_opt_set(hda_opts, "trans", "lba");
2060 if (translation == BIOS_ATA_TRANSLATION_NONE)
2061 qemu_opt_set(hda_opts, "trans", "none");
2062 }
330d0414
FB
2063 }
2064 break;
268a362c
AL
2065 case QEMU_OPTION_numa:
2066 if (nb_numa_nodes >= MAX_NODES) {
2067 fprintf(stderr, "qemu: too many NUMA nodes\n");
2068 exit(1);
2069 }
2070 numa_add(optarg);
2071 break;
cd6f1169 2072 case QEMU_OPTION_nographic:
993fbfdb 2073 display_type = DT_NOGRAPHIC;
a20dd508 2074 break;
4d3b6f6e
AZ
2075#ifdef CONFIG_CURSES
2076 case QEMU_OPTION_curses:
993fbfdb 2077 display_type = DT_CURSES;
4d3b6f6e
AZ
2078 break;
2079#endif
a171fe39
AZ
2080 case QEMU_OPTION_portrait:
2081 graphic_rotate = 1;
2082 break;
cd6f1169 2083 case QEMU_OPTION_kernel:
a20dd508
FB
2084 kernel_filename = optarg;
2085 break;
cd6f1169 2086 case QEMU_OPTION_append:
a20dd508 2087 kernel_cmdline = optarg;
313aa567 2088 break;
cd6f1169 2089 case QEMU_OPTION_cdrom:
609497ab 2090 drive_add(optarg, CDROM_ALIAS);
36b486bb 2091 break;
cd6f1169 2092 case QEMU_OPTION_boot:
28c5af54 2093 {
ef3adf68 2094 static const char * const params[] = {
95387491 2095 "order", "once", "menu", NULL
ef3adf68
JK
2096 };
2097 char buf[sizeof(boot_devices)];
e0f084bf 2098 char *standard_boot_devices;
ef3adf68
JK
2099 int legacy = 0;
2100
2101 if (!strchr(optarg, '=')) {
2102 legacy = 1;
2103 pstrcpy(buf, sizeof(buf), optarg);
2104 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2105 fprintf(stderr,
2106 "qemu: unknown boot parameter '%s' in '%s'\n",
2107 buf, optarg);
2108 exit(1);
2109 }
2110
2111 if (legacy ||
2112 get_param_value(buf, sizeof(buf), "order", optarg)) {
4e9e9d6e 2113 validate_bootdevices(buf);
ef3adf68 2114 pstrcpy(boot_devices, sizeof(boot_devices), buf);
28c5af54 2115 }
e0f084bf
JK
2116 if (!legacy) {
2117 if (get_param_value(buf, sizeof(buf),
2118 "once", optarg)) {
4e9e9d6e 2119 validate_bootdevices(buf);
e0f084bf
JK
2120 standard_boot_devices = qemu_strdup(boot_devices);
2121 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2122 qemu_register_reset(restore_boot_devices,
2123 standard_boot_devices);
2124 }
95387491
JK
2125 if (get_param_value(buf, sizeof(buf),
2126 "menu", optarg)) {
2127 if (!strcmp(buf, "on")) {
2128 boot_menu = 1;
2129 } else if (!strcmp(buf, "off")) {
2130 boot_menu = 0;
2131 } else {
2132 fprintf(stderr,
2133 "qemu: invalid option value '%s'\n",
2134 buf);
2135 exit(1);
2136 }
2137 }
e0f084bf 2138 }
36b486bb
FB
2139 }
2140 break;
cd6f1169 2141 case QEMU_OPTION_fda:
cd6f1169 2142 case QEMU_OPTION_fdb:
609497ab 2143 drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda);
c45886db 2144 break;
52ca8d6a
FB
2145 case QEMU_OPTION_no_fd_bootchk:
2146 fd_bootchk = 0;
2147 break;
a1ea458f 2148 case QEMU_OPTION_netdev:
3329f07b 2149 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
a1ea458f
MM
2150 exit(1);
2151 }
2152 break;
7c9d8e07 2153 case QEMU_OPTION_net:
3329f07b 2154 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
c4b1fcc0
FB
2155 exit(1);
2156 }
702c651c 2157 break;
c7f74643
FB
2158#ifdef CONFIG_SLIRP
2159 case QEMU_OPTION_tftp:
ad196a9d 2160 legacy_tftp_prefix = optarg;
9bf05444 2161 break;
47d5d01a 2162 case QEMU_OPTION_bootp:
ad196a9d 2163 legacy_bootp_filename = optarg;
47d5d01a 2164 break;
9bf05444 2165 case QEMU_OPTION_redir:
0752706d
MA
2166 if (net_slirp_redir(optarg) < 0)
2167 exit(1);
9bf05444 2168 break;
c7f74643 2169#endif
dc72ac14 2170 case QEMU_OPTION_bt:
bd3c948d 2171 add_device_config(DEV_BT, optarg);
dc72ac14 2172 break;
1d14ffa9 2173 case QEMU_OPTION_audio_help:
ad96090a
BS
2174 if (!(audio_available())) {
2175 printf("Option %s not supported for this target\n", popt->name);
2176 exit(1);
2177 }
1d14ffa9
FB
2178 AUD_help ();
2179 exit (0);
2180 break;
2181 case QEMU_OPTION_soundhw:
ad96090a
BS
2182 if (!(audio_available())) {
2183 printf("Option %s not supported for this target\n", popt->name);
2184 exit(1);
2185 }
1d14ffa9
FB
2186 select_soundhw (optarg);
2187 break;
cd6f1169 2188 case QEMU_OPTION_h:
15f82208 2189 help(0);
cd6f1169 2190 break;
9bd7e6d9
PB
2191 case QEMU_OPTION_version:
2192 version();
2193 exit(0);
2194 break;
00f82b8a 2195 case QEMU_OPTION_m: {
9f9b17a4
JS
2196 ssize_t value;
2197
2198 value = strtosz(optarg, NULL);
2199 if (value < 0) {
00f82b8a 2200 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
cd6f1169
FB
2201 exit(1);
2202 }
00f82b8a
AJ
2203
2204 /* On 32-bit hosts, QEMU is limited by virtual address space */
4a1418e0 2205 if (value > (2047 << 20) && HOST_LONG_BITS == 32) {
00f82b8a
AJ
2206 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
2207 exit(1);
2208 }
c227f099 2209 if (value != (uint64_t)(ram_addr_t)value) {
00f82b8a
AJ
2210 fprintf(stderr, "qemu: ram size too large\n");
2211 exit(1);
2212 }
2213 ram_size = value;
cd6f1169 2214 break;
00f82b8a 2215 }
c902760f
MT
2216 case QEMU_OPTION_mempath:
2217 mem_path = optarg;
2218 break;
2219#ifdef MAP_POPULATE
2220 case QEMU_OPTION_mem_prealloc:
2221 mem_prealloc = 1;
2222 break;
2223#endif
cd6f1169 2224 case QEMU_OPTION_d:
de06f8d1 2225 set_cpu_log(optarg);
cd6f1169 2226 break;
cd6f1169 2227 case QEMU_OPTION_s:
59030a8c 2228 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
cd6f1169 2229 break;
59030a8c
AL
2230 case QEMU_OPTION_gdb:
2231 gdbstub_dev = optarg;
cd6f1169 2232 break;
cd6f1169 2233 case QEMU_OPTION_L:
5cea8590 2234 data_dir = optarg;
cd6f1169 2235 break;
1192dad8
JM
2236 case QEMU_OPTION_bios:
2237 bios_name = optarg;
2238 break;
1b530a6d
AJ
2239 case QEMU_OPTION_singlestep:
2240 singlestep = 1;
2241 break;
cd6f1169 2242 case QEMU_OPTION_S:
3c07f8e8 2243 autostart = 0;
cd6f1169 2244 break;
3d11d0eb
FB
2245 case QEMU_OPTION_k:
2246 keyboard_layout = optarg;
2247 break;
ee22c2f7
FB
2248 case QEMU_OPTION_localtime:
2249 rtc_utc = 0;
2250 break;
3893c124 2251 case QEMU_OPTION_vga:
2252 select_vgahw (optarg);
1bfe856e 2253 break;
e9b137c2
FB
2254 case QEMU_OPTION_g:
2255 {
2256 const char *p;
2257 int w, h, depth;
2258 p = optarg;
2259 w = strtol(p, (char **)&p, 10);
2260 if (w <= 0) {
2261 graphic_error:
2262 fprintf(stderr, "qemu: invalid resolution or depth\n");
2263 exit(1);
2264 }
2265 if (*p != 'x')
2266 goto graphic_error;
2267 p++;
2268 h = strtol(p, (char **)&p, 10);
2269 if (h <= 0)
2270 goto graphic_error;
2271 if (*p == 'x') {
2272 p++;
2273 depth = strtol(p, (char **)&p, 10);
5fafdf24 2274 if (depth != 8 && depth != 15 && depth != 16 &&
e9b137c2
FB
2275 depth != 24 && depth != 32)
2276 goto graphic_error;
2277 } else if (*p == '\0') {
2278 depth = graphic_depth;
2279 } else {
2280 goto graphic_error;
2281 }
3b46e624 2282
e9b137c2
FB
2283 graphic_width = w;
2284 graphic_height = h;
2285 graphic_depth = depth;
2286 }
2287 break;
20d8a3ed
TS
2288 case QEMU_OPTION_echr:
2289 {
2290 char *r;
2291 term_escape_char = strtol(optarg, &r, 0);
2292 if (r == optarg)
2293 printf("Bad argument to echr\n");
2294 break;
2295 }
82c643ff 2296 case QEMU_OPTION_monitor:
6ca5582d
GH
2297 monitor_parse(optarg, "readline");
2298 default_monitor = 0;
2299 break;
2300 case QEMU_OPTION_qmp:
2301 monitor_parse(optarg, "control");
2d114dc1 2302 default_monitor = 0;
82c643ff 2303 break;
22a0e04b 2304 case QEMU_OPTION_mon:
3329f07b 2305 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
22a0e04b 2306 if (!opts) {
22a0e04b
GH
2307 exit(1);
2308 }
2d114dc1 2309 default_monitor = 0;
22a0e04b 2310 break;
191bc01b 2311 case QEMU_OPTION_chardev:
3329f07b 2312 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
191bc01b 2313 if (!opts) {
191bc01b
GH
2314 exit(1);
2315 }
191bc01b 2316 break;
74db920c 2317 case QEMU_OPTION_fsdev:
03b0ba70
GH
2318 olist = qemu_find_opts("fsdev");
2319 if (!olist) {
2320 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2321 exit(1);
2322 }
2323 opts = qemu_opts_parse(olist, optarg, 1);
74db920c
GS
2324 if (!opts) {
2325 fprintf(stderr, "parse error: %s\n", optarg);
2326 exit(1);
2327 }
2328 break;
3d54abc7
GS
2329 case QEMU_OPTION_virtfs: {
2330 char *arg_fsdev = NULL;
2331 char *arg_9p = NULL;
2332 int len = 0;
2333
03b0ba70
GH
2334 olist = qemu_find_opts("virtfs");
2335 if (!olist) {
2336 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2337 exit(1);
2338 }
2339 opts = qemu_opts_parse(olist, optarg, 1);
3d54abc7
GS
2340 if (!opts) {
2341 fprintf(stderr, "parse error: %s\n", optarg);
2342 exit(1);
2343 }
2344
9ce56db6
VJJ
2345 if (qemu_opt_get(opts, "fstype") == NULL ||
2346 qemu_opt_get(opts, "mount_tag") == NULL ||
2347 qemu_opt_get(opts, "path") == NULL ||
2348 qemu_opt_get(opts, "security_model") == NULL) {
2349 fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
12848bfc 2350 "security_model=[mapped|passthrough|none],"
9ce56db6
VJJ
2351 "mnt_tag=tag.\n");
2352 exit(1);
2353 }
2354
2355 len = strlen(",id=,path=,security_model=");
3d54abc7
GS
2356 len += strlen(qemu_opt_get(opts, "fstype"));
2357 len += strlen(qemu_opt_get(opts, "mount_tag"));
2358 len += strlen(qemu_opt_get(opts, "path"));
9ce56db6 2359 len += strlen(qemu_opt_get(opts, "security_model"));
3d54abc7
GS
2360 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
2361
c93031e5 2362 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
cb93bbdd
BS
2363 "%s,id=%s,path=%s,security_model=%s",
2364 qemu_opt_get(opts, "fstype"),
2365 qemu_opt_get(opts, "mount_tag"),
2366 qemu_opt_get(opts, "path"),
2367 qemu_opt_get(opts, "security_model"));
3d54abc7
GS
2368
2369 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
2370 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
2371 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
2372
c93031e5 2373 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
cb93bbdd
BS
2374 "virtio-9p-pci,fsdev=%s,mount_tag=%s",
2375 qemu_opt_get(opts, "mount_tag"),
2376 qemu_opt_get(opts, "mount_tag"));
3d54abc7 2377
3329f07b 2378 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
3d54abc7
GS
2379 fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
2380 exit(1);
2381 }
2382
3329f07b 2383 if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) {
3d54abc7
GS
2384 fprintf(stderr, "parse error [device]: %s\n", optarg);
2385 exit(1);
2386 }
2387
2388 qemu_free(arg_fsdev);
2389 qemu_free(arg_9p);
2390 break;
2391 }
82c643ff 2392 case QEMU_OPTION_serial:
998bbd74
GH
2393 add_device_config(DEV_SERIAL, optarg);
2394 default_serial = 0;
18141ed6
JK
2395 if (strncmp(optarg, "mon:", 4) == 0) {
2396 default_monitor = 0;
2397 }
82c643ff 2398 break;
9dd986cc 2399 case QEMU_OPTION_watchdog:
09aaa160
MA
2400 if (watchdog) {
2401 fprintf(stderr,
2402 "qemu: only one watchdog option may be given\n");
2403 return 1;
2404 }
2405 watchdog = optarg;
9dd986cc
RJ
2406 break;
2407 case QEMU_OPTION_watchdog_action:
2408 if (select_watchdog_action(optarg) == -1) {
2409 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2410 exit(1);
2411 }
2412 break;
51ecf136 2413 case QEMU_OPTION_virtiocon:
aee1b935
GH
2414 add_device_config(DEV_VIRTCON, optarg);
2415 default_virtcon = 0;
18141ed6
JK
2416 if (strncmp(optarg, "mon:", 4) == 0) {
2417 default_monitor = 0;
2418 }
51ecf136 2419 break;
6508fe59 2420 case QEMU_OPTION_parallel:
6a5e8b0e
GH
2421 add_device_config(DEV_PARALLEL, optarg);
2422 default_parallel = 0;
18141ed6
JK
2423 if (strncmp(optarg, "mon:", 4) == 0) {
2424 default_monitor = 0;
2425 }
6508fe59 2426 break;
c9f398e5
PA
2427 case QEMU_OPTION_debugcon:
2428 add_device_config(DEV_DEBUGCON, optarg);
2429 break;
d63d307f
FB
2430 case QEMU_OPTION_loadvm:
2431 loadvm = optarg;
2432 break;
2433 case QEMU_OPTION_full_screen:
2434 full_screen = 1;
2435 break;
667accab 2436#ifdef CONFIG_SDL
43523e93
TS
2437 case QEMU_OPTION_no_frame:
2438 no_frame = 1;
2439 break;
3780e197
TS
2440 case QEMU_OPTION_alt_grab:
2441 alt_grab = 1;
2442 break;
0ca9f8a4
DK
2443 case QEMU_OPTION_ctrl_grab:
2444 ctrl_grab = 1;
2445 break;
667accab
TS
2446 case QEMU_OPTION_no_quit:
2447 no_quit = 1;
2448 break;
7d957bd8 2449 case QEMU_OPTION_sdl:
993fbfdb 2450 display_type = DT_SDL;
7d957bd8 2451 break;
667accab 2452#endif
f7cce898 2453 case QEMU_OPTION_pidfile:
93815bc2 2454 pid_file = optarg;
f7cce898 2455 break;
a09db21f
FB
2456 case QEMU_OPTION_win2k_hack:
2457 win2k_install_hack = 1;
2458 break;
73822ec8
AL
2459 case QEMU_OPTION_rtc_td_hack:
2460 rtc_td_hack = 1;
2461 break;
8a92ea2f 2462 case QEMU_OPTION_acpitable:
de06f8d1 2463 do_acpitable_option(optarg);
8a92ea2f 2464 break;
b6f6e3d3 2465 case QEMU_OPTION_smbios:
de06f8d1 2466 do_smbios_option(optarg);
b6f6e3d3 2467 break;
7ba1e619
AL
2468 case QEMU_OPTION_enable_kvm:
2469 kvm_allowed = 1;
7ba1e619 2470 break;
bb36d470
FB
2471 case QEMU_OPTION_usb:
2472 usb_enabled = 1;
2473 break;
a594cfbf
FB
2474 case QEMU_OPTION_usbdevice:
2475 usb_enabled = 1;
bd3c948d
GH
2476 add_device_config(DEV_USB, optarg);
2477 break;
2478 case QEMU_OPTION_device:
3329f07b 2479 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
f31d07d1
GH
2480 exit(1);
2481 }
a594cfbf 2482 break;
6a00d601 2483 case QEMU_OPTION_smp:
dc6b1c09 2484 smp_parse(optarg);
b2097003 2485 if (smp_cpus < 1) {
6a00d601
FB
2486 fprintf(stderr, "Invalid number of CPUs\n");
2487 exit(1);
2488 }
6be68d7e
JS
2489 if (max_cpus < smp_cpus) {
2490 fprintf(stderr, "maxcpus must be equal to or greater than "
2491 "smp\n");
2492 exit(1);
2493 }
2494 if (max_cpus > 255) {
2495 fprintf(stderr, "Unsupported number of maxcpus\n");
2496 exit(1);
2497 }
6a00d601 2498 break;
24236869 2499 case QEMU_OPTION_vnc:
6b62dc2d 2500 display_remote++;
73fc9742 2501 vnc_display = optarg;
24236869 2502 break;
6515b203
FB
2503 case QEMU_OPTION_no_acpi:
2504 acpi_enabled = 0;
2505 break;
16b29ae1
AL
2506 case QEMU_OPTION_no_hpet:
2507 no_hpet = 1;
2508 break;
7d4c3d53
MA
2509 case QEMU_OPTION_balloon:
2510 if (balloon_parse(optarg) < 0) {
2511 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
2512 exit(1);
2513 }
df97b920 2514 break;
d1beab82
FB
2515 case QEMU_OPTION_no_reboot:
2516 no_reboot = 1;
2517 break;
b2f76161
AJ
2518 case QEMU_OPTION_no_shutdown:
2519 no_shutdown = 1;
2520 break;
9467cd46
AZ
2521 case QEMU_OPTION_show_cursor:
2522 cursor_hide = 0;
2523 break;
8fcb1b90
BS
2524 case QEMU_OPTION_uuid:
2525 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
2526 fprintf(stderr, "Fail to parse UUID string."
2527 " Wrong format.\n");
2528 exit(1);
2529 }
2530 break;
9ae02555
TS
2531 case QEMU_OPTION_option_rom:
2532 if (nb_option_roms >= MAX_OPTION_ROMS) {
2533 fprintf(stderr, "Too many option ROMs\n");
2534 exit(1);
2535 }
2e55e842
GN
2536 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
2537 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
2538 option_rom[nb_option_roms].bootindex =
2539 qemu_opt_get_number(opts, "bootindex", -1);
2540 if (!option_rom[nb_option_roms].name) {
2541 fprintf(stderr, "Option ROM file is not specified\n");
2542 exit(1);
2543 }
9ae02555
TS
2544 nb_option_roms++;
2545 break;
8e71621f
PB
2546 case QEMU_OPTION_semihosting:
2547 semihosting_enabled = 1;
2548 break;
c35734b2 2549 case QEMU_OPTION_name:
1889465a
AK
2550 qemu_name = qemu_strdup(optarg);
2551 {
2552 char *p = strchr(qemu_name, ',');
2553 if (p != NULL) {
2554 *p++ = 0;
2555 if (strncmp(p, "process=", 8)) {
2556 fprintf(stderr, "Unknown subargument %s to -name", p);
2557 exit(1);
2558 }
2559 p += 8;
ce798cf2 2560 os_set_proc_name(p);
1889465a
AK
2561 }
2562 }
c35734b2 2563 break;
66508601
BS
2564 case QEMU_OPTION_prom_env:
2565 if (nb_prom_envs >= MAX_PROM_ENVS) {
2566 fprintf(stderr, "Too many prom variables\n");
2567 exit(1);
2568 }
2569 prom_envs[nb_prom_envs] = optarg;
2570 nb_prom_envs++;
2571 break;
2b8f2d41
AZ
2572 case QEMU_OPTION_old_param:
2573 old_param = 1;
05ebd537 2574 break;
f3dcfada
TS
2575 case QEMU_OPTION_clock:
2576 configure_alarms(optarg);
2577 break;
7e0af5d0 2578 case QEMU_OPTION_startdate:
1ed2fc1f
JK
2579 configure_rtc_date_offset(optarg, 1);
2580 break;
2581 case QEMU_OPTION_rtc:
3329f07b 2582 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
1ed2fc1f 2583 if (!opts) {
1ed2fc1f 2584 exit(1);
7e0af5d0 2585 }
1ed2fc1f 2586 configure_rtc(opts);
7e0af5d0 2587 break;
26a5f13b
FB
2588 case QEMU_OPTION_tb_size:
2589 tb_size = strtol(optarg, NULL, 0);
2590 if (tb_size < 0)
2591 tb_size = 0;
2592 break;
2e70f6ef 2593 case QEMU_OPTION_icount:
4e3de9e9 2594 icount_option = optarg;
2e70f6ef 2595 break;
5bb7910a
AL
2596 case QEMU_OPTION_incoming:
2597 incoming = optarg;
8e84865e 2598 incoming_expected = true;
5bb7910a 2599 break;
d8c208dd
GH
2600 case QEMU_OPTION_nodefaults:
2601 default_serial = 0;
2602 default_parallel = 0;
aee1b935 2603 default_virtcon = 0;
d8c208dd
GH
2604 default_monitor = 0;
2605 default_vga = 0;
cb4522cc 2606 default_net = 0;
ac33f8fa
GH
2607 default_floppy = 0;
2608 default_cdrom = 0;
2609 default_sdcard = 0;
d8c208dd 2610 break;
e37630ca 2611 case QEMU_OPTION_xen_domid:
ad96090a
BS
2612 if (!(xen_available())) {
2613 printf("Option %s not supported for this target\n", popt->name);
2614 exit(1);
2615 }
e37630ca
AL
2616 xen_domid = atoi(optarg);
2617 break;
2618 case QEMU_OPTION_xen_create:
ad96090a
BS
2619 if (!(xen_available())) {
2620 printf("Option %s not supported for this target\n", popt->name);
2621 exit(1);
2622 }
e37630ca
AL
2623 xen_mode = XEN_CREATE;
2624 break;
2625 case QEMU_OPTION_xen_attach:
ad96090a
BS
2626 if (!(xen_available())) {
2627 printf("Option %s not supported for this target\n", popt->name);
2628 exit(1);
2629 }
e37630ca
AL
2630 xen_mode = XEN_ATTACH;
2631 break;
ab6540d5
PS
2632#ifdef CONFIG_SIMPLE_TRACE
2633 case QEMU_OPTION_trace:
2634 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
2635 if (opts) {
2636 trace_file = qemu_opt_get(opts, "file");
2637 }
2638 break;
2639#endif
715a664a
GH
2640 case QEMU_OPTION_readconfig:
2641 {
dcfb0939
KW
2642 int ret = qemu_read_config_file(optarg);
2643 if (ret < 0) {
2644 fprintf(stderr, "read config %s: %s\n", optarg,
2645 strerror(-ret));
715a664a
GH
2646 exit(1);
2647 }
715a664a
GH
2648 break;
2649 }
29b0040b
GH
2650 case QEMU_OPTION_spice:
2651 olist = qemu_find_opts("spice");
2652 if (!olist) {
2653 fprintf(stderr, "spice is not supported by this qemu build.\n");
2654 exit(1);
2655 }
2656 opts = qemu_opts_parse(olist, optarg, 0);
2657 if (!opts) {
2658 fprintf(stderr, "parse error: %s\n", optarg);
2659 exit(1);
2660 }
2661 break;
715a664a
GH
2662 case QEMU_OPTION_writeconfig:
2663 {
2664 FILE *fp;
2665 if (strcmp(optarg, "-") == 0) {
2666 fp = stdout;
2667 } else {
2668 fp = fopen(optarg, "w");
2669 if (fp == NULL) {
2670 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
2671 exit(1);
2672 }
2673 }
2674 qemu_config_write(fp);
2675 fclose(fp);
2676 break;
2677 }
59a5264b
JS
2678 default:
2679 os_parse_cmd_args(popt->index, optarg);
cd6f1169 2680 }
0824d6fc
FB
2681 }
2682 }
0f0bc3f1 2683 loc_set_none();
330d0414 2684
5cea8590
PB
2685 /* If no data_dir is specified then try to find it relative to the
2686 executable path. */
2687 if (!data_dir) {
6170540b 2688 data_dir = os_find_datadir(argv[0]);
5cea8590
PB
2689 }
2690 /* If all else fails use the install patch specified when building. */
2691 if (!data_dir) {
1dabe05c 2692 data_dir = CONFIG_QEMU_DATADIR;
5cea8590
PB
2693 }
2694
ab6540d5
PS
2695#ifdef CONFIG_SIMPLE_TRACE
2696 /*
2697 * Set the trace file name, if specified.
2698 */
2699 st_set_trace_file(trace_file);
2700#endif
6be68d7e
JS
2701 /*
2702 * Default to max_cpus = smp_cpus, in case the user doesn't
2703 * specify a max_cpus value.
2704 */
2705 if (!max_cpus)
2706 max_cpus = smp_cpus;
2707
3d878caa 2708 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
b2097003
AL
2709 if (smp_cpus > machine->max_cpus) {
2710 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
2711 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
2712 machine->max_cpus);
2713 exit(1);
2714 }
2715
3329f07b
GH
2716 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
2717 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
998bbd74 2718
986c5f78
GH
2719 if (machine->no_serial) {
2720 default_serial = 0;
2721 }
2722 if (machine->no_parallel) {
2723 default_parallel = 0;
2724 }
2725 if (!machine->use_virtcon) {
2726 default_virtcon = 0;
2727 }
2728 if (machine->no_vga) {
2729 default_vga = 0;
2730 }
ac33f8fa
GH
2731 if (machine->no_floppy) {
2732 default_floppy = 0;
2733 }
2734 if (machine->no_cdrom) {
2735 default_cdrom = 0;
2736 }
2737 if (machine->no_sdcard) {
2738 default_sdcard = 0;
2739 }
986c5f78 2740
993fbfdb 2741 if (display_type == DT_NOGRAPHIC) {
6a5e8b0e
GH
2742 if (default_parallel)
2743 add_device_config(DEV_PARALLEL, "null");
e1c09175
GH
2744 if (default_serial && default_monitor) {
2745 add_device_config(DEV_SERIAL, "mon:stdio");
986c5f78
GH
2746 } else if (default_virtcon && default_monitor) {
2747 add_device_config(DEV_VIRTCON, "mon:stdio");
e1c09175
GH
2748 } else {
2749 if (default_serial)
2750 add_device_config(DEV_SERIAL, "stdio");
986c5f78
GH
2751 if (default_virtcon)
2752 add_device_config(DEV_VIRTCON, "stdio");
e1c09175 2753 if (default_monitor)
6ca5582d 2754 monitor_parse("stdio", "readline");
e1c09175 2755 }
998bbd74
GH
2756 } else {
2757 if (default_serial)
2758 add_device_config(DEV_SERIAL, "vc:80Cx24C");
6a5e8b0e
GH
2759 if (default_parallel)
2760 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
abdeed06 2761 if (default_monitor)
6ca5582d 2762 monitor_parse("vc:80Cx24C", "readline");
38536da1
AG
2763 if (default_virtcon)
2764 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
bc0129d9 2765 }
64465297
GH
2766 if (default_vga)
2767 vga_interface_type = VGA_CIRRUS;
bc0129d9 2768
a5829fd9
T
2769 socket_init();
2770
3329f07b 2771 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
1a688d3b 2772 exit(1);
758e8e38 2773#ifdef CONFIG_VIRTFS
3329f07b 2774 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
74db920c
GS
2775 exit(1);
2776 }
2777#endif
1a688d3b 2778
eb505be1 2779 os_daemonize();
71e3ceb8 2780
aa26bb2d 2781 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
eb505be1 2782 os_pidfile_error();
93815bc2
TS
2783 exit(1);
2784 }
2785
98c8573e
PB
2786 if (kvm_allowed) {
2787 int ret = kvm_init(smp_cpus);
214910a7 2788 if (ret < 0) {
98c8573e
PB
2789 if (!kvm_available()) {
2790 printf("KVM not supported for this target\n");
2791 } else {
2792 fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret));
2793 }
214910a7
MT
2794 exit(1);
2795 }
2796 }
2797
3fcf7b6b
AL
2798 if (qemu_init_main_loop()) {
2799 fprintf(stderr, "qemu_init_main_loop failed\n");
2800 exit(1);
2801 }
a20dd508 2802 linux_boot = (kernel_filename != NULL);
6c41b272 2803
f8d39c01
TS
2804 if (!linux_boot && *kernel_cmdline != '\0') {
2805 fprintf(stderr, "-append only allowed with -kernel option\n");
2806 exit(1);
2807 }
2808
2809 if (!linux_boot && initrd_filename != NULL) {
2810 fprintf(stderr, "-initrd only allowed with -kernel option\n");
2811 exit(1);
2812 }
2813
9156d763 2814 os_set_line_buffering();
3b46e624 2815
7183b4b4
AL
2816 if (init_timer_alarm() < 0) {
2817 fprintf(stderr, "could not initialize alarm timer\n");
2818 exit(1);
2819 }
4e3de9e9 2820 configure_icount(icount_option);
634fce96 2821
dc1c9fe8
MM
2822 if (net_init_clients() < 0) {
2823 exit(1);
702c651c 2824 }
f1510b2c 2825
dc72ac14 2826 /* init the bluetooth world */
bd3c948d
GH
2827 if (foreach_device_config(DEV_BT, bt_parse))
2828 exit(1);
dc72ac14 2829
0824d6fc 2830 /* init the memory */
94a6b54f
PB
2831 if (ram_size == 0)
2832 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
9ae02555 2833
26a5f13b
FB
2834 /* init the dynamic translator */
2835 cpu_exec_init_all(tb_size * 1024 * 1024);
2836
eb852011 2837 bdrv_init_with_whitelist();
c4b1fcc0 2838
c163b5ca 2839 blk_mig_init();
2840
ac33f8fa 2841 if (default_cdrom) {
aa40fc9c
GH
2842 /* we always create the cdrom drive, even if no disk is there */
2843 drive_add(NULL, CDROM_ALIAS);
ac33f8fa 2844 }
c4b1fcc0 2845
ac33f8fa 2846 if (default_floppy) {
aa40fc9c
GH
2847 /* we always create at least one floppy */
2848 drive_add(NULL, FD_ALIAS, 0);
ac33f8fa 2849 }
86f55663 2850
ac33f8fa 2851 if (default_sdcard) {
aa40fc9c
GH
2852 /* we always create one sd slot, even if no card is in it */
2853 drive_add(NULL, SD_ALIAS);
2854 }
9d413d1d 2855
e4bcb14c 2856 /* open the virtual block devices */
9dfd7c7a 2857 if (snapshot)
3329f07b
GH
2858 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
2859 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
9dfd7c7a 2860 exit(1);
3e3d5815 2861
97ab12d4 2862 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
c163b5ca 2863 ram_load, NULL);
8a7ddc38 2864
268a362c
AL
2865 if (nb_numa_nodes > 0) {
2866 int i;
2867
2868 if (nb_numa_nodes > smp_cpus) {
2869 nb_numa_nodes = smp_cpus;
2870 }
2871
2872 /* If no memory size if given for any node, assume the default case
2873 * and distribute the available memory equally across all nodes
2874 */
2875 for (i = 0; i < nb_numa_nodes; i++) {
2876 if (node_mem[i] != 0)
2877 break;
2878 }
2879 if (i == nb_numa_nodes) {
2880 uint64_t usedmem = 0;
2881
2882 /* On Linux, the each node's border has to be 8MB aligned,
2883 * the final node gets the rest.
2884 */
2885 for (i = 0; i < nb_numa_nodes - 1; i++) {
2886 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
2887 usedmem += node_mem[i];
2888 }
2889 node_mem[i] = ram_size - usedmem;
2890 }
2891
2892 for (i = 0; i < nb_numa_nodes; i++) {
2893 if (node_cpumask[i] != 0)
2894 break;
2895 }
2896 /* assigning the VCPUs round-robin is easier to implement, guest OSes
2897 * must cope with this anyway, because there are BIOSes out there in
2898 * real machines which also use this scheme.
2899 */
2900 if (i == nb_numa_nodes) {
2901 for (i = 0; i < smp_cpus; i++) {
2902 node_cpumask[i % nb_numa_nodes] |= 1 << i;
2903 }
2904 }
2905 }
2906
3329f07b 2907 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
157b9319
JK
2908 exit(1);
2909 }
2910
998bbd74
GH
2911 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
2912 exit(1);
6a5e8b0e
GH
2913 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
2914 exit(1);
aee1b935
GH
2915 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
2916 exit(1);
c9f398e5
PA
2917 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
2918 exit(1);
2796dae0 2919
aae9460e
PB
2920 module_call_init(MODULE_INIT_DEVICE);
2921
3329f07b 2922 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
ff952ba2
MA
2923 exit(0);
2924
09aaa160
MA
2925 if (watchdog) {
2926 i = select_watchdog(watchdog);
2927 if (i > 0)
2928 exit (i == 1 ? 1 : 0);
2929 }
2930
b6b61144 2931 if (machine->compat_props) {
458fb679 2932 qdev_prop_register_global_list(machine->compat_props);
b6b61144 2933 }
d0fef6fb
GH
2934 qemu_add_globals();
2935
fbe1b595 2936 machine->init(ram_size, boot_devices,
3023f332
AL
2937 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
2938
ea375f9a 2939 cpu_synchronize_all_post_init();
268a362c 2940
67b3b71d 2941 /* must be after terminal init, SDL library changes signal handlers */
8d963e6a 2942 os_setup_signal_handling();
67b3b71d 2943
87d0a28e 2944 set_numa_modes();
268a362c 2945
6f338c34
AL
2946 current_machine = machine;
2947
3023f332
AL
2948 /* init USB devices */
2949 if (usb_enabled) {
0752706d
MA
2950 if (foreach_device_config(DEV_USB, usb_parse) < 0)
2951 exit(1);
3023f332
AL
2952 }
2953
bd3c948d 2954 /* init generic devices */
3329f07b 2955 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
bd3c948d
GH
2956 exit(1);
2957
668680f7
MA
2958 net_check_clients();
2959
3023f332 2960 /* just use the first displaystate for the moment */
b473df6e 2961 ds = get_displaystate();
993fbfdb 2962
a3e22260
GH
2963 if (using_spice)
2964 display_remote++;
6b62dc2d 2965 if (display_type == DT_DEFAULT && !display_remote) {
993fbfdb
AL
2966#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
2967 display_type = DT_SDL;
2968#else
993fbfdb
AL
2969 vnc_display = "localhost:0,to=99";
2970 show_vnc_port = 1;
2971#endif
2972 }
2973
2974
6b62dc2d 2975 /* init local displays */
993fbfdb
AL
2976 switch (display_type) {
2977 case DT_NOGRAPHIC:
2978 break;
4d3b6f6e 2979#if defined(CONFIG_CURSES)
993fbfdb
AL
2980 case DT_CURSES:
2981 curses_display_init(ds, full_screen);
2982 break;
4d3b6f6e 2983#endif
5b0753e0 2984#if defined(CONFIG_SDL)
993fbfdb
AL
2985 case DT_SDL:
2986 sdl_display_init(ds, full_screen, no_frame);
2987 break;
5b0753e0 2988#elif defined(CONFIG_COCOA)
993fbfdb
AL
2989 case DT_SDL:
2990 cocoa_display_init(ds, full_screen);
2991 break;
313aa567 2992#endif
6b62dc2d
GH
2993 default:
2994 break;
2995 }
2996
2997 /* init remote displays */
2998 if (vnc_display) {
993fbfdb
AL
2999 vnc_display_init(ds);
3000 if (vnc_display_open(ds, vnc_display) < 0)
3001 exit(1);
f92f8afe 3002
993fbfdb
AL
3003 if (show_vnc_port) {
3004 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
f92f8afe 3005 }
313aa567 3006 }
a3e22260
GH
3007#ifdef CONFIG_SPICE
3008 if (using_spice) {
3009 qemu_spice_display_init(ds);
3010 }
3011#endif
5b08fc10 3012
6b62dc2d
GH
3013 /* display setup */
3014 dpy_resize(ds);
3023f332
AL
3015 dcl = ds->listeners;
3016 while (dcl != NULL) {
3017 if (dcl->dpy_refresh != NULL) {
3018 ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
3019 qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
0f2ad63f 3020 break;
20d8a3ed 3021 }
3023f332 3022 dcl = dcl->next;
20d8a3ed 3023 }
6b62dc2d 3024 if (ds->gui_timer == NULL) {
9043b62d
BS
3025 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
3026 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
3027 }
b473df6e 3028 text_consoles_set_display(ds);
2796dae0 3029
59030a8c
AL
3030 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
3031 fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
3032 gdbstub_dev);
3033 exit(1);
45669e00 3034 }
45669e00 3035
3418bd25
GH
3036 qdev_machine_creation_done();
3037
15ff7705
GH
3038 if (rom_load_all() != 0) {
3039 fprintf(stderr, "rom loading failed\n");
3040 exit(1);
3041 }
45a50b16 3042
ec990eb6 3043 qemu_register_reset((void *)qbus_reset_all, sysbus_get_default());
4cab946a
GN
3044 qemu_run_machine_init_done_notifiers();
3045
504c2948 3046 qemu_system_reset();
05f2401e 3047 if (loadvm) {
03cd4655 3048 if (load_vmstate(loadvm) < 0) {
05f2401e
JQ
3049 autostart = 0;
3050 }
3051 }
d63d307f 3052
2bb8c10c 3053 if (incoming) {
8ca5e801
JQ
3054 int ret = qemu_start_incoming_migration(incoming);
3055 if (ret < 0) {
3056 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3057 incoming, ret);
3058 exit(ret);
3059 }
6b99dadc 3060 } else if (autostart) {
c0f4ce77 3061 vm_start();
6b99dadc 3062 }
ffd843bc 3063
eb505be1 3064 os_setup_post();
71e3ceb8 3065
8a7ddc38 3066 main_loop();
40c3bac3 3067 quit_timers();
63a01ef8 3068 net_cleanup();
b46a8906 3069
0824d6fc
FB
3070 return 0;
3071}