]> git.proxmox.com Git - qemu.git/blame - vl.c
configure: Use QEMU instead of Qemu
[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 50
71e72a19 51#ifdef CONFIG_BSD
7d3505c5 52#include <sys/stat.h>
a167ba50 53#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
7d3505c5 54#include <libutil.h>
92c0e657 55#include <sys/sysctl.h>
24646c7e
BS
56#else
57#include <util.h>
128ab2ff 58#endif
bbe813a2 59#else
223f0d72 60#ifdef __linux__
7d3505c5
FB
61#include <pty.h>
62#include <malloc.h>
bd494f4c 63
e57a8c0e 64#include <linux/ppdev.h>
5867c88a 65#include <linux/parport.h>
223f0d72
BS
66#endif
67#ifdef __sun__
d5d10bc3
TS
68#include <sys/stat.h>
69#include <sys/ethernet.h>
70#include <sys/sockio.h>
d5d10bc3 71#include <netinet/arp.h>
d5d10bc3
TS
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>
77#include <net/if.h>
78#include <syslog.h>
79#include <stropts.h>
67b915a5 80#endif
7d3505c5 81#endif
ec530c81 82#endif
67b915a5 83
9892fbfb
BS
84#if defined(__OpenBSD__)
85#include <util.h>
86#endif
87
8a16d273
TS
88#if defined(CONFIG_VDE)
89#include <libvdeplug.h>
90#endif
91
67b915a5 92#ifdef _WIN32
49dc768d 93#include <windows.h>
67b915a5
FB
94#endif
95
73332e5c 96#ifdef CONFIG_SDL
59a36a2f 97#if defined(__APPLE__) || defined(main)
6693665a 98#include <SDL.h>
880fec5d 99int qemu_main(int argc, char **argv, char **envp);
100int main(int argc, char **argv)
101{
59a36a2f 102 return qemu_main(argc, argv, NULL);
880fec5d 103}
104#undef main
105#define main qemu_main
96bcd4f8 106#endif
73332e5c 107#endif /* CONFIG_SDL */
0824d6fc 108
5b0753e0
FB
109#ifdef CONFIG_COCOA
110#undef main
111#define main qemu_main
112#endif /* CONFIG_COCOA */
113
69e5bb68
AL
114#include <glib.h>
115
511d2b14
BS
116#include "hw/hw.h"
117#include "hw/boards.h"
118#include "hw/usb.h"
119#include "hw/pcmcia.h"
120#include "hw/pc.h"
511d2b14
BS
121#include "hw/isa.h"
122#include "hw/baum.h"
123#include "hw/bt.h"
9dd986cc 124#include "hw/watchdog.h"
b6f6e3d3 125#include "hw/smbios.h"
e37630ca 126#include "hw/xen.h"
bd3c948d 127#include "hw/qdev.h"
45a50b16 128#include "hw/loader.h"
5ef4efa4 129#include "bt-host.h"
511d2b14 130#include "net.h"
68ac40d2 131#include "net/slirp.h"
511d2b14
BS
132#include "monitor.h"
133#include "console.h"
134#include "sysemu.h"
135#include "gdbstub.h"
136#include "qemu-timer.h"
137#include "qemu-char.h"
138#include "cache-utils.h"
139#include "block.h"
666daa68 140#include "blockdev.h"
c163b5ca 141#include "block-migration.h"
a718acec 142#include "dma.h"
511d2b14
BS
143#include "audio/audio.h"
144#include "migration.h"
145#include "kvm.h"
f795e743 146#include "qjson.h"
d3f24367 147#include "qemu-option.h"
7282a033 148#include "qemu-config.h"
59a5264b 149#include "qemu-options.h"
1fa9a5e4 150#include "qmp-commands.h"
44a9b356 151#include "main-loop.h"
758e8e38 152#ifdef CONFIG_VIRTFS
74db920c
GS
153#include "fsdev/qemu-fsdev.h"
154#endif
c7f0f3b1 155#include "qtest.h"
511d2b14 156
0824d6fc 157#include "disas.h"
fc01f7e7 158
511d2b14
BS
159#include "qemu_socket.h"
160
d918f23e 161#include "slirp/libslirp.h"
511d2b14 162
94b0b5ff 163#include "trace.h"
e4858974 164#include "trace/control.h"
72cf2d4f 165#include "qemu-queue.h"
296af7c9 166#include "cpus.h"
ad96090a 167#include "arch_init.h"
72cf2d4f 168
29b0040b
GH
169#include "ui/qemu-spice.h"
170
9dc63a1e
BS
171//#define DEBUG_NET
172//#define DEBUG_SLIRP
330d0414 173
1bfe856e 174#define DEFAULT_RAM_SIZE 128
313aa567 175
98b19252
AS
176#define MAX_VIRTIO_CONSOLES 1
177
5cea8590 178static const char *data_dir;
1192dad8 179const char *bios_name = NULL;
cb5a7aa8 180enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
993fbfdb 181DisplayType display_type = DT_DEFAULT;
6b62dc2d 182int display_remote = 0;
3d11d0eb 183const char* keyboard_layout = NULL;
c227f099 184ram_addr_t ram_size;
c902760f
MT
185const char *mem_path = NULL;
186#ifdef MAP_POPULATE
187int mem_prealloc = 0; /* force preallocation of physical target memory */
188#endif
c4b1fcc0 189int nb_nics;
7c9d8e07 190NICInfo nd_table[MAX_NICS];
d399f677 191int autostart;
f6503059
AZ
192static int rtc_utc = 1;
193static int rtc_date_offset = -1; /* -1 means no change */
6875204c 194QEMUClock *rtc_clock;
64465297 195int vga_interface_type = VGA_NONE;
dbed7e40 196static int full_screen = 0;
634a21f6 197#ifdef CONFIG_SDL
dbed7e40 198static int no_frame = 0;
634a21f6 199#endif
667accab 200int no_quit = 0;
8d11df9e 201CharDriverState *serial_hds[MAX_SERIAL_PORTS];
6508fe59 202CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
9ede2fde 203CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
a09db21f 204int win2k_install_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;
821601ea 211#ifdef CONFIG_VNC
73fc9742 212const char *vnc_display;
821601ea 213#endif
6515b203 214int acpi_enabled = 1;
16b29ae1 215int no_hpet = 0;
52ca8d6a 216int fd_bootchk = 1;
d1beab82 217int no_reboot = 0;
b2f76161 218int no_shutdown = 0;
9467cd46 219int cursor_hide = 1;
a171fe39 220int graphic_rotate = 0;
09aaa160 221const char *watchdog;
2e55e842 222QEMUOptionRom option_rom[MAX_OPTION_ROMS];
9ae02555 223int nb_option_roms;
8e71621f 224int semihosting_enabled = 0;
2b8f2d41 225int old_param = 0;
c35734b2 226const char *qemu_name;
3780e197 227int alt_grab = 0;
0ca9f8a4 228int ctrl_grab = 0;
66508601
BS
229unsigned int nb_prom_envs = 0;
230const char *prom_envs[MAX_PROM_ENVS];
95387491 231int boot_menu;
3d3b8303 232uint8_t *boot_splash_filedata;
233int boot_splash_filedata_size;
234uint8_t qemu_extra_params_fw[2];
0824d6fc 235
1ca4d09a
GN
236typedef struct FWBootEntry FWBootEntry;
237
238struct FWBootEntry {
239 QTAILQ_ENTRY(FWBootEntry) link;
240 int32_t bootindex;
241 DeviceState *dev;
242 char *suffix;
243};
244
245QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order);
246
268a362c
AL
247int nb_numa_nodes;
248uint64_t node_mem[MAX_NODES];
249uint64_t node_cpumask[MAX_NODES];
250
8fcb1b90
BS
251uint8_t qemu_uuid[16];
252
76e30d0f
JK
253static QEMUBootSetHandler *boot_set_handler;
254static void *boot_set_opaque;
255
fd42deeb
GH
256static NotifierList exit_notifiers =
257 NOTIFIER_LIST_INITIALIZER(exit_notifiers);
258
4cab946a
GN
259static NotifierList machine_init_done_notifiers =
260 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
261
303d4e86 262static int tcg_allowed = 1;
d745bef8 263int kvm_allowed = 0;
3285cf4f 264int xen_allowed = 0;
d745bef8
BS
265uint32_t xen_domid;
266enum xen_mode xen_mode = XEN_EMULATE;
d5ab9713 267static int tcg_tb_size;
d745bef8 268
998bbd74 269static int default_serial = 1;
6a5e8b0e 270static int default_parallel = 1;
986c5f78 271static int default_virtcon = 1;
abdeed06 272static int default_monitor = 1;
ac33f8fa
GH
273static int default_floppy = 1;
274static int default_cdrom = 1;
275static int default_sdcard = 1;
7f1b17f2 276static int default_vga = 1;
998bbd74
GH
277
278static struct {
279 const char *driver;
280 int *flag;
281} default_list[] = {
6a5e8b0e
GH
282 { .driver = "isa-serial", .flag = &default_serial },
283 { .driver = "isa-parallel", .flag = &default_parallel },
d8bcbabf 284 { .driver = "isa-fdc", .flag = &default_floppy },
af6bf132
MA
285 { .driver = "ide-cd", .flag = &default_cdrom },
286 { .driver = "ide-hd", .flag = &default_cdrom },
d8bcbabf 287 { .driver = "ide-drive", .flag = &default_cdrom },
af6bf132 288 { .driver = "scsi-cd", .flag = &default_cdrom },
392ecf54
AS
289 { .driver = "virtio-serial-pci", .flag = &default_virtcon },
290 { .driver = "virtio-serial-s390", .flag = &default_virtcon },
291 { .driver = "virtio-serial", .flag = &default_virtcon },
7f1b17f2
PB
292 { .driver = "VGA", .flag = &default_vga },
293 { .driver = "isa-vga", .flag = &default_vga },
294 { .driver = "cirrus-vga", .flag = &default_vga },
295 { .driver = "isa-cirrus-vga", .flag = &default_vga },
296 { .driver = "vmware-svga", .flag = &default_vga },
297 { .driver = "qxl-vga", .flag = &default_vga },
998bbd74
GH
298};
299
3d3b8303 300static void res_free(void)
301{
302 if (boot_splash_filedata != NULL) {
7267c094 303 g_free(boot_splash_filedata);
3d3b8303 304 boot_splash_filedata = NULL;
305 }
306}
307
998bbd74
GH
308static int default_driver_check(QemuOpts *opts, void *opaque)
309{
310 const char *driver = qemu_opt_get(opts, "driver");
311 int i;
312
313 if (!driver)
314 return 0;
315 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
316 if (strcmp(default_list[i].driver, driver) != 0)
317 continue;
318 *(default_list[i].flag) = 0;
319 }
320 return 0;
321}
322
f5bbfba1
LC
323/***********************************************************/
324/* QEMU state */
325
0461d5a6 326static RunState current_run_state = RUN_STATE_PRELAUNCH;
f5bbfba1 327
5db9d4d1
LC
328typedef struct {
329 RunState from;
330 RunState to;
331} RunStateTransition;
332
333static const RunStateTransition runstate_transitions_def[] = {
334 /* from -> to */
0461d5a6 335 { RUN_STATE_DEBUG, RUN_STATE_RUNNING },
5db9d4d1 336
0461d5a6
LC
337 { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },
338 { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH },
5db9d4d1 339
0461d5a6 340 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },
8a9236f1 341 { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
5db9d4d1 342
0461d5a6 343 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
8a9236f1 344 { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },
5db9d4d1 345
0461d5a6 346 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
8a9236f1 347 { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
5db9d4d1 348
0461d5a6 349 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
8a9236f1 350 { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
5db9d4d1 351
0461d5a6 352 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
8a9236f1 353 { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },
0461d5a6 354 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
5db9d4d1 355
0461d5a6
LC
356 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },
357 { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },
5db9d4d1 358
0461d5a6 359 { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },
5db9d4d1 360
0461d5a6
LC
361 { RUN_STATE_RUNNING, RUN_STATE_DEBUG },
362 { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },
363 { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },
364 { RUN_STATE_RUNNING, RUN_STATE_PAUSED },
365 { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },
366 { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },
367 { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },
368 { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },
369 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
5db9d4d1 370
0461d5a6 371 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
5db9d4d1 372
0461d5a6 373 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
8a9236f1 374 { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
5db9d4d1 375
ad02b96a
LC
376 { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
377 { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
378 { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },
379 { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
380
0461d5a6 381 { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
8a9236f1 382 { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
5db9d4d1 383
0461d5a6 384 { RUN_STATE_MAX, RUN_STATE_MAX },
5db9d4d1
LC
385};
386
0461d5a6
LC
387static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX];
388
f5bbfba1
LC
389bool runstate_check(RunState state)
390{
391 return current_run_state == state;
392}
393
5db9d4d1
LC
394void runstate_init(void)
395{
396 const RunStateTransition *p;
397
398 memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions));
399
0461d5a6 400 for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) {
5db9d4d1
LC
401 runstate_valid_transitions[p->from][p->to] = true;
402 }
403}
404
405/* This function will abort() on invalid state transitions */
f5bbfba1
LC
406void runstate_set(RunState new_state)
407{
207c5cd2
LC
408 assert(new_state < RUN_STATE_MAX);
409
410 if (!runstate_valid_transitions[current_run_state][new_state]) {
411 fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n",
412 RunState_lookup[current_run_state],
413 RunState_lookup[new_state]);
5db9d4d1
LC
414 abort();
415 }
416
f5bbfba1
LC
417 current_run_state = new_state;
418}
419
1fa9a5e4 420int runstate_is_running(void)
9e37b9dc 421{
1fa9a5e4 422 return runstate_check(RUN_STATE_RUNNING);
9e37b9dc
LC
423}
424
1fa9a5e4 425StatusInfo *qmp_query_status(Error **errp)
1354869c 426{
1fa9a5e4
LC
427 StatusInfo *info = g_malloc0(sizeof(*info));
428
429 info->running = runstate_is_running();
430 info->singlestep = singlestep;
431 info->status = current_run_state;
432
433 return info;
1354869c
LC
434}
435
8f0056b7
PB
436/***********************************************************/
437/* real time host monotonic timer */
09b26c5e 438
f6503059
AZ
439/***********************************************************/
440/* host time/date access */
441void qemu_get_timedate(struct tm *tm, int offset)
442{
443 time_t ti;
444 struct tm *ret;
445
446 time(&ti);
447 ti += offset;
448 if (rtc_date_offset == -1) {
449 if (rtc_utc)
450 ret = gmtime(&ti);
451 else
452 ret = localtime(&ti);
453 } else {
454 ti -= rtc_date_offset;
455 ret = gmtime(&ti);
456 }
457
458 memcpy(tm, ret, sizeof(struct tm));
459}
460
461int qemu_timedate_diff(struct tm *tm)
462{
463 time_t seconds;
464
465 if (rtc_date_offset == -1)
466 if (rtc_utc)
467 seconds = mktimegm(tm);
f54c556c
GN
468 else {
469 struct tm tmp = *tm;
470 tmp.tm_isdst = -1; /* use timezone to figure it out */
471 seconds = mktime(&tmp);
472 }
f6503059
AZ
473 else
474 seconds = mktimegm(tm) + rtc_date_offset;
475
476 return seconds - time(NULL);
477}
478
80cd3478
LC
479void rtc_change_mon_event(struct tm *tm)
480{
481 QObject *data;
482
483 data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
484 monitor_protocol_event(QEVENT_RTC_CHANGE, data);
485 qobject_decref(data);
486}
487
1ed2fc1f
JK
488static void configure_rtc_date_offset(const char *startdate, int legacy)
489{
490 time_t rtc_start_date;
491 struct tm tm;
492
493 if (!strcmp(startdate, "now") && legacy) {
494 rtc_date_offset = -1;
495 } else {
496 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d",
497 &tm.tm_year,
498 &tm.tm_mon,
499 &tm.tm_mday,
500 &tm.tm_hour,
501 &tm.tm_min,
502 &tm.tm_sec) == 6) {
503 /* OK */
504 } else if (sscanf(startdate, "%d-%d-%d",
505 &tm.tm_year,
506 &tm.tm_mon,
507 &tm.tm_mday) == 3) {
508 tm.tm_hour = 0;
509 tm.tm_min = 0;
510 tm.tm_sec = 0;
511 } else {
512 goto date_fail;
513 }
514 tm.tm_year -= 1900;
515 tm.tm_mon--;
516 rtc_start_date = mktimegm(&tm);
517 if (rtc_start_date == -1) {
518 date_fail:
519 fprintf(stderr, "Invalid date format. Valid formats are:\n"
520 "'2006-06-17T16:01:21' or '2006-06-17'\n");
521 exit(1);
522 }
523 rtc_date_offset = time(NULL) - rtc_start_date;
524 }
525}
526
527static void configure_rtc(QemuOpts *opts)
528{
529 const char *value;
530
531 value = qemu_opt_get(opts, "base");
532 if (value) {
533 if (!strcmp(value, "utc")) {
534 rtc_utc = 1;
535 } else if (!strcmp(value, "localtime")) {
536 rtc_utc = 0;
537 } else {
538 configure_rtc_date_offset(value, 0);
539 }
540 }
6875204c
JK
541 value = qemu_opt_get(opts, "clock");
542 if (value) {
543 if (!strcmp(value, "host")) {
544 rtc_clock = host_clock;
78808141
PB
545 } else if (!strcmp(value, "rt")) {
546 rtc_clock = rt_clock;
6875204c
JK
547 } else if (!strcmp(value, "vm")) {
548 rtc_clock = vm_clock;
549 } else {
550 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
551 exit(1);
552 }
553 }
1ed2fc1f
JK
554 value = qemu_opt_get(opts, "driftfix");
555 if (value) {
7e4c0336 556 if (!strcmp(value, "slew")) {
433acf0d
JK
557 static GlobalProperty slew_lost_ticks[] = {
558 {
559 .driver = "mc146818rtc",
560 .property = "lost_tick_policy",
561 .value = "slew",
562 },
563 { /* end of list */ }
564 };
565
566 qdev_prop_register_global_list(slew_lost_ticks);
7e4c0336 567 } else if (!strcmp(value, "none")) {
433acf0d 568 /* discard is default */
1ed2fc1f
JK
569 } else {
570 fprintf(stderr, "qemu: invalid option value '%s'\n", value);
571 exit(1);
572 }
573 }
1ed2fc1f
JK
574}
575
1ae26a18
AZ
576/***********************************************************/
577/* Bluetooth support */
578static int nb_hcis;
579static int cur_hci;
580static struct HCIInfo *hci_table[MAX_NICS];
dc72ac14 581
1ae26a18
AZ
582static struct bt_vlan_s {
583 struct bt_scatternet_s net;
584 int id;
585 struct bt_vlan_s *next;
586} *first_bt_vlan;
587
588/* find or alloc a new bluetooth "VLAN" */
674bb261 589static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
1ae26a18
AZ
590{
591 struct bt_vlan_s **pvlan, *vlan;
592 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
593 if (vlan->id == id)
594 return &vlan->net;
595 }
7267c094 596 vlan = g_malloc0(sizeof(struct bt_vlan_s));
1ae26a18
AZ
597 vlan->id = id;
598 pvlan = &first_bt_vlan;
599 while (*pvlan != NULL)
600 pvlan = &(*pvlan)->next;
601 *pvlan = vlan;
602 return &vlan->net;
603}
604
605static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
606{
607}
608
609static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
610{
611 return -ENOTSUP;
612}
613
614static struct HCIInfo null_hci = {
615 .cmd_send = null_hci_send,
616 .sco_send = null_hci_send,
617 .acl_send = null_hci_send,
618 .bdaddr_set = null_hci_addr_set,
619};
620
621struct HCIInfo *qemu_next_hci(void)
622{
623 if (cur_hci == nb_hcis)
624 return &null_hci;
625
626 return hci_table[cur_hci++];
627}
628
dc72ac14
AZ
629static struct HCIInfo *hci_init(const char *str)
630{
631 char *endp;
632 struct bt_scatternet_s *vlan = 0;
633
634 if (!strcmp(str, "null"))
635 /* null */
636 return &null_hci;
637 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
638 /* host[:hciN] */
639 return bt_host_hci(str[4] ? str + 5 : "hci0");
640 else if (!strncmp(str, "hci", 3)) {
641 /* hci[,vlan=n] */
642 if (str[3]) {
643 if (!strncmp(str + 3, ",vlan=", 6)) {
644 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
645 if (*endp)
646 vlan = 0;
647 }
648 } else
649 vlan = qemu_find_bt_vlan(0);
650 if (vlan)
651 return bt_new_hci(vlan);
652 }
653
654 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
655
656 return 0;
657}
658
659static int bt_hci_parse(const char *str)
660{
661 struct HCIInfo *hci;
c227f099 662 bdaddr_t bdaddr;
dc72ac14
AZ
663
664 if (nb_hcis >= MAX_NICS) {
665 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
666 return -1;
667 }
668
669 hci = hci_init(str);
670 if (!hci)
671 return -1;
672
673 bdaddr.b[0] = 0x52;
674 bdaddr.b[1] = 0x54;
675 bdaddr.b[2] = 0x00;
676 bdaddr.b[3] = 0x12;
677 bdaddr.b[4] = 0x34;
678 bdaddr.b[5] = 0x56 + nb_hcis;
679 hci->bdaddr_set(hci, bdaddr.b);
680
681 hci_table[nb_hcis++] = hci;
682
683 return 0;
684}
685
686static void bt_vhci_add(int vlan_id)
687{
688 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
689
690 if (!vlan->slave)
691 fprintf(stderr, "qemu: warning: adding a VHCI to "
692 "an empty scatternet %i\n", vlan_id);
693
694 bt_vhci_init(bt_new_hci(vlan));
695}
696
697static struct bt_device_s *bt_device_add(const char *opt)
698{
699 struct bt_scatternet_s *vlan;
700 int vlan_id = 0;
701 char *endp = strstr(opt, ",vlan=");
702 int len = (endp ? endp - opt : strlen(opt)) + 1;
703 char devname[10];
704
705 pstrcpy(devname, MIN(sizeof(devname), len), opt);
706
707 if (endp) {
708 vlan_id = strtol(endp + 6, &endp, 0);
709 if (*endp) {
710 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
711 return 0;
712 }
713 }
714
715 vlan = qemu_find_bt_vlan(vlan_id);
716
717 if (!vlan->slave)
718 fprintf(stderr, "qemu: warning: adding a slave device to "
719 "an empty scatternet %i\n", vlan_id);
720
721 if (!strcmp(devname, "keyboard"))
722 return bt_keyboard_init(vlan);
723
724 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
725 return 0;
726}
727
728static int bt_parse(const char *opt)
729{
730 const char *endp, *p;
731 int vlan;
732
733 if (strstart(opt, "hci", &endp)) {
734 if (!*endp || *endp == ',') {
735 if (*endp)
736 if (!strstart(endp, ",vlan=", 0))
737 opt = endp + 1;
738
739 return bt_hci_parse(opt);
740 }
741 } else if (strstart(opt, "vhci", &endp)) {
742 if (!*endp || *endp == ',') {
743 if (*endp) {
744 if (strstart(endp, ",vlan=", &p)) {
745 vlan = strtol(p, (char **) &endp, 0);
746 if (*endp) {
747 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
748 return 1;
749 }
750 } else {
751 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
752 return 1;
753 }
754 } else
755 vlan = 0;
756
757 bt_vhci_add(vlan);
758 return 0;
759 }
760 } else if (strstart(opt, "device:", &endp))
761 return !bt_device_add(endp);
762
763 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
764 return 1;
765}
766
1ae26a18
AZ
767/***********************************************************/
768/* QEMU Block devices */
769
2292ddae
MA
770#define HD_OPTS "media=disk"
771#define CDROM_OPTS "media=cdrom"
772#define FD_OPTS ""
773#define PFLASH_OPTS ""
774#define MTD_OPTS ""
775#define SD_OPTS ""
e4bcb14c 776
9dfd7c7a
GH
777static int drive_init_func(QemuOpts *opts, void *opaque)
778{
a803cb8e 779 int *use_scsi = opaque;
9dfd7c7a 780
319ae529 781 return drive_init(opts, *use_scsi) == NULL;
9dfd7c7a
GH
782}
783
784static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
785{
786 if (NULL == qemu_opt_get(opts, "snapshot")) {
787 qemu_opt_set(opts, "snapshot", "on");
788 }
789 return 0;
790}
791
4e5d9b57
MA
792static void default_drive(int enable, int snapshot, int use_scsi,
793 BlockInterfaceType type, int index,
794 const char *optstr)
795{
796 QemuOpts *opts;
797
798 if (type == IF_DEFAULT) {
799 type = use_scsi ? IF_SCSI : IF_IDE;
800 }
801
802 if (!enable || drive_get_by_index(type, index)) {
803 return;
804 }
805
806 opts = drive_add(type, index, NULL, optstr);
807 if (snapshot) {
808 drive_enable_snapshot(opts, NULL);
809 }
319ae529 810 if (!drive_init(opts, use_scsi)) {
4e5d9b57
MA
811 exit(1);
812 }
813}
814
76e30d0f
JK
815void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque)
816{
817 boot_set_handler = func;
818 boot_set_opaque = opaque;
819}
820
821int qemu_boot_set(const char *boot_devices)
822{
823 if (!boot_set_handler) {
824 return -EINVAL;
825 }
826 return boot_set_handler(boot_set_opaque, boot_devices);
827}
828
4e9e9d6e 829static void validate_bootdevices(char *devices)
ef3adf68
JK
830{
831 /* We just do some generic consistency checks */
832 const char *p;
833 int bitmap = 0;
834
835 for (p = devices; *p != '\0'; p++) {
836 /* Allowed boot devices are:
837 * a-b: floppy disk drives
838 * c-f: IDE disk drives
07f35073 839 * g-m: machine implementation dependent drives
ef3adf68
JK
840 * n-p: network devices
841 * It's up to each machine implementation to check if the given boot
842 * devices match the actual hardware implementation and firmware
843 * features.
844 */
845 if (*p < 'a' || *p > 'p') {
846 fprintf(stderr, "Invalid boot device '%c'\n", *p);
847 exit(1);
848 }
849 if (bitmap & (1 << (*p - 'a'))) {
850 fprintf(stderr, "Boot device '%c' was given twice\n", *p);
851 exit(1);
852 }
853 bitmap |= 1 << (*p - 'a');
854 }
ef3adf68
JK
855}
856
e0f084bf
JK
857static void restore_boot_devices(void *opaque)
858{
859 char *standard_boot_devices = opaque;
37905d6a
AW
860 static int first = 1;
861
862 /* Restore boot order and remove ourselves after the first boot */
863 if (first) {
864 first = 0;
865 return;
866 }
e0f084bf
JK
867
868 qemu_boot_set(standard_boot_devices);
869
870 qemu_unregister_reset(restore_boot_devices, standard_boot_devices);
7267c094 871 g_free(standard_boot_devices);
e0f084bf
JK
872}
873
1ca4d09a
GN
874void add_boot_device_path(int32_t bootindex, DeviceState *dev,
875 const char *suffix)
876{
877 FWBootEntry *node, *i;
878
879 if (bootindex < 0) {
880 return;
881 }
882
883 assert(dev != NULL || suffix != NULL);
884
7267c094 885 node = g_malloc0(sizeof(FWBootEntry));
1ca4d09a 886 node->bootindex = bootindex;
7267c094 887 node->suffix = suffix ? g_strdup(suffix) : NULL;
1ca4d09a
GN
888 node->dev = dev;
889
890 QTAILQ_FOREACH(i, &fw_boot_order, link) {
891 if (i->bootindex == bootindex) {
892 fprintf(stderr, "Two devices with same boot index %d\n", bootindex);
893 exit(1);
894 } else if (i->bootindex < bootindex) {
895 continue;
896 }
897 QTAILQ_INSERT_BEFORE(i, node, link);
898 return;
899 }
900 QTAILQ_INSERT_TAIL(&fw_boot_order, node, link);
901}
902
962630f2
GN
903/*
904 * This function returns null terminated string that consist of new line
71785aba 905 * separated device paths.
962630f2
GN
906 *
907 * memory pointed by "size" is assigned total length of the array in bytes
908 *
909 */
910char *get_boot_devices_list(uint32_t *size)
911{
912 FWBootEntry *i;
913 uint32_t total = 0;
914 char *list = NULL;
915
916 QTAILQ_FOREACH(i, &fw_boot_order, link) {
917 char *devpath = NULL, *bootpath;
918 int len;
919
920 if (i->dev) {
921 devpath = qdev_get_fw_dev_path(i->dev);
922 assert(devpath);
923 }
924
925 if (i->suffix && devpath) {
4fd37a98
BS
926 size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
927
7267c094 928 bootpath = g_malloc(bootpathlen);
4fd37a98 929 snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix);
7267c094 930 g_free(devpath);
962630f2
GN
931 } else if (devpath) {
932 bootpath = devpath;
933 } else {
1bf6ccd3 934 assert(i->suffix);
7267c094 935 bootpath = g_strdup(i->suffix);
962630f2
GN
936 }
937
938 if (total) {
939 list[total-1] = '\n';
940 }
941 len = strlen(bootpath) + 1;
7267c094 942 list = g_realloc(list, total + len);
962630f2
GN
943 memcpy(&list[total], bootpath, len);
944 total += len;
7267c094 945 g_free(bootpath);
962630f2
GN
946 }
947
948 *size = total;
949
950 return list;
951}
952
268a362c
AL
953static void numa_add(const char *optarg)
954{
955 char option[128];
956 char *endptr;
957 unsigned long long value, endvalue;
958 int nodenr;
959
960 optarg = get_opt_name(option, 128, optarg, ',') + 1;
961 if (!strcmp(option, "node")) {
962 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
963 nodenr = nb_numa_nodes;
964 } else {
965 nodenr = strtoull(option, NULL, 10);
966 }
967
968 if (get_param_value(option, 128, "mem", optarg) == 0) {
969 node_mem[nodenr] = 0;
970 } else {
70b4f4bb 971 int64_t sval;
c03417b4
MA
972 sval = strtosz(option, &endptr);
973 if (sval < 0 || *endptr) {
9f9b17a4
JS
974 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
975 exit(1);
268a362c 976 }
9f9b17a4 977 node_mem[nodenr] = sval;
268a362c
AL
978 }
979 if (get_param_value(option, 128, "cpus", optarg) == 0) {
980 node_cpumask[nodenr] = 0;
981 } else {
982 value = strtoull(option, &endptr, 10);
983 if (value >= 64) {
984 value = 63;
985 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
986 } else {
987 if (*endptr == '-') {
988 endvalue = strtoull(endptr+1, &endptr, 10);
989 if (endvalue >= 63) {
990 endvalue = 62;
991 fprintf(stderr,
992 "only 63 CPUs in NUMA mode supported.\n");
993 }
0dfbd514 994 value = (2ULL << endvalue) - (1ULL << value);
268a362c 995 } else {
0dfbd514 996 value = 1ULL << value;
268a362c
AL
997 }
998 }
999 node_cpumask[nodenr] = value;
1000 }
1001 nb_numa_nodes++;
1002 }
1003 return;
1004}
1005
dc6b1c09
AP
1006static void smp_parse(const char *optarg)
1007{
1008 int smp, sockets = 0, threads = 0, cores = 0;
1009 char *endptr;
1010 char option[128];
1011
1012 smp = strtoul(optarg, &endptr, 10);
1013 if (endptr != optarg) {
1014 if (*endptr == ',') {
1015 endptr++;
1016 }
1017 }
1018 if (get_param_value(option, 128, "sockets", endptr) != 0)
1019 sockets = strtoull(option, NULL, 10);
1020 if (get_param_value(option, 128, "cores", endptr) != 0)
1021 cores = strtoull(option, NULL, 10);
1022 if (get_param_value(option, 128, "threads", endptr) != 0)
1023 threads = strtoull(option, NULL, 10);
1024 if (get_param_value(option, 128, "maxcpus", endptr) != 0)
1025 max_cpus = strtoull(option, NULL, 10);
1026
1027 /* compute missing values, prefer sockets over cores over threads */
1028 if (smp == 0 || sockets == 0) {
1029 sockets = sockets > 0 ? sockets : 1;
1030 cores = cores > 0 ? cores : 1;
1031 threads = threads > 0 ? threads : 1;
1032 if (smp == 0) {
1033 smp = cores * threads * sockets;
dc6b1c09
AP
1034 }
1035 } else {
1036 if (cores == 0) {
1037 threads = threads > 0 ? threads : 1;
1038 cores = smp / (sockets * threads);
1039 } else {
dca98169 1040 threads = smp / (cores * sockets);
dc6b1c09
AP
1041 }
1042 }
1043 smp_cpus = smp;
1044 smp_cores = cores > 0 ? cores : 1;
1045 smp_threads = threads > 0 ? threads : 1;
1046 if (max_cpus == 0)
1047 max_cpus = smp_cpus;
1048}
1049
a594cfbf
FB
1050/***********************************************************/
1051/* USB devices */
1052
fb08000c 1053static int usb_device_add(const char *devname)
a594cfbf
FB
1054{
1055 const char *p;
a5d2f727 1056 USBDevice *dev = NULL;
a594cfbf 1057
a5d2f727 1058 if (!usb_enabled)
a594cfbf
FB
1059 return -1;
1060
0958b4cc
GH
1061 /* drivers with .usbdevice_name entry in USBDeviceInfo */
1062 dev = usbdevice_create(devname);
1063 if (dev)
1064 goto done;
1065
a5d2f727 1066 /* the other ones */
e447fc63
GH
1067#ifndef CONFIG_LINUX
1068 /* only the linux version is qdev-ified, usb-bsd still needs this */
a594cfbf 1069 if (strstart(devname, "host:", &p)) {
3741715c 1070 dev = usb_host_device_open(usb_bus_find(-1), p);
e447fc63
GH
1071 } else
1072#endif
1073 if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
3741715c
JK
1074 dev = usb_bt_init(usb_bus_find(-1),
1075 devname[2] ? hci_init(p)
1076 : bt_new_hci(qemu_find_bt_vlan(0)));
a594cfbf
FB
1077 } else {
1078 return -1;
1079 }
0d92ed30
PB
1080 if (!dev)
1081 return -1;
1082
a5d2f727 1083done:
a594cfbf
FB
1084 return 0;
1085}
1086
1f3870ab
AL
1087static int usb_device_del(const char *devname)
1088{
1089 int bus_num, addr;
1090 const char *p;
1091
5d0c5750
AL
1092 if (strstart(devname, "host:", &p))
1093 return usb_host_device_close(p);
1094
a5d2f727 1095 if (!usb_enabled)
1f3870ab
AL
1096 return -1;
1097
1098 p = strchr(devname, '.');
1099 if (!p)
1100 return -1;
1101 bus_num = strtoul(devname, NULL, 0);
1102 addr = strtoul(p + 1, NULL, 0);
1103
a5d2f727 1104 return usb_device_delete_addr(bus_num, addr);
1f3870ab
AL
1105}
1106
bd3c948d
GH
1107static int usb_parse(const char *cmdline)
1108{
59d1c1c2 1109 int r;
fb08000c 1110 r = usb_device_add(cmdline);
59d1c1c2
ST
1111 if (r < 0) {
1112 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
1113 }
1114 return r;
bd3c948d
GH
1115}
1116
d54908a5 1117void do_usb_add(Monitor *mon, const QDict *qdict)
a594cfbf 1118{
59d1c1c2 1119 const char *devname = qdict_get_str(qdict, "devname");
fb08000c 1120 if (usb_device_add(devname) < 0) {
1ecda02b 1121 error_report("could not add USB device '%s'", devname);
59d1c1c2 1122 }
a594cfbf
FB
1123}
1124
d54908a5 1125void do_usb_del(Monitor *mon, const QDict *qdict)
a594cfbf 1126{
59d1c1c2
ST
1127 const char *devname = qdict_get_str(qdict, "devname");
1128 if (usb_device_del(devname) < 0) {
1ecda02b 1129 error_report("could not delete USB device '%s'", devname);
59d1c1c2 1130 }
a594cfbf
FB
1131}
1132
201a51fc
AZ
1133/***********************************************************/
1134/* PCMCIA/Cardbus */
1135
1136static struct pcmcia_socket_entry_s {
bc24a225 1137 PCMCIASocket *socket;
201a51fc
AZ
1138 struct pcmcia_socket_entry_s *next;
1139} *pcmcia_sockets = 0;
1140
bc24a225 1141void pcmcia_socket_register(PCMCIASocket *socket)
201a51fc
AZ
1142{
1143 struct pcmcia_socket_entry_s *entry;
1144
7267c094 1145 entry = g_malloc(sizeof(struct pcmcia_socket_entry_s));
201a51fc
AZ
1146 entry->socket = socket;
1147 entry->next = pcmcia_sockets;
1148 pcmcia_sockets = entry;
1149}
1150
bc24a225 1151void pcmcia_socket_unregister(PCMCIASocket *socket)
201a51fc
AZ
1152{
1153 struct pcmcia_socket_entry_s *entry, **ptr;
1154
1155 ptr = &pcmcia_sockets;
1156 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1157 if (entry->socket == socket) {
1158 *ptr = entry->next;
7267c094 1159 g_free(entry);
201a51fc
AZ
1160 }
1161}
1162
376253ec 1163void pcmcia_info(Monitor *mon)
201a51fc
AZ
1164{
1165 struct pcmcia_socket_entry_s *iter;
376253ec 1166
201a51fc 1167 if (!pcmcia_sockets)
376253ec 1168 monitor_printf(mon, "No PCMCIA sockets\n");
201a51fc
AZ
1169
1170 for (iter = pcmcia_sockets; iter; iter = iter->next)
376253ec
AL
1171 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1172 iter->socket->attached ? iter->socket->card_string :
1173 "Empty");
201a51fc
AZ
1174}
1175
cc1daa40
FB
1176/***********************************************************/
1177/* machine registration */
1178
bdaf78e0 1179static QEMUMachine *first_machine = NULL;
6f338c34 1180QEMUMachine *current_machine = NULL;
cc1daa40
FB
1181
1182int qemu_register_machine(QEMUMachine *m)
1183{
1184 QEMUMachine **pm;
1185 pm = &first_machine;
1186 while (*pm != NULL)
1187 pm = &(*pm)->next;
1188 m->next = NULL;
1189 *pm = m;
1190 return 0;
1191}
1192
9596ebb7 1193static QEMUMachine *find_machine(const char *name)
cc1daa40
FB
1194{
1195 QEMUMachine *m;
1196
1197 for(m = first_machine; m != NULL; m = m->next) {
1198 if (!strcmp(m->name, name))
1199 return m;
3f6599e6
MM
1200 if (m->alias && !strcmp(m->alias, name))
1201 return m;
cc1daa40
FB
1202 }
1203 return NULL;
1204}
1205
2c8cffa5 1206QEMUMachine *find_default_machine(void)
0c257437
AL
1207{
1208 QEMUMachine *m;
1209
1210 for(m = first_machine; m != NULL; m = m->next) {
1211 if (m->is_default) {
1212 return m;
1213 }
1214 }
1215 return NULL;
1216}
1217
8a7ddc38
FB
1218/***********************************************************/
1219/* main execution loop */
1220
9596ebb7 1221static void gui_update(void *opaque)
8a7ddc38 1222{
7d957bd8 1223 uint64_t interval = GUI_REFRESH_INTERVAL;
740733bb 1224 DisplayState *ds = opaque;
7d957bd8
AL
1225 DisplayChangeListener *dcl = ds->listeners;
1226
1227 dpy_refresh(ds);
1228
1229 while (dcl != NULL) {
1230 if (dcl->gui_timer_interval &&
1231 dcl->gui_timer_interval < interval)
1232 interval = dcl->gui_timer_interval;
1233 dcl = dcl->next;
1234 }
7bd427d8 1235 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
8a7ddc38
FB
1236}
1237
0bd48850
FB
1238struct vm_change_state_entry {
1239 VMChangeStateHandler *cb;
1240 void *opaque;
72cf2d4f 1241 QLIST_ENTRY (vm_change_state_entry) entries;
0bd48850
FB
1242};
1243
72cf2d4f 1244static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
0bd48850
FB
1245
1246VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
1247 void *opaque)
1248{
1249 VMChangeStateEntry *e;
1250
7267c094 1251 e = g_malloc0(sizeof (*e));
0bd48850
FB
1252
1253 e->cb = cb;
1254 e->opaque = opaque;
72cf2d4f 1255 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
0bd48850
FB
1256 return e;
1257}
1258
1259void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
1260{
72cf2d4f 1261 QLIST_REMOVE (e, entries);
7267c094 1262 g_free (e);
0bd48850
FB
1263}
1264
1dfb4dd9 1265void vm_state_notify(int running, RunState state)
0bd48850
FB
1266{
1267 VMChangeStateEntry *e;
1268
1dfb4dd9 1269 trace_vm_state_notify(running, state);
94b0b5ff 1270
0bd48850 1271 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
1dfb4dd9 1272 e->cb(e->opaque, running, state);
0bd48850
FB
1273 }
1274}
1275
8a7ddc38
FB
1276void vm_start(void)
1277{
1354869c 1278 if (!runstate_is_running()) {
8a7ddc38 1279 cpu_enable_ticks();
0461d5a6
LC
1280 runstate_set(RUN_STATE_RUNNING);
1281 vm_state_notify(1, RUN_STATE_RUNNING);
d6dc3d42 1282 resume_all_vcpus();
6ed2c484 1283 monitor_protocol_event(QEVENT_RESUME, NULL);
8a7ddc38
FB
1284 }
1285}
1286
bb0c6722
FB
1287/* reset/shutdown handler */
1288
1289typedef struct QEMUResetEntry {
72cf2d4f 1290 QTAILQ_ENTRY(QEMUResetEntry) entry;
bb0c6722
FB
1291 QEMUResetHandler *func;
1292 void *opaque;
bb0c6722
FB
1293} QEMUResetEntry;
1294
72cf2d4f
BS
1295static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
1296 QTAILQ_HEAD_INITIALIZER(reset_handlers);
bb0c6722 1297static int reset_requested;
f64622c4
GN
1298static int shutdown_requested, shutdown_signal = -1;
1299static pid_t shutdown_pid;
3475187d 1300static int powerdown_requested;
8cf71710 1301static int debug_requested;
95b363b5 1302static int suspend_requested;
95b363b5
GH
1303static NotifierList suspend_notifiers =
1304 NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
1305static NotifierList wakeup_notifiers =
1306 NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
1307static uint32_t wakeup_reason_mask = ~0;
0461d5a6 1308static RunState vmstop_requested = RUN_STATE_MAX;
bb0c6722 1309
1291eb35
AP
1310int qemu_shutdown_requested_get(void)
1311{
1312 return shutdown_requested;
1313}
1314
1315int qemu_reset_requested_get(void)
1316{
1317 return reset_requested;
1318}
1319
cf7a2fe2
AJ
1320int qemu_shutdown_requested(void)
1321{
1322 int r = shutdown_requested;
1323 shutdown_requested = 0;
1324 return r;
1325}
1326
f64622c4
GN
1327void qemu_kill_report(void)
1328{
c7f0f3b1 1329 if (!qtest_enabled() && shutdown_signal != -1) {
f1d3fb04
PM
1330 fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
1331 if (shutdown_pid == 0) {
1332 /* This happens for eg ^C at the terminal, so it's worth
1333 * avoiding printing an odd message in that case.
1334 */
1335 fputc('\n', stderr);
1336 } else {
953ffe0f 1337 fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
f1d3fb04 1338 }
f64622c4
GN
1339 shutdown_signal = -1;
1340 }
1341}
1342
cf7a2fe2
AJ
1343int qemu_reset_requested(void)
1344{
1345 int r = reset_requested;
1346 reset_requested = 0;
1347 return r;
1348}
1349
95b363b5
GH
1350static int qemu_suspend_requested(void)
1351{
1352 int r = suspend_requested;
1353 suspend_requested = 0;
1354 return r;
1355}
1356
cf7a2fe2
AJ
1357int qemu_powerdown_requested(void)
1358{
1359 int r = powerdown_requested;
1360 powerdown_requested = 0;
1361 return r;
1362}
1363
e568902a
AL
1364static int qemu_debug_requested(void)
1365{
1366 int r = debug_requested;
1367 debug_requested = 0;
1368 return r;
1369}
1370
0461d5a6 1371/* We use RUN_STATE_MAX but any invalid value will do */
0d45b702 1372static bool qemu_vmstop_requested(RunState *r)
6e29f5da 1373{
0461d5a6 1374 if (vmstop_requested < RUN_STATE_MAX) {
0d45b702 1375 *r = vmstop_requested;
0461d5a6 1376 vmstop_requested = RUN_STATE_MAX;
0d45b702
LC
1377 return true;
1378 }
1379
1380 return false;
6e29f5da
AL
1381}
1382
a08d4367 1383void qemu_register_reset(QEMUResetHandler *func, void *opaque)
bb0c6722 1384{
7267c094 1385 QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
bb0c6722 1386
bb0c6722
FB
1387 re->func = func;
1388 re->opaque = opaque;
72cf2d4f 1389 QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
bb0c6722
FB
1390}
1391
dda9b29f 1392void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
bb0c6722
FB
1393{
1394 QEMUResetEntry *re;
1395
72cf2d4f 1396 QTAILQ_FOREACH(re, &reset_handlers, entry) {
dda9b29f 1397 if (re->func == func && re->opaque == opaque) {
72cf2d4f 1398 QTAILQ_REMOVE(&reset_handlers, re, entry);
7267c094 1399 g_free(re);
dda9b29f
JK
1400 return;
1401 }
1402 }
1403}
1404
e063eb1f 1405void qemu_system_reset(bool report)
dda9b29f
JK
1406{
1407 QEMUResetEntry *re, *nre;
1408
1409 /* reset all devices */
72cf2d4f 1410 QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
bb0c6722
FB
1411 re->func(re->opaque);
1412 }
e063eb1f
JK
1413 if (report) {
1414 monitor_protocol_event(QEVENT_RESET, NULL);
1415 }
ea375f9a 1416 cpu_synchronize_all_post_reset();
bb0c6722
FB
1417}
1418
1419void qemu_system_reset_request(void)
1420{
d1beab82
FB
1421 if (no_reboot) {
1422 shutdown_requested = 1;
1423 } else {
1424 reset_requested = 1;
1425 }
b4a3d965 1426 cpu_stop_current();
d9f75a4e 1427 qemu_notify_event();
bb0c6722
FB
1428}
1429
95b363b5
GH
1430static void qemu_system_suspend(void)
1431{
1432 pause_all_vcpus();
1433 notifier_list_notify(&suspend_notifiers, NULL);
ad02b96a 1434 runstate_set(RUN_STATE_SUSPENDED);
53370b78 1435 monitor_protocol_event(QEVENT_SUSPEND, NULL);
95b363b5
GH
1436}
1437
1438void qemu_system_suspend_request(void)
1439{
9abc62f6 1440 if (runstate_check(RUN_STATE_SUSPENDED)) {
95b363b5
GH
1441 return;
1442 }
1443 suspend_requested = 1;
1444 cpu_stop_current();
1445 qemu_notify_event();
1446}
1447
1448void qemu_register_suspend_notifier(Notifier *notifier)
1449{
1450 notifier_list_add(&suspend_notifiers, notifier);
1451}
1452
1453void qemu_system_wakeup_request(WakeupReason reason)
1454{
9abc62f6 1455 if (!runstate_check(RUN_STATE_SUSPENDED)) {
95b363b5
GH
1456 return;
1457 }
1458 if (!(wakeup_reason_mask & (1 << reason))) {
1459 return;
1460 }
ad02b96a 1461 runstate_set(RUN_STATE_RUNNING);
53370b78 1462 monitor_protocol_event(QEVENT_WAKEUP, NULL);
95b363b5
GH
1463 notifier_list_notify(&wakeup_notifiers, &reason);
1464 reset_requested = 1;
1465 qemu_notify_event();
95b363b5
GH
1466}
1467
1468void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
1469{
1470 if (enabled) {
1471 wakeup_reason_mask |= (1 << reason);
1472 } else {
1473 wakeup_reason_mask &= ~(1 << reason);
1474 }
1475}
1476
1477void qemu_register_wakeup_notifier(Notifier *notifier)
1478{
1479 notifier_list_add(&wakeup_notifiers, notifier);
1480}
1481
f64622c4
GN
1482void qemu_system_killed(int signal, pid_t pid)
1483{
1484 shutdown_signal = signal;
1485 shutdown_pid = pid;
d9389b96 1486 no_shutdown = 0;
f64622c4
GN
1487 qemu_system_shutdown_request();
1488}
1489
bb0c6722
FB
1490void qemu_system_shutdown_request(void)
1491{
1492 shutdown_requested = 1;
d9f75a4e 1493 qemu_notify_event();
bb0c6722
FB
1494}
1495
3475187d
FB
1496void qemu_system_powerdown_request(void)
1497{
1498 powerdown_requested = 1;
d9f75a4e
AL
1499 qemu_notify_event();
1500}
1501
8cf71710
JK
1502void qemu_system_debug_request(void)
1503{
1504 debug_requested = 1;
83f338f7 1505 qemu_notify_event();
8cf71710
JK
1506}
1507
1dfb4dd9 1508void qemu_system_vmstop_request(RunState state)
8cf71710 1509{
1dfb4dd9 1510 vmstop_requested = state;
8cf71710
JK
1511 qemu_notify_event();
1512}
1513
d9c32310
BS
1514qemu_irq qemu_system_powerdown;
1515
99435906
PB
1516static bool main_loop_should_exit(void)
1517{
1518 RunState r;
1519 if (qemu_debug_requested()) {
1520 vm_stop(RUN_STATE_DEBUG);
1521 }
95b363b5
GH
1522 if (qemu_suspend_requested()) {
1523 qemu_system_suspend();
1524 }
99435906
PB
1525 if (qemu_shutdown_requested()) {
1526 qemu_kill_report();
1527 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
1528 if (no_shutdown) {
1529 vm_stop(RUN_STATE_SHUTDOWN);
1530 } else {
1531 return true;
1532 }
1533 }
1534 if (qemu_reset_requested()) {
1535 pause_all_vcpus();
1536 cpu_synchronize_all_states();
1537 qemu_system_reset(VMRESET_REPORT);
1538 resume_all_vcpus();
1539 if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
1540 runstate_check(RUN_STATE_SHUTDOWN)) {
1541 runstate_set(RUN_STATE_PAUSED);
1542 }
1543 }
1544 if (qemu_powerdown_requested()) {
1545 monitor_protocol_event(QEVENT_POWERDOWN, NULL);
1546 qemu_irq_raise(qemu_system_powerdown);
1547 }
1548 if (qemu_vmstop_requested(&r)) {
1549 vm_stop(r);
1550 }
1551 return false;
1552}
1553
43b96858
AL
1554static void main_loop(void)
1555{
c9f711a5 1556 bool nonblocking;
99435906 1557 int last_io = 0;
8e1b90ec
JK
1558#ifdef CONFIG_PROFILER
1559 int64_t ti;
1560#endif
99435906 1561 do {
c9f711a5 1562 nonblocking = !kvm_enabled() && last_io > 0;
89bfc105 1563#ifdef CONFIG_PROFILER
46481d39 1564 ti = profile_getclock();
89bfc105 1565#endif
c9f711a5 1566 last_io = main_loop_wait(nonblocking);
89bfc105 1567#ifdef CONFIG_PROFILER
46481d39 1568 dev_time += profile_getclock() - ti;
89bfc105 1569#endif
99435906 1570 } while (!main_loop_should_exit());
b4608c04
FB
1571}
1572
9bd7e6d9
PB
1573static void version(void)
1574{
f75ca1ae 1575 printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
9bd7e6d9
PB
1576}
1577
15f82208 1578static void help(int exitcode)
0824d6fc 1579{
a3adb7ad
ME
1580 version();
1581 printf("usage: %s [options] [disk_image]\n\n"
1582 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
1583 error_get_progname());
1584
77bd1119
ME
1585#define QEMU_OPTIONS_GENERATE_HELP
1586#include "qemu-options-wrapper.h"
a3adb7ad
ME
1587
1588 printf("\nDuring emulation, the following keys are useful:\n"
3f020d70 1589 "ctrl-alt-f toggle full screen\n"
1590 "ctrl-alt-n switch to virtual console 'n'\n"
1591 "ctrl-alt toggle mouse and keyboard grab\n"
1592 "\n"
a3adb7ad
ME
1593 "When using -nographic, press 'ctrl-a h' to get some help.\n");
1594
15f82208 1595 exit(exitcode);
0824d6fc
FB
1596}
1597
cd6f1169
FB
1598#define HAS_ARG 0x0001
1599
cd6f1169
FB
1600typedef struct QEMUOption {
1601 const char *name;
1602 int flags;
1603 int index;
ad96090a 1604 uint32_t arch_mask;
cd6f1169
FB
1605} QEMUOption;
1606
dbed7e40 1607static const QEMUOption qemu_options[] = {
ad96090a 1608 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
77bd1119
ME
1609#define QEMU_OPTIONS_GENERATE_OPTIONS
1610#include "qemu-options-wrapper.h"
cd6f1169 1611 { NULL },
fc01f7e7 1612};
a369da5f
BS
1613
1614static bool vga_available(void)
1615{
1616 return qdev_exists("VGA") || qdev_exists("isa-vga");
1617}
1618
1619static bool cirrus_vga_available(void)
1620{
1621 return qdev_exists("cirrus-vga") || qdev_exists("isa-cirrus-vga");
1622}
1623
1624static bool vmware_vga_available(void)
1625{
1626 return qdev_exists("vmware-svga");
1627}
1628
3893c124 1629static void select_vgahw (const char *p)
1630{
1631 const char *opts;
1632
86176759 1633 vga_interface_type = VGA_NONE;
3893c124 1634 if (strstart(p, "std", &opts)) {
a369da5f
BS
1635 if (vga_available()) {
1636 vga_interface_type = VGA_STD;
1637 } else {
1638 fprintf(stderr, "Error: standard VGA not available\n");
1639 exit(0);
1640 }
3893c124 1641 } else if (strstart(p, "cirrus", &opts)) {
a369da5f
BS
1642 if (cirrus_vga_available()) {
1643 vga_interface_type = VGA_CIRRUS;
1644 } else {
1645 fprintf(stderr, "Error: Cirrus VGA not available\n");
1646 exit(0);
1647 }
3893c124 1648 } else if (strstart(p, "vmware", &opts)) {
a369da5f
BS
1649 if (vmware_vga_available()) {
1650 vga_interface_type = VGA_VMWARE;
1651 } else {
1652 fprintf(stderr, "Error: VMWare SVGA not available\n");
1653 exit(0);
1654 }
94909d9f 1655 } else if (strstart(p, "xenfb", &opts)) {
86176759 1656 vga_interface_type = VGA_XENFB;
a19cbfb3
GH
1657 } else if (strstart(p, "qxl", &opts)) {
1658 vga_interface_type = VGA_QXL;
28b85ed8 1659 } else if (!strstart(p, "none", &opts)) {
3893c124 1660 invalid_vga:
1661 fprintf(stderr, "Unknown vga type: %s\n", p);
1662 exit(1);
1663 }
cb5a7aa8 1664 while (*opts) {
1665 const char *nextopt;
1666
1667 if (strstart(opts, ",retrace=", &nextopt)) {
1668 opts = nextopt;
1669 if (strstart(opts, "dumb", &nextopt))
1670 vga_retrace_method = VGA_RETRACE_DUMB;
1671 else if (strstart(opts, "precise", &nextopt))
1672 vga_retrace_method = VGA_RETRACE_PRECISE;
1673 else goto invalid_vga;
1674 } else goto invalid_vga;
1675 opts = nextopt;
1676 }
3893c124 1677}
1678
1472a95b
JS
1679static DisplayType select_display(const char *p)
1680{
1681 const char *opts;
1682 DisplayType display = DT_DEFAULT;
1683
1684 if (strstart(p, "sdl", &opts)) {
1685#ifdef CONFIG_SDL
1686 display = DT_SDL;
1687 while (*opts) {
1688 const char *nextopt;
1689
1690 if (strstart(opts, ",frame=", &nextopt)) {
1691 opts = nextopt;
1692 if (strstart(opts, "on", &nextopt)) {
1693 no_frame = 0;
1694 } else if (strstart(opts, "off", &nextopt)) {
1695 no_frame = 1;
1696 } else {
05175535 1697 goto invalid_sdl_args;
1472a95b
JS
1698 }
1699 } else if (strstart(opts, ",alt_grab=", &nextopt)) {
1700 opts = nextopt;
1701 if (strstart(opts, "on", &nextopt)) {
1702 alt_grab = 1;
1703 } else if (strstart(opts, "off", &nextopt)) {
1704 alt_grab = 0;
1705 } else {
05175535 1706 goto invalid_sdl_args;
1472a95b
JS
1707 }
1708 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1709 opts = nextopt;
1710 if (strstart(opts, "on", &nextopt)) {
1711 ctrl_grab = 1;
1712 } else if (strstart(opts, "off", &nextopt)) {
1713 ctrl_grab = 0;
1714 } else {
05175535 1715 goto invalid_sdl_args;
1472a95b
JS
1716 }
1717 } else if (strstart(opts, ",window_close=", &nextopt)) {
1718 opts = nextopt;
1719 if (strstart(opts, "on", &nextopt)) {
1720 no_quit = 0;
1721 } else if (strstart(opts, "off", &nextopt)) {
1722 no_quit = 1;
1723 } else {
05175535 1724 goto invalid_sdl_args;
1472a95b
JS
1725 }
1726 } else {
05175535
PM
1727 invalid_sdl_args:
1728 fprintf(stderr, "Invalid SDL option string: %s\n", p);
1729 exit(1);
1472a95b
JS
1730 }
1731 opts = nextopt;
1732 }
1733#else
1734 fprintf(stderr, "SDL support is disabled\n");
1735 exit(1);
1736#endif
3264ff12 1737 } else if (strstart(p, "vnc", &opts)) {
821601ea 1738#ifdef CONFIG_VNC
3264ff12
JS
1739 display_remote++;
1740
1741 if (*opts) {
1742 const char *nextopt;
1743
1744 if (strstart(opts, "=", &nextopt)) {
1745 vnc_display = nextopt;
1746 }
1747 }
1748 if (!vnc_display) {
1749 fprintf(stderr, "VNC requires a display argument vnc=<display>\n");
1750 exit(1);
1751 }
821601ea
JS
1752#else
1753 fprintf(stderr, "VNC support is disabled\n");
1754 exit(1);
1755#endif
1472a95b
JS
1756 } else if (strstart(p, "curses", &opts)) {
1757#ifdef CONFIG_CURSES
1758 display = DT_CURSES;
1759#else
1760 fprintf(stderr, "Curses support is disabled\n");
1761 exit(1);
1762#endif
4171d32e
JS
1763 } else if (strstart(p, "none", &opts)) {
1764 display = DT_NONE;
1472a95b 1765 } else {
1472a95b
JS
1766 fprintf(stderr, "Unknown display type: %s\n", p);
1767 exit(1);
1768 }
1769
1770 return display;
1771}
1772
7d4c3d53
MA
1773static int balloon_parse(const char *arg)
1774{
382f0743 1775 QemuOpts *opts;
7d4c3d53 1776
382f0743
GH
1777 if (strcmp(arg, "none") == 0) {
1778 return 0;
1779 }
1780
1781 if (!strncmp(arg, "virtio", 6)) {
1782 if (arg[6] == ',') {
1783 /* have params -> parse them */
3329f07b 1784 opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0);
382f0743
GH
1785 if (!opts)
1786 return -1;
1787 } else {
1788 /* create empty opts */
3329f07b 1789 opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
7d4c3d53 1790 }
29f82b37 1791 qemu_opt_set(opts, "driver", "virtio-balloon");
382f0743 1792 return 0;
7d4c3d53 1793 }
382f0743
GH
1794
1795 return -1;
7d4c3d53 1796}
7d4c3d53 1797
5cea8590
PB
1798char *qemu_find_file(int type, const char *name)
1799{
1800 int len;
1801 const char *subdir;
1802 char *buf;
1803
1804 /* If name contains path separators then try it as a straight path. */
1805 if ((strchr(name, '/') || strchr(name, '\\'))
1806 && access(name, R_OK) == 0) {
7267c094 1807 return g_strdup(name);
5cea8590
PB
1808 }
1809 switch (type) {
1810 case QEMU_FILE_TYPE_BIOS:
1811 subdir = "";
1812 break;
1813 case QEMU_FILE_TYPE_KEYMAP:
1814 subdir = "keymaps/";
1815 break;
1816 default:
1817 abort();
1818 }
1819 len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
7267c094 1820 buf = g_malloc0(len);
3a41759d 1821 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
5cea8590 1822 if (access(buf, R_OK)) {
7267c094 1823 g_free(buf);
5cea8590
PB
1824 return NULL;
1825 }
1826 return buf;
1827}
1828
ff952ba2
MA
1829static int device_help_func(QemuOpts *opts, void *opaque)
1830{
1831 return qdev_device_help(opts);
1832}
1833
f31d07d1
GH
1834static int device_init_func(QemuOpts *opts, void *opaque)
1835{
1836 DeviceState *dev;
1837
1838 dev = qdev_device_add(opts);
1839 if (!dev)
1840 return -1;
1841 return 0;
1842}
1843
1a688d3b
GH
1844static int chardev_init_func(QemuOpts *opts, void *opaque)
1845{
1846 CharDriverState *chr;
1847
f69554b9 1848 chr = qemu_chr_new_from_opts(opts, NULL);
1a688d3b
GH
1849 if (!chr)
1850 return -1;
1851 return 0;
1852}
1853
758e8e38 1854#ifdef CONFIG_VIRTFS
74db920c
GS
1855static int fsdev_init_func(QemuOpts *opts, void *opaque)
1856{
1857 int ret;
1858 ret = qemu_fsdev_add(opts);
1859
1860 return ret;
1861}
1862#endif
1863
88589343
GH
1864static int mon_init_func(QemuOpts *opts, void *opaque)
1865{
1866 CharDriverState *chr;
1867 const char *chardev;
1868 const char *mode;
1869 int flags;
1870
1871 mode = qemu_opt_get(opts, "mode");
1872 if (mode == NULL) {
1873 mode = "readline";
1874 }
1875 if (strcmp(mode, "readline") == 0) {
1876 flags = MONITOR_USE_READLINE;
1877 } else if (strcmp(mode, "control") == 0) {
1878 flags = MONITOR_USE_CONTROL;
1879 } else {
1880 fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
1881 exit(1);
1882 }
1883
39eaab9a
DB
1884 if (qemu_opt_get_bool(opts, "pretty", 0))
1885 flags |= MONITOR_USE_PRETTY;
1886
88589343
GH
1887 if (qemu_opt_get_bool(opts, "default", 0))
1888 flags |= MONITOR_IS_DEFAULT;
1889
1890 chardev = qemu_opt_get(opts, "chardev");
1891 chr = qemu_chr_find(chardev);
1892 if (chr == NULL) {
1893 fprintf(stderr, "chardev \"%s\" not found\n", chardev);
1894 exit(1);
1895 }
1896
1897 monitor_init(chr, flags);
1898 return 0;
1899}
1900
6ca5582d 1901static void monitor_parse(const char *optarg, const char *mode)
88589343
GH
1902{
1903 static int monitor_device_index = 0;
1904 QemuOpts *opts;
1905 const char *p;
1906 char label[32];
1907 int def = 0;
1908
1909 if (strstart(optarg, "chardev:", &p)) {
1910 snprintf(label, sizeof(label), "%s", p);
1911 } else {
140e065d
JK
1912 snprintf(label, sizeof(label), "compat_monitor%d",
1913 monitor_device_index);
1914 if (monitor_device_index == 0) {
88589343
GH
1915 def = 1;
1916 }
1917 opts = qemu_chr_parse_compat(label, optarg);
1918 if (!opts) {
1919 fprintf(stderr, "parse error: %s\n", optarg);
1920 exit(1);
1921 }
1922 }
1923
3329f07b 1924 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1);
88589343
GH
1925 if (!opts) {
1926 fprintf(stderr, "duplicate chardev: %s\n", label);
1927 exit(1);
1928 }
6ca5582d 1929 qemu_opt_set(opts, "mode", mode);
88589343
GH
1930 qemu_opt_set(opts, "chardev", label);
1931 if (def)
1932 qemu_opt_set(opts, "default", "on");
1933 monitor_device_index++;
1934}
1935
bd3c948d
GH
1936struct device_config {
1937 enum {
aee1b935
GH
1938 DEV_USB, /* -usbdevice */
1939 DEV_BT, /* -bt */
1940 DEV_SERIAL, /* -serial */
1941 DEV_PARALLEL, /* -parallel */
1942 DEV_VIRTCON, /* -virtioconsole */
c9f398e5 1943 DEV_DEBUGCON, /* -debugcon */
ef0c4a0d 1944 DEV_GDB, /* -gdb, -s */
bd3c948d
GH
1945 } type;
1946 const char *cmdline;
d9a5954d 1947 Location loc;
72cf2d4f 1948 QTAILQ_ENTRY(device_config) next;
bd3c948d 1949};
72cf2d4f 1950QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
bd3c948d
GH
1951
1952static void add_device_config(int type, const char *cmdline)
1953{
1954 struct device_config *conf;
1955
7267c094 1956 conf = g_malloc0(sizeof(*conf));
bd3c948d
GH
1957 conf->type = type;
1958 conf->cmdline = cmdline;
d9a5954d 1959 loc_save(&conf->loc);
72cf2d4f 1960 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
bd3c948d
GH
1961}
1962
1963static int foreach_device_config(int type, int (*func)(const char *cmdline))
1964{
1965 struct device_config *conf;
1966 int rc;
1967
72cf2d4f 1968 QTAILQ_FOREACH(conf, &device_configs, next) {
bd3c948d
GH
1969 if (conf->type != type)
1970 continue;
d9a5954d 1971 loc_push_restore(&conf->loc);
bd3c948d 1972 rc = func(conf->cmdline);
d9a5954d 1973 loc_pop(&conf->loc);
bd3c948d
GH
1974 if (0 != rc)
1975 return rc;
1976 }
1977 return 0;
1978}
1979
998bbd74
GH
1980static int serial_parse(const char *devname)
1981{
1982 static int index = 0;
1983 char label[32];
1984
1985 if (strcmp(devname, "none") == 0)
1986 return 0;
1987 if (index == MAX_SERIAL_PORTS) {
1988 fprintf(stderr, "qemu: too many serial ports\n");
1989 exit(1);
1990 }
1991 snprintf(label, sizeof(label), "serial%d", index);
27143a44 1992 serial_hds[index] = qemu_chr_new(label, devname, NULL);
998bbd74
GH
1993 if (!serial_hds[index]) {
1994 fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
1995 devname, strerror(errno));
1996 return -1;
1997 }
1998 index++;
1999 return 0;
2000}
2001
6a5e8b0e
GH
2002static int parallel_parse(const char *devname)
2003{
2004 static int index = 0;
2005 char label[32];
2006
2007 if (strcmp(devname, "none") == 0)
2008 return 0;
2009 if (index == MAX_PARALLEL_PORTS) {
2010 fprintf(stderr, "qemu: too many parallel ports\n");
2011 exit(1);
2012 }
2013 snprintf(label, sizeof(label), "parallel%d", index);
27143a44 2014 parallel_hds[index] = qemu_chr_new(label, devname, NULL);
6a5e8b0e
GH
2015 if (!parallel_hds[index]) {
2016 fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
2017 devname, strerror(errno));
2018 return -1;
2019 }
2020 index++;
2021 return 0;
2022}
2023
aee1b935
GH
2024static int virtcon_parse(const char *devname)
2025{
3329f07b 2026 QemuOptsList *device = qemu_find_opts("device");
aee1b935
GH
2027 static int index = 0;
2028 char label[32];
392ecf54 2029 QemuOpts *bus_opts, *dev_opts;
aee1b935
GH
2030
2031 if (strcmp(devname, "none") == 0)
2032 return 0;
2033 if (index == MAX_VIRTIO_CONSOLES) {
2034 fprintf(stderr, "qemu: too many virtio consoles\n");
2035 exit(1);
2036 }
392ecf54 2037
3329f07b 2038 bus_opts = qemu_opts_create(device, NULL, 0);
e87f7fc6
AL
2039 if (arch_type == QEMU_ARCH_S390X) {
2040 qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
2041 } else {
2042 qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
2043 }
392ecf54 2044
3329f07b 2045 dev_opts = qemu_opts_create(device, NULL, 0);
392ecf54
AS
2046 qemu_opt_set(dev_opts, "driver", "virtconsole");
2047
aee1b935 2048 snprintf(label, sizeof(label), "virtcon%d", index);
27143a44 2049 virtcon_hds[index] = qemu_chr_new(label, devname, NULL);
aee1b935
GH
2050 if (!virtcon_hds[index]) {
2051 fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
2052 devname, strerror(errno));
2053 return -1;
2054 }
392ecf54
AS
2055 qemu_opt_set(dev_opts, "chardev", label);
2056
aee1b935
GH
2057 index++;
2058 return 0;
2059}
2060
c9f398e5
PA
2061static int debugcon_parse(const char *devname)
2062{
2063 QemuOpts *opts;
2064
27143a44 2065 if (!qemu_chr_new("debugcon", devname, NULL)) {
c9f398e5
PA
2066 exit(1);
2067 }
3329f07b 2068 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1);
c9f398e5
PA
2069 if (!opts) {
2070 fprintf(stderr, "qemu: already have a debugcon device\n");
2071 exit(1);
2072 }
2073 qemu_opt_set(opts, "driver", "isa-debugcon");
2074 qemu_opt_set(opts, "chardev", "debugcon");
2075 return 0;
2076}
2077
9052ea6b
JK
2078static QEMUMachine *machine_parse(const char *name)
2079{
2080 QEMUMachine *m, *machine = NULL;
2081
2082 if (name) {
2083 machine = find_machine(name);
2084 }
2085 if (machine) {
2086 return machine;
2087 }
2088 printf("Supported machines are:\n");
2089 for (m = first_machine; m != NULL; m = m->next) {
2090 if (m->alias) {
3b26486a 2091 printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
9052ea6b 2092 }
3b26486a 2093 printf("%-20s %s%s\n", m->name, m->desc,
9052ea6b
JK
2094 m->is_default ? " (default)" : "");
2095 }
2096 exit(!name || *name != '?');
2097}
2098
303d4e86
AP
2099static int tcg_init(void)
2100{
d5ab9713 2101 tcg_exec_init(tcg_tb_size * 1024 * 1024);
303d4e86
AP
2102 return 0;
2103}
2104
2105static struct {
2106 const char *opt_name;
2107 const char *name;
2108 int (*available)(void);
2109 int (*init)(void);
2110 int *allowed;
2111} accel_list[] = {
2112 { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
3285cf4f 2113 { "xen", "Xen", xen_available, xen_init, &xen_allowed },
303d4e86 2114 { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
c7f0f3b1 2115 { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed },
303d4e86
AP
2116};
2117
2118static int configure_accelerator(void)
2119{
2120 const char *p = NULL;
2121 char buf[10];
2122 int i, ret;
1b785a97 2123 bool accel_initialised = 0;
303d4e86
AP
2124 bool init_failed = 0;
2125
2126 QemuOptsList *list = qemu_find_opts("machine");
2127 if (!QTAILQ_EMPTY(&list->head)) {
2128 p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
2129 }
2130
2131 if (p == NULL) {
2132 /* Use the default "accelerator", tcg */
2133 p = "tcg";
2134 }
2135
1b785a97 2136 while (!accel_initialised && *p != '\0') {
303d4e86
AP
2137 if (*p == ':') {
2138 p++;
2139 }
2140 p = get_opt_name(buf, sizeof (buf), p, ':');
2141 for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
2142 if (strcmp(accel_list[i].opt_name, buf) == 0) {
a16c53b1 2143 *(accel_list[i].allowed) = 1;
303d4e86
AP
2144 ret = accel_list[i].init();
2145 if (ret < 0) {
2146 init_failed = 1;
2147 if (!accel_list[i].available()) {
2148 printf("%s not supported for this target\n",
2149 accel_list[i].name);
2150 } else {
2151 fprintf(stderr, "failed to initialize %s: %s\n",
2152 accel_list[i].name,
2153 strerror(-ret));
2154 }
a16c53b1 2155 *(accel_list[i].allowed) = 0;
303d4e86 2156 } else {
1b785a97 2157 accel_initialised = 1;
303d4e86
AP
2158 }
2159 break;
2160 }
2161 }
2162 if (i == ARRAY_SIZE(accel_list)) {
2163 fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf);
2164 }
2165 }
2166
1b785a97 2167 if (!accel_initialised) {
303d4e86
AP
2168 fprintf(stderr, "No accelerator found!\n");
2169 exit(1);
2170 }
2171
2172 if (init_failed) {
2173 fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name);
2174 }
2175
1b785a97 2176 return !accel_initialised;
303d4e86
AP
2177}
2178
fd42deeb
GH
2179void qemu_add_exit_notifier(Notifier *notify)
2180{
2181 notifier_list_add(&exit_notifiers, notify);
2182}
2183
2184void qemu_remove_exit_notifier(Notifier *notify)
2185{
31552529 2186 notifier_remove(notify);
fd42deeb
GH
2187}
2188
2189static void qemu_run_exit_notifiers(void)
2190{
9e8dd451 2191 notifier_list_notify(&exit_notifiers, NULL);
fd42deeb
GH
2192}
2193
4cab946a
GN
2194void qemu_add_machine_init_done_notifier(Notifier *notify)
2195{
2196 notifier_list_add(&machine_init_done_notifiers, notify);
2197}
2198
2199static void qemu_run_machine_init_done_notifiers(void)
2200{
9e8dd451 2201 notifier_list_notify(&machine_init_done_notifiers, NULL);
4cab946a
GN
2202}
2203
6530a97b
AL
2204static const QEMUOption *lookup_opt(int argc, char **argv,
2205 const char **poptarg, int *poptind)
2206{
2207 const QEMUOption *popt;
2208 int optind = *poptind;
2209 char *r = argv[optind];
2210 const char *optarg;
2211
0f0bc3f1 2212 loc_set_cmdline(argv, optind, 1);
6530a97b
AL
2213 optind++;
2214 /* Treat --foo the same as -foo. */
2215 if (r[1] == '-')
2216 r++;
2217 popt = qemu_options;
2218 for(;;) {
2219 if (!popt->name) {
0f0bc3f1 2220 error_report("invalid option");
6530a97b
AL
2221 exit(1);
2222 }
2223 if (!strcmp(popt->name, r + 1))
2224 break;
2225 popt++;
2226 }
2227 if (popt->flags & HAS_ARG) {
2228 if (optind >= argc) {
0f0bc3f1 2229 error_report("requires an argument");
6530a97b
AL
2230 exit(1);
2231 }
2232 optarg = argv[optind++];
0f0bc3f1 2233 loc_set_cmdline(argv, optind - 2, 2);
6530a97b
AL
2234 } else {
2235 optarg = NULL;
2236 }
2237
2238 *poptarg = optarg;
2239 *poptind = optind;
2240
2241 return popt;
2242}
2243
0750112a
AL
2244static gpointer malloc_and_trace(gsize n_bytes)
2245{
2246 void *ptr = malloc(n_bytes);
a74cd8cc 2247 trace_g_malloc(n_bytes, ptr);
0750112a
AL
2248 return ptr;
2249}
2250
2251static gpointer realloc_and_trace(gpointer mem, gsize n_bytes)
2252{
2253 void *ptr = realloc(mem, n_bytes);
a74cd8cc 2254 trace_g_realloc(mem, n_bytes, ptr);
0750112a
AL
2255 return ptr;
2256}
2257
2258static void free_and_trace(gpointer mem)
2259{
a74cd8cc 2260 trace_g_free(mem);
0750112a
AL
2261 free(mem);
2262}
2263
d34e8f6e
MR
2264int qemu_init_main_loop(void)
2265{
2266 return main_loop_init();
2267}
2268
902b3d5c 2269int main(int argc, char **argv, char **envp)
0824d6fc 2270{
e4bcb14c 2271 int i;
da1fcfda 2272 int snapshot, linux_boot;
4e3de9e9 2273 const char *icount_option = NULL;
7f7f9873 2274 const char *initrd_filename;
a20dd508 2275 const char *kernel_filename, *kernel_cmdline;
195325a4 2276 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
3023f332 2277 DisplayState *ds;
7d957bd8 2278 DisplayChangeListener *dcl;
46d4767d 2279 int cyls, heads, secs, translation;
967c0da7 2280 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
03b0ba70 2281 QemuOptsList *olist;
cd6f1169 2282 int optind;
6530a97b 2283 const char *optarg;
d63d307f 2284 const char *loadvm = NULL;
cc1daa40 2285 QEMUMachine *machine;
94fc95cd 2286 const char *cpu_model;
7f1b17f2 2287 const char *vga_model = "none";
93815bc2 2288 const char *pid_file = NULL;
5bb7910a 2289 const char *incoming = NULL;
821601ea 2290#ifdef CONFIG_VNC
993fbfdb 2291 int show_vnc_port = 0;
821601ea 2292#endif
292444cb 2293 int defconfig = 1;
c235d738
MF
2294 const char *log_mask = NULL;
2295 const char *log_file = NULL;
0750112a
AL
2296 GMemVTable mem_trace = {
2297 .malloc = malloc_and_trace,
2298 .realloc = realloc_and_trace,
2299 .free = free_and_trace,
2300 };
23d15e86 2301 const char *trace_events = NULL;
e4858974 2302 const char *trace_file = NULL;
0b5538c3 2303
fd42deeb 2304 atexit(qemu_run_exit_notifiers);
65abca0a
MA
2305 error_set_progname(argv[0]);
2306
0750112a 2307 g_mem_set_vtable(&mem_trace);
db529aab 2308 if (!g_thread_supported()) {
42ed3727 2309#if !GLIB_CHECK_VERSION(2, 31, 0)
db529aab 2310 g_thread_init(NULL);
42ed3727
AL
2311#else
2312 fprintf(stderr, "glib threading failed to initialize.\n");
2313 exit(1);
2314#endif
db529aab 2315 }
0750112a 2316
1b71f7c1
AF
2317 module_call_init(MODULE_INIT_QOM);
2318
5db9d4d1
LC
2319 runstate_init();
2320
6875204c 2321 init_clocks();
2ff68d07 2322 rtc_clock = host_clock;
6875204c 2323
902b3d5c 2324 qemu_cache_utils_init(envp);
2325
72cf2d4f 2326 QLIST_INIT (&vm_change_state_head);
fe98ac14 2327 os_setup_early_signal_handling();
be995c27 2328
f80f9ec9 2329 module_call_init(MODULE_INIT_MACHINE);
0c257437 2330 machine = find_default_machine();
94fc95cd 2331 cpu_model = NULL;
4fc5d071 2332 ram_size = 0;
33e3963e 2333 snapshot = 0;
c4b1fcc0 2334 cyls = heads = secs = 0;
46d4767d 2335 translation = BIOS_ATA_TRANSLATION_AUTO;
c4b1fcc0 2336
268a362c
AL
2337 for (i = 0; i < MAX_NODES; i++) {
2338 node_mem[i] = 0;
2339 node_cpumask[i] = 0;
2340 }
2341
268a362c 2342 nb_numa_nodes = 0;
7c9d8e07 2343 nb_nics = 0;
3b46e624 2344
41bd639b
BS
2345 autostart= 1;
2346
292444cb
AL
2347 /* first pass of option parsing */
2348 optind = 1;
2349 while (optind < argc) {
2350 if (argv[optind][0] != '-') {
2351 /* disk image */
28e68d68 2352 optind++;
292444cb
AL
2353 continue;
2354 } else {
2355 const QEMUOption *popt;
2356
2357 popt = lookup_opt(argc, argv, &optarg, &optind);
2358 switch (popt->index) {
2359 case QEMU_OPTION_nodefconfig:
2360 defconfig=0;
2361 break;
2362 }
2363 }
2364 }
2365
2366 if (defconfig) {
dcfb0939 2367 int ret;
cf5a65aa 2368
dcfb0939 2369 ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
019e78ba 2370 if (ret < 0 && ret != -ENOENT) {
dcfb0939 2371 exit(1);
292444cb
AL
2372 }
2373
dcfb0939 2374 ret = qemu_read_config_file(arch_config_name);
019e78ba 2375 if (ret < 0 && ret != -ENOENT) {
dcfb0939 2376 exit(1);
292444cb
AL
2377 }
2378 }
2379
2380 /* second pass of option parsing */
cd6f1169 2381 optind = 1;
0824d6fc 2382 for(;;) {
cd6f1169 2383 if (optind >= argc)
0824d6fc 2384 break;
6530a97b 2385 if (argv[optind][0] != '-') {
2292ddae 2386 hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
cd6f1169
FB
2387 } else {
2388 const QEMUOption *popt;
2389
6530a97b 2390 popt = lookup_opt(argc, argv, &optarg, &optind);
ad96090a
BS
2391 if (!(popt->arch_mask & arch_type)) {
2392 printf("Option %s not supported for this target\n", popt->name);
2393 exit(1);
2394 }
cd6f1169 2395 switch(popt->index) {
cc1daa40 2396 case QEMU_OPTION_M:
9052ea6b 2397 machine = machine_parse(optarg);
cc1daa40 2398 break;
94fc95cd
JM
2399 case QEMU_OPTION_cpu:
2400 /* hw initialization will check this */
ecf40bea 2401 cpu_model = optarg;
94fc95cd 2402 break;
cd6f1169 2403 case QEMU_OPTION_hda:
5645b0f4
MA
2404 {
2405 char buf[256];
2406 if (cyls == 0)
2407 snprintf(buf, sizeof(buf), "%s", HD_OPTS);
2408 else
2409 snprintf(buf, sizeof(buf),
2410 "%s,cyls=%d,heads=%d,secs=%d%s",
2411 HD_OPTS , cyls, heads, secs,
2412 translation == BIOS_ATA_TRANSLATION_LBA ?
e4bcb14c 2413 ",trans=lba" :
5645b0f4 2414 translation == BIOS_ATA_TRANSLATION_NONE ?
e4bcb14c 2415 ",trans=none" : "");
5645b0f4
MA
2416 drive_add(IF_DEFAULT, 0, optarg, buf);
2417 break;
2418 }
cd6f1169 2419 case QEMU_OPTION_hdb:
cc1daa40
FB
2420 case QEMU_OPTION_hdc:
2421 case QEMU_OPTION_hdd:
2292ddae
MA
2422 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2423 HD_OPTS);
fc01f7e7 2424 break;
e4bcb14c 2425 case QEMU_OPTION_drive:
e2982c3a
MT
2426 if (drive_def(optarg) == NULL) {
2427 exit(1);
2428 }
e4bcb14c 2429 break;
d058fe03
GH
2430 case QEMU_OPTION_set:
2431 if (qemu_set_option(optarg) != 0)
2432 exit(1);
2433 break;
d0fef6fb
GH
2434 case QEMU_OPTION_global:
2435 if (qemu_global_option(optarg) != 0)
2436 exit(1);
2437 break;
3e3d5815 2438 case QEMU_OPTION_mtdblock:
2292ddae 2439 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
3e3d5815 2440 break;
a1bb27b1 2441 case QEMU_OPTION_sd:
2292ddae 2442 drive_add(IF_SD, 0, optarg, SD_OPTS);
a1bb27b1 2443 break;
86f55663 2444 case QEMU_OPTION_pflash:
2292ddae 2445 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
86f55663 2446 break;
cd6f1169 2447 case QEMU_OPTION_snapshot:
33e3963e
FB
2448 snapshot = 1;
2449 break;
cd6f1169 2450 case QEMU_OPTION_hdachs:
330d0414 2451 {
330d0414
FB
2452 const char *p;
2453 p = optarg;
2454 cyls = strtol(p, (char **)&p, 0);
46d4767d
FB
2455 if (cyls < 1 || cyls > 16383)
2456 goto chs_fail;
330d0414
FB
2457 if (*p != ',')
2458 goto chs_fail;
2459 p++;
2460 heads = strtol(p, (char **)&p, 0);
46d4767d
FB
2461 if (heads < 1 || heads > 16)
2462 goto chs_fail;
330d0414
FB
2463 if (*p != ',')
2464 goto chs_fail;
2465 p++;
2466 secs = strtol(p, (char **)&p, 0);
46d4767d
FB
2467 if (secs < 1 || secs > 63)
2468 goto chs_fail;
2469 if (*p == ',') {
2470 p++;
2471 if (!strcmp(p, "none"))
2472 translation = BIOS_ATA_TRANSLATION_NONE;
2473 else if (!strcmp(p, "lba"))
2474 translation = BIOS_ATA_TRANSLATION_LBA;
2475 else if (!strcmp(p, "auto"))
2476 translation = BIOS_ATA_TRANSLATION_AUTO;
2477 else
2478 goto chs_fail;
2479 } else if (*p != '\0') {
c4b1fcc0 2480 chs_fail:
46d4767d
FB
2481 fprintf(stderr, "qemu: invalid physical CHS format\n");
2482 exit(1);
c4b1fcc0 2483 }
9dfd7c7a
GH
2484 if (hda_opts != NULL) {
2485 char num[16];
2486 snprintf(num, sizeof(num), "%d", cyls);
2487 qemu_opt_set(hda_opts, "cyls", num);
2488 snprintf(num, sizeof(num), "%d", heads);
2489 qemu_opt_set(hda_opts, "heads", num);
2490 snprintf(num, sizeof(num), "%d", secs);
2491 qemu_opt_set(hda_opts, "secs", num);
2492 if (translation == BIOS_ATA_TRANSLATION_LBA)
2493 qemu_opt_set(hda_opts, "trans", "lba");
2494 if (translation == BIOS_ATA_TRANSLATION_NONE)
2495 qemu_opt_set(hda_opts, "trans", "none");
2496 }
330d0414
FB
2497 }
2498 break;
268a362c
AL
2499 case QEMU_OPTION_numa:
2500 if (nb_numa_nodes >= MAX_NODES) {
2501 fprintf(stderr, "qemu: too many NUMA nodes\n");
2502 exit(1);
2503 }
2504 numa_add(optarg);
2505 break;
1472a95b
JS
2506 case QEMU_OPTION_display:
2507 display_type = select_display(optarg);
2508 break;
cd6f1169 2509 case QEMU_OPTION_nographic:
993fbfdb 2510 display_type = DT_NOGRAPHIC;
a20dd508 2511 break;
4d3b6f6e 2512 case QEMU_OPTION_curses:
47b05369 2513#ifdef CONFIG_CURSES
993fbfdb 2514 display_type = DT_CURSES;
47b05369
JS
2515#else
2516 fprintf(stderr, "Curses support is disabled\n");
2517 exit(1);
4d3b6f6e 2518#endif
47b05369 2519 break;
a171fe39 2520 case QEMU_OPTION_portrait:
9312805d
VK
2521 graphic_rotate = 90;
2522 break;
2523 case QEMU_OPTION_rotate:
2524 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2525 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2526 graphic_rotate != 180 && graphic_rotate != 270) {
2527 fprintf(stderr,
2528 "qemu: only 90, 180, 270 deg rotation is available\n");
2529 exit(1);
2530 }
a171fe39 2531 break;
cd6f1169 2532 case QEMU_OPTION_kernel:
a0abe474
PM
2533 qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
2534 break;
2535 case QEMU_OPTION_initrd:
2536 qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
a20dd508 2537 break;
cd6f1169 2538 case QEMU_OPTION_append:
a0abe474 2539 qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
313aa567 2540 break;
412beee6
GL
2541 case QEMU_OPTION_dtb:
2542 qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
2543 break;
cd6f1169 2544 case QEMU_OPTION_cdrom:
2292ddae 2545 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
36b486bb 2546 break;
cd6f1169 2547 case QEMU_OPTION_boot:
28c5af54 2548 {
ef3adf68 2549 static const char * const params[] = {
3d3b8303 2550 "order", "once", "menu",
2551 "splash", "splash-time", NULL
ef3adf68
JK
2552 };
2553 char buf[sizeof(boot_devices)];
e0f084bf 2554 char *standard_boot_devices;
ef3adf68
JK
2555 int legacy = 0;
2556
2557 if (!strchr(optarg, '=')) {
2558 legacy = 1;
2559 pstrcpy(buf, sizeof(buf), optarg);
2560 } else if (check_params(buf, sizeof(buf), params, optarg) < 0) {
2561 fprintf(stderr,
2562 "qemu: unknown boot parameter '%s' in '%s'\n",
2563 buf, optarg);
2564 exit(1);
2565 }
2566
2567 if (legacy ||
2568 get_param_value(buf, sizeof(buf), "order", optarg)) {
4e9e9d6e 2569 validate_bootdevices(buf);
ef3adf68 2570 pstrcpy(boot_devices, sizeof(boot_devices), buf);
28c5af54 2571 }
e0f084bf
JK
2572 if (!legacy) {
2573 if (get_param_value(buf, sizeof(buf),
2574 "once", optarg)) {
4e9e9d6e 2575 validate_bootdevices(buf);
7267c094 2576 standard_boot_devices = g_strdup(boot_devices);
e0f084bf
JK
2577 pstrcpy(boot_devices, sizeof(boot_devices), buf);
2578 qemu_register_reset(restore_boot_devices,
2579 standard_boot_devices);
2580 }
95387491
JK
2581 if (get_param_value(buf, sizeof(buf),
2582 "menu", optarg)) {
2583 if (!strcmp(buf, "on")) {
2584 boot_menu = 1;
2585 } else if (!strcmp(buf, "off")) {
2586 boot_menu = 0;
2587 } else {
2588 fprintf(stderr,
2589 "qemu: invalid option value '%s'\n",
2590 buf);
2591 exit(1);
2592 }
2593 }
3d3b8303 2594 qemu_opts_parse(qemu_find_opts("boot-opts"),
2595 optarg, 0);
e0f084bf 2596 }
36b486bb
FB
2597 }
2598 break;
cd6f1169 2599 case QEMU_OPTION_fda:
cd6f1169 2600 case QEMU_OPTION_fdb:
2292ddae
MA
2601 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2602 optarg, FD_OPTS);
c45886db 2603 break;
52ca8d6a
FB
2604 case QEMU_OPTION_no_fd_bootchk:
2605 fd_bootchk = 0;
2606 break;
a1ea458f 2607 case QEMU_OPTION_netdev:
3329f07b 2608 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
a1ea458f
MM
2609 exit(1);
2610 }
2611 break;
7c9d8e07 2612 case QEMU_OPTION_net:
3329f07b 2613 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
c4b1fcc0
FB
2614 exit(1);
2615 }
702c651c 2616 break;
f9dadc98
RS
2617#ifdef CONFIG_LIBISCSI
2618 case QEMU_OPTION_iscsi:
2619 opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
2620 if (!opts) {
2621 exit(1);
2622 }
2623 break;
2624#endif
c7f74643
FB
2625#ifdef CONFIG_SLIRP
2626 case QEMU_OPTION_tftp:
ad196a9d 2627 legacy_tftp_prefix = optarg;
9bf05444 2628 break;
47d5d01a 2629 case QEMU_OPTION_bootp:
ad196a9d 2630 legacy_bootp_filename = optarg;
47d5d01a 2631 break;
9bf05444 2632 case QEMU_OPTION_redir:
0752706d
MA
2633 if (net_slirp_redir(optarg) < 0)
2634 exit(1);
9bf05444 2635 break;
c7f74643 2636#endif
dc72ac14 2637 case QEMU_OPTION_bt:
bd3c948d 2638 add_device_config(DEV_BT, optarg);
dc72ac14 2639 break;
1d14ffa9 2640 case QEMU_OPTION_audio_help:
ad96090a
BS
2641 if (!(audio_available())) {
2642 printf("Option %s not supported for this target\n", popt->name);
2643 exit(1);
2644 }
1d14ffa9
FB
2645 AUD_help ();
2646 exit (0);
2647 break;
2648 case QEMU_OPTION_soundhw:
ad96090a
BS
2649 if (!(audio_available())) {
2650 printf("Option %s not supported for this target\n", popt->name);
2651 exit(1);
2652 }
1d14ffa9
FB
2653 select_soundhw (optarg);
2654 break;
cd6f1169 2655 case QEMU_OPTION_h:
15f82208 2656 help(0);
cd6f1169 2657 break;
9bd7e6d9
PB
2658 case QEMU_OPTION_version:
2659 version();
2660 exit(0);
2661 break;
00f82b8a 2662 case QEMU_OPTION_m: {
70b4f4bb 2663 int64_t value;
961b42b9 2664 char *end;
9f9b17a4 2665
961b42b9
MA
2666 value = strtosz(optarg, &end);
2667 if (value < 0 || *end) {
00f82b8a 2668 fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
cd6f1169
FB
2669 exit(1);
2670 }
00f82b8a 2671
c227f099 2672 if (value != (uint64_t)(ram_addr_t)value) {
00f82b8a
AJ
2673 fprintf(stderr, "qemu: ram size too large\n");
2674 exit(1);
2675 }
2676 ram_size = value;
cd6f1169 2677 break;
00f82b8a 2678 }
c902760f
MT
2679 case QEMU_OPTION_mempath:
2680 mem_path = optarg;
2681 break;
2682#ifdef MAP_POPULATE
2683 case QEMU_OPTION_mem_prealloc:
2684 mem_prealloc = 1;
2685 break;
2686#endif
cd6f1169 2687 case QEMU_OPTION_d:
c235d738
MF
2688 log_mask = optarg;
2689 break;
2690 case QEMU_OPTION_D:
2691 log_file = optarg;
cd6f1169 2692 break;
cd6f1169 2693 case QEMU_OPTION_s:
ef0c4a0d 2694 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
cd6f1169 2695 break;
59030a8c 2696 case QEMU_OPTION_gdb:
ef0c4a0d 2697 add_device_config(DEV_GDB, optarg);
cd6f1169 2698 break;
cd6f1169 2699 case QEMU_OPTION_L:
5cea8590 2700 data_dir = optarg;
cd6f1169 2701 break;
1192dad8
JM
2702 case QEMU_OPTION_bios:
2703 bios_name = optarg;
2704 break;
1b530a6d
AJ
2705 case QEMU_OPTION_singlestep:
2706 singlestep = 1;
2707 break;
cd6f1169 2708 case QEMU_OPTION_S:
3c07f8e8 2709 autostart = 0;
cd6f1169 2710 break;
3d11d0eb
FB
2711 case QEMU_OPTION_k:
2712 keyboard_layout = optarg;
2713 break;
ee22c2f7
FB
2714 case QEMU_OPTION_localtime:
2715 rtc_utc = 0;
2716 break;
3893c124 2717 case QEMU_OPTION_vga:
a369da5f 2718 vga_model = optarg;
7f1b17f2 2719 default_vga = 0;
1bfe856e 2720 break;
e9b137c2
FB
2721 case QEMU_OPTION_g:
2722 {
2723 const char *p;
2724 int w, h, depth;
2725 p = optarg;
2726 w = strtol(p, (char **)&p, 10);
2727 if (w <= 0) {
2728 graphic_error:
2729 fprintf(stderr, "qemu: invalid resolution or depth\n");
2730 exit(1);
2731 }
2732 if (*p != 'x')
2733 goto graphic_error;
2734 p++;
2735 h = strtol(p, (char **)&p, 10);
2736 if (h <= 0)
2737 goto graphic_error;
2738 if (*p == 'x') {
2739 p++;
2740 depth = strtol(p, (char **)&p, 10);
5fafdf24 2741 if (depth != 8 && depth != 15 && depth != 16 &&
e9b137c2
FB
2742 depth != 24 && depth != 32)
2743 goto graphic_error;
2744 } else if (*p == '\0') {
2745 depth = graphic_depth;
2746 } else {
2747 goto graphic_error;
2748 }
3b46e624 2749
e9b137c2
FB
2750 graphic_width = w;
2751 graphic_height = h;
2752 graphic_depth = depth;
2753 }
2754 break;
20d8a3ed
TS
2755 case QEMU_OPTION_echr:
2756 {
2757 char *r;
2758 term_escape_char = strtol(optarg, &r, 0);
2759 if (r == optarg)
2760 printf("Bad argument to echr\n");
2761 break;
2762 }
82c643ff 2763 case QEMU_OPTION_monitor:
6ca5582d
GH
2764 monitor_parse(optarg, "readline");
2765 default_monitor = 0;
2766 break;
2767 case QEMU_OPTION_qmp:
2768 monitor_parse(optarg, "control");
2d114dc1 2769 default_monitor = 0;
82c643ff 2770 break;
22a0e04b 2771 case QEMU_OPTION_mon:
3329f07b 2772 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
22a0e04b 2773 if (!opts) {
22a0e04b
GH
2774 exit(1);
2775 }
2d114dc1 2776 default_monitor = 0;
22a0e04b 2777 break;
191bc01b 2778 case QEMU_OPTION_chardev:
3329f07b 2779 opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1);
191bc01b 2780 if (!opts) {
191bc01b
GH
2781 exit(1);
2782 }
191bc01b 2783 break;
74db920c 2784 case QEMU_OPTION_fsdev:
03b0ba70
GH
2785 olist = qemu_find_opts("fsdev");
2786 if (!olist) {
2787 fprintf(stderr, "fsdev is not supported by this qemu build.\n");
2788 exit(1);
2789 }
2790 opts = qemu_opts_parse(olist, optarg, 1);
74db920c
GS
2791 if (!opts) {
2792 fprintf(stderr, "parse error: %s\n", optarg);
2793 exit(1);
2794 }
2795 break;
3d54abc7 2796 case QEMU_OPTION_virtfs: {
e14ea479
SH
2797 QemuOpts *fsdev;
2798 QemuOpts *device;
84a87cc4 2799 const char *writeout, *sock_fd, *socket;
3d54abc7 2800
03b0ba70
GH
2801 olist = qemu_find_opts("virtfs");
2802 if (!olist) {
2803 fprintf(stderr, "virtfs is not supported by this qemu build.\n");
2804 exit(1);
2805 }
2806 opts = qemu_opts_parse(olist, optarg, 1);
3d54abc7
GS
2807 if (!opts) {
2808 fprintf(stderr, "parse error: %s\n", optarg);
2809 exit(1);
2810 }
2811
fbcbf101 2812 if (qemu_opt_get(opts, "fsdriver") == NULL ||
99519f0a
AK
2813 qemu_opt_get(opts, "mount_tag") == NULL) {
2814 fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n");
9ce56db6
VJJ
2815 exit(1);
2816 }
e14ea479
SH
2817 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
2818 qemu_opt_get(opts, "mount_tag"), 1);
2819 if (!fsdev) {
2820 fprintf(stderr, "duplicate fsdev id: %s\n",
2821 qemu_opt_get(opts, "mount_tag"));
3d54abc7
GS
2822 exit(1);
2823 }
d3ab98e6
AK
2824
2825 writeout = qemu_opt_get(opts, "writeout");
2826 if (writeout) {
2827#ifdef CONFIG_SYNC_FILE_RANGE
2828 qemu_opt_set(fsdev, "writeout", writeout);
2829#else
2830 fprintf(stderr, "writeout=immediate not supported on "
2831 "this platform\n");
2832 exit(1);
2833#endif
2834 }
fbcbf101 2835 qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
e14ea479
SH
2836 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
2837 qemu_opt_set(fsdev, "security_model",
2838 qemu_opt_get(opts, "security_model"));
84a87cc4
MK
2839 socket = qemu_opt_get(opts, "socket");
2840 if (socket) {
2841 qemu_opt_set(fsdev, "socket", socket);
2842 }
4c793dda
MK
2843 sock_fd = qemu_opt_get(opts, "sock_fd");
2844 if (sock_fd) {
2845 qemu_opt_set(fsdev, "sock_fd", sock_fd);
2846 }
e14ea479 2847
2c74c2cb
MK
2848 qemu_opt_set_bool(fsdev, "readonly",
2849 qemu_opt_get_bool(opts, "readonly", 0));
e14ea479
SH
2850 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
2851 qemu_opt_set(device, "driver", "virtio-9p-pci");
2852 qemu_opt_set(device, "fsdev",
2853 qemu_opt_get(opts, "mount_tag"));
2854 qemu_opt_set(device, "mount_tag",
2855 qemu_opt_get(opts, "mount_tag"));
3d54abc7
GS
2856 break;
2857 }
9db221ae
AK
2858 case QEMU_OPTION_virtfs_synth: {
2859 QemuOpts *fsdev;
2860 QemuOpts *device;
2861
2862 fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth", 1);
2863 if (!fsdev) {
2864 fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
2865 exit(1);
2866 }
2867 qemu_opt_set(fsdev, "fsdriver", "synth");
9db221ae
AK
2868
2869 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
2870 qemu_opt_set(device, "driver", "virtio-9p-pci");
2871 qemu_opt_set(device, "fsdev", "v_synth");
2872 qemu_opt_set(device, "mount_tag", "v_synth");
2873 break;
2874 }
82c643ff 2875 case QEMU_OPTION_serial:
998bbd74
GH
2876 add_device_config(DEV_SERIAL, optarg);
2877 default_serial = 0;
18141ed6
JK
2878 if (strncmp(optarg, "mon:", 4) == 0) {
2879 default_monitor = 0;
2880 }
82c643ff 2881 break;
9dd986cc 2882 case QEMU_OPTION_watchdog:
09aaa160
MA
2883 if (watchdog) {
2884 fprintf(stderr,
2885 "qemu: only one watchdog option may be given\n");
2886 return 1;
2887 }
2888 watchdog = optarg;
9dd986cc
RJ
2889 break;
2890 case QEMU_OPTION_watchdog_action:
2891 if (select_watchdog_action(optarg) == -1) {
2892 fprintf(stderr, "Unknown -watchdog-action parameter\n");
2893 exit(1);
2894 }
2895 break;
51ecf136 2896 case QEMU_OPTION_virtiocon:
aee1b935
GH
2897 add_device_config(DEV_VIRTCON, optarg);
2898 default_virtcon = 0;
18141ed6
JK
2899 if (strncmp(optarg, "mon:", 4) == 0) {
2900 default_monitor = 0;
2901 }
51ecf136 2902 break;
6508fe59 2903 case QEMU_OPTION_parallel:
6a5e8b0e
GH
2904 add_device_config(DEV_PARALLEL, optarg);
2905 default_parallel = 0;
18141ed6
JK
2906 if (strncmp(optarg, "mon:", 4) == 0) {
2907 default_monitor = 0;
2908 }
6508fe59 2909 break;
c9f398e5
PA
2910 case QEMU_OPTION_debugcon:
2911 add_device_config(DEV_DEBUGCON, optarg);
2912 break;
d63d307f
FB
2913 case QEMU_OPTION_loadvm:
2914 loadvm = optarg;
2915 break;
2916 case QEMU_OPTION_full_screen:
2917 full_screen = 1;
2918 break;
667accab 2919#ifdef CONFIG_SDL
43523e93
TS
2920 case QEMU_OPTION_no_frame:
2921 no_frame = 1;
2922 break;
3780e197
TS
2923 case QEMU_OPTION_alt_grab:
2924 alt_grab = 1;
2925 break;
0ca9f8a4
DK
2926 case QEMU_OPTION_ctrl_grab:
2927 ctrl_grab = 1;
2928 break;
667accab
TS
2929 case QEMU_OPTION_no_quit:
2930 no_quit = 1;
2931 break;
7d957bd8 2932 case QEMU_OPTION_sdl:
993fbfdb 2933 display_type = DT_SDL;
7d957bd8 2934 break;
58fc096c
JS
2935#else
2936 case QEMU_OPTION_no_frame:
2937 case QEMU_OPTION_alt_grab:
2938 case QEMU_OPTION_ctrl_grab:
2939 case QEMU_OPTION_no_quit:
2940 case QEMU_OPTION_sdl:
2941 fprintf(stderr, "SDL support is disabled\n");
2942 exit(1);
667accab 2943#endif
f7cce898 2944 case QEMU_OPTION_pidfile:
93815bc2 2945 pid_file = optarg;
f7cce898 2946 break;
a09db21f
FB
2947 case QEMU_OPTION_win2k_hack:
2948 win2k_install_hack = 1;
2949 break;
433acf0d
JK
2950 case QEMU_OPTION_rtc_td_hack: {
2951 static GlobalProperty slew_lost_ticks[] = {
2952 {
2953 .driver = "mc146818rtc",
2954 .property = "lost_tick_policy",
2955 .value = "slew",
2956 },
2957 { /* end of list */ }
2958 };
2959
2960 qdev_prop_register_global_list(slew_lost_ticks);
73822ec8 2961 break;
433acf0d 2962 }
8a92ea2f 2963 case QEMU_OPTION_acpitable:
de06f8d1 2964 do_acpitable_option(optarg);
8a92ea2f 2965 break;
b6f6e3d3 2966 case QEMU_OPTION_smbios:
de06f8d1 2967 do_smbios_option(optarg);
b6f6e3d3 2968 break;
7ba1e619 2969 case QEMU_OPTION_enable_kvm:
303d4e86 2970 olist = qemu_find_opts("machine");
303d4e86
AP
2971 qemu_opts_parse(olist, "accel=kvm", 0);
2972 break;
2973 case QEMU_OPTION_machine:
2974 olist = qemu_find_opts("machine");
9052ea6b 2975 opts = qemu_opts_parse(olist, optarg, 1);
303d4e86
AP
2976 if (!opts) {
2977 fprintf(stderr, "parse error: %s\n", optarg);
2978 exit(1);
2979 }
2645c6dc
JK
2980 optarg = qemu_opt_get(opts, "type");
2981 if (optarg) {
2982 machine = machine_parse(optarg);
2983 }
7ba1e619 2984 break;
bb36d470
FB
2985 case QEMU_OPTION_usb:
2986 usb_enabled = 1;
2987 break;
a594cfbf
FB
2988 case QEMU_OPTION_usbdevice:
2989 usb_enabled = 1;
bd3c948d
GH
2990 add_device_config(DEV_USB, optarg);
2991 break;
2992 case QEMU_OPTION_device:
3329f07b 2993 if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) {
f31d07d1
GH
2994 exit(1);
2995 }
a594cfbf 2996 break;
6a00d601 2997 case QEMU_OPTION_smp:
dc6b1c09 2998 smp_parse(optarg);
b2097003 2999 if (smp_cpus < 1) {
6a00d601
FB
3000 fprintf(stderr, "Invalid number of CPUs\n");
3001 exit(1);
3002 }
6be68d7e
JS
3003 if (max_cpus < smp_cpus) {
3004 fprintf(stderr, "maxcpus must be equal to or greater than "
3005 "smp\n");
3006 exit(1);
3007 }
3008 if (max_cpus > 255) {
3009 fprintf(stderr, "Unsupported number of maxcpus\n");
3010 exit(1);
3011 }
6a00d601 3012 break;
24236869 3013 case QEMU_OPTION_vnc:
821601ea 3014#ifdef CONFIG_VNC
6b62dc2d 3015 display_remote++;
821601ea
JS
3016 vnc_display = optarg;
3017#else
3018 fprintf(stderr, "VNC support is disabled\n");
3019 exit(1);
3020#endif
3021 break;
6515b203
FB
3022 case QEMU_OPTION_no_acpi:
3023 acpi_enabled = 0;
3024 break;
16b29ae1
AL
3025 case QEMU_OPTION_no_hpet:
3026 no_hpet = 1;
3027 break;
7d4c3d53
MA
3028 case QEMU_OPTION_balloon:
3029 if (balloon_parse(optarg) < 0) {
3030 fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
3031 exit(1);
3032 }
df97b920 3033 break;
d1beab82
FB
3034 case QEMU_OPTION_no_reboot:
3035 no_reboot = 1;
3036 break;
b2f76161
AJ
3037 case QEMU_OPTION_no_shutdown:
3038 no_shutdown = 1;
3039 break;
9467cd46
AZ
3040 case QEMU_OPTION_show_cursor:
3041 cursor_hide = 0;
3042 break;
8fcb1b90
BS
3043 case QEMU_OPTION_uuid:
3044 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
3045 fprintf(stderr, "Fail to parse UUID string."
3046 " Wrong format.\n");
3047 exit(1);
3048 }
3049 break;
9ae02555
TS
3050 case QEMU_OPTION_option_rom:
3051 if (nb_option_roms >= MAX_OPTION_ROMS) {
3052 fprintf(stderr, "Too many option ROMs\n");
3053 exit(1);
3054 }
2e55e842
GN
3055 opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1);
3056 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3057 option_rom[nb_option_roms].bootindex =
3058 qemu_opt_get_number(opts, "bootindex", -1);
3059 if (!option_rom[nb_option_roms].name) {
3060 fprintf(stderr, "Option ROM file is not specified\n");
3061 exit(1);
3062 }
9ae02555
TS
3063 nb_option_roms++;
3064 break;
8e71621f
PB
3065 case QEMU_OPTION_semihosting:
3066 semihosting_enabled = 1;
3067 break;
c35734b2 3068 case QEMU_OPTION_name:
7267c094 3069 qemu_name = g_strdup(optarg);
1889465a
AK
3070 {
3071 char *p = strchr(qemu_name, ',');
3072 if (p != NULL) {
3073 *p++ = 0;
3074 if (strncmp(p, "process=", 8)) {
5697f6ae 3075 fprintf(stderr, "Unknown subargument %s to -name\n", p);
1889465a
AK
3076 exit(1);
3077 }
3078 p += 8;
ce798cf2 3079 os_set_proc_name(p);
1889465a
AK
3080 }
3081 }
c35734b2 3082 break;
66508601
BS
3083 case QEMU_OPTION_prom_env:
3084 if (nb_prom_envs >= MAX_PROM_ENVS) {
3085 fprintf(stderr, "Too many prom variables\n");
3086 exit(1);
3087 }
3088 prom_envs[nb_prom_envs] = optarg;
3089 nb_prom_envs++;
3090 break;
2b8f2d41
AZ
3091 case QEMU_OPTION_old_param:
3092 old_param = 1;
05ebd537 3093 break;
f3dcfada
TS
3094 case QEMU_OPTION_clock:
3095 configure_alarms(optarg);
3096 break;
7e0af5d0 3097 case QEMU_OPTION_startdate:
1ed2fc1f
JK
3098 configure_rtc_date_offset(optarg, 1);
3099 break;
3100 case QEMU_OPTION_rtc:
3329f07b 3101 opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0);
1ed2fc1f 3102 if (!opts) {
1ed2fc1f 3103 exit(1);
7e0af5d0 3104 }
1ed2fc1f 3105 configure_rtc(opts);
7e0af5d0 3106 break;
26a5f13b 3107 case QEMU_OPTION_tb_size:
d5ab9713
JK
3108 tcg_tb_size = strtol(optarg, NULL, 0);
3109 if (tcg_tb_size < 0) {
3110 tcg_tb_size = 0;
3111 }
26a5f13b 3112 break;
2e70f6ef 3113 case QEMU_OPTION_icount:
4e3de9e9 3114 icount_option = optarg;
2e70f6ef 3115 break;
5bb7910a
AL
3116 case QEMU_OPTION_incoming:
3117 incoming = optarg;
81323a6c 3118 runstate_set(RUN_STATE_INMIGRATE);
5bb7910a 3119 break;
d8c208dd
GH
3120 case QEMU_OPTION_nodefaults:
3121 default_serial = 0;
3122 default_parallel = 0;
aee1b935 3123 default_virtcon = 0;
d8c208dd 3124 default_monitor = 0;
cb4522cc 3125 default_net = 0;
ac33f8fa
GH
3126 default_floppy = 0;
3127 default_cdrom = 0;
3128 default_sdcard = 0;
7f1b17f2 3129 default_vga = 0;
d8c208dd 3130 break;
e37630ca 3131 case QEMU_OPTION_xen_domid:
ad96090a
BS
3132 if (!(xen_available())) {
3133 printf("Option %s not supported for this target\n", popt->name);
3134 exit(1);
3135 }
e37630ca
AL
3136 xen_domid = atoi(optarg);
3137 break;
3138 case QEMU_OPTION_xen_create:
ad96090a
BS
3139 if (!(xen_available())) {
3140 printf("Option %s not supported for this target\n", popt->name);
3141 exit(1);
3142 }
e37630ca
AL
3143 xen_mode = XEN_CREATE;
3144 break;
3145 case QEMU_OPTION_xen_attach:
ad96090a
BS
3146 if (!(xen_available())) {
3147 printf("Option %s not supported for this target\n", popt->name);
3148 exit(1);
3149 }
e37630ca
AL
3150 xen_mode = XEN_ATTACH;
3151 break;
ab6540d5 3152 case QEMU_OPTION_trace:
e4858974 3153 {
ab6540d5 3154 opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0);
e4858974
L
3155 if (!opts) {
3156 exit(1);
ab6540d5 3157 }
23d15e86 3158 trace_events = qemu_opt_get(opts, "events");
e4858974 3159 trace_file = qemu_opt_get(opts, "file");
ab6540d5 3160 break;
e4858974 3161 }
715a664a
GH
3162 case QEMU_OPTION_readconfig:
3163 {
dcfb0939
KW
3164 int ret = qemu_read_config_file(optarg);
3165 if (ret < 0) {
3166 fprintf(stderr, "read config %s: %s\n", optarg,
3167 strerror(-ret));
715a664a
GH
3168 exit(1);
3169 }
715a664a
GH
3170 break;
3171 }
29b0040b
GH
3172 case QEMU_OPTION_spice:
3173 olist = qemu_find_opts("spice");
3174 if (!olist) {
3175 fprintf(stderr, "spice is not supported by this qemu build.\n");
3176 exit(1);
3177 }
3178 opts = qemu_opts_parse(olist, optarg, 0);
3179 if (!opts) {
3180 fprintf(stderr, "parse error: %s\n", optarg);
3181 exit(1);
3182 }
3183 break;
715a664a
GH
3184 case QEMU_OPTION_writeconfig:
3185 {
3186 FILE *fp;
3187 if (strcmp(optarg, "-") == 0) {
3188 fp = stdout;
3189 } else {
3190 fp = fopen(optarg, "w");
3191 if (fp == NULL) {
3192 fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
3193 exit(1);
3194 }
3195 }
3196 qemu_config_write(fp);
3197 fclose(fp);
3198 break;
3199 }
c7f0f3b1
AL
3200 case QEMU_OPTION_qtest:
3201 qtest_chrdev = optarg;
3202 break;
3203 case QEMU_OPTION_qtest_log:
3204 qtest_log = optarg;
3205 break;
59a5264b
JS
3206 default:
3207 os_parse_cmd_args(popt->index, optarg);
cd6f1169 3208 }
0824d6fc
FB
3209 }
3210 }
0f0bc3f1 3211 loc_set_none();
c235d738 3212
ecf40bea
EH
3213 /* Init CPU def lists, based on config
3214 * - Must be called after all the qemu_read_config_file() calls
3215 * - Must be called before list_cpus()
3216 * - Must be called before machine->init()
3217 */
3218 cpudef_init();
3219
3220 if (cpu_model && *cpu_model == '?') {
1d6528af 3221 list_cpus(stdout, &fprintf, cpu_model);
ecf40bea
EH
3222 exit(0);
3223 }
3224
c235d738
MF
3225 /* Open the logfile at this point, if necessary. We can't open the logfile
3226 * when encountering either of the logging options (-d or -D) because the
3227 * other one may be encountered later on the command line, changing the
3228 * location or level of logging.
3229 */
3230 if (log_mask) {
3231 if (log_file) {
3232 set_cpu_log_filename(log_file);
3233 }
3234 set_cpu_log(log_mask);
3235 }
330d0414 3236
23d15e86 3237 if (!trace_backend_init(trace_events, trace_file)) {
e4858974 3238 exit(1);
31d3c9b8 3239 }
0b5538c3 3240
5cea8590
PB
3241 /* If no data_dir is specified then try to find it relative to the
3242 executable path. */
3243 if (!data_dir) {
6170540b 3244 data_dir = os_find_datadir(argv[0]);
5cea8590 3245 }
60474fb5 3246 /* If all else fails use the install path specified when building. */
5cea8590 3247 if (!data_dir) {
1dabe05c 3248 data_dir = CONFIG_QEMU_DATADIR;
5cea8590
PB
3249 }
3250
d423675c
AF
3251 if (machine == NULL) {
3252 fprintf(stderr, "No machine found.\n");
3253 exit(1);
3254 }
3255
6be68d7e
JS
3256 /*
3257 * Default to max_cpus = smp_cpus, in case the user doesn't
3258 * specify a max_cpus value.
3259 */
3260 if (!max_cpus)
3261 max_cpus = smp_cpus;
3262
3d878caa 3263 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
b2097003
AL
3264 if (smp_cpus > machine->max_cpus) {
3265 fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
3266 "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
3267 machine->max_cpus);
3268 exit(1);
3269 }
3270
67b724e6
AP
3271 /*
3272 * Get the default machine options from the machine if it is not already
3273 * specified either by the configuration file or by the command line.
3274 */
3275 if (machine->default_machine_opts) {
25de5935
JK
3276 qemu_opts_set_defaults(qemu_find_opts("machine"),
3277 machine->default_machine_opts, 0);
67b724e6
AP
3278 }
3279
3329f07b
GH
3280 qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0);
3281 qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0);
998bbd74 3282
986c5f78
GH
3283 if (machine->no_serial) {
3284 default_serial = 0;
3285 }
3286 if (machine->no_parallel) {
3287 default_parallel = 0;
3288 }
3289 if (!machine->use_virtcon) {
3290 default_virtcon = 0;
3291 }
ac33f8fa
GH
3292 if (machine->no_floppy) {
3293 default_floppy = 0;
3294 }
3295 if (machine->no_cdrom) {
3296 default_cdrom = 0;
3297 }
3298 if (machine->no_sdcard) {
3299 default_sdcard = 0;
3300 }
986c5f78 3301
993fbfdb 3302 if (display_type == DT_NOGRAPHIC) {
6a5e8b0e
GH
3303 if (default_parallel)
3304 add_device_config(DEV_PARALLEL, "null");
e1c09175
GH
3305 if (default_serial && default_monitor) {
3306 add_device_config(DEV_SERIAL, "mon:stdio");
986c5f78
GH
3307 } else if (default_virtcon && default_monitor) {
3308 add_device_config(DEV_VIRTCON, "mon:stdio");
e1c09175
GH
3309 } else {
3310 if (default_serial)
3311 add_device_config(DEV_SERIAL, "stdio");
986c5f78
GH
3312 if (default_virtcon)
3313 add_device_config(DEV_VIRTCON, "stdio");
e1c09175 3314 if (default_monitor)
6ca5582d 3315 monitor_parse("stdio", "readline");
e1c09175 3316 }
998bbd74
GH
3317 } else {
3318 if (default_serial)
3319 add_device_config(DEV_SERIAL, "vc:80Cx24C");
6a5e8b0e
GH
3320 if (default_parallel)
3321 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
abdeed06 3322 if (default_monitor)
6ca5582d 3323 monitor_parse("vc:80Cx24C", "readline");
38536da1
AG
3324 if (default_virtcon)
3325 add_device_config(DEV_VIRTCON, "vc:80Cx24C");
bc0129d9
AL
3326 }
3327
a5829fd9
T
3328 socket_init();
3329
3329f07b 3330 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
1a688d3b 3331 exit(1);
758e8e38 3332#ifdef CONFIG_VIRTFS
3329f07b 3333 if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
74db920c
GS
3334 exit(1);
3335 }
3336#endif
1a688d3b 3337
eb505be1 3338 os_daemonize();
71e3ceb8 3339
aa26bb2d 3340 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
eb505be1 3341 os_pidfile_error();
93815bc2
TS
3342 exit(1);
3343 }
3344
0ac543de
JK
3345 /* init the memory */
3346 if (ram_size == 0) {
3347 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
3348 }
3349
303d4e86 3350 configure_accelerator();
214910a7 3351
d3b12f5d 3352 qemu_init_cpu_loop();
3fcf7b6b
AL
3353 if (qemu_init_main_loop()) {
3354 fprintf(stderr, "qemu_init_main_loop failed\n");
3355 exit(1);
3356 }
a0abe474 3357
967c0da7
PM
3358 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
3359 if (machine_opts) {
3360 kernel_filename = qemu_opt_get(machine_opts, "kernel");
3361 initrd_filename = qemu_opt_get(machine_opts, "initrd");
3362 kernel_cmdline = qemu_opt_get(machine_opts, "append");
3363 } else {
3364 kernel_filename = initrd_filename = kernel_cmdline = NULL;
3365 }
3366
a0abe474
PM
3367 if (!kernel_cmdline) {
3368 kernel_cmdline = "";
3369 }
3370
a20dd508 3371 linux_boot = (kernel_filename != NULL);
6c41b272 3372
f8d39c01
TS
3373 if (!linux_boot && *kernel_cmdline != '\0') {
3374 fprintf(stderr, "-append only allowed with -kernel option\n");
3375 exit(1);
3376 }
3377
3378 if (!linux_boot && initrd_filename != NULL) {
3379 fprintf(stderr, "-initrd only allowed with -kernel option\n");
3380 exit(1);
3381 }
3382
412beee6
GL
3383 if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) {
3384 fprintf(stderr, "-dtb only allowed with -kernel option\n");
3385 exit(1);
3386 }
3387
9156d763 3388 os_set_line_buffering();
3b46e624 3389
7183b4b4
AL
3390 if (init_timer_alarm() < 0) {
3391 fprintf(stderr, "could not initialize alarm timer\n");
3392 exit(1);
3393 }
0abe905d 3394
ad1be899
AL
3395#ifdef CONFIG_SPICE
3396 /* spice needs the timers to be initialized by this point */
3397 qemu_spice_init();
3398#endif
3399
0abe905d
MF
3400 if (icount_option && (kvm_enabled() || xen_enabled())) {
3401 fprintf(stderr, "-icount is not allowed with kvm or xen\n");
3402 exit(1);
3403 }
4e3de9e9 3404 configure_icount(icount_option);
634fce96 3405
dc1c9fe8
MM
3406 if (net_init_clients() < 0) {
3407 exit(1);
702c651c 3408 }
f1510b2c 3409
dc72ac14 3410 /* init the bluetooth world */
bd3c948d
GH
3411 if (foreach_device_config(DEV_BT, bt_parse))
3412 exit(1);
dc72ac14 3413
834e76ea
AP
3414 if (!xen_enabled()) {
3415 /* On 32-bit hosts, QEMU is limited by virtual address space */
3416 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
3417 fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
3418 exit(1);
3419 }
3420 }
9ae02555 3421
d5ab9713 3422 cpu_exec_init_all();
26a5f13b 3423
eb852011 3424 bdrv_init_with_whitelist();
c4b1fcc0 3425
c163b5ca 3426 blk_mig_init();
3427
e4bcb14c 3428 /* open the virtual block devices */
9dfd7c7a 3429 if (snapshot)
3329f07b
GH
3430 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
3431 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
9dfd7c7a 3432 exit(1);
3e3d5815 3433
4e5d9b57
MA
3434 default_drive(default_cdrom, snapshot, machine->use_scsi,
3435 IF_DEFAULT, 2, CDROM_OPTS);
3436 default_drive(default_floppy, snapshot, machine->use_scsi,
3437 IF_FLOPPY, 0, FD_OPTS);
3438 default_drive(default_sdcard, snapshot, machine->use_scsi,
3439 IF_SD, 0, SD_OPTS);
3440
97ab12d4 3441 register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
c163b5ca 3442 ram_load, NULL);
8a7ddc38 3443
268a362c
AL
3444 if (nb_numa_nodes > 0) {
3445 int i;
3446
ea0e5418
SL
3447 if (nb_numa_nodes > MAX_NODES) {
3448 nb_numa_nodes = MAX_NODES;
268a362c
AL
3449 }
3450
3451 /* If no memory size if given for any node, assume the default case
3452 * and distribute the available memory equally across all nodes
3453 */
3454 for (i = 0; i < nb_numa_nodes; i++) {
3455 if (node_mem[i] != 0)
3456 break;
3457 }
3458 if (i == nb_numa_nodes) {
3459 uint64_t usedmem = 0;
3460
3461 /* On Linux, the each node's border has to be 8MB aligned,
3462 * the final node gets the rest.
3463 */
3464 for (i = 0; i < nb_numa_nodes - 1; i++) {
3465 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
3466 usedmem += node_mem[i];
3467 }
3468 node_mem[i] = ram_size - usedmem;
3469 }
3470
3471 for (i = 0; i < nb_numa_nodes; i++) {
3472 if (node_cpumask[i] != 0)
3473 break;
3474 }
3475 /* assigning the VCPUs round-robin is easier to implement, guest OSes
3476 * must cope with this anyway, because there are BIOSes out there in
3477 * real machines which also use this scheme.
3478 */
3479 if (i == nb_numa_nodes) {
991dfefd 3480 for (i = 0; i < max_cpus; i++) {
268a362c
AL
3481 node_cpumask[i % nb_numa_nodes] |= 1 << i;
3482 }
3483 }
3484 }
3485
3329f07b 3486 if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
157b9319
JK
3487 exit(1);
3488 }
3489
998bbd74
GH
3490 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
3491 exit(1);
6a5e8b0e
GH
3492 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
3493 exit(1);
aee1b935
GH
3494 if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
3495 exit(1);
c9f398e5
PA
3496 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
3497 exit(1);
2796dae0 3498
7f1b17f2
PB
3499 /* If no default VGA is requested, the default is "none". */
3500 if (default_vga && cirrus_vga_available()) {
3501 vga_model = "cirrus";
a369da5f 3502 }
7f1b17f2 3503 select_vgahw(vga_model);
a369da5f 3504
3329f07b 3505 if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0)
ff952ba2
MA
3506 exit(0);
3507
09aaa160
MA
3508 if (watchdog) {
3509 i = select_watchdog(watchdog);
3510 if (i > 0)
3511 exit (i == 1 ? 1 : 0);
3512 }
3513
b6b61144 3514 if (machine->compat_props) {
458fb679 3515 qdev_prop_register_global_list(machine->compat_props);
b6b61144 3516 }
d0fef6fb
GH
3517 qemu_add_globals();
3518
1de81d28
AL
3519 qdev_machine_init();
3520
fbe1b595 3521 machine->init(ram_size, boot_devices,
3023f332
AL
3522 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
3523
ea375f9a 3524 cpu_synchronize_all_post_init();
268a362c 3525
87d0a28e 3526 set_numa_modes();
268a362c 3527
6f338c34
AL
3528 current_machine = machine;
3529
3023f332
AL
3530 /* init USB devices */
3531 if (usb_enabled) {
0752706d
MA
3532 if (foreach_device_config(DEV_USB, usb_parse) < 0)
3533 exit(1);
3023f332
AL
3534 }
3535
bd3c948d 3536 /* init generic devices */
3329f07b 3537 if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0)
bd3c948d
GH
3538 exit(1);
3539
668680f7
MA
3540 net_check_clients();
3541
3023f332 3542 /* just use the first displaystate for the moment */
b473df6e 3543 ds = get_displaystate();
993fbfdb 3544
a3e22260
GH
3545 if (using_spice)
3546 display_remote++;
6b62dc2d 3547 if (display_type == DT_DEFAULT && !display_remote) {
993fbfdb
AL
3548#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
3549 display_type = DT_SDL;
821601ea 3550#elif defined(CONFIG_VNC)
993fbfdb
AL
3551 vnc_display = "localhost:0,to=99";
3552 show_vnc_port = 1;
821601ea
JS
3553#else
3554 display_type = DT_NONE;
993fbfdb
AL
3555#endif
3556 }
821601ea 3557
993fbfdb 3558
6b62dc2d 3559 /* init local displays */
993fbfdb
AL
3560 switch (display_type) {
3561 case DT_NOGRAPHIC:
3562 break;
4d3b6f6e 3563#if defined(CONFIG_CURSES)
993fbfdb
AL
3564 case DT_CURSES:
3565 curses_display_init(ds, full_screen);
3566 break;
4d3b6f6e 3567#endif
5b0753e0 3568#if defined(CONFIG_SDL)
993fbfdb
AL
3569 case DT_SDL:
3570 sdl_display_init(ds, full_screen, no_frame);
3571 break;
5b0753e0 3572#elif defined(CONFIG_COCOA)
993fbfdb
AL
3573 case DT_SDL:
3574 cocoa_display_init(ds, full_screen);
3575 break;
313aa567 3576#endif
6b62dc2d
GH
3577 default:
3578 break;
3579 }
3580
0ce235a7
GN
3581 /* must be after terminal init, SDL library changes signal handlers */
3582 os_setup_signal_handling();
3583
821601ea 3584#ifdef CONFIG_VNC
6b62dc2d
GH
3585 /* init remote displays */
3586 if (vnc_display) {
993fbfdb
AL
3587 vnc_display_init(ds);
3588 if (vnc_display_open(ds, vnc_display) < 0)
3589 exit(1);
f92f8afe 3590
993fbfdb
AL
3591 if (show_vnc_port) {
3592 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
f92f8afe 3593 }
313aa567 3594 }
821601ea 3595#endif
a3e22260 3596#ifdef CONFIG_SPICE
a19cbfb3 3597 if (using_spice && !qxl_enabled) {
a3e22260
GH
3598 qemu_spice_display_init(ds);
3599 }
3600#endif
5b08fc10 3601
6b62dc2d
GH
3602 /* display setup */
3603 dpy_resize(ds);
3023f332
AL
3604 dcl = ds->listeners;
3605 while (dcl != NULL) {
3606 if (dcl->dpy_refresh != NULL) {
7bd427d8
PB
3607 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
3608 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
0f2ad63f 3609 break;
20d8a3ed 3610 }
3023f332 3611 dcl = dcl->next;
20d8a3ed 3612 }
b473df6e 3613 text_consoles_set_display(ds);
2796dae0 3614
ef0c4a0d 3615 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
59030a8c 3616 exit(1);
45669e00 3617 }
45669e00 3618
3418bd25
GH
3619 qdev_machine_creation_done();
3620
15ff7705
GH
3621 if (rom_load_all() != 0) {
3622 fprintf(stderr, "rom loading failed\n");
3623 exit(1);
3624 }
45a50b16 3625
80376c3f
IY
3626 /* TODO: once all bus devices are qdevified, this should be done
3627 * when bus is created by qdev.c */
3628 qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());
4cab946a
GN
3629 qemu_run_machine_init_done_notifiers();
3630
e063eb1f 3631 qemu_system_reset(VMRESET_SILENT);
05f2401e 3632 if (loadvm) {
03cd4655 3633 if (load_vmstate(loadvm) < 0) {
05f2401e
JQ
3634 autostart = 0;
3635 }
3636 }
d63d307f 3637
2bb8c10c 3638 if (incoming) {
8ca5e801
JQ
3639 int ret = qemu_start_incoming_migration(incoming);
3640 if (ret < 0) {
3641 fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",
3642 incoming, ret);
3643 exit(ret);
3644 }
6b99dadc 3645 } else if (autostart) {
c0f4ce77 3646 vm_start();
6b99dadc 3647 }
ffd843bc 3648
eb505be1 3649 os_setup_post();
71e3ceb8 3650
99435906 3651 resume_all_vcpus();
8a7ddc38 3652 main_loop();
99435906
PB
3653 bdrv_close_all();
3654 pause_all_vcpus();
63a01ef8 3655 net_cleanup();
3d3b8303 3656 res_free();
b46a8906 3657
0824d6fc
FB
3658 return 0;
3659}