bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1 | /* |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 2 | * QEMU System Emulator |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 68d0f70 | 2008-01-06 17:21:48 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | 1df912c | 2003-06-25 16:20:35 +0000 | [diff] [blame] | 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. |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 23 | */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 24 | #include <unistd.h> |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 25 | #include <fcntl.h> |
| 26 | #include <signal.h> |
| 27 | #include <time.h> |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 28 | #include <errno.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 29 | #include <sys/time.h> |
| 30 | |
blueswir1 | d40cdb1 | 2009-03-07 16:52:02 +0000 | [diff] [blame] | 31 | #include "config-host.h" |
| 32 | |
Eduardo Otubo | 452dfbe | 2012-08-14 18:44:07 -0300 | [diff] [blame] | 33 | #ifdef CONFIG_SECCOMP |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 34 | #include "sysemu/seccomp.h" |
Eduardo Otubo | 452dfbe | 2012-08-14 18:44:07 -0300 | [diff] [blame] | 35 | #endif |
| 36 | |
ths | 8a16d27 | 2008-07-19 09:56:24 +0000 | [diff] [blame] | 37 | #if defined(CONFIG_VDE) |
| 38 | #include <libvdeplug.h> |
| 39 | #endif |
| 40 | |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 41 | #ifdef CONFIG_SDL |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 42 | #if defined(__APPLE__) || defined(main) |
Stefan Weil | 6693665 | 2009-06-13 13:19:11 +0200 | [diff] [blame] | 43 | #include <SDL.h> |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 44 | int qemu_main(int argc, char **argv, char **envp); |
| 45 | int main(int argc, char **argv) |
| 46 | { |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 47 | return qemu_main(argc, argv, NULL); |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 48 | } |
| 49 | #undef main |
| 50 | #define main qemu_main |
bellard | 96bcd4f | 2004-07-10 16:26:15 +0000 | [diff] [blame] | 51 | #endif |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 52 | #endif /* CONFIG_SDL */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 53 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 54 | #ifdef CONFIG_COCOA |
| 55 | #undef main |
| 56 | #define main qemu_main |
| 57 | #endif /* CONFIG_COCOA */ |
| 58 | |
Anthony Liguori | 69e5bb6 | 2011-08-22 08:12:52 -0500 | [diff] [blame] | 59 | #include <glib.h> |
| 60 | |
Marcel Apfelbaum | c8897e8 | 2014-03-18 17:26:35 +0200 | [diff] [blame] | 61 | #include "qemu/sockets.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 62 | #include "hw/hw.h" |
| 63 | #include "hw/boards.h" |
| 64 | #include "hw/usb.h" |
| 65 | #include "hw/pcmcia.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 66 | #include "hw/i386/pc.h" |
| 67 | #include "hw/isa/isa.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 68 | #include "hw/bt.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 69 | #include "sysemu/watchdog.h" |
| 70 | #include "hw/i386/smbios.h" |
| 71 | #include "hw/xen/xen.h" |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 72 | #include "hw/qdev.h" |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 73 | #include "hw/loader.h" |
Paolo Bonzini | b4a42f8 | 2013-02-04 11:37:52 +0100 | [diff] [blame] | 74 | #include "monitor/qdev.h" |
Paolo Bonzini | dccfcd0 | 2013-04-08 16:55:25 +0200 | [diff] [blame] | 75 | #include "sysemu/bt.h" |
Paolo Bonzini | 1422e32 | 2012-10-24 08:43:34 +0200 | [diff] [blame] | 76 | #include "net/net.h" |
Mark McLoughlin | 68ac40d | 2009-11-25 18:48:54 +0000 | [diff] [blame] | 77 | #include "net/slirp.h" |
Paolo Bonzini | 83c9089 | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 78 | #include "monitor/monitor.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 79 | #include "ui/console.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 80 | #include "sysemu/sysemu.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 81 | #include "exec/gdbstub.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 82 | #include "qemu/timer.h" |
Paolo Bonzini | dccfcd0 | 2013-04-08 16:55:25 +0200 | [diff] [blame] | 83 | #include "sysemu/char.h" |
Michael Tokarev | b33276a | 2014-02-07 12:26:14 +0400 | [diff] [blame] | 84 | #include "qemu/bitmap.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 85 | #include "qemu/cache-utils.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 86 | #include "sysemu/blockdev.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 87 | #include "hw/block/block.h" |
Paolo Bonzini | caf71f8 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 88 | #include "migration/block.h" |
Paolo Bonzini | bdee56f | 2013-04-02 18:28:41 +0200 | [diff] [blame] | 89 | #include "sysemu/tpm.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 90 | #include "sysemu/dma.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 91 | #include "audio/audio.h" |
Paolo Bonzini | caf71f8 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 92 | #include "migration/migration.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 93 | #include "sysemu/kvm.h" |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 94 | #include "qapi/qmp/qjson.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 95 | #include "qemu/option.h" |
| 96 | #include "qemu/config-file.h" |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 97 | #include "qemu-options.h" |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 98 | #include "qmp-commands.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 99 | #include "qemu/main-loop.h" |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 100 | #ifdef CONFIG_VIRTFS |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 101 | #include "fsdev/qemu-fsdev.h" |
| 102 | #endif |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 103 | #include "sysemu/qtest.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 104 | |
Paolo Bonzini | 76cad71 | 2012-10-24 11:12:21 +0200 | [diff] [blame] | 105 | #include "disas/disas.h" |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 106 | |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 107 | |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 108 | #include "slirp/libslirp.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 109 | |
Stefan Hajnoczi | 94b0b5f | 2010-11-16 12:20:25 +0000 | [diff] [blame] | 110 | #include "trace.h" |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 111 | #include "trace/control.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 112 | #include "qemu/queue.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 113 | #include "sysemu/cpus.h" |
| 114 | #include "sysemu/arch_init.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 115 | #include "qemu/osdep.h" |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 116 | |
Gerd Hoffmann | 29b0040 | 2010-03-11 11:13:27 -0300 | [diff] [blame] | 117 | #include "ui/qemu-spice.h" |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 118 | #include "qapi/string-input-visitor.h" |
Igor Mammedov | 269e09f | 2014-01-16 17:34:38 +0100 | [diff] [blame] | 119 | #include "qom/object_interfaces.h" |
Gerd Hoffmann | 29b0040 | 2010-03-11 11:13:27 -0300 | [diff] [blame] | 120 | |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 121 | #define DEFAULT_RAM_SIZE 128 |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 122 | |
Amit Shah | 98b1925 | 2010-01-20 00:36:52 +0530 | [diff] [blame] | 123 | #define MAX_VIRTIO_CONSOLES 1 |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 124 | #define MAX_SCLP_CONSOLES 1 |
Amit Shah | 98b1925 | 2010-01-20 00:36:52 +0530 | [diff] [blame] | 125 | |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 126 | static const char *data_dir[16]; |
| 127 | static int data_dir_idx; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 128 | const char *bios_name = NULL; |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 129 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 130 | DisplayType display_type = DT_DEFAULT; |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 131 | static int display_remote; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 132 | const char* keyboard_layout = NULL; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 133 | ram_addr_t ram_size; |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 134 | const char *mem_path = NULL; |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 135 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 136 | int nb_nics; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 137 | NICInfo nd_table[MAX_NICS]; |
Paolo Bonzini | d399f67 | 2009-07-27 23:17:51 +0200 | [diff] [blame] | 138 | int autostart; |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 139 | static int rtc_utc = 1; |
| 140 | static int rtc_date_offset = -1; /* -1 means no change */ |
Alex Bligh | 884f17c | 2013-08-21 16:03:04 +0100 | [diff] [blame] | 141 | QEMUClockType rtc_clock; |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 142 | int vga_interface_type = VGA_NONE; |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 143 | static int full_screen = 0; |
| 144 | static int no_frame = 0; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 145 | int no_quit = 0; |
Jan Kiszka | 881249c | 2014-03-12 08:33:50 +0100 | [diff] [blame] | 146 | #ifdef CONFIG_GTK |
| 147 | static bool grab_on_hover; |
| 148 | #endif |
bellard | 8d11df9 | 2004-08-24 21:13:40 +0000 | [diff] [blame] | 149 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 150 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
aliguori | 9ede2fd | 2009-01-15 20:05:25 +0000 | [diff] [blame] | 151 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 152 | CharDriverState *sclp_hds[MAX_SCLP_CONSOLES]; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 153 | int win2k_install_hack = 0; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 154 | int singlestep = 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 155 | int smp_cpus = 1; |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 156 | int max_cpus = 0; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 157 | int smp_cores = 1; |
| 158 | int smp_threads = 1; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 159 | #ifdef CONFIG_VNC |
ths | 73fc974 | 2006-12-22 02:09:07 +0000 | [diff] [blame] | 160 | const char *vnc_display; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 161 | #endif |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 162 | int acpi_enabled = 1; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 163 | int no_hpet = 0; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 164 | int fd_bootchk = 1; |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 165 | static int no_reboot; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 166 | int no_shutdown = 0; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 167 | int cursor_hide = 1; |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 168 | int graphic_rotate = 0; |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 169 | const char *watchdog; |
Gleb Natapov | 2e55e84 | 2010-12-08 13:35:07 +0200 | [diff] [blame] | 170 | QEMUOptionRom option_rom[MAX_OPTION_ROMS]; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 171 | int nb_option_roms; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 172 | int semihosting_enabled = 0; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 173 | int old_param = 0; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 174 | const char *qemu_name; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 175 | int alt_grab = 0; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 176 | int ctrl_grab = 0; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 177 | unsigned int nb_prom_envs = 0; |
| 178 | const char *prom_envs[MAX_PROM_ENVS]; |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 179 | int boot_menu; |
Michael Tokarev | 6f2bfda | 2013-12-09 12:18:46 +0400 | [diff] [blame] | 180 | static bool boot_strict; |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 181 | uint8_t *boot_splash_filedata; |
Markus Armbruster | d09acb9 | 2013-01-23 18:25:08 +0100 | [diff] [blame] | 182 | size_t boot_splash_filedata_size; |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 183 | uint8_t qemu_extra_params_fw[2]; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 184 | |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 185 | typedef struct FWBootEntry FWBootEntry; |
| 186 | |
| 187 | struct FWBootEntry { |
| 188 | QTAILQ_ENTRY(FWBootEntry) link; |
| 189 | int32_t bootindex; |
| 190 | DeviceState *dev; |
| 191 | char *suffix; |
| 192 | }; |
| 193 | |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 194 | static QTAILQ_HEAD(, FWBootEntry) fw_boot_order = |
| 195 | QTAILQ_HEAD_INITIALIZER(fw_boot_order); |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 196 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 197 | int nb_numa_nodes; |
| 198 | uint64_t node_mem[MAX_NODES]; |
Chegu Vinod | ee785fe | 2012-07-16 21:31:30 -0700 | [diff] [blame] | 199 | unsigned long *node_cpumask[MAX_NODES]; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 200 | |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 201 | uint8_t qemu_uuid[16]; |
Markus Armbruster | fc3b329 | 2013-08-16 15:18:31 +0200 | [diff] [blame] | 202 | bool qemu_uuid_set; |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 203 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 204 | static QEMUBootSetHandler *boot_set_handler; |
| 205 | static void *boot_set_opaque; |
| 206 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 207 | static NotifierList exit_notifiers = |
| 208 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); |
| 209 | |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 210 | static NotifierList machine_init_done_notifiers = |
| 211 | NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); |
| 212 | |
liguang | d5286af | 2013-01-24 13:03:27 +0800 | [diff] [blame] | 213 | static bool tcg_allowed = true; |
liguang | d5286af | 2013-01-24 13:03:27 +0800 | [diff] [blame] | 214 | bool xen_allowed; |
Blue Swirl | d745bef | 2010-03-29 19:23:49 +0000 | [diff] [blame] | 215 | uint32_t xen_domid; |
| 216 | enum xen_mode xen_mode = XEN_EMULATE; |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 217 | static int tcg_tb_size; |
Blue Swirl | d745bef | 2010-03-29 19:23:49 +0000 | [diff] [blame] | 218 | |
Mark Wu | d44229c | 2014-03-10 22:37:40 +0800 | [diff] [blame] | 219 | static int has_defaults = 1; |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 220 | static int default_serial = 1; |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 221 | static int default_parallel = 1; |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 222 | static int default_virtcon = 1; |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 223 | static int default_sclp = 1; |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 224 | static int default_monitor = 1; |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 225 | static int default_floppy = 1; |
| 226 | static int default_cdrom = 1; |
| 227 | static int default_sdcard = 1; |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 228 | static int default_vga = 1; |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 229 | |
| 230 | static struct { |
| 231 | const char *driver; |
| 232 | int *flag; |
| 233 | } default_list[] = { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 234 | { .driver = "isa-serial", .flag = &default_serial }, |
| 235 | { .driver = "isa-parallel", .flag = &default_parallel }, |
Gerd Hoffmann | d8bcbab | 2009-12-16 14:25:40 +0100 | [diff] [blame] | 236 | { .driver = "isa-fdc", .flag = &default_floppy }, |
Markus Armbruster | af6bf13 | 2011-05-18 18:31:02 +0200 | [diff] [blame] | 237 | { .driver = "ide-cd", .flag = &default_cdrom }, |
| 238 | { .driver = "ide-hd", .flag = &default_cdrom }, |
Gerd Hoffmann | d8bcbab | 2009-12-16 14:25:40 +0100 | [diff] [blame] | 239 | { .driver = "ide-drive", .flag = &default_cdrom }, |
Markus Armbruster | af6bf13 | 2011-05-18 18:31:02 +0200 | [diff] [blame] | 240 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 241 | { .driver = "virtio-serial-pci", .flag = &default_virtcon }, |
| 242 | { .driver = "virtio-serial-s390", .flag = &default_virtcon }, |
| 243 | { .driver = "virtio-serial", .flag = &default_virtcon }, |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 244 | { .driver = "VGA", .flag = &default_vga }, |
| 245 | { .driver = "isa-vga", .flag = &default_vga }, |
| 246 | { .driver = "cirrus-vga", .flag = &default_vga }, |
| 247 | { .driver = "isa-cirrus-vga", .flag = &default_vga }, |
| 248 | { .driver = "vmware-svga", .flag = &default_vga }, |
| 249 | { .driver = "qxl-vga", .flag = &default_vga }, |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 250 | }; |
| 251 | |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 252 | static QemuOptsList qemu_rtc_opts = { |
| 253 | .name = "rtc", |
| 254 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), |
| 255 | .desc = { |
| 256 | { |
| 257 | .name = "base", |
| 258 | .type = QEMU_OPT_STRING, |
| 259 | },{ |
| 260 | .name = "clock", |
| 261 | .type = QEMU_OPT_STRING, |
| 262 | },{ |
| 263 | .name = "driftfix", |
| 264 | .type = QEMU_OPT_STRING, |
| 265 | }, |
| 266 | { /* end of list */ } |
| 267 | }, |
| 268 | }; |
| 269 | |
| 270 | static QemuOptsList qemu_sandbox_opts = { |
| 271 | .name = "sandbox", |
| 272 | .implied_opt_name = "enable", |
| 273 | .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head), |
| 274 | .desc = { |
| 275 | { |
| 276 | .name = "enable", |
| 277 | .type = QEMU_OPT_BOOL, |
| 278 | }, |
| 279 | { /* end of list */ } |
| 280 | }, |
| 281 | }; |
| 282 | |
| 283 | static QemuOptsList qemu_trace_opts = { |
| 284 | .name = "trace", |
| 285 | .implied_opt_name = "trace", |
| 286 | .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head), |
| 287 | .desc = { |
| 288 | { |
| 289 | .name = "events", |
| 290 | .type = QEMU_OPT_STRING, |
| 291 | },{ |
| 292 | .name = "file", |
| 293 | .type = QEMU_OPT_STRING, |
| 294 | }, |
| 295 | { /* end of list */ } |
| 296 | }, |
| 297 | }; |
| 298 | |
| 299 | static QemuOptsList qemu_option_rom_opts = { |
| 300 | .name = "option-rom", |
| 301 | .implied_opt_name = "romfile", |
| 302 | .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head), |
| 303 | .desc = { |
| 304 | { |
| 305 | .name = "bootindex", |
| 306 | .type = QEMU_OPT_NUMBER, |
| 307 | }, { |
| 308 | .name = "romfile", |
| 309 | .type = QEMU_OPT_STRING, |
| 310 | }, |
| 311 | { /* end of list */ } |
| 312 | }, |
| 313 | }; |
| 314 | |
| 315 | static QemuOptsList qemu_machine_opts = { |
| 316 | .name = "machine", |
| 317 | .implied_opt_name = "type", |
| 318 | .merge_lists = true, |
| 319 | .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), |
| 320 | .desc = { |
| 321 | { |
| 322 | .name = "type", |
| 323 | .type = QEMU_OPT_STRING, |
| 324 | .help = "emulated machine" |
| 325 | }, { |
| 326 | .name = "accel", |
| 327 | .type = QEMU_OPT_STRING, |
| 328 | .help = "accelerator list", |
| 329 | }, { |
| 330 | .name = "kernel_irqchip", |
| 331 | .type = QEMU_OPT_BOOL, |
| 332 | .help = "use KVM in-kernel irqchip", |
| 333 | }, { |
| 334 | .name = "kvm_shadow_mem", |
| 335 | .type = QEMU_OPT_SIZE, |
| 336 | .help = "KVM shadow MMU size", |
| 337 | }, { |
| 338 | .name = "kernel", |
| 339 | .type = QEMU_OPT_STRING, |
| 340 | .help = "Linux kernel image file", |
| 341 | }, { |
| 342 | .name = "initrd", |
| 343 | .type = QEMU_OPT_STRING, |
| 344 | .help = "Linux initial ramdisk file", |
| 345 | }, { |
| 346 | .name = "append", |
| 347 | .type = QEMU_OPT_STRING, |
| 348 | .help = "Linux kernel command line", |
| 349 | }, { |
| 350 | .name = "dtb", |
| 351 | .type = QEMU_OPT_STRING, |
| 352 | .help = "Linux kernel device tree file", |
| 353 | }, { |
| 354 | .name = "dumpdtb", |
| 355 | .type = QEMU_OPT_STRING, |
| 356 | .help = "Dump current dtb to a file and quit", |
| 357 | }, { |
| 358 | .name = "phandle_start", |
Markus Armbruster | c1b71b0 | 2013-07-04 15:09:23 +0200 | [diff] [blame] | 359 | .type = QEMU_OPT_NUMBER, |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 360 | .help = "The first phandle ID we may generate dynamically", |
| 361 | }, { |
| 362 | .name = "dt_compatible", |
| 363 | .type = QEMU_OPT_STRING, |
| 364 | .help = "Overrides the \"compatible\" property of the dt root node", |
| 365 | }, { |
| 366 | .name = "dump-guest-core", |
| 367 | .type = QEMU_OPT_BOOL, |
| 368 | .help = "Include guest memory in a core dump", |
| 369 | }, { |
| 370 | .name = "mem-merge", |
| 371 | .type = QEMU_OPT_BOOL, |
| 372 | .help = "enable/disable memory merge support", |
| 373 | },{ |
| 374 | .name = "usb", |
| 375 | .type = QEMU_OPT_BOOL, |
| 376 | .help = "Set on/off to enable/disable usb", |
Gerd Hoffmann | 1442d3e | 2013-10-15 16:57:45 +0200 | [diff] [blame] | 377 | },{ |
| 378 | .name = "firmware", |
| 379 | .type = QEMU_OPT_STRING, |
| 380 | .help = "firmware image", |
Aneesh Kumar K.V | 135a129 | 2013-12-23 21:10:40 +0530 | [diff] [blame] | 381 | },{ |
| 382 | .name = "kvm-type", |
| 383 | .type = QEMU_OPT_STRING, |
| 384 | .help = "Specifies the KVM virtualization mode (HV, PR)", |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 385 | }, |
| 386 | { /* End of list */ } |
| 387 | }, |
| 388 | }; |
| 389 | |
| 390 | static QemuOptsList qemu_boot_opts = { |
| 391 | .name = "boot-opts", |
Markus Armbruster | 6ef4716 | 2013-06-14 13:15:01 +0200 | [diff] [blame] | 392 | .implied_opt_name = "order", |
| 393 | .merge_lists = true, |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 394 | .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), |
| 395 | .desc = { |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 396 | { |
| 397 | .name = "order", |
| 398 | .type = QEMU_OPT_STRING, |
| 399 | }, { |
| 400 | .name = "once", |
| 401 | .type = QEMU_OPT_STRING, |
| 402 | }, { |
| 403 | .name = "menu", |
Markus Armbruster | 6ef4716 | 2013-06-14 13:15:01 +0200 | [diff] [blame] | 404 | .type = QEMU_OPT_BOOL, |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 405 | }, { |
| 406 | .name = "splash", |
| 407 | .type = QEMU_OPT_STRING, |
| 408 | }, { |
| 409 | .name = "splash-time", |
| 410 | .type = QEMU_OPT_STRING, |
| 411 | }, { |
| 412 | .name = "reboot-timeout", |
| 413 | .type = QEMU_OPT_STRING, |
Amos Kong | c8a6ae8 | 2013-03-19 14:23:27 +0800 | [diff] [blame] | 414 | }, { |
| 415 | .name = "strict", |
Amos Kong | e5187b5 | 2013-12-09 19:53:15 +0800 | [diff] [blame] | 416 | .type = QEMU_OPT_BOOL, |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 417 | }, |
| 418 | { /*End of list */ } |
| 419 | }, |
| 420 | }; |
| 421 | |
| 422 | static QemuOptsList qemu_add_fd_opts = { |
| 423 | .name = "add-fd", |
| 424 | .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), |
| 425 | .desc = { |
| 426 | { |
| 427 | .name = "fd", |
| 428 | .type = QEMU_OPT_NUMBER, |
| 429 | .help = "file descriptor of which a duplicate is added to fd set", |
| 430 | },{ |
| 431 | .name = "set", |
| 432 | .type = QEMU_OPT_NUMBER, |
| 433 | .help = "ID of the fd set to add fd to", |
| 434 | },{ |
| 435 | .name = "opaque", |
| 436 | .type = QEMU_OPT_STRING, |
| 437 | .help = "free-form string used to describe fd", |
| 438 | }, |
| 439 | { /* end of list */ } |
| 440 | }, |
| 441 | }; |
| 442 | |
| 443 | static QemuOptsList qemu_object_opts = { |
| 444 | .name = "object", |
| 445 | .implied_opt_name = "qom-type", |
| 446 | .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), |
| 447 | .desc = { |
| 448 | { } |
| 449 | }, |
| 450 | }; |
| 451 | |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 452 | static QemuOptsList qemu_tpmdev_opts = { |
| 453 | .name = "tpmdev", |
| 454 | .implied_opt_name = "type", |
| 455 | .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head), |
| 456 | .desc = { |
Stefan Berger | bb71623 | 2013-04-22 10:41:39 -0400 | [diff] [blame] | 457 | /* options are defined in the TPM backends */ |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 458 | { /* end of list */ } |
| 459 | }, |
| 460 | }; |
| 461 | |
Satoru Moriya | 888a6bc | 2013-04-19 16:42:06 +0200 | [diff] [blame] | 462 | static QemuOptsList qemu_realtime_opts = { |
| 463 | .name = "realtime", |
| 464 | .head = QTAILQ_HEAD_INITIALIZER(qemu_realtime_opts.head), |
| 465 | .desc = { |
| 466 | { |
| 467 | .name = "mlock", |
| 468 | .type = QEMU_OPT_BOOL, |
| 469 | }, |
| 470 | { /* end of list */ } |
| 471 | }, |
| 472 | }; |
| 473 | |
Seiji Aguchi | 5e2ac51 | 2013-07-03 23:02:46 -0400 | [diff] [blame] | 474 | static QemuOptsList qemu_msg_opts = { |
| 475 | .name = "msg", |
| 476 | .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head), |
| 477 | .desc = { |
| 478 | { |
| 479 | .name = "timestamp", |
| 480 | .type = QEMU_OPT_BOOL, |
| 481 | }, |
| 482 | { /* end of list */ } |
| 483 | }, |
| 484 | }; |
| 485 | |
Dr. David Alan Gilbert | 5d12f96 | 2014-01-30 10:20:30 +0000 | [diff] [blame] | 486 | static QemuOptsList qemu_name_opts = { |
| 487 | .name = "name", |
| 488 | .implied_opt_name = "guest", |
| 489 | .merge_lists = true, |
| 490 | .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head), |
| 491 | .desc = { |
| 492 | { |
| 493 | .name = "guest", |
| 494 | .type = QEMU_OPT_STRING, |
| 495 | .help = "Sets the name of the guest.\n" |
| 496 | "This name will be displayed in the SDL window caption.\n" |
| 497 | "The name will also be used for the VNC server", |
| 498 | }, { |
| 499 | .name = "process", |
| 500 | .type = QEMU_OPT_STRING, |
| 501 | .help = "Sets the name of the QEMU process, as shown in top etc", |
Dr. David Alan Gilbert | 8f480de | 2014-01-30 10:20:31 +0000 | [diff] [blame] | 502 | }, { |
| 503 | .name = "debug-threads", |
| 504 | .type = QEMU_OPT_BOOL, |
| 505 | .help = "When enabled, name the individual threads; defaults off.\n" |
| 506 | "NOTE: The thread names are for debugging and not a\n" |
| 507 | "stable API.", |
Dr. David Alan Gilbert | 5d12f96 | 2014-01-30 10:20:30 +0000 | [diff] [blame] | 508 | }, |
| 509 | { /* End of list */ } |
| 510 | }, |
| 511 | }; |
| 512 | |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 513 | static QemuOptsList qemu_mem_opts = { |
| 514 | .name = "memory", |
| 515 | .implied_opt_name = "size", |
| 516 | .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head), |
| 517 | .merge_lists = true, |
| 518 | .desc = { |
| 519 | { |
| 520 | .name = "size", |
| 521 | .type = QEMU_OPT_SIZE, |
| 522 | }, |
Igor Mammedov | c270fb9 | 2014-06-02 15:25:02 +0200 | [diff] [blame] | 523 | { |
| 524 | .name = "slots", |
| 525 | .type = QEMU_OPT_NUMBER, |
| 526 | }, |
| 527 | { |
| 528 | .name = "maxmem", |
| 529 | .type = QEMU_OPT_SIZE, |
| 530 | }, |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 531 | { /* end of list */ } |
| 532 | }, |
| 533 | }; |
| 534 | |
Markus Armbruster | 7f9d6e5 | 2013-07-04 15:09:19 +0200 | [diff] [blame] | 535 | /** |
| 536 | * Get machine options |
| 537 | * |
| 538 | * Returns: machine options (never null). |
| 539 | */ |
| 540 | QemuOpts *qemu_get_machine_opts(void) |
| 541 | { |
Paolo Bonzini | e96e5ae | 2014-03-06 10:39:24 +0100 | [diff] [blame] | 542 | return qemu_find_opts_singleton("machine"); |
Markus Armbruster | 7f9d6e5 | 2013-07-04 15:09:19 +0200 | [diff] [blame] | 543 | } |
| 544 | |
Ronnie Sahlberg | 31459f4 | 2012-08-06 18:24:55 +1000 | [diff] [blame] | 545 | const char *qemu_get_vm_name(void) |
| 546 | { |
| 547 | return qemu_name; |
| 548 | } |
| 549 | |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 550 | static void res_free(void) |
| 551 | { |
| 552 | if (boot_splash_filedata != NULL) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 553 | g_free(boot_splash_filedata); |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 554 | boot_splash_filedata = NULL; |
| 555 | } |
| 556 | } |
| 557 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 558 | static int default_driver_check(QemuOpts *opts, void *opaque) |
| 559 | { |
| 560 | const char *driver = qemu_opt_get(opts, "driver"); |
| 561 | int i; |
| 562 | |
| 563 | if (!driver) |
| 564 | return 0; |
| 565 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { |
| 566 | if (strcmp(default_list[i].driver, driver) != 0) |
| 567 | continue; |
| 568 | *(default_list[i].flag) = 0; |
| 569 | } |
| 570 | return 0; |
| 571 | } |
| 572 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 573 | /***********************************************************/ |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 574 | /* QEMU state */ |
| 575 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 576 | static RunState current_run_state = RUN_STATE_PRELAUNCH; |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 577 | |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 578 | typedef struct { |
| 579 | RunState from; |
| 580 | RunState to; |
| 581 | } RunStateTransition; |
| 582 | |
| 583 | static const RunStateTransition runstate_transitions_def[] = { |
| 584 | /* from -> to */ |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 585 | { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, |
Paolo Bonzini | eca01d3 | 2013-12-03 13:00:15 +0100 | [diff] [blame] | 586 | { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 587 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 588 | { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, |
Paolo Bonzini | 29ed72f | 2012-10-19 16:45:24 +0200 | [diff] [blame] | 589 | { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 590 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 591 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 592 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 593 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 594 | { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 595 | { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 596 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 597 | { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 598 | { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 599 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 600 | { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 601 | { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 602 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 603 | { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 604 | { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 605 | { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 606 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 607 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, |
| 608 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 609 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 610 | { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 611 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 612 | { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, |
| 613 | { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, |
| 614 | { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR }, |
| 615 | { RUN_STATE_RUNNING, RUN_STATE_PAUSED }, |
| 616 | { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE }, |
| 617 | { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM }, |
| 618 | { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM }, |
| 619 | { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, |
| 620 | { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 621 | { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 622 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 623 | { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 624 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 625 | { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 626 | { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 627 | |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 628 | { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED }, |
| 629 | { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED }, |
| 630 | { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING }, |
| 631 | { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE }, |
| 632 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 633 | { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, |
Luiz Capitulino | 8a9236f | 2011-10-14 11:18:09 -0300 | [diff] [blame] | 634 | { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 635 | |
Paolo Bonzini | df39076 | 2013-11-04 14:30:47 +0100 | [diff] [blame] | 636 | { RUN_STATE_GUEST_PANICKED, RUN_STATE_RUNNING }, |
Hu Tao | fd2a2e1 | 2013-05-20 12:46:20 +0200 | [diff] [blame] | 637 | { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE }, |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 638 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 639 | { RUN_STATE_MAX, RUN_STATE_MAX }, |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 640 | }; |
| 641 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 642 | static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX]; |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 643 | |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 644 | bool runstate_check(RunState state) |
| 645 | { |
| 646 | return current_run_state == state; |
| 647 | } |
| 648 | |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 649 | static void runstate_init(void) |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 650 | { |
| 651 | const RunStateTransition *p; |
| 652 | |
| 653 | memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); |
| 654 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 655 | for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) { |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 656 | runstate_valid_transitions[p->from][p->to] = true; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | /* This function will abort() on invalid state transitions */ |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 661 | void runstate_set(RunState new_state) |
| 662 | { |
Luiz Capitulino | 207c5cd | 2011-10-13 10:59:07 -0300 | [diff] [blame] | 663 | assert(new_state < RUN_STATE_MAX); |
| 664 | |
| 665 | if (!runstate_valid_transitions[current_run_state][new_state]) { |
| 666 | fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n", |
| 667 | RunState_lookup[current_run_state], |
| 668 | RunState_lookup[new_state]); |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 669 | abort(); |
| 670 | } |
Kazuya Saito | 7e86600 | 2013-03-22 17:26:59 +0900 | [diff] [blame] | 671 | trace_runstate_set(new_state); |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 672 | current_run_state = new_state; |
| 673 | } |
| 674 | |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 675 | int runstate_is_running(void) |
| 676 | { |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 677 | return runstate_check(RUN_STATE_RUNNING); |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 678 | } |
| 679 | |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 680 | bool runstate_needs_reset(void) |
| 681 | { |
| 682 | return runstate_check(RUN_STATE_INTERNAL_ERROR) || |
Paolo Bonzini | df39076 | 2013-11-04 14:30:47 +0100 | [diff] [blame] | 683 | runstate_check(RUN_STATE_SHUTDOWN); |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 684 | } |
| 685 | |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 686 | StatusInfo *qmp_query_status(Error **errp) |
| 687 | { |
| 688 | StatusInfo *info = g_malloc0(sizeof(*info)); |
| 689 | |
| 690 | info->running = runstate_is_running(); |
| 691 | info->singlestep = singlestep; |
| 692 | info->status = current_run_state; |
| 693 | |
| 694 | return info; |
| 695 | } |
| 696 | |
Luiz Capitulino | f5bbfba | 2011-07-29 15:04:45 -0300 | [diff] [blame] | 697 | /***********************************************************/ |
Paolo Bonzini | 8f0056b | 2010-01-13 14:05:34 +0100 | [diff] [blame] | 698 | /* real time host monotonic timer */ |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 699 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 700 | /***********************************************************/ |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 701 | /* host time/date access */ |
| 702 | void qemu_get_timedate(struct tm *tm, int offset) |
| 703 | { |
| 704 | time_t ti; |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 705 | |
| 706 | time(&ti); |
| 707 | ti += offset; |
| 708 | if (rtc_date_offset == -1) { |
| 709 | if (rtc_utc) |
Stefan Weil | eb7ff6f | 2013-01-07 23:08:13 +0100 | [diff] [blame] | 710 | gmtime_r(&ti, tm); |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 711 | else |
Stefan Weil | eb7ff6f | 2013-01-07 23:08:13 +0100 | [diff] [blame] | 712 | localtime_r(&ti, tm); |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 713 | } else { |
| 714 | ti -= rtc_date_offset; |
Stefan Weil | eb7ff6f | 2013-01-07 23:08:13 +0100 | [diff] [blame] | 715 | gmtime_r(&ti, tm); |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 716 | } |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | int qemu_timedate_diff(struct tm *tm) |
| 720 | { |
| 721 | time_t seconds; |
| 722 | |
| 723 | if (rtc_date_offset == -1) |
| 724 | if (rtc_utc) |
| 725 | seconds = mktimegm(tm); |
Gleb Natapov | f54c556 | 2011-11-06 18:00:22 +0200 | [diff] [blame] | 726 | else { |
| 727 | struct tm tmp = *tm; |
| 728 | tmp.tm_isdst = -1; /* use timezone to figure it out */ |
| 729 | seconds = mktime(&tmp); |
| 730 | } |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 731 | else |
| 732 | seconds = mktimegm(tm) + rtc_date_offset; |
| 733 | |
| 734 | return seconds - time(NULL); |
| 735 | } |
| 736 | |
Luiz Capitulino | 80cd347 | 2010-02-25 12:11:44 -0300 | [diff] [blame] | 737 | void rtc_change_mon_event(struct tm *tm) |
| 738 | { |
| 739 | QObject *data; |
| 740 | |
| 741 | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); |
| 742 | monitor_protocol_event(QEVENT_RTC_CHANGE, data); |
| 743 | qobject_decref(data); |
| 744 | } |
| 745 | |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 746 | static void configure_rtc_date_offset(const char *startdate, int legacy) |
| 747 | { |
| 748 | time_t rtc_start_date; |
| 749 | struct tm tm; |
| 750 | |
| 751 | if (!strcmp(startdate, "now") && legacy) { |
| 752 | rtc_date_offset = -1; |
| 753 | } else { |
| 754 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", |
| 755 | &tm.tm_year, |
| 756 | &tm.tm_mon, |
| 757 | &tm.tm_mday, |
| 758 | &tm.tm_hour, |
| 759 | &tm.tm_min, |
| 760 | &tm.tm_sec) == 6) { |
| 761 | /* OK */ |
| 762 | } else if (sscanf(startdate, "%d-%d-%d", |
| 763 | &tm.tm_year, |
| 764 | &tm.tm_mon, |
| 765 | &tm.tm_mday) == 3) { |
| 766 | tm.tm_hour = 0; |
| 767 | tm.tm_min = 0; |
| 768 | tm.tm_sec = 0; |
| 769 | } else { |
| 770 | goto date_fail; |
| 771 | } |
| 772 | tm.tm_year -= 1900; |
| 773 | tm.tm_mon--; |
| 774 | rtc_start_date = mktimegm(&tm); |
| 775 | if (rtc_start_date == -1) { |
| 776 | date_fail: |
| 777 | fprintf(stderr, "Invalid date format. Valid formats are:\n" |
| 778 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); |
| 779 | exit(1); |
| 780 | } |
| 781 | rtc_date_offset = time(NULL) - rtc_start_date; |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | static void configure_rtc(QemuOpts *opts) |
| 786 | { |
| 787 | const char *value; |
| 788 | |
| 789 | value = qemu_opt_get(opts, "base"); |
| 790 | if (value) { |
| 791 | if (!strcmp(value, "utc")) { |
| 792 | rtc_utc = 1; |
| 793 | } else if (!strcmp(value, "localtime")) { |
| 794 | rtc_utc = 0; |
| 795 | } else { |
| 796 | configure_rtc_date_offset(value, 0); |
| 797 | } |
| 798 | } |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 799 | value = qemu_opt_get(opts, "clock"); |
| 800 | if (value) { |
| 801 | if (!strcmp(value, "host")) { |
Alex Bligh | 884f17c | 2013-08-21 16:03:04 +0100 | [diff] [blame] | 802 | rtc_clock = QEMU_CLOCK_HOST; |
Paolo Bonzini | 7880814 | 2012-03-30 10:31:21 +0000 | [diff] [blame] | 803 | } else if (!strcmp(value, "rt")) { |
Alex Bligh | 884f17c | 2013-08-21 16:03:04 +0100 | [diff] [blame] | 804 | rtc_clock = QEMU_CLOCK_REALTIME; |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 805 | } else if (!strcmp(value, "vm")) { |
Alex Bligh | 884f17c | 2013-08-21 16:03:04 +0100 | [diff] [blame] | 806 | rtc_clock = QEMU_CLOCK_VIRTUAL; |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 807 | } else { |
| 808 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 809 | exit(1); |
| 810 | } |
| 811 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 812 | value = qemu_opt_get(opts, "driftfix"); |
| 813 | if (value) { |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 814 | if (!strcmp(value, "slew")) { |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 815 | static GlobalProperty slew_lost_ticks[] = { |
| 816 | { |
| 817 | .driver = "mc146818rtc", |
| 818 | .property = "lost_tick_policy", |
| 819 | .value = "slew", |
| 820 | }, |
| 821 | { /* end of list */ } |
| 822 | }; |
| 823 | |
| 824 | qdev_prop_register_global_list(slew_lost_ticks); |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 825 | } else if (!strcmp(value, "none")) { |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 826 | /* discard is default */ |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 827 | } else { |
| 828 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 829 | exit(1); |
| 830 | } |
| 831 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 832 | } |
| 833 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 834 | /***********************************************************/ |
| 835 | /* Bluetooth support */ |
| 836 | static int nb_hcis; |
| 837 | static int cur_hci; |
| 838 | static struct HCIInfo *hci_table[MAX_NICS]; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 839 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 840 | struct HCIInfo *qemu_next_hci(void) |
| 841 | { |
| 842 | if (cur_hci == nb_hcis) |
| 843 | return &null_hci; |
| 844 | |
| 845 | return hci_table[cur_hci++]; |
| 846 | } |
| 847 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 848 | static int bt_hci_parse(const char *str) |
| 849 | { |
| 850 | struct HCIInfo *hci; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 851 | bdaddr_t bdaddr; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 852 | |
| 853 | if (nb_hcis >= MAX_NICS) { |
| 854 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); |
| 855 | return -1; |
| 856 | } |
| 857 | |
| 858 | hci = hci_init(str); |
| 859 | if (!hci) |
| 860 | return -1; |
| 861 | |
| 862 | bdaddr.b[0] = 0x52; |
| 863 | bdaddr.b[1] = 0x54; |
| 864 | bdaddr.b[2] = 0x00; |
| 865 | bdaddr.b[3] = 0x12; |
| 866 | bdaddr.b[4] = 0x34; |
| 867 | bdaddr.b[5] = 0x56 + nb_hcis; |
| 868 | hci->bdaddr_set(hci, bdaddr.b); |
| 869 | |
| 870 | hci_table[nb_hcis++] = hci; |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | static void bt_vhci_add(int vlan_id) |
| 876 | { |
| 877 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); |
| 878 | |
| 879 | if (!vlan->slave) |
| 880 | fprintf(stderr, "qemu: warning: adding a VHCI to " |
| 881 | "an empty scatternet %i\n", vlan_id); |
| 882 | |
| 883 | bt_vhci_init(bt_new_hci(vlan)); |
| 884 | } |
| 885 | |
| 886 | static struct bt_device_s *bt_device_add(const char *opt) |
| 887 | { |
| 888 | struct bt_scatternet_s *vlan; |
| 889 | int vlan_id = 0; |
| 890 | char *endp = strstr(opt, ",vlan="); |
| 891 | int len = (endp ? endp - opt : strlen(opt)) + 1; |
| 892 | char devname[10]; |
| 893 | |
| 894 | pstrcpy(devname, MIN(sizeof(devname), len), opt); |
| 895 | |
| 896 | if (endp) { |
| 897 | vlan_id = strtol(endp + 6, &endp, 0); |
| 898 | if (*endp) { |
| 899 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); |
| 900 | return 0; |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | vlan = qemu_find_bt_vlan(vlan_id); |
| 905 | |
| 906 | if (!vlan->slave) |
| 907 | fprintf(stderr, "qemu: warning: adding a slave device to " |
| 908 | "an empty scatternet %i\n", vlan_id); |
| 909 | |
| 910 | if (!strcmp(devname, "keyboard")) |
| 911 | return bt_keyboard_init(vlan); |
| 912 | |
| 913 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | static int bt_parse(const char *opt) |
| 918 | { |
| 919 | const char *endp, *p; |
| 920 | int vlan; |
| 921 | |
| 922 | if (strstart(opt, "hci", &endp)) { |
| 923 | if (!*endp || *endp == ',') { |
| 924 | if (*endp) |
| 925 | if (!strstart(endp, ",vlan=", 0)) |
| 926 | opt = endp + 1; |
| 927 | |
| 928 | return bt_hci_parse(opt); |
| 929 | } |
| 930 | } else if (strstart(opt, "vhci", &endp)) { |
| 931 | if (!*endp || *endp == ',') { |
| 932 | if (*endp) { |
| 933 | if (strstart(endp, ",vlan=", &p)) { |
| 934 | vlan = strtol(p, (char **) &endp, 0); |
| 935 | if (*endp) { |
| 936 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); |
| 937 | return 1; |
| 938 | } |
| 939 | } else { |
| 940 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); |
| 941 | return 1; |
| 942 | } |
| 943 | } else |
| 944 | vlan = 0; |
| 945 | |
| 946 | bt_vhci_add(vlan); |
| 947 | return 0; |
| 948 | } |
| 949 | } else if (strstart(opt, "device:", &endp)) |
| 950 | return !bt_device_add(endp); |
| 951 | |
| 952 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); |
| 953 | return 1; |
| 954 | } |
| 955 | |
Eduardo Otubo | 7d76ad4 | 2012-08-14 18:44:08 -0300 | [diff] [blame] | 956 | static int parse_sandbox(QemuOpts *opts, void *opaque) |
| 957 | { |
| 958 | /* FIXME: change this to true for 1.3 */ |
| 959 | if (qemu_opt_get_bool(opts, "enable", false)) { |
| 960 | #ifdef CONFIG_SECCOMP |
| 961 | if (seccomp_start() < 0) { |
| 962 | qerror_report(ERROR_CLASS_GENERIC_ERROR, |
| 963 | "failed to install seccomp syscall filter in the kernel"); |
| 964 | return -1; |
| 965 | } |
| 966 | #else |
| 967 | qerror_report(ERROR_CLASS_GENERIC_ERROR, |
| 968 | "sandboxing request but seccomp is not compiled into this build"); |
| 969 | return -1; |
| 970 | #endif |
| 971 | } |
| 972 | |
| 973 | return 0; |
| 974 | } |
| 975 | |
Dr. David Alan Gilbert | 5b9d313 | 2014-05-06 12:15:55 +0100 | [diff] [blame] | 976 | static int parse_name(QemuOpts *opts, void *opaque) |
Dr. David Alan Gilbert | 5d12f96 | 2014-01-30 10:20:30 +0000 | [diff] [blame] | 977 | { |
| 978 | const char *proc_name; |
| 979 | |
Dr. David Alan Gilbert | 8f480de | 2014-01-30 10:20:31 +0000 | [diff] [blame] | 980 | if (qemu_opt_get(opts, "debug-threads")) { |
| 981 | qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false)); |
| 982 | } |
Dr. David Alan Gilbert | 5d12f96 | 2014-01-30 10:20:30 +0000 | [diff] [blame] | 983 | qemu_name = qemu_opt_get(opts, "guest"); |
| 984 | |
| 985 | proc_name = qemu_opt_get(opts, "process"); |
| 986 | if (proc_name) { |
| 987 | os_set_proc_name(proc_name); |
| 988 | } |
Dr. David Alan Gilbert | 5b9d313 | 2014-05-06 12:15:55 +0100 | [diff] [blame] | 989 | |
| 990 | return 0; |
Dr. David Alan Gilbert | 5d12f96 | 2014-01-30 10:20:30 +0000 | [diff] [blame] | 991 | } |
| 992 | |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 993 | bool usb_enabled(bool default_usb) |
| 994 | { |
Mark Wu | 7effdaa | 2014-03-10 22:37:41 +0800 | [diff] [blame] | 995 | return qemu_opt_get_bool(qemu_get_machine_opts(), "usb", |
| 996 | has_defaults && default_usb); |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Corey Bryant | 587ed6b | 2012-10-18 15:19:34 -0400 | [diff] [blame] | 999 | #ifndef _WIN32 |
| 1000 | static int parse_add_fd(QemuOpts *opts, void *opaque) |
| 1001 | { |
| 1002 | int fd, dupfd, flags; |
| 1003 | int64_t fdset_id; |
| 1004 | const char *fd_opaque = NULL; |
| 1005 | |
| 1006 | fd = qemu_opt_get_number(opts, "fd", -1); |
| 1007 | fdset_id = qemu_opt_get_number(opts, "set", -1); |
| 1008 | fd_opaque = qemu_opt_get(opts, "opaque"); |
| 1009 | |
| 1010 | if (fd < 0) { |
| 1011 | qerror_report(ERROR_CLASS_GENERIC_ERROR, |
| 1012 | "fd option is required and must be non-negative"); |
| 1013 | return -1; |
| 1014 | } |
| 1015 | |
| 1016 | if (fd <= STDERR_FILENO) { |
| 1017 | qerror_report(ERROR_CLASS_GENERIC_ERROR, |
| 1018 | "fd cannot be a standard I/O stream"); |
| 1019 | return -1; |
| 1020 | } |
| 1021 | |
| 1022 | /* |
| 1023 | * All fds inherited across exec() necessarily have FD_CLOEXEC |
| 1024 | * clear, while qemu sets FD_CLOEXEC on all other fds used internally. |
| 1025 | */ |
| 1026 | flags = fcntl(fd, F_GETFD); |
| 1027 | if (flags == -1 || (flags & FD_CLOEXEC)) { |
| 1028 | qerror_report(ERROR_CLASS_GENERIC_ERROR, |
| 1029 | "fd is not valid or already in use"); |
| 1030 | return -1; |
| 1031 | } |
| 1032 | |
| 1033 | if (fdset_id < 0) { |
| 1034 | qerror_report(ERROR_CLASS_GENERIC_ERROR, |
| 1035 | "set option is required and must be non-negative"); |
| 1036 | return -1; |
| 1037 | } |
| 1038 | |
| 1039 | #ifdef F_DUPFD_CLOEXEC |
| 1040 | dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0); |
| 1041 | #else |
| 1042 | dupfd = dup(fd); |
| 1043 | if (dupfd != -1) { |
| 1044 | qemu_set_cloexec(dupfd); |
| 1045 | } |
| 1046 | #endif |
| 1047 | if (dupfd == -1) { |
| 1048 | qerror_report(ERROR_CLASS_GENERIC_ERROR, |
| 1049 | "Error duplicating fd: %s", strerror(errno)); |
| 1050 | return -1; |
| 1051 | } |
| 1052 | |
| 1053 | /* add the duplicate fd, and optionally the opaque string, to the fd set */ |
| 1054 | monitor_fdset_add_fd(dupfd, true, fdset_id, fd_opaque ? true : false, |
| 1055 | fd_opaque, NULL); |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | static int cleanup_add_fd(QemuOpts *opts, void *opaque) |
| 1061 | { |
| 1062 | int fd; |
| 1063 | |
| 1064 | fd = qemu_opt_get_number(opts, "fd", -1); |
| 1065 | close(fd); |
| 1066 | |
| 1067 | return 0; |
| 1068 | } |
| 1069 | #endif |
| 1070 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 1071 | /***********************************************************/ |
| 1072 | /* QEMU Block devices */ |
| 1073 | |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 1074 | #define HD_OPTS "media=disk" |
| 1075 | #define CDROM_OPTS "media=cdrom" |
| 1076 | #define FD_OPTS "" |
| 1077 | #define PFLASH_OPTS "" |
| 1078 | #define MTD_OPTS "" |
| 1079 | #define SD_OPTS "" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1080 | |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1081 | static int drive_init_func(QemuOpts *opts, void *opaque) |
| 1082 | { |
Christian Borntraeger | 2d0d283 | 2012-11-20 15:30:34 +0100 | [diff] [blame] | 1083 | BlockInterfaceType *block_default_type = opaque; |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1084 | |
Markus Armbruster | 60e19e0 | 2014-06-06 14:50:58 +0200 | [diff] [blame] | 1085 | return drive_new(opts, *block_default_type) == NULL; |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) |
| 1089 | { |
| 1090 | if (NULL == qemu_opt_get(opts, "snapshot")) { |
| 1091 | qemu_opt_set(opts, "snapshot", "on"); |
| 1092 | } |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
Christian Borntraeger | 3c42ea6 | 2012-11-22 21:02:55 +0100 | [diff] [blame] | 1096 | static void default_drive(int enable, int snapshot, BlockInterfaceType type, |
| 1097 | int index, const char *optstr) |
Markus Armbruster | 4e5d9b5 | 2011-01-28 11:21:45 +0100 | [diff] [blame] | 1098 | { |
| 1099 | QemuOpts *opts; |
| 1100 | |
Markus Armbruster | 4e5d9b5 | 2011-01-28 11:21:45 +0100 | [diff] [blame] | 1101 | if (!enable || drive_get_by_index(type, index)) { |
| 1102 | return; |
| 1103 | } |
| 1104 | |
| 1105 | opts = drive_add(type, index, NULL, optstr); |
| 1106 | if (snapshot) { |
| 1107 | drive_enable_snapshot(opts, NULL); |
| 1108 | } |
Markus Armbruster | 60e19e0 | 2014-06-06 14:50:58 +0200 | [diff] [blame] | 1109 | if (!drive_new(opts, type)) { |
Markus Armbruster | 4e5d9b5 | 2011-01-28 11:21:45 +0100 | [diff] [blame] | 1110 | exit(1); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1114 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
| 1115 | { |
| 1116 | boot_set_handler = func; |
| 1117 | boot_set_opaque = opaque; |
| 1118 | } |
| 1119 | |
Markus Armbruster | 083b79c | 2013-06-14 13:15:04 +0200 | [diff] [blame] | 1120 | int qemu_boot_set(const char *boot_order) |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1121 | { |
| 1122 | if (!boot_set_handler) { |
| 1123 | return -EINVAL; |
| 1124 | } |
Markus Armbruster | 083b79c | 2013-06-14 13:15:04 +0200 | [diff] [blame] | 1125 | return boot_set_handler(boot_set_opaque, boot_order); |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1126 | } |
| 1127 | |
Markus Armbruster | 6ef4716 | 2013-06-14 13:15:01 +0200 | [diff] [blame] | 1128 | static void validate_bootdevices(const char *devices) |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1129 | { |
| 1130 | /* We just do some generic consistency checks */ |
| 1131 | const char *p; |
| 1132 | int bitmap = 0; |
| 1133 | |
| 1134 | for (p = devices; *p != '\0'; p++) { |
| 1135 | /* Allowed boot devices are: |
| 1136 | * a-b: floppy disk drives |
| 1137 | * c-f: IDE disk drives |
Dong Xu Wang | 07f3507 | 2011-11-22 18:06:26 +0800 | [diff] [blame] | 1138 | * g-m: machine implementation dependent drives |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1139 | * n-p: network devices |
| 1140 | * It's up to each machine implementation to check if the given boot |
| 1141 | * devices match the actual hardware implementation and firmware |
| 1142 | * features. |
| 1143 | */ |
| 1144 | if (*p < 'a' || *p > 'p') { |
| 1145 | fprintf(stderr, "Invalid boot device '%c'\n", *p); |
| 1146 | exit(1); |
| 1147 | } |
| 1148 | if (bitmap & (1 << (*p - 'a'))) { |
| 1149 | fprintf(stderr, "Boot device '%c' was given twice\n", *p); |
| 1150 | exit(1); |
| 1151 | } |
| 1152 | bitmap |= 1 << (*p - 'a'); |
| 1153 | } |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1154 | } |
| 1155 | |
Markus Armbruster | 083b79c | 2013-06-14 13:15:04 +0200 | [diff] [blame] | 1156 | static void restore_boot_order(void *opaque) |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1157 | { |
Markus Armbruster | 083b79c | 2013-06-14 13:15:04 +0200 | [diff] [blame] | 1158 | char *normal_boot_order = opaque; |
Alex Williamson | 37905d6 | 2010-04-30 15:21:11 -0600 | [diff] [blame] | 1159 | static int first = 1; |
| 1160 | |
| 1161 | /* Restore boot order and remove ourselves after the first boot */ |
| 1162 | if (first) { |
| 1163 | first = 0; |
| 1164 | return; |
| 1165 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1166 | |
Markus Armbruster | 083b79c | 2013-06-14 13:15:04 +0200 | [diff] [blame] | 1167 | qemu_boot_set(normal_boot_order); |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1168 | |
Markus Armbruster | 083b79c | 2013-06-14 13:15:04 +0200 | [diff] [blame] | 1169 | qemu_unregister_reset(restore_boot_order, normal_boot_order); |
| 1170 | g_free(normal_boot_order); |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1171 | } |
| 1172 | |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 1173 | void add_boot_device_path(int32_t bootindex, DeviceState *dev, |
| 1174 | const char *suffix) |
| 1175 | { |
| 1176 | FWBootEntry *node, *i; |
| 1177 | |
| 1178 | if (bootindex < 0) { |
| 1179 | return; |
| 1180 | } |
| 1181 | |
| 1182 | assert(dev != NULL || suffix != NULL); |
| 1183 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1184 | node = g_malloc0(sizeof(FWBootEntry)); |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 1185 | node->bootindex = bootindex; |
Dong Xu Wang | 7f303ad | 2013-05-09 15:53:49 +0800 | [diff] [blame] | 1186 | node->suffix = g_strdup(suffix); |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 1187 | node->dev = dev; |
| 1188 | |
| 1189 | QTAILQ_FOREACH(i, &fw_boot_order, link) { |
| 1190 | if (i->bootindex == bootindex) { |
| 1191 | fprintf(stderr, "Two devices with same boot index %d\n", bootindex); |
| 1192 | exit(1); |
| 1193 | } else if (i->bootindex < bootindex) { |
| 1194 | continue; |
| 1195 | } |
| 1196 | QTAILQ_INSERT_BEFORE(i, node, link); |
| 1197 | return; |
| 1198 | } |
| 1199 | QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); |
| 1200 | } |
| 1201 | |
Dominik Dingel | 7dc5af5 | 2013-04-26 02:12:49 +0000 | [diff] [blame] | 1202 | DeviceState *get_boot_device(uint32_t position) |
| 1203 | { |
| 1204 | uint32_t counter = 0; |
| 1205 | FWBootEntry *i = NULL; |
| 1206 | DeviceState *res = NULL; |
| 1207 | |
| 1208 | if (!QTAILQ_EMPTY(&fw_boot_order)) { |
| 1209 | QTAILQ_FOREACH(i, &fw_boot_order, link) { |
| 1210 | if (counter == position) { |
| 1211 | res = i->dev; |
| 1212 | break; |
| 1213 | } |
| 1214 | counter++; |
| 1215 | } |
| 1216 | } |
| 1217 | return res; |
| 1218 | } |
| 1219 | |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1220 | /* |
| 1221 | * This function returns null terminated string that consist of new line |
Brad Hards | 71785ab | 2011-04-23 21:50:06 +1000 | [diff] [blame] | 1222 | * separated device paths. |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1223 | * |
| 1224 | * memory pointed by "size" is assigned total length of the array in bytes |
| 1225 | * |
| 1226 | */ |
Alexey Kardashevskiy | 30e32af | 2014-03-17 13:40:22 +1100 | [diff] [blame] | 1227 | char *get_boot_devices_list(size_t *size, bool ignore_suffixes) |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1228 | { |
| 1229 | FWBootEntry *i; |
Markus Armbruster | 0e7a759 | 2013-01-16 14:50:29 +0100 | [diff] [blame] | 1230 | size_t total = 0; |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1231 | char *list = NULL; |
| 1232 | |
| 1233 | QTAILQ_FOREACH(i, &fw_boot_order, link) { |
| 1234 | char *devpath = NULL, *bootpath; |
Markus Armbruster | 0e7a759 | 2013-01-16 14:50:29 +0100 | [diff] [blame] | 1235 | size_t len; |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1236 | |
| 1237 | if (i->dev) { |
| 1238 | devpath = qdev_get_fw_dev_path(i->dev); |
| 1239 | assert(devpath); |
| 1240 | } |
| 1241 | |
Alexey Kardashevskiy | 30e32af | 2014-03-17 13:40:22 +1100 | [diff] [blame] | 1242 | if (i->suffix && !ignore_suffixes && devpath) { |
Blue Swirl | 4fd37a9 | 2010-12-19 14:05:43 +0000 | [diff] [blame] | 1243 | size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1; |
| 1244 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1245 | bootpath = g_malloc(bootpathlen); |
Blue Swirl | 4fd37a9 | 2010-12-19 14:05:43 +0000 | [diff] [blame] | 1246 | snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1247 | g_free(devpath); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1248 | } else if (devpath) { |
| 1249 | bootpath = devpath; |
Alexey Kardashevskiy | 30e32af | 2014-03-17 13:40:22 +1100 | [diff] [blame] | 1250 | } else if (!ignore_suffixes) { |
Markus Armbruster | 1bf6ccd | 2011-11-08 10:58:00 +0100 | [diff] [blame] | 1251 | assert(i->suffix); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1252 | bootpath = g_strdup(i->suffix); |
Alexey Kardashevskiy | 30e32af | 2014-03-17 13:40:22 +1100 | [diff] [blame] | 1253 | } else { |
| 1254 | bootpath = g_strdup(""); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | if (total) { |
| 1258 | list[total-1] = '\n'; |
| 1259 | } |
| 1260 | len = strlen(bootpath) + 1; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1261 | list = g_realloc(list, total + len); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1262 | memcpy(&list[total], bootpath, len); |
| 1263 | total += len; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1264 | g_free(bootpath); |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | *size = total; |
| 1268 | |
Amos Kong | c8a6ae8 | 2013-03-19 14:23:27 +0800 | [diff] [blame] | 1269 | if (boot_strict && *size > 0) { |
| 1270 | list[total-1] = '\n'; |
Amos Kong | 4690579 | 2013-03-20 18:16:34 +0800 | [diff] [blame] | 1271 | list = g_realloc(list, total + 5); |
| 1272 | memcpy(&list[total], "HALT", 5); |
| 1273 | *size = total + 5; |
Amos Kong | c8a6ae8 | 2013-03-19 14:23:27 +0800 | [diff] [blame] | 1274 | } |
Gleb Natapov | 962630f | 2010-12-08 13:35:09 +0200 | [diff] [blame] | 1275 | return list; |
| 1276 | } |
| 1277 | |
Eduardo Habkost | 845e5bf | 2013-02-04 16:27:51 -0200 | [diff] [blame] | 1278 | static void numa_node_parse_cpus(int nodenr, const char *cpus) |
| 1279 | { |
| 1280 | char *endptr; |
| 1281 | unsigned long long value, endvalue; |
| 1282 | |
Eduardo Habkost | c881e20 | 2013-02-04 16:27:52 -0200 | [diff] [blame] | 1283 | /* Empty CPU range strings will be considered valid, they will simply |
| 1284 | * not set any bit in the CPU bitmap. |
| 1285 | */ |
| 1286 | if (!*cpus) { |
| 1287 | return; |
Eduardo Habkost | 845e5bf | 2013-02-04 16:27:51 -0200 | [diff] [blame] | 1288 | } |
| 1289 | |
Eduardo Habkost | c881e20 | 2013-02-04 16:27:52 -0200 | [diff] [blame] | 1290 | if (parse_uint(cpus, &value, &endptr, 10) < 0) { |
| 1291 | goto error; |
| 1292 | } |
| 1293 | if (*endptr == '-') { |
| 1294 | if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) { |
| 1295 | goto error; |
| 1296 | } |
| 1297 | } else if (*endptr == '\0') { |
| 1298 | endvalue = value; |
| 1299 | } else { |
| 1300 | goto error; |
| 1301 | } |
| 1302 | |
| 1303 | if (endvalue >= MAX_CPUMASK_BITS) { |
Eduardo Habkost | 845e5bf | 2013-02-04 16:27:51 -0200 | [diff] [blame] | 1304 | endvalue = MAX_CPUMASK_BITS - 1; |
| 1305 | fprintf(stderr, |
Eduardo Habkost | c881e20 | 2013-02-04 16:27:52 -0200 | [diff] [blame] | 1306 | "qemu: NUMA: A max of %d VCPUs are supported\n", |
Eduardo Habkost | 845e5bf | 2013-02-04 16:27:51 -0200 | [diff] [blame] | 1307 | MAX_CPUMASK_BITS); |
| 1308 | } |
| 1309 | |
Eduardo Habkost | c881e20 | 2013-02-04 16:27:52 -0200 | [diff] [blame] | 1310 | if (endvalue < value) { |
| 1311 | goto error; |
| 1312 | } |
| 1313 | |
Eduardo Habkost | 845e5bf | 2013-02-04 16:27:51 -0200 | [diff] [blame] | 1314 | bitmap_set(node_cpumask[nodenr], value, endvalue-value+1); |
Eduardo Habkost | c881e20 | 2013-02-04 16:27:52 -0200 | [diff] [blame] | 1315 | return; |
| 1316 | |
| 1317 | error: |
| 1318 | fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus); |
| 1319 | exit(1); |
Eduardo Habkost | 845e5bf | 2013-02-04 16:27:51 -0200 | [diff] [blame] | 1320 | } |
| 1321 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1322 | static void numa_add(const char *optarg) |
| 1323 | { |
| 1324 | char option[128]; |
| 1325 | char *endptr; |
Eduardo Habkost | e4ce85b | 2013-02-04 16:27:49 -0200 | [diff] [blame] | 1326 | unsigned long long nodenr; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1327 | |
Eduardo Habkost | 8f302cb | 2013-02-04 16:27:46 -0200 | [diff] [blame] | 1328 | optarg = get_opt_name(option, 128, optarg, ','); |
| 1329 | if (*optarg == ',') { |
| 1330 | optarg++; |
| 1331 | } |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1332 | if (!strcmp(option, "node")) { |
Eduardo Habkost | ca4c6d3 | 2013-02-04 16:27:48 -0200 | [diff] [blame] | 1333 | |
| 1334 | if (nb_numa_nodes >= MAX_NODES) { |
| 1335 | fprintf(stderr, "qemu: too many NUMA nodes\n"); |
| 1336 | exit(1); |
| 1337 | } |
| 1338 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1339 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
| 1340 | nodenr = nb_numa_nodes; |
| 1341 | } else { |
Eduardo Habkost | 5f13996 | 2013-02-04 16:27:50 -0200 | [diff] [blame] | 1342 | if (parse_uint_full(option, &nodenr, 10) < 0) { |
| 1343 | fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option); |
| 1344 | exit(1); |
| 1345 | } |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Eduardo Habkost | e4ce85b | 2013-02-04 16:27:49 -0200 | [diff] [blame] | 1348 | if (nodenr >= MAX_NODES) { |
| 1349 | fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr); |
| 1350 | exit(1); |
| 1351 | } |
| 1352 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1353 | if (get_param_value(option, 128, "mem", optarg) == 0) { |
| 1354 | node_mem[nodenr] = 0; |
| 1355 | } else { |
Jes Sorensen | 70b4f4b | 2011-01-05 11:41:02 +0100 | [diff] [blame] | 1356 | int64_t sval; |
Markus Armbruster | c03417b | 2011-11-22 09:46:02 +0100 | [diff] [blame] | 1357 | sval = strtosz(option, &endptr); |
| 1358 | if (sval < 0 || *endptr) { |
Jes Sorensen | 9f9b17a | 2010-10-21 17:15:46 +0200 | [diff] [blame] | 1359 | fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg); |
| 1360 | exit(1); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1361 | } |
Jes Sorensen | 9f9b17a | 2010-10-21 17:15:46 +0200 | [diff] [blame] | 1362 | node_mem[nodenr] = sval; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1363 | } |
Chegu Vinod | ee785fe | 2012-07-16 21:31:30 -0700 | [diff] [blame] | 1364 | if (get_param_value(option, 128, "cpus", optarg) != 0) { |
Eduardo Habkost | 845e5bf | 2013-02-04 16:27:51 -0200 | [diff] [blame] | 1365 | numa_node_parse_cpus(nodenr, option); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1366 | } |
| 1367 | nb_numa_nodes++; |
Eduardo Habkost | 12e53a9 | 2013-02-04 16:27:47 -0200 | [diff] [blame] | 1368 | } else { |
| 1369 | fprintf(stderr, "Invalid -numa option: %s\n", option); |
| 1370 | exit(1); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1371 | } |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1374 | static QemuOptsList qemu_smp_opts = { |
| 1375 | .name = "smp-opts", |
| 1376 | .implied_opt_name = "cpus", |
| 1377 | .merge_lists = true, |
| 1378 | .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head), |
| 1379 | .desc = { |
| 1380 | { |
| 1381 | .name = "cpus", |
| 1382 | .type = QEMU_OPT_NUMBER, |
| 1383 | }, { |
| 1384 | .name = "sockets", |
| 1385 | .type = QEMU_OPT_NUMBER, |
| 1386 | }, { |
| 1387 | .name = "cores", |
| 1388 | .type = QEMU_OPT_NUMBER, |
| 1389 | }, { |
| 1390 | .name = "threads", |
| 1391 | .type = QEMU_OPT_NUMBER, |
| 1392 | }, { |
| 1393 | .name = "maxcpus", |
| 1394 | .type = QEMU_OPT_NUMBER, |
| 1395 | }, |
| 1396 | { /*End of list */ } |
| 1397 | }, |
| 1398 | }; |
| 1399 | |
| 1400 | static void smp_parse(QemuOpts *opts) |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1401 | { |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1402 | if (opts) { |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1403 | |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1404 | unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); |
| 1405 | unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); |
| 1406 | unsigned cores = qemu_opt_get_number(opts, "cores", 0); |
| 1407 | unsigned threads = qemu_opt_get_number(opts, "threads", 0); |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1408 | |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1409 | /* compute missing values, prefer sockets over cores over threads */ |
| 1410 | if (cpus == 0 || sockets == 0) { |
| 1411 | sockets = sockets > 0 ? sockets : 1; |
| 1412 | cores = cores > 0 ? cores : 1; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1413 | threads = threads > 0 ? threads : 1; |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1414 | if (cpus == 0) { |
| 1415 | cpus = cores * threads * sockets; |
| 1416 | } |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1417 | } else { |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1418 | if (cores == 0) { |
| 1419 | threads = threads > 0 ? threads : 1; |
| 1420 | cores = cpus / (sockets * threads); |
| 1421 | } else { |
| 1422 | threads = cpus / (cores * sockets); |
| 1423 | } |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1424 | } |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1425 | |
| 1426 | max_cpus = qemu_opt_get_number(opts, "maxcpus", 0); |
| 1427 | |
| 1428 | smp_cpus = cpus; |
| 1429 | smp_cores = cores > 0 ? cores : 1; |
| 1430 | smp_threads = threads > 0 ? threads : 1; |
| 1431 | |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1432 | } |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1433 | |
| 1434 | if (max_cpus == 0) { |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1435 | max_cpus = smp_cpus; |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1436 | } |
| 1437 | |
Eduardo Habkost | af67ee9 | 2014-03-18 16:29:24 -0300 | [diff] [blame] | 1438 | if (max_cpus > MAX_CPUMASK_BITS) { |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 1439 | fprintf(stderr, "Unsupported number of maxcpus\n"); |
| 1440 | exit(1); |
| 1441 | } |
| 1442 | if (max_cpus < smp_cpus) { |
| 1443 | fprintf(stderr, "maxcpus must be equal to or greater than smp\n"); |
| 1444 | exit(1); |
| 1445 | } |
| 1446 | |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 1447 | } |
| 1448 | |
Satoru Moriya | 888a6bc | 2013-04-19 16:42:06 +0200 | [diff] [blame] | 1449 | static void configure_realtime(QemuOpts *opts) |
| 1450 | { |
| 1451 | bool enable_mlock; |
| 1452 | |
| 1453 | enable_mlock = qemu_opt_get_bool(opts, "mlock", true); |
| 1454 | |
| 1455 | if (enable_mlock) { |
| 1456 | if (os_mlock() < 0) { |
| 1457 | fprintf(stderr, "qemu: locking memory failed\n"); |
| 1458 | exit(1); |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | |
Seiji Aguchi | 5e2ac51 | 2013-07-03 23:02:46 -0400 | [diff] [blame] | 1463 | |
| 1464 | static void configure_msg(QemuOpts *opts) |
| 1465 | { |
| 1466 | enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true); |
| 1467 | } |
| 1468 | |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1469 | /***********************************************************/ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1470 | /* USB devices */ |
| 1471 | |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 1472 | static int usb_device_add(const char *devname) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1473 | { |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1474 | USBDevice *dev = NULL; |
Miroslav Rezanina | 615fe4d | 2013-09-03 11:23:09 +0200 | [diff] [blame] | 1475 | #ifndef CONFIG_LINUX |
| 1476 | const char *p; |
| 1477 | #endif |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1478 | |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 1479 | if (!usb_enabled(false)) { |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1480 | return -1; |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 1481 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1482 | |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 1483 | /* drivers with .usbdevice_name entry in USBDeviceInfo */ |
| 1484 | dev = usbdevice_create(devname); |
| 1485 | if (dev) |
| 1486 | goto done; |
| 1487 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1488 | /* the other ones */ |
Gerd Hoffmann | e447fc6 | 2011-06-01 14:41:59 +0200 | [diff] [blame] | 1489 | #ifndef CONFIG_LINUX |
| 1490 | /* only the linux version is qdev-ified, usb-bsd still needs this */ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1491 | if (strstart(devname, "host:", &p)) { |
Jan Kiszka | 3741715 | 2012-02-27 15:18:47 +0100 | [diff] [blame] | 1492 | dev = usb_host_device_open(usb_bus_find(-1), p); |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1493 | } |
Miroslav Rezanina | 615fe4d | 2013-09-03 11:23:09 +0200 | [diff] [blame] | 1494 | #endif |
pbrook | 0d92ed3 | 2006-05-21 16:30:15 +0000 | [diff] [blame] | 1495 | if (!dev) |
| 1496 | return -1; |
| 1497 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1498 | done: |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1499 | return 0; |
| 1500 | } |
| 1501 | |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 1502 | static int usb_device_del(const char *devname) |
| 1503 | { |
| 1504 | int bus_num, addr; |
| 1505 | const char *p; |
| 1506 | |
Gerd Hoffmann | 1a3973b | 2012-11-30 13:02:47 +0100 | [diff] [blame] | 1507 | if (strstart(devname, "host:", &p)) { |
| 1508 | return -1; |
| 1509 | } |
aliguori | 5d0c575 | 2008-09-14 01:07:41 +0000 | [diff] [blame] | 1510 | |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 1511 | if (!usb_enabled(false)) { |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 1512 | return -1; |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 1513 | } |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 1514 | |
| 1515 | p = strchr(devname, '.'); |
| 1516 | if (!p) |
| 1517 | return -1; |
| 1518 | bus_num = strtoul(devname, NULL, 0); |
| 1519 | addr = strtoul(p + 1, NULL, 0); |
| 1520 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 1521 | return usb_device_delete_addr(bus_num, addr); |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 1522 | } |
| 1523 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1524 | static int usb_parse(const char *cmdline) |
| 1525 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1526 | int r; |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 1527 | r = usb_device_add(cmdline); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1528 | if (r < 0) { |
| 1529 | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline); |
| 1530 | } |
| 1531 | return r; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1532 | } |
| 1533 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1534 | void do_usb_add(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1535 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1536 | const char *devname = qdict_get_str(qdict, "devname"); |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 1537 | if (usb_device_add(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 1538 | error_report("could not add USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1539 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 1542 | void do_usb_del(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1543 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1544 | const char *devname = qdict_get_str(qdict, "devname"); |
| 1545 | if (usb_device_del(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 1546 | error_report("could not delete USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 1547 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 1550 | /***********************************************************/ |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1551 | /* PCMCIA/Cardbus */ |
| 1552 | |
| 1553 | static struct pcmcia_socket_entry_s { |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 1554 | PCMCIASocket *socket; |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1555 | struct pcmcia_socket_entry_s *next; |
| 1556 | } *pcmcia_sockets = 0; |
| 1557 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 1558 | void pcmcia_socket_register(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1559 | { |
| 1560 | struct pcmcia_socket_entry_s *entry; |
| 1561 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1562 | entry = g_malloc(sizeof(struct pcmcia_socket_entry_s)); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1563 | entry->socket = socket; |
| 1564 | entry->next = pcmcia_sockets; |
| 1565 | pcmcia_sockets = entry; |
| 1566 | } |
| 1567 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 1568 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1569 | { |
| 1570 | struct pcmcia_socket_entry_s *entry, **ptr; |
| 1571 | |
| 1572 | ptr = &pcmcia_sockets; |
| 1573 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) |
| 1574 | if (entry->socket == socket) { |
| 1575 | *ptr = entry->next; |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1576 | g_free(entry); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1577 | } |
| 1578 | } |
| 1579 | |
Wenchao Xia | 84f2d0e | 2013-01-14 14:06:25 +0800 | [diff] [blame] | 1580 | void pcmcia_info(Monitor *mon, const QDict *qdict) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1581 | { |
| 1582 | struct pcmcia_socket_entry_s *iter; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1583 | |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1584 | if (!pcmcia_sockets) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1585 | monitor_printf(mon, "No PCMCIA sockets\n"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1586 | |
| 1587 | for (iter = pcmcia_sockets; iter; iter = iter->next) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 1588 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
| 1589 | iter->socket->attached ? iter->socket->card_string : |
| 1590 | "Empty"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | /***********************************************************/ |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1594 | /* machine registration */ |
| 1595 | |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1596 | MachineState *current_machine; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1597 | |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1598 | static void machine_class_init(ObjectClass *oc, void *data) |
| 1599 | { |
| 1600 | MachineClass *mc = MACHINE_CLASS(oc); |
Marcel Apfelbaum | 00b4fbe | 2014-04-09 20:34:50 +0300 | [diff] [blame] | 1601 | QEMUMachine *qm = data; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1602 | |
Marcel Apfelbaum | 00b4fbe | 2014-04-09 20:34:50 +0300 | [diff] [blame] | 1603 | mc->name = qm->name; |
| 1604 | mc->alias = qm->alias; |
| 1605 | mc->desc = qm->desc; |
| 1606 | mc->init = qm->init; |
| 1607 | mc->reset = qm->reset; |
| 1608 | mc->hot_add_cpu = qm->hot_add_cpu; |
| 1609 | mc->kvm_type = qm->kvm_type; |
| 1610 | mc->block_default_type = qm->block_default_type; |
| 1611 | mc->max_cpus = qm->max_cpus; |
| 1612 | mc->no_serial = qm->no_serial; |
| 1613 | mc->no_parallel = qm->no_parallel; |
| 1614 | mc->use_virtcon = qm->use_virtcon; |
| 1615 | mc->use_sclp = qm->use_sclp; |
| 1616 | mc->no_floppy = qm->no_floppy; |
| 1617 | mc->no_cdrom = qm->no_cdrom; |
| 1618 | mc->no_sdcard = qm->no_sdcard; |
| 1619 | mc->is_default = qm->is_default; |
| 1620 | mc->default_machine_opts = qm->default_machine_opts; |
| 1621 | mc->default_boot_order = qm->default_boot_order; |
| 1622 | mc->compat_props = qm->compat_props; |
| 1623 | mc->hw_version = qm->hw_version; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1624 | } |
| 1625 | |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1626 | int qemu_register_machine(QEMUMachine *m) |
| 1627 | { |
Christian Borntraeger | f5946db | 2014-03-19 12:24:27 +0100 | [diff] [blame] | 1628 | char *name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL); |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1629 | TypeInfo ti = { |
Christian Borntraeger | f5946db | 2014-03-19 12:24:27 +0100 | [diff] [blame] | 1630 | .name = name, |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1631 | .parent = TYPE_MACHINE, |
| 1632 | .class_init = machine_class_init, |
| 1633 | .class_data = (void *)m, |
| 1634 | }; |
| 1635 | |
| 1636 | type_register(&ti); |
Christian Borntraeger | f5946db | 2014-03-19 12:24:27 +0100 | [diff] [blame] | 1637 | g_free(name); |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1638 | |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1639 | return 0; |
| 1640 | } |
| 1641 | |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1642 | static MachineClass *find_machine(const char *name) |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1643 | { |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1644 | GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1645 | MachineClass *mc = NULL; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1646 | |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1647 | for (el = machines; el; el = el->next) { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1648 | MachineClass *temp = el->data; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1649 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1650 | if (!strcmp(temp->name, name)) { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1651 | mc = temp; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1652 | break; |
| 1653 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1654 | if (temp->alias && |
| 1655 | !strcmp(temp->alias, name)) { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1656 | mc = temp; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1657 | break; |
| 1658 | } |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1659 | } |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1660 | |
| 1661 | g_slist_free(machines); |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1662 | return mc; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1665 | MachineClass *find_default_machine(void) |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1666 | { |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1667 | GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1668 | MachineClass *mc = NULL; |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1669 | |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1670 | for (el = machines; el; el = el->next) { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1671 | MachineClass *temp = el->data; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1672 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1673 | if (temp->is_default) { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1674 | mc = temp; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1675 | break; |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1676 | } |
| 1677 | } |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1678 | |
| 1679 | g_slist_free(machines); |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1680 | return mc; |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1681 | } |
| 1682 | |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1683 | MachineInfoList *qmp_query_machines(Error **errp) |
| 1684 | { |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1685 | GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1686 | MachineInfoList *mach_list = NULL; |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1687 | |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1688 | for (el = machines; el; el = el->next) { |
| 1689 | MachineClass *mc = el->data; |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1690 | MachineInfoList *entry; |
| 1691 | MachineInfo *info; |
| 1692 | |
| 1693 | info = g_malloc0(sizeof(*info)); |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1694 | if (mc->is_default) { |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1695 | info->has_is_default = true; |
| 1696 | info->is_default = true; |
| 1697 | } |
| 1698 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1699 | if (mc->alias) { |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1700 | info->has_alias = true; |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1701 | info->alias = g_strdup(mc->alias); |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1702 | } |
| 1703 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1704 | info->name = g_strdup(mc->name); |
| 1705 | info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus; |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1706 | |
| 1707 | entry = g_malloc0(sizeof(*entry)); |
| 1708 | entry->value = info; |
| 1709 | entry->next = mach_list; |
| 1710 | mach_list = entry; |
| 1711 | } |
| 1712 | |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 1713 | g_slist_free(machines); |
Anthony Liguori | 01d3c80 | 2012-08-10 11:04:11 -0500 | [diff] [blame] | 1714 | return mach_list; |
| 1715 | } |
| 1716 | |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1717 | /***********************************************************/ |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1718 | /* main execution loop */ |
| 1719 | |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1720 | struct vm_change_state_entry { |
| 1721 | VMChangeStateHandler *cb; |
| 1722 | void *opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1723 | QLIST_ENTRY (vm_change_state_entry) entries; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1724 | }; |
| 1725 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1726 | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1727 | |
| 1728 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
| 1729 | void *opaque) |
| 1730 | { |
| 1731 | VMChangeStateEntry *e; |
| 1732 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1733 | e = g_malloc0(sizeof (*e)); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1734 | |
| 1735 | e->cb = cb; |
| 1736 | e->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1737 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1738 | return e; |
| 1739 | } |
| 1740 | |
| 1741 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) |
| 1742 | { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1743 | QLIST_REMOVE (e, entries); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1744 | g_free (e); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1747 | void vm_state_notify(int running, RunState state) |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1748 | { |
| 1749 | VMChangeStateEntry *e; |
| 1750 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1751 | trace_vm_state_notify(running, state); |
Stefan Hajnoczi | 94b0b5f | 2010-11-16 12:20:25 +0000 | [diff] [blame] | 1752 | |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1753 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 1754 | e->cb(e->opaque, running, state); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1755 | } |
| 1756 | } |
| 1757 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1758 | void vm_start(void) |
| 1759 | { |
Luiz Capitulino | 1354869 | 2011-07-29 15:36:43 -0300 | [diff] [blame] | 1760 | if (!runstate_is_running()) { |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1761 | cpu_enable_ticks(); |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1762 | runstate_set(RUN_STATE_RUNNING); |
| 1763 | vm_state_notify(1, RUN_STATE_RUNNING); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1764 | resume_all_vcpus(); |
Luiz Capitulino | 6ed2c48 | 2010-04-27 20:35:59 -0300 | [diff] [blame] | 1765 | monitor_protocol_event(QEVENT_RESUME, NULL); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1769 | /* reset/shutdown handler */ |
| 1770 | |
| 1771 | typedef struct QEMUResetEntry { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1772 | QTAILQ_ENTRY(QEMUResetEntry) entry; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1773 | QEMUResetHandler *func; |
| 1774 | void *opaque; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1775 | } QEMUResetEntry; |
| 1776 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1777 | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = |
| 1778 | QTAILQ_HEAD_INITIALIZER(reset_handlers); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1779 | static int reset_requested; |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1780 | static int shutdown_requested, shutdown_signal = -1; |
| 1781 | static pid_t shutdown_pid; |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1782 | static int powerdown_requested; |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 1783 | static int debug_requested; |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1784 | static int suspend_requested; |
Liu, Jinsong | 4bc78a8 | 2013-09-25 16:38:29 +0000 | [diff] [blame] | 1785 | static WakeupReason wakeup_reason; |
Igor Mammedov | a9552c8 | 2012-09-05 23:06:21 +0200 | [diff] [blame] | 1786 | static NotifierList powerdown_notifiers = |
| 1787 | NOTIFIER_LIST_INITIALIZER(powerdown_notifiers); |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1788 | static NotifierList suspend_notifiers = |
| 1789 | NOTIFIER_LIST_INITIALIZER(suspend_notifiers); |
| 1790 | static NotifierList wakeup_notifiers = |
| 1791 | NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); |
Liu, Jinsong | 4bc78a8 | 2013-09-25 16:38:29 +0000 | [diff] [blame] | 1792 | static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE); |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1793 | static RunState vmstop_requested = RUN_STATE_MAX; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1794 | |
Anthony PERARD | 1291eb3 | 2010-07-22 15:52:48 +0100 | [diff] [blame] | 1795 | int qemu_shutdown_requested_get(void) |
| 1796 | { |
| 1797 | return shutdown_requested; |
| 1798 | } |
| 1799 | |
| 1800 | int qemu_reset_requested_get(void) |
| 1801 | { |
| 1802 | return reset_requested; |
| 1803 | } |
| 1804 | |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 1805 | static int qemu_shutdown_requested(void) |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1806 | { |
| 1807 | int r = shutdown_requested; |
| 1808 | shutdown_requested = 0; |
| 1809 | return r; |
| 1810 | } |
| 1811 | |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 1812 | static void qemu_kill_report(void) |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1813 | { |
Michael S. Tsirkin | 35b3071 | 2014-02-04 20:04:21 +0200 | [diff] [blame] | 1814 | if (!qtest_driver() && shutdown_signal != -1) { |
Peter Maydell | f1d3fb0 | 2011-03-30 22:03:38 +0100 | [diff] [blame] | 1815 | fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal); |
| 1816 | if (shutdown_pid == 0) { |
| 1817 | /* This happens for eg ^C at the terminal, so it's worth |
| 1818 | * avoiding printing an odd message in that case. |
| 1819 | */ |
| 1820 | fputc('\n', stderr); |
| 1821 | } else { |
Andreas Färber | 953ffe0 | 2011-06-02 19:58:06 +0200 | [diff] [blame] | 1822 | fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid); |
Peter Maydell | f1d3fb0 | 2011-03-30 22:03:38 +0100 | [diff] [blame] | 1823 | } |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1824 | shutdown_signal = -1; |
| 1825 | } |
| 1826 | } |
| 1827 | |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 1828 | static int qemu_reset_requested(void) |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1829 | { |
| 1830 | int r = reset_requested; |
| 1831 | reset_requested = 0; |
| 1832 | return r; |
| 1833 | } |
| 1834 | |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1835 | static int qemu_suspend_requested(void) |
| 1836 | { |
| 1837 | int r = suspend_requested; |
| 1838 | suspend_requested = 0; |
| 1839 | return r; |
| 1840 | } |
| 1841 | |
Liu, Jinsong | 4bc78a8 | 2013-09-25 16:38:29 +0000 | [diff] [blame] | 1842 | static WakeupReason qemu_wakeup_requested(void) |
Luiz Capitulino | 1405819 | 2012-08-08 17:29:17 -0300 | [diff] [blame] | 1843 | { |
Liu, Jinsong | 4bc78a8 | 2013-09-25 16:38:29 +0000 | [diff] [blame] | 1844 | return wakeup_reason; |
Luiz Capitulino | 1405819 | 2012-08-08 17:29:17 -0300 | [diff] [blame] | 1845 | } |
| 1846 | |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 1847 | static int qemu_powerdown_requested(void) |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1848 | { |
| 1849 | int r = powerdown_requested; |
| 1850 | powerdown_requested = 0; |
| 1851 | return r; |
| 1852 | } |
| 1853 | |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1854 | static int qemu_debug_requested(void) |
| 1855 | { |
| 1856 | int r = debug_requested; |
| 1857 | debug_requested = 0; |
| 1858 | return r; |
| 1859 | } |
| 1860 | |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1861 | /* We use RUN_STATE_MAX but any invalid value will do */ |
Luiz Capitulino | 0d45b70 | 2011-09-30 14:27:11 -0300 | [diff] [blame] | 1862 | static bool qemu_vmstop_requested(RunState *r) |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1863 | { |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1864 | if (vmstop_requested < RUN_STATE_MAX) { |
Luiz Capitulino | 0d45b70 | 2011-09-30 14:27:11 -0300 | [diff] [blame] | 1865 | *r = vmstop_requested; |
Luiz Capitulino | 0461d5a | 2011-09-30 14:45:27 -0300 | [diff] [blame] | 1866 | vmstop_requested = RUN_STATE_MAX; |
Luiz Capitulino | 0d45b70 | 2011-09-30 14:27:11 -0300 | [diff] [blame] | 1867 | return true; |
| 1868 | } |
| 1869 | |
| 1870 | return false; |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 1873 | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1874 | { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1875 | QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry)); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1876 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1877 | re->func = func; |
| 1878 | re->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1879 | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1880 | } |
| 1881 | |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1882 | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1883 | { |
| 1884 | QEMUResetEntry *re; |
| 1885 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1886 | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1887 | if (re->func == func && re->opaque == opaque) { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1888 | QTAILQ_REMOVE(&reset_handlers, re, entry); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 1889 | g_free(re); |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1890 | return; |
| 1891 | } |
| 1892 | } |
| 1893 | } |
| 1894 | |
David Gibson | be52202 | 2012-08-07 16:41:51 +1000 | [diff] [blame] | 1895 | void qemu_devices_reset(void) |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1896 | { |
| 1897 | QEMUResetEntry *re, *nre; |
| 1898 | |
| 1899 | /* reset all devices */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1900 | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1901 | re->func(re->opaque); |
| 1902 | } |
David Gibson | be52202 | 2012-08-07 16:41:51 +1000 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | void qemu_system_reset(bool report) |
| 1906 | { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 1907 | MachineClass *mc; |
| 1908 | |
| 1909 | mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; |
| 1910 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 1911 | if (mc && mc->reset) { |
| 1912 | mc->reset(); |
David Gibson | be52202 | 2012-08-07 16:41:51 +1000 | [diff] [blame] | 1913 | } else { |
| 1914 | qemu_devices_reset(); |
| 1915 | } |
Jan Kiszka | e063eb1 | 2011-06-14 18:29:43 +0200 | [diff] [blame] | 1916 | if (report) { |
| 1917 | monitor_protocol_event(QEVENT_RESET, NULL); |
| 1918 | } |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 1919 | cpu_synchronize_all_post_reset(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | void qemu_system_reset_request(void) |
| 1923 | { |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 1924 | if (no_reboot) { |
| 1925 | shutdown_requested = 1; |
| 1926 | } else { |
| 1927 | reset_requested = 1; |
| 1928 | } |
Jan Kiszka | b4a3d96 | 2011-02-01 22:15:43 +0100 | [diff] [blame] | 1929 | cpu_stop_current(); |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1930 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1933 | static void qemu_system_suspend(void) |
| 1934 | { |
| 1935 | pause_all_vcpus(); |
| 1936 | notifier_list_notify(&suspend_notifiers, NULL); |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 1937 | runstate_set(RUN_STATE_SUSPENDED); |
Gerd Hoffmann | 53370b7 | 2012-02-23 13:45:26 +0100 | [diff] [blame] | 1938 | monitor_protocol_event(QEVENT_SUSPEND, NULL); |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | void qemu_system_suspend_request(void) |
| 1942 | { |
Luiz Capitulino | 9abc62f | 2012-04-27 14:31:12 -0300 | [diff] [blame] | 1943 | if (runstate_check(RUN_STATE_SUSPENDED)) { |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1944 | return; |
| 1945 | } |
| 1946 | suspend_requested = 1; |
| 1947 | cpu_stop_current(); |
| 1948 | qemu_notify_event(); |
| 1949 | } |
| 1950 | |
| 1951 | void qemu_register_suspend_notifier(Notifier *notifier) |
| 1952 | { |
| 1953 | notifier_list_add(&suspend_notifiers, notifier); |
| 1954 | } |
| 1955 | |
| 1956 | void qemu_system_wakeup_request(WakeupReason reason) |
| 1957 | { |
Alexey Kardashevskiy | 4fed942 | 2014-03-07 01:33:36 +0530 | [diff] [blame] | 1958 | trace_system_wakeup_request(reason); |
| 1959 | |
Luiz Capitulino | 9abc62f | 2012-04-27 14:31:12 -0300 | [diff] [blame] | 1960 | if (!runstate_check(RUN_STATE_SUSPENDED)) { |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1961 | return; |
| 1962 | } |
| 1963 | if (!(wakeup_reason_mask & (1 << reason))) { |
| 1964 | return; |
| 1965 | } |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 1966 | runstate_set(RUN_STATE_RUNNING); |
Liu, Jinsong | 4bc78a8 | 2013-09-25 16:38:29 +0000 | [diff] [blame] | 1967 | wakeup_reason = reason; |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1968 | qemu_notify_event(); |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void qemu_system_wakeup_enable(WakeupReason reason, bool enabled) |
| 1972 | { |
| 1973 | if (enabled) { |
| 1974 | wakeup_reason_mask |= (1 << reason); |
| 1975 | } else { |
| 1976 | wakeup_reason_mask &= ~(1 << reason); |
| 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | void qemu_register_wakeup_notifier(Notifier *notifier) |
| 1981 | { |
| 1982 | notifier_list_add(&wakeup_notifiers, notifier); |
| 1983 | } |
| 1984 | |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1985 | void qemu_system_killed(int signal, pid_t pid) |
| 1986 | { |
| 1987 | shutdown_signal = signal; |
| 1988 | shutdown_pid = pid; |
Kevin Wolf | d9389b9 | 2011-09-14 15:38:40 +0200 | [diff] [blame] | 1989 | no_shutdown = 0; |
Gleb Natapov | f64622c | 2011-03-15 13:56:04 +0200 | [diff] [blame] | 1990 | qemu_system_shutdown_request(); |
| 1991 | } |
| 1992 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1993 | void qemu_system_shutdown_request(void) |
| 1994 | { |
| 1995 | shutdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1996 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
Igor Mammedov | 013c2f1 | 2012-09-05 23:06:25 +0200 | [diff] [blame] | 1999 | static void qemu_system_powerdown(void) |
| 2000 | { |
| 2001 | monitor_protocol_event(QEVENT_POWERDOWN, NULL); |
| 2002 | notifier_list_notify(&powerdown_notifiers, NULL); |
| 2003 | } |
| 2004 | |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 2005 | void qemu_system_powerdown_request(void) |
| 2006 | { |
| 2007 | powerdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 2008 | qemu_notify_event(); |
| 2009 | } |
| 2010 | |
Igor Mammedov | a9552c8 | 2012-09-05 23:06:21 +0200 | [diff] [blame] | 2011 | void qemu_register_powerdown_notifier(Notifier *notifier) |
| 2012 | { |
| 2013 | notifier_list_add(&powerdown_notifiers, notifier); |
| 2014 | } |
| 2015 | |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 2016 | void qemu_system_debug_request(void) |
| 2017 | { |
| 2018 | debug_requested = 1; |
Jan Kiszka | 83f338f | 2011-02-07 12:19:17 +0100 | [diff] [blame] | 2019 | qemu_notify_event(); |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 2020 | } |
| 2021 | |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 2022 | void qemu_system_vmstop_request(RunState state) |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 2023 | { |
Luiz Capitulino | 1dfb4dd | 2011-07-29 14:26:33 -0300 | [diff] [blame] | 2024 | vmstop_requested = state; |
Jan Kiszka | 8cf7171 | 2011-02-07 12:19:16 +0100 | [diff] [blame] | 2025 | qemu_notify_event(); |
| 2026 | } |
| 2027 | |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2028 | static bool main_loop_should_exit(void) |
| 2029 | { |
| 2030 | RunState r; |
| 2031 | if (qemu_debug_requested()) { |
| 2032 | vm_stop(RUN_STATE_DEBUG); |
| 2033 | } |
Gerd Hoffmann | 95b363b | 2012-02-23 13:45:19 +0100 | [diff] [blame] | 2034 | if (qemu_suspend_requested()) { |
| 2035 | qemu_system_suspend(); |
| 2036 | } |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2037 | if (qemu_shutdown_requested()) { |
| 2038 | qemu_kill_report(); |
| 2039 | monitor_protocol_event(QEVENT_SHUTDOWN, NULL); |
| 2040 | if (no_shutdown) { |
| 2041 | vm_stop(RUN_STATE_SHUTDOWN); |
| 2042 | } else { |
| 2043 | return true; |
| 2044 | } |
| 2045 | } |
| 2046 | if (qemu_reset_requested()) { |
| 2047 | pause_all_vcpus(); |
| 2048 | cpu_synchronize_all_states(); |
| 2049 | qemu_system_reset(VMRESET_REPORT); |
| 2050 | resume_all_vcpus(); |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 2051 | if (runstate_needs_reset()) { |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2052 | runstate_set(RUN_STATE_PAUSED); |
| 2053 | } |
| 2054 | } |
Luiz Capitulino | 1405819 | 2012-08-08 17:29:17 -0300 | [diff] [blame] | 2055 | if (qemu_wakeup_requested()) { |
| 2056 | pause_all_vcpus(); |
| 2057 | cpu_synchronize_all_states(); |
| 2058 | qemu_system_reset(VMRESET_SILENT); |
Liu, Jinsong | 4bc78a8 | 2013-09-25 16:38:29 +0000 | [diff] [blame] | 2059 | notifier_list_notify(&wakeup_notifiers, &wakeup_reason); |
| 2060 | wakeup_reason = QEMU_WAKEUP_REASON_NONE; |
Luiz Capitulino | 1405819 | 2012-08-08 17:29:17 -0300 | [diff] [blame] | 2061 | resume_all_vcpus(); |
Luiz Capitulino | 17c8660 | 2012-08-09 11:27:30 -0300 | [diff] [blame] | 2062 | monitor_protocol_event(QEVENT_WAKEUP, NULL); |
Luiz Capitulino | 1405819 | 2012-08-08 17:29:17 -0300 | [diff] [blame] | 2063 | } |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2064 | if (qemu_powerdown_requested()) { |
Igor Mammedov | 013c2f1 | 2012-09-05 23:06:25 +0200 | [diff] [blame] | 2065 | qemu_system_powerdown(); |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2066 | } |
| 2067 | if (qemu_vmstop_requested(&r)) { |
| 2068 | vm_stop(r); |
| 2069 | } |
| 2070 | return false; |
| 2071 | } |
| 2072 | |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 2073 | static void main_loop(void) |
| 2074 | { |
Jan Kiszka | c9f711a | 2011-08-22 17:46:02 +0200 | [diff] [blame] | 2075 | bool nonblocking; |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2076 | int last_io = 0; |
Jan Kiszka | 8e1b90e | 2011-02-01 22:15:46 +0100 | [diff] [blame] | 2077 | #ifdef CONFIG_PROFILER |
| 2078 | int64_t ti; |
| 2079 | #endif |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2080 | do { |
Stefano Stabellini | a7d4207 | 2013-06-03 15:38:43 +0000 | [diff] [blame] | 2081 | nonblocking = !kvm_enabled() && !xen_enabled() && last_io > 0; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 2082 | #ifdef CONFIG_PROFILER |
Jan Kiszka | 46481d3 | 2011-02-01 22:15:47 +0100 | [diff] [blame] | 2083 | ti = profile_getclock(); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 2084 | #endif |
Jan Kiszka | c9f711a | 2011-08-22 17:46:02 +0200 | [diff] [blame] | 2085 | last_io = main_loop_wait(nonblocking); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 2086 | #ifdef CONFIG_PROFILER |
Jan Kiszka | 46481d3 | 2011-02-01 22:15:47 +0100 | [diff] [blame] | 2087 | dev_time += profile_getclock() - ti; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 2088 | #endif |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 2089 | } while (!main_loop_should_exit()); |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 2092 | static void version(void) |
| 2093 | { |
Thomas Monjalon | f75ca1a | 2010-04-28 14:42:01 +0200 | [diff] [blame] | 2094 | printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 2097 | static void help(int exitcode) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2098 | { |
Michael Ellerman | a3adb7a | 2011-12-19 17:19:31 +1100 | [diff] [blame] | 2099 | version(); |
| 2100 | printf("usage: %s [options] [disk_image]\n\n" |
| 2101 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n", |
| 2102 | error_get_progname()); |
| 2103 | |
Michael Ellerman | 77bd111 | 2011-12-19 17:19:30 +1100 | [diff] [blame] | 2104 | #define QEMU_OPTIONS_GENERATE_HELP |
| 2105 | #include "qemu-options-wrapper.h" |
Michael Ellerman | a3adb7a | 2011-12-19 17:19:31 +1100 | [diff] [blame] | 2106 | |
| 2107 | printf("\nDuring emulation, the following keys are useful:\n" |
malc | 3f020d7 | 2010-02-08 12:04:56 +0300 | [diff] [blame] | 2108 | "ctrl-alt-f toggle full screen\n" |
| 2109 | "ctrl-alt-n switch to virtual console 'n'\n" |
| 2110 | "ctrl-alt toggle mouse and keyboard grab\n" |
| 2111 | "\n" |
Michael Ellerman | a3adb7a | 2011-12-19 17:19:31 +1100 | [diff] [blame] | 2112 | "When using -nographic, press 'ctrl-a h' to get some help.\n"); |
| 2113 | |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 2114 | exit(exitcode); |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2117 | #define HAS_ARG 0x0001 |
| 2118 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2119 | typedef struct QEMUOption { |
| 2120 | const char *name; |
| 2121 | int flags; |
| 2122 | int index; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2123 | uint32_t arch_mask; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2124 | } QEMUOption; |
| 2125 | |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 2126 | static const QEMUOption qemu_options[] = { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2127 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
Michael Ellerman | 77bd111 | 2011-12-19 17:19:30 +1100 | [diff] [blame] | 2128 | #define QEMU_OPTIONS_GENERATE_OPTIONS |
| 2129 | #include "qemu-options-wrapper.h" |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2130 | { NULL }, |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 2131 | }; |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2132 | |
| 2133 | static bool vga_available(void) |
| 2134 | { |
Aurelien Jarno | 36b7f27 | 2012-09-08 16:01:20 +0200 | [diff] [blame] | 2135 | return object_class_by_name("VGA") || object_class_by_name("isa-vga"); |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | static bool cirrus_vga_available(void) |
| 2139 | { |
Aurelien Jarno | 36b7f27 | 2012-09-08 16:01:20 +0200 | [diff] [blame] | 2140 | return object_class_by_name("cirrus-vga") |
| 2141 | || object_class_by_name("isa-cirrus-vga"); |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | static bool vmware_vga_available(void) |
| 2145 | { |
Aurelien Jarno | 36b7f27 | 2012-09-08 16:01:20 +0200 | [diff] [blame] | 2146 | return object_class_by_name("vmware-svga"); |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Aurelien Jarno | 879049a | 2012-09-08 12:01:06 +0200 | [diff] [blame] | 2149 | static bool qxl_vga_available(void) |
| 2150 | { |
| 2151 | return object_class_by_name("qxl-vga"); |
| 2152 | } |
| 2153 | |
Mark Cave-Ayland | af87bf2 | 2013-10-15 21:03:04 +0100 | [diff] [blame] | 2154 | static bool tcx_vga_available(void) |
| 2155 | { |
| 2156 | return object_class_by_name("SUNW,tcx"); |
| 2157 | } |
| 2158 | |
| 2159 | static bool cg3_vga_available(void) |
| 2160 | { |
| 2161 | return object_class_by_name("cgthree"); |
| 2162 | } |
| 2163 | |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2164 | static void select_vgahw (const char *p) |
| 2165 | { |
| 2166 | const char *opts; |
| 2167 | |
Mark Wu | d44229c | 2014-03-10 22:37:40 +0800 | [diff] [blame] | 2168 | assert(vga_interface_type == VGA_NONE); |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2169 | if (strstart(p, "std", &opts)) { |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2170 | if (vga_available()) { |
| 2171 | vga_interface_type = VGA_STD; |
| 2172 | } else { |
| 2173 | fprintf(stderr, "Error: standard VGA not available\n"); |
| 2174 | exit(0); |
| 2175 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2176 | } else if (strstart(p, "cirrus", &opts)) { |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2177 | if (cirrus_vga_available()) { |
| 2178 | vga_interface_type = VGA_CIRRUS; |
| 2179 | } else { |
| 2180 | fprintf(stderr, "Error: Cirrus VGA not available\n"); |
| 2181 | exit(0); |
| 2182 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2183 | } else if (strstart(p, "vmware", &opts)) { |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 2184 | if (vmware_vga_available()) { |
| 2185 | vga_interface_type = VGA_VMWARE; |
| 2186 | } else { |
| 2187 | fprintf(stderr, "Error: VMWare SVGA not available\n"); |
| 2188 | exit(0); |
| 2189 | } |
aliguori | 94909d9 | 2009-04-22 15:19:53 +0000 | [diff] [blame] | 2190 | } else if (strstart(p, "xenfb", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 2191 | vga_interface_type = VGA_XENFB; |
Gerd Hoffmann | a19cbfb | 2010-04-27 11:50:11 +0200 | [diff] [blame] | 2192 | } else if (strstart(p, "qxl", &opts)) { |
Aurelien Jarno | 879049a | 2012-09-08 12:01:06 +0200 | [diff] [blame] | 2193 | if (qxl_vga_available()) { |
| 2194 | vga_interface_type = VGA_QXL; |
| 2195 | } else { |
| 2196 | fprintf(stderr, "Error: QXL VGA not available\n"); |
| 2197 | exit(0); |
| 2198 | } |
Mark Cave-Ayland | af87bf2 | 2013-10-15 21:03:04 +0100 | [diff] [blame] | 2199 | } else if (strstart(p, "tcx", &opts)) { |
| 2200 | if (tcx_vga_available()) { |
| 2201 | vga_interface_type = VGA_TCX; |
| 2202 | } else { |
| 2203 | fprintf(stderr, "Error: TCX framebuffer not available\n"); |
| 2204 | exit(0); |
| 2205 | } |
| 2206 | } else if (strstart(p, "cg3", &opts)) { |
| 2207 | if (cg3_vga_available()) { |
| 2208 | vga_interface_type = VGA_CG3; |
| 2209 | } else { |
| 2210 | fprintf(stderr, "Error: CG3 framebuffer not available\n"); |
| 2211 | exit(0); |
| 2212 | } |
aliguori | 28b85ed | 2009-04-22 15:19:48 +0000 | [diff] [blame] | 2213 | } else if (!strstart(p, "none", &opts)) { |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2214 | invalid_vga: |
| 2215 | fprintf(stderr, "Unknown vga type: %s\n", p); |
| 2216 | exit(1); |
| 2217 | } |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 2218 | while (*opts) { |
| 2219 | const char *nextopt; |
| 2220 | |
| 2221 | if (strstart(opts, ",retrace=", &nextopt)) { |
| 2222 | opts = nextopt; |
| 2223 | if (strstart(opts, "dumb", &nextopt)) |
| 2224 | vga_retrace_method = VGA_RETRACE_DUMB; |
| 2225 | else if (strstart(opts, "precise", &nextopt)) |
| 2226 | vga_retrace_method = VGA_RETRACE_PRECISE; |
| 2227 | else goto invalid_vga; |
| 2228 | } else goto invalid_vga; |
| 2229 | opts = nextopt; |
| 2230 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2233 | static DisplayType select_display(const char *p) |
| 2234 | { |
| 2235 | const char *opts; |
| 2236 | DisplayType display = DT_DEFAULT; |
| 2237 | |
| 2238 | if (strstart(p, "sdl", &opts)) { |
| 2239 | #ifdef CONFIG_SDL |
| 2240 | display = DT_SDL; |
| 2241 | while (*opts) { |
| 2242 | const char *nextopt; |
| 2243 | |
| 2244 | if (strstart(opts, ",frame=", &nextopt)) { |
| 2245 | opts = nextopt; |
| 2246 | if (strstart(opts, "on", &nextopt)) { |
| 2247 | no_frame = 0; |
| 2248 | } else if (strstart(opts, "off", &nextopt)) { |
| 2249 | no_frame = 1; |
| 2250 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 2251 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2252 | } |
| 2253 | } else if (strstart(opts, ",alt_grab=", &nextopt)) { |
| 2254 | opts = nextopt; |
| 2255 | if (strstart(opts, "on", &nextopt)) { |
| 2256 | alt_grab = 1; |
| 2257 | } else if (strstart(opts, "off", &nextopt)) { |
| 2258 | alt_grab = 0; |
| 2259 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 2260 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2261 | } |
| 2262 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { |
| 2263 | opts = nextopt; |
| 2264 | if (strstart(opts, "on", &nextopt)) { |
| 2265 | ctrl_grab = 1; |
| 2266 | } else if (strstart(opts, "off", &nextopt)) { |
| 2267 | ctrl_grab = 0; |
| 2268 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 2269 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2270 | } |
| 2271 | } else if (strstart(opts, ",window_close=", &nextopt)) { |
| 2272 | opts = nextopt; |
| 2273 | if (strstart(opts, "on", &nextopt)) { |
| 2274 | no_quit = 0; |
| 2275 | } else if (strstart(opts, "off", &nextopt)) { |
| 2276 | no_quit = 1; |
| 2277 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 2278 | goto invalid_sdl_args; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2279 | } |
| 2280 | } else { |
Peter Maydell | 0517553 | 2011-03-23 03:40:57 +0000 | [diff] [blame] | 2281 | invalid_sdl_args: |
| 2282 | fprintf(stderr, "Invalid SDL option string: %s\n", p); |
| 2283 | exit(1); |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2284 | } |
| 2285 | opts = nextopt; |
| 2286 | } |
| 2287 | #else |
| 2288 | fprintf(stderr, "SDL support is disabled\n"); |
| 2289 | exit(1); |
| 2290 | #endif |
Jes Sorensen | 3264ff1 | 2011-03-16 13:33:33 +0100 | [diff] [blame] | 2291 | } else if (strstart(p, "vnc", &opts)) { |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 2292 | #ifdef CONFIG_VNC |
Jes Sorensen | 3264ff1 | 2011-03-16 13:33:33 +0100 | [diff] [blame] | 2293 | display_remote++; |
| 2294 | |
| 2295 | if (*opts) { |
| 2296 | const char *nextopt; |
| 2297 | |
| 2298 | if (strstart(opts, "=", &nextopt)) { |
| 2299 | vnc_display = nextopt; |
| 2300 | } |
| 2301 | } |
| 2302 | if (!vnc_display) { |
| 2303 | fprintf(stderr, "VNC requires a display argument vnc=<display>\n"); |
| 2304 | exit(1); |
| 2305 | } |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 2306 | #else |
| 2307 | fprintf(stderr, "VNC support is disabled\n"); |
| 2308 | exit(1); |
| 2309 | #endif |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2310 | } else if (strstart(p, "curses", &opts)) { |
| 2311 | #ifdef CONFIG_CURSES |
| 2312 | display = DT_CURSES; |
| 2313 | #else |
| 2314 | fprintf(stderr, "Curses support is disabled\n"); |
| 2315 | exit(1); |
| 2316 | #endif |
Anthony Liguori | 1554642 | 2013-02-20 07:43:25 -0600 | [diff] [blame] | 2317 | } else if (strstart(p, "gtk", &opts)) { |
| 2318 | #ifdef CONFIG_GTK |
| 2319 | display = DT_GTK; |
Jan Kiszka | 881249c | 2014-03-12 08:33:50 +0100 | [diff] [blame] | 2320 | while (*opts) { |
| 2321 | const char *nextopt; |
| 2322 | |
| 2323 | if (strstart(opts, ",grab_on_hover=", &nextopt)) { |
| 2324 | opts = nextopt; |
| 2325 | if (strstart(opts, "on", &nextopt)) { |
| 2326 | grab_on_hover = true; |
| 2327 | } else if (strstart(opts, "off", &nextopt)) { |
| 2328 | grab_on_hover = false; |
| 2329 | } else { |
| 2330 | goto invalid_gtk_args; |
| 2331 | } |
| 2332 | } else { |
| 2333 | invalid_gtk_args: |
| 2334 | fprintf(stderr, "Invalid GTK option string: %s\n", p); |
| 2335 | exit(1); |
| 2336 | } |
| 2337 | opts = nextopt; |
| 2338 | } |
Anthony Liguori | 1554642 | 2013-02-20 07:43:25 -0600 | [diff] [blame] | 2339 | #else |
| 2340 | fprintf(stderr, "GTK support is disabled\n"); |
| 2341 | exit(1); |
| 2342 | #endif |
Jes Sorensen | 4171d32 | 2011-03-16 13:33:32 +0100 | [diff] [blame] | 2343 | } else if (strstart(p, "none", &opts)) { |
| 2344 | display = DT_NONE; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2345 | } else { |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 2346 | fprintf(stderr, "Unknown display type: %s\n", p); |
| 2347 | exit(1); |
| 2348 | } |
| 2349 | |
| 2350 | return display; |
| 2351 | } |
| 2352 | |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 2353 | static int balloon_parse(const char *arg) |
| 2354 | { |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 2355 | QemuOpts *opts; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 2356 | |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 2357 | if (strcmp(arg, "none") == 0) { |
| 2358 | return 0; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 2359 | } |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 2360 | |
| 2361 | if (!strncmp(arg, "virtio", 6)) { |
| 2362 | if (arg[6] == ',') { |
| 2363 | /* have params -> parse them */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2364 | opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 2365 | if (!opts) |
| 2366 | return -1; |
| 2367 | } else { |
| 2368 | /* create empty opts */ |
Peter Crosthwaite | 87ea75d | 2014-01-01 18:49:17 -0800 | [diff] [blame] | 2369 | opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
| 2370 | &error_abort); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 2371 | } |
Alexander Graf | 29f82b3 | 2011-03-29 15:29:29 +0200 | [diff] [blame] | 2372 | qemu_opt_set(opts, "driver", "virtio-balloon"); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 2373 | return 0; |
| 2374 | } |
| 2375 | |
| 2376 | return -1; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 2377 | } |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 2378 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2379 | char *qemu_find_file(int type, const char *name) |
| 2380 | { |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 2381 | int i; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2382 | const char *subdir; |
| 2383 | char *buf; |
| 2384 | |
Peter Maydell | 3178320 | 2012-05-25 13:07:01 +0100 | [diff] [blame] | 2385 | /* Try the name as a straight path first */ |
| 2386 | if (access(name, R_OK) == 0) { |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 2387 | trace_load_file(name, name); |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2388 | return g_strdup(name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2389 | } |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 2390 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2391 | switch (type) { |
| 2392 | case QEMU_FILE_TYPE_BIOS: |
| 2393 | subdir = ""; |
| 2394 | break; |
| 2395 | case QEMU_FILE_TYPE_KEYMAP: |
| 2396 | subdir = "keymaps/"; |
| 2397 | break; |
| 2398 | default: |
| 2399 | abort(); |
| 2400 | } |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 2401 | |
| 2402 | for (i = 0; i < data_dir_idx; i++) { |
| 2403 | buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name); |
| 2404 | if (access(buf, R_OK) == 0) { |
| 2405 | trace_load_file(name, buf); |
| 2406 | return buf; |
| 2407 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2408 | g_free(buf); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2409 | } |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 2410 | return NULL; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2411 | } |
| 2412 | |
Markus Armbruster | ff952ba | 2010-01-29 19:48:57 +0100 | [diff] [blame] | 2413 | static int device_help_func(QemuOpts *opts, void *opaque) |
| 2414 | { |
| 2415 | return qdev_device_help(opts); |
| 2416 | } |
| 2417 | |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 2418 | static int device_init_func(QemuOpts *opts, void *opaque) |
| 2419 | { |
| 2420 | DeviceState *dev; |
| 2421 | |
| 2422 | dev = qdev_device_add(opts); |
| 2423 | if (!dev) |
| 2424 | return -1; |
Paolo Bonzini | b09995a | 2013-01-25 14:12:37 +0100 | [diff] [blame] | 2425 | object_unref(OBJECT(dev)); |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 2426 | return 0; |
| 2427 | } |
| 2428 | |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 2429 | static int chardev_init_func(QemuOpts *opts, void *opaque) |
| 2430 | { |
Gerd Hoffmann | bd2d80b | 2012-10-15 09:28:05 +0200 | [diff] [blame] | 2431 | Error *local_err = NULL; |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 2432 | |
Gerd Hoffmann | bd2d80b | 2012-10-15 09:28:05 +0200 | [diff] [blame] | 2433 | qemu_chr_new_from_opts(opts, NULL, &local_err); |
Markus Armbruster | 84d18f0 | 2014-01-30 15:07:28 +0100 | [diff] [blame] | 2434 | if (local_err) { |
Seiji Aguchi | 4a44d85 | 2013-08-05 15:40:44 -0400 | [diff] [blame] | 2435 | error_report("%s", error_get_pretty(local_err)); |
Gerd Hoffmann | bd2d80b | 2012-10-15 09:28:05 +0200 | [diff] [blame] | 2436 | error_free(local_err); |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 2437 | return -1; |
Gerd Hoffmann | bd2d80b | 2012-10-15 09:28:05 +0200 | [diff] [blame] | 2438 | } |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 2439 | return 0; |
| 2440 | } |
| 2441 | |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 2442 | #ifdef CONFIG_VIRTFS |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2443 | static int fsdev_init_func(QemuOpts *opts, void *opaque) |
| 2444 | { |
| 2445 | int ret; |
| 2446 | ret = qemu_fsdev_add(opts); |
| 2447 | |
| 2448 | return ret; |
| 2449 | } |
| 2450 | #endif |
| 2451 | |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 2452 | static int mon_init_func(QemuOpts *opts, void *opaque) |
| 2453 | { |
| 2454 | CharDriverState *chr; |
| 2455 | const char *chardev; |
| 2456 | const char *mode; |
| 2457 | int flags; |
| 2458 | |
| 2459 | mode = qemu_opt_get(opts, "mode"); |
| 2460 | if (mode == NULL) { |
| 2461 | mode = "readline"; |
| 2462 | } |
| 2463 | if (strcmp(mode, "readline") == 0) { |
| 2464 | flags = MONITOR_USE_READLINE; |
| 2465 | } else if (strcmp(mode, "control") == 0) { |
| 2466 | flags = MONITOR_USE_CONTROL; |
| 2467 | } else { |
| 2468 | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); |
| 2469 | exit(1); |
| 2470 | } |
| 2471 | |
Daniel P. Berrange | 39eaab9 | 2010-06-07 15:42:31 +0100 | [diff] [blame] | 2472 | if (qemu_opt_get_bool(opts, "pretty", 0)) |
| 2473 | flags |= MONITOR_USE_PRETTY; |
| 2474 | |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 2475 | if (qemu_opt_get_bool(opts, "default", 0)) |
| 2476 | flags |= MONITOR_IS_DEFAULT; |
| 2477 | |
| 2478 | chardev = qemu_opt_get(opts, "chardev"); |
| 2479 | chr = qemu_chr_find(chardev); |
| 2480 | if (chr == NULL) { |
| 2481 | fprintf(stderr, "chardev \"%s\" not found\n", chardev); |
| 2482 | exit(1); |
| 2483 | } |
| 2484 | |
Hans de Goede | 456d606 | 2013-03-27 20:29:40 +0100 | [diff] [blame] | 2485 | qemu_chr_fe_claim_no_fail(chr); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 2486 | monitor_init(chr, flags); |
| 2487 | return 0; |
| 2488 | } |
| 2489 | |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2490 | static void monitor_parse(const char *optarg, const char *mode) |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 2491 | { |
| 2492 | static int monitor_device_index = 0; |
| 2493 | QemuOpts *opts; |
| 2494 | const char *p; |
| 2495 | char label[32]; |
| 2496 | int def = 0; |
| 2497 | |
| 2498 | if (strstart(optarg, "chardev:", &p)) { |
| 2499 | snprintf(label, sizeof(label), "%s", p); |
| 2500 | } else { |
Jan Kiszka | 140e065 | 2010-04-06 16:55:52 +0200 | [diff] [blame] | 2501 | snprintf(label, sizeof(label), "compat_monitor%d", |
| 2502 | monitor_device_index); |
| 2503 | if (monitor_device_index == 0) { |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 2504 | def = 1; |
| 2505 | } |
| 2506 | opts = qemu_chr_parse_compat(label, optarg); |
| 2507 | if (!opts) { |
| 2508 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2509 | exit(1); |
| 2510 | } |
| 2511 | } |
| 2512 | |
Luiz Capitulino | 8be7e7e | 2012-03-20 15:51:57 -0300 | [diff] [blame] | 2513 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 2514 | if (!opts) { |
| 2515 | fprintf(stderr, "duplicate chardev: %s\n", label); |
| 2516 | exit(1); |
| 2517 | } |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2518 | qemu_opt_set(opts, "mode", mode); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 2519 | qemu_opt_set(opts, "chardev", label); |
| 2520 | if (def) |
| 2521 | qemu_opt_set(opts, "default", "on"); |
| 2522 | monitor_device_index++; |
| 2523 | } |
| 2524 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2525 | struct device_config { |
| 2526 | enum { |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2527 | DEV_USB, /* -usbdevice */ |
| 2528 | DEV_BT, /* -bt */ |
| 2529 | DEV_SERIAL, /* -serial */ |
| 2530 | DEV_PARALLEL, /* -parallel */ |
| 2531 | DEV_VIRTCON, /* -virtioconsole */ |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2532 | DEV_DEBUGCON, /* -debugcon */ |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 2533 | DEV_GDB, /* -gdb, -s */ |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 2534 | DEV_SCLP, /* s390 sclp */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2535 | } type; |
| 2536 | const char *cmdline; |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 2537 | Location loc; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2538 | QTAILQ_ENTRY(device_config) next; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2539 | }; |
Blue Swirl | 4fdcac0 | 2012-10-28 11:04:47 +0000 | [diff] [blame] | 2540 | |
| 2541 | static QTAILQ_HEAD(, device_config) device_configs = |
| 2542 | QTAILQ_HEAD_INITIALIZER(device_configs); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2543 | |
| 2544 | static void add_device_config(int type, const char *cmdline) |
| 2545 | { |
| 2546 | struct device_config *conf; |
| 2547 | |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 2548 | conf = g_malloc0(sizeof(*conf)); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2549 | conf->type = type; |
| 2550 | conf->cmdline = cmdline; |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 2551 | loc_save(&conf->loc); |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2552 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) |
| 2556 | { |
| 2557 | struct device_config *conf; |
| 2558 | int rc; |
| 2559 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 2560 | QTAILQ_FOREACH(conf, &device_configs, next) { |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2561 | if (conf->type != type) |
| 2562 | continue; |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 2563 | loc_push_restore(&conf->loc); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2564 | rc = func(conf->cmdline); |
Markus Armbruster | d9a5954 | 2012-02-07 15:09:12 +0100 | [diff] [blame] | 2565 | loc_pop(&conf->loc); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2566 | if (0 != rc) |
| 2567 | return rc; |
| 2568 | } |
| 2569 | return 0; |
| 2570 | } |
| 2571 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2572 | static int serial_parse(const char *devname) |
| 2573 | { |
| 2574 | static int index = 0; |
| 2575 | char label[32]; |
| 2576 | |
| 2577 | if (strcmp(devname, "none") == 0) |
| 2578 | return 0; |
| 2579 | if (index == MAX_SERIAL_PORTS) { |
| 2580 | fprintf(stderr, "qemu: too many serial ports\n"); |
| 2581 | exit(1); |
| 2582 | } |
| 2583 | snprintf(label, sizeof(label), "serial%d", index); |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 2584 | serial_hds[index] = qemu_chr_new(label, devname, NULL); |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2585 | if (!serial_hds[index]) { |
Peter Maydell | 52d0613 | 2012-07-09 04:28:30 +0000 | [diff] [blame] | 2586 | fprintf(stderr, "qemu: could not connect serial device" |
| 2587 | " to character backend '%s'\n", devname); |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2588 | return -1; |
| 2589 | } |
| 2590 | index++; |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2594 | static int parallel_parse(const char *devname) |
| 2595 | { |
| 2596 | static int index = 0; |
| 2597 | char label[32]; |
| 2598 | |
| 2599 | if (strcmp(devname, "none") == 0) |
| 2600 | return 0; |
| 2601 | if (index == MAX_PARALLEL_PORTS) { |
| 2602 | fprintf(stderr, "qemu: too many parallel ports\n"); |
| 2603 | exit(1); |
| 2604 | } |
| 2605 | snprintf(label, sizeof(label), "parallel%d", index); |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 2606 | parallel_hds[index] = qemu_chr_new(label, devname, NULL); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2607 | if (!parallel_hds[index]) { |
Peter Maydell | 52d0613 | 2012-07-09 04:28:30 +0000 | [diff] [blame] | 2608 | fprintf(stderr, "qemu: could not connect parallel device" |
| 2609 | " to character backend '%s'\n", devname); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2610 | return -1; |
| 2611 | } |
| 2612 | index++; |
| 2613 | return 0; |
| 2614 | } |
| 2615 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2616 | static int virtcon_parse(const char *devname) |
| 2617 | { |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2618 | QemuOptsList *device = qemu_find_opts("device"); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2619 | static int index = 0; |
| 2620 | char label[32]; |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2621 | QemuOpts *bus_opts, *dev_opts; |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2622 | |
| 2623 | if (strcmp(devname, "none") == 0) |
| 2624 | return 0; |
| 2625 | if (index == MAX_VIRTIO_CONSOLES) { |
| 2626 | fprintf(stderr, "qemu: too many virtio consoles\n"); |
| 2627 | exit(1); |
| 2628 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2629 | |
Peter Crosthwaite | 87ea75d | 2014-01-01 18:49:17 -0800 | [diff] [blame] | 2630 | bus_opts = qemu_opts_create(device, NULL, 0, &error_abort); |
Anthony Liguori | e87f7fc | 2012-02-06 11:07:18 -0600 | [diff] [blame] | 2631 | if (arch_type == QEMU_ARCH_S390X) { |
| 2632 | qemu_opt_set(bus_opts, "driver", "virtio-serial-s390"); |
| 2633 | } else { |
| 2634 | qemu_opt_set(bus_opts, "driver", "virtio-serial-pci"); |
Laszlo Ersek | 4d8b3c6 | 2013-03-21 00:23:13 +0100 | [diff] [blame] | 2635 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2636 | |
Peter Crosthwaite | 87ea75d | 2014-01-01 18:49:17 -0800 | [diff] [blame] | 2637 | dev_opts = qemu_opts_create(device, NULL, 0, &error_abort); |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2638 | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
| 2639 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2640 | snprintf(label, sizeof(label), "virtcon%d", index); |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 2641 | virtcon_hds[index] = qemu_chr_new(label, devname, NULL); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2642 | if (!virtcon_hds[index]) { |
Peter Maydell | 52d0613 | 2012-07-09 04:28:30 +0000 | [diff] [blame] | 2643 | fprintf(stderr, "qemu: could not connect virtio console" |
| 2644 | " to character backend '%s'\n", devname); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2645 | return -1; |
| 2646 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 2647 | qemu_opt_set(dev_opts, "chardev", label); |
| 2648 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2649 | index++; |
| 2650 | return 0; |
| 2651 | } |
| 2652 | |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 2653 | static int sclp_parse(const char *devname) |
| 2654 | { |
| 2655 | QemuOptsList *device = qemu_find_opts("device"); |
| 2656 | static int index = 0; |
| 2657 | char label[32]; |
| 2658 | QemuOpts *dev_opts; |
| 2659 | |
| 2660 | if (strcmp(devname, "none") == 0) { |
| 2661 | return 0; |
| 2662 | } |
| 2663 | if (index == MAX_SCLP_CONSOLES) { |
| 2664 | fprintf(stderr, "qemu: too many sclp consoles\n"); |
| 2665 | exit(1); |
| 2666 | } |
| 2667 | |
| 2668 | assert(arch_type == QEMU_ARCH_S390X); |
| 2669 | |
| 2670 | dev_opts = qemu_opts_create(device, NULL, 0, NULL); |
| 2671 | qemu_opt_set(dev_opts, "driver", "sclpconsole"); |
| 2672 | |
| 2673 | snprintf(label, sizeof(label), "sclpcon%d", index); |
| 2674 | sclp_hds[index] = qemu_chr_new(label, devname, NULL); |
| 2675 | if (!sclp_hds[index]) { |
| 2676 | fprintf(stderr, "qemu: could not connect sclp console" |
| 2677 | " to character backend '%s'\n", devname); |
| 2678 | return -1; |
| 2679 | } |
| 2680 | qemu_opt_set(dev_opts, "chardev", label); |
| 2681 | |
| 2682 | index++; |
| 2683 | return 0; |
| 2684 | } |
| 2685 | |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2686 | static int debugcon_parse(const char *devname) |
Laszlo Ersek | 4d8b3c6 | 2013-03-21 00:23:13 +0100 | [diff] [blame] | 2687 | { |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2688 | QemuOpts *opts; |
| 2689 | |
Anthony Liguori | 27143a4 | 2011-08-15 11:17:36 -0500 | [diff] [blame] | 2690 | if (!qemu_chr_new("debugcon", devname, NULL)) { |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2691 | exit(1); |
| 2692 | } |
Luiz Capitulino | 8be7e7e | 2012-03-20 15:51:57 -0300 | [diff] [blame] | 2693 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2694 | if (!opts) { |
| 2695 | fprintf(stderr, "qemu: already have a debugcon device\n"); |
| 2696 | exit(1); |
| 2697 | } |
| 2698 | qemu_opt_set(opts, "driver", "isa-debugcon"); |
| 2699 | qemu_opt_set(opts, "chardev", "debugcon"); |
| 2700 | return 0; |
| 2701 | } |
| 2702 | |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 2703 | static MachineClass *machine_parse(const char *name) |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2704 | { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 2705 | MachineClass *mc = NULL; |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 2706 | GSList *el, *machines = object_class_get_list(TYPE_MACHINE, false); |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2707 | |
| 2708 | if (name) { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 2709 | mc = find_machine(name); |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2710 | } |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 2711 | if (mc) { |
| 2712 | return mc; |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2713 | } |
Miroslav Rezanina | 025172d | 2014-03-14 13:06:54 +0100 | [diff] [blame] | 2714 | if (name && !is_help_option(name)) { |
| 2715 | error_report("Unsupported machine type"); |
| 2716 | error_printf("Use -machine help to list supported machines!\n"); |
| 2717 | } else { |
| 2718 | printf("Supported machines are:\n"); |
| 2719 | for (el = machines; el; el = el->next) { |
| 2720 | MachineClass *mc = el->data; |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 2721 | if (mc->alias) { |
| 2722 | printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name); |
Miroslav Rezanina | 025172d | 2014-03-14 13:06:54 +0100 | [diff] [blame] | 2723 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 2724 | printf("%-20s %s%s\n", mc->name, mc->desc, |
| 2725 | mc->is_default ? " (default)" : ""); |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2726 | } |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2727 | } |
Marcel Apfelbaum | 261747f | 2014-03-05 19:30:46 +0200 | [diff] [blame] | 2728 | |
| 2729 | g_slist_free(machines); |
Peter Maydell | c8057f9 | 2012-08-02 13:45:54 +0100 | [diff] [blame] | 2730 | exit(!name || !is_help_option(name)); |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 2731 | } |
| 2732 | |
Marcel Apfelbaum | f1e2987 | 2014-04-09 20:34:52 +0300 | [diff] [blame] | 2733 | static int tcg_init(MachineClass *mc) |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2734 | { |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 2735 | tcg_exec_init(tcg_tb_size * 1024 * 1024); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2736 | return 0; |
| 2737 | } |
| 2738 | |
| 2739 | static struct { |
| 2740 | const char *opt_name; |
| 2741 | const char *name; |
| 2742 | int (*available)(void); |
Marcel Apfelbaum | f1e2987 | 2014-04-09 20:34:52 +0300 | [diff] [blame] | 2743 | int (*init)(MachineClass *mc); |
liguang | d5286af | 2013-01-24 13:03:27 +0800 | [diff] [blame] | 2744 | bool *allowed; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2745 | } accel_list[] = { |
| 2746 | { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, |
Anthony PERARD | 3285cf4 | 2010-08-19 12:27:56 +0100 | [diff] [blame] | 2747 | { "xen", "Xen", xen_available, xen_init, &xen_allowed }, |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2748 | { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, |
Paolo Bonzini | d4fce24 | 2013-10-18 13:51:11 +0200 | [diff] [blame] | 2749 | { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed }, |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2750 | }; |
| 2751 | |
Marcel Apfelbaum | f1e2987 | 2014-04-09 20:34:52 +0300 | [diff] [blame] | 2752 | static int configure_accelerator(MachineClass *mc) |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2753 | { |
Markus Armbruster | 36ad0e9 | 2013-07-04 15:09:20 +0200 | [diff] [blame] | 2754 | const char *p; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2755 | char buf[10]; |
| 2756 | int i, ret; |
liguang | 217e21b | 2013-01-24 13:03:26 +0800 | [diff] [blame] | 2757 | bool accel_initialised = false; |
| 2758 | bool init_failed = false; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2759 | |
Markus Armbruster | 36ad0e9 | 2013-07-04 15:09:20 +0200 | [diff] [blame] | 2760 | p = qemu_opt_get(qemu_get_machine_opts(), "accel"); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2761 | if (p == NULL) { |
| 2762 | /* Use the default "accelerator", tcg */ |
| 2763 | p = "tcg"; |
| 2764 | } |
| 2765 | |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2766 | while (!accel_initialised && *p != '\0') { |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2767 | if (*p == ':') { |
| 2768 | p++; |
| 2769 | } |
| 2770 | p = get_opt_name(buf, sizeof (buf), p, ':'); |
| 2771 | for (i = 0; i < ARRAY_SIZE(accel_list); i++) { |
| 2772 | if (strcmp(accel_list[i].opt_name, buf) == 0) { |
liguang | e3c66d9 | 2013-01-24 13:03:25 +0800 | [diff] [blame] | 2773 | if (!accel_list[i].available()) { |
| 2774 | printf("%s not supported for this target\n", |
| 2775 | accel_list[i].name); |
Chen Gang | b321afb | 2014-04-04 17:39:33 +0800 | [diff] [blame] | 2776 | break; |
liguang | e3c66d9 | 2013-01-24 13:03:25 +0800 | [diff] [blame] | 2777 | } |
liguang | d5286af | 2013-01-24 13:03:27 +0800 | [diff] [blame] | 2778 | *(accel_list[i].allowed) = true; |
Marcel Apfelbaum | f1e2987 | 2014-04-09 20:34:52 +0300 | [diff] [blame] | 2779 | ret = accel_list[i].init(mc); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2780 | if (ret < 0) { |
liguang | 217e21b | 2013-01-24 13:03:26 +0800 | [diff] [blame] | 2781 | init_failed = true; |
liguang | e3c66d9 | 2013-01-24 13:03:25 +0800 | [diff] [blame] | 2782 | fprintf(stderr, "failed to initialize %s: %s\n", |
| 2783 | accel_list[i].name, |
| 2784 | strerror(-ret)); |
liguang | d5286af | 2013-01-24 13:03:27 +0800 | [diff] [blame] | 2785 | *(accel_list[i].allowed) = false; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2786 | } else { |
liguang | 217e21b | 2013-01-24 13:03:26 +0800 | [diff] [blame] | 2787 | accel_initialised = true; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2788 | } |
| 2789 | break; |
| 2790 | } |
| 2791 | } |
| 2792 | if (i == ARRAY_SIZE(accel_list)) { |
| 2793 | fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); |
| 2794 | } |
| 2795 | } |
| 2796 | |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2797 | if (!accel_initialised) { |
liguang | 217e21b | 2013-01-24 13:03:26 +0800 | [diff] [blame] | 2798 | if (!init_failed) { |
| 2799 | fprintf(stderr, "No accelerator found!\n"); |
| 2800 | } |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2801 | exit(1); |
| 2802 | } |
| 2803 | |
| 2804 | if (init_failed) { |
| 2805 | fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); |
| 2806 | } |
| 2807 | |
Peter Maydell | 1b785a9 | 2012-02-07 20:57:27 +0000 | [diff] [blame] | 2808 | return !accel_initialised; |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 2809 | } |
| 2810 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 2811 | void qemu_add_exit_notifier(Notifier *notify) |
| 2812 | { |
| 2813 | notifier_list_add(&exit_notifiers, notify); |
| 2814 | } |
| 2815 | |
| 2816 | void qemu_remove_exit_notifier(Notifier *notify) |
| 2817 | { |
Paolo Bonzini | 3155252 | 2012-01-13 17:34:01 +0100 | [diff] [blame] | 2818 | notifier_remove(notify); |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | static void qemu_run_exit_notifiers(void) |
| 2822 | { |
Jan Kiszka | 9e8dd45 | 2011-06-20 14:06:26 +0200 | [diff] [blame] | 2823 | notifier_list_notify(&exit_notifiers, NULL); |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 2824 | } |
| 2825 | |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 2826 | void qemu_add_machine_init_done_notifier(Notifier *notify) |
| 2827 | { |
| 2828 | notifier_list_add(&machine_init_done_notifiers, notify); |
| 2829 | } |
| 2830 | |
| 2831 | static void qemu_run_machine_init_done_notifiers(void) |
| 2832 | { |
Jan Kiszka | 9e8dd45 | 2011-06-20 14:06:26 +0200 | [diff] [blame] | 2833 | notifier_list_notify(&machine_init_done_notifiers, NULL); |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 2834 | } |
| 2835 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2836 | static const QEMUOption *lookup_opt(int argc, char **argv, |
| 2837 | const char **poptarg, int *poptind) |
| 2838 | { |
| 2839 | const QEMUOption *popt; |
| 2840 | int optind = *poptind; |
| 2841 | char *r = argv[optind]; |
| 2842 | const char *optarg; |
| 2843 | |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2844 | loc_set_cmdline(argv, optind, 1); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2845 | optind++; |
| 2846 | /* Treat --foo the same as -foo. */ |
| 2847 | if (r[1] == '-') |
| 2848 | r++; |
| 2849 | popt = qemu_options; |
| 2850 | for(;;) { |
| 2851 | if (!popt->name) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2852 | error_report("invalid option"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2853 | exit(1); |
| 2854 | } |
| 2855 | if (!strcmp(popt->name, r + 1)) |
| 2856 | break; |
| 2857 | popt++; |
| 2858 | } |
| 2859 | if (popt->flags & HAS_ARG) { |
| 2860 | if (optind >= argc) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2861 | error_report("requires an argument"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2862 | exit(1); |
| 2863 | } |
| 2864 | optarg = argv[optind++]; |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2865 | loc_set_cmdline(argv, optind - 2, 2); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2866 | } else { |
| 2867 | optarg = NULL; |
| 2868 | } |
| 2869 | |
| 2870 | *poptarg = optarg; |
| 2871 | *poptind = optind; |
| 2872 | |
| 2873 | return popt; |
| 2874 | } |
| 2875 | |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2876 | static gpointer malloc_and_trace(gsize n_bytes) |
| 2877 | { |
| 2878 | void *ptr = malloc(n_bytes); |
Frediano Ziglio | a74cd8c | 2011-08-31 09:25:35 +0200 | [diff] [blame] | 2879 | trace_g_malloc(n_bytes, ptr); |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2880 | return ptr; |
| 2881 | } |
| 2882 | |
| 2883 | static gpointer realloc_and_trace(gpointer mem, gsize n_bytes) |
| 2884 | { |
| 2885 | void *ptr = realloc(mem, n_bytes); |
Frediano Ziglio | a74cd8c | 2011-08-31 09:25:35 +0200 | [diff] [blame] | 2886 | trace_g_realloc(mem, n_bytes, ptr); |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2887 | return ptr; |
| 2888 | } |
| 2889 | |
| 2890 | static void free_and_trace(gpointer mem) |
| 2891 | { |
Frediano Ziglio | a74cd8c | 2011-08-31 09:25:35 +0200 | [diff] [blame] | 2892 | trace_g_free(mem); |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2893 | free(mem); |
| 2894 | } |
| 2895 | |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 2896 | static int object_set_property(const char *name, const char *value, void *opaque) |
| 2897 | { |
| 2898 | Object *obj = OBJECT(opaque); |
| 2899 | StringInputVisitor *siv; |
| 2900 | Error *local_err = NULL; |
| 2901 | |
Marcel Apfelbaum | 13d7adf | 2014-05-26 15:40:57 +0300 | [diff] [blame] | 2902 | if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0 || |
| 2903 | strcmp(name, "type") == 0) { |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 2904 | return 0; |
| 2905 | } |
| 2906 | |
| 2907 | siv = string_input_visitor_new(value); |
| 2908 | object_property_set(obj, string_input_get_visitor(siv), name, &local_err); |
| 2909 | string_input_visitor_cleanup(siv); |
| 2910 | |
| 2911 | if (local_err) { |
| 2912 | qerror_report_err(local_err); |
| 2913 | error_free(local_err); |
| 2914 | return -1; |
| 2915 | } |
| 2916 | |
| 2917 | return 0; |
| 2918 | } |
| 2919 | |
| 2920 | static int object_create(QemuOpts *opts, void *opaque) |
| 2921 | { |
| 2922 | const char *type = qemu_opt_get(opts, "qom-type"); |
| 2923 | const char *id = qemu_opts_id(opts); |
Igor Mammedov | 90e9cf2 | 2014-01-16 17:34:37 +0100 | [diff] [blame] | 2924 | Error *local_err = NULL; |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 2925 | Object *obj; |
| 2926 | |
| 2927 | g_assert(type != NULL); |
| 2928 | |
| 2929 | if (id == NULL) { |
| 2930 | qerror_report(QERR_MISSING_PARAMETER, "id"); |
| 2931 | return -1; |
| 2932 | } |
| 2933 | |
| 2934 | obj = object_new(type); |
| 2935 | if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) { |
Paolo Bonzini | 28ec259 | 2013-12-20 23:21:07 +0100 | [diff] [blame] | 2936 | object_unref(obj); |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 2937 | return -1; |
| 2938 | } |
| 2939 | |
Igor Mammedov | 269e09f | 2014-01-16 17:34:38 +0100 | [diff] [blame] | 2940 | if (!object_dynamic_cast(obj, TYPE_USER_CREATABLE)) { |
| 2941 | error_setg(&local_err, "object '%s' isn't supported by -object", |
| 2942 | id); |
| 2943 | goto out; |
| 2944 | } |
| 2945 | |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 2946 | object_property_add_child(container_get(object_get_root(), "/objects"), |
Igor Mammedov | 90e9cf2 | 2014-01-16 17:34:37 +0100 | [diff] [blame] | 2947 | id, obj, &local_err); |
| 2948 | |
Igor Mammedov | a790f4e | 2014-06-02 15:24:59 +0200 | [diff] [blame] | 2949 | user_creatable_complete(obj, &local_err); |
| 2950 | if (local_err) { |
| 2951 | object_property_del(container_get(object_get_root(), "/objects"), |
| 2952 | id, &error_abort); |
| 2953 | goto out; |
| 2954 | } |
Igor Mammedov | 269e09f | 2014-01-16 17:34:38 +0100 | [diff] [blame] | 2955 | out: |
Paolo Bonzini | 28ec259 | 2013-12-20 23:21:07 +0100 | [diff] [blame] | 2956 | object_unref(obj); |
Igor Mammedov | 90e9cf2 | 2014-01-16 17:34:37 +0100 | [diff] [blame] | 2957 | if (local_err) { |
| 2958 | qerror_report_err(local_err); |
| 2959 | error_free(local_err); |
| 2960 | return -1; |
| 2961 | } |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 2962 | return 0; |
| 2963 | } |
| 2964 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 2965 | int main(int argc, char **argv, char **envp) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2966 | { |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2967 | int i; |
Eduardo Habkost | da1fcfd | 2010-04-06 19:22:07 -0300 | [diff] [blame] | 2968 | int snapshot, linux_boot; |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 2969 | const char *icount_option = NULL; |
bellard | 7f7f987 | 2003-10-30 01:11:23 +0000 | [diff] [blame] | 2970 | const char *initrd_filename; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2971 | const char *kernel_filename, *kernel_cmdline; |
Markus Armbruster | e3fdc53 | 2013-10-01 13:47:22 +0200 | [diff] [blame] | 2972 | const char *boot_order; |
aliguori | 3023f332 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2973 | DisplayState *ds; |
malc | 9f227bc | 2012-08-27 18:33:22 +0400 | [diff] [blame] | 2974 | int cyls, heads, secs, translation; |
| 2975 | QemuOpts *hda_opts = NULL, *opts, *machine_opts; |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 2976 | QemuOptsList *olist; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2977 | int optind; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 2978 | const char *optarg; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 2979 | const char *loadvm = NULL; |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 2980 | MachineClass *machine_class; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 2981 | const char *cpu_model; |
Mark Wu | d44229c | 2014-03-10 22:37:40 +0800 | [diff] [blame] | 2982 | const char *vga_model = NULL; |
Paolo Bonzini | d4fce24 | 2013-10-18 13:51:11 +0200 | [diff] [blame] | 2983 | const char *qtest_chrdev = NULL; |
| 2984 | const char *qtest_log = NULL; |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 2985 | const char *pid_file = NULL; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 2986 | const char *incoming = NULL; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 2987 | #ifdef CONFIG_VNC |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2988 | int show_vnc_port = 0; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 2989 | #endif |
Eduardo Habkost | 3ed2d9e | 2012-05-02 13:07:28 -0300 | [diff] [blame] | 2990 | bool defconfig = true; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 2991 | bool userconfig = true; |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 2992 | const char *log_mask = NULL; |
| 2993 | const char *log_file = NULL; |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 2994 | GMemVTable mem_trace = { |
| 2995 | .malloc = malloc_and_trace, |
| 2996 | .realloc = realloc_and_trace, |
| 2997 | .free = free_and_trace, |
| 2998 | }; |
Lluís | 23d15e8 | 2011-08-31 20:31:31 +0200 | [diff] [blame] | 2999 | const char *trace_events = NULL; |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3000 | const char *trace_file = NULL; |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 3001 | const ram_addr_t default_ram_size = (ram_addr_t)DEFAULT_RAM_SIZE * |
| 3002 | 1024 * 1024; |
Igor Mammedov | c270fb9 | 2014-06-02 15:25:02 +0200 | [diff] [blame] | 3003 | ram_addr_t maxram_size = default_ram_size; |
| 3004 | uint64_t ram_slots = 0; |
Stefan Hajnoczi | 0b5538c | 2011-02-26 18:38:39 +0000 | [diff] [blame] | 3005 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 3006 | atexit(qemu_run_exit_notifiers); |
Markus Armbruster | 65abca0 | 2010-02-24 14:37:14 +0100 | [diff] [blame] | 3007 | error_set_progname(argv[0]); |
Fam Zheng | 10f5bff | 2014-02-10 14:48:51 +0800 | [diff] [blame] | 3008 | qemu_init_exec_dir(argv[0]); |
Markus Armbruster | 65abca0 | 2010-02-24 14:37:14 +0100 | [diff] [blame] | 3009 | |
Anthony Liguori | 0750112 | 2011-08-20 22:38:31 -0500 | [diff] [blame] | 3010 | g_mem_set_vtable(&mem_trace); |
| 3011 | |
Andreas Färber | 1b71f7c | 2012-03-04 21:32:35 +0100 | [diff] [blame] | 3012 | module_call_init(MODULE_INIT_QOM); |
| 3013 | |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 3014 | qemu_add_opts(&qemu_drive_opts); |
Amos Kong | 968854c | 2013-11-09 12:15:47 +0800 | [diff] [blame] | 3015 | qemu_add_drive_opts(&qemu_legacy_drive_opts); |
| 3016 | qemu_add_drive_opts(&qemu_common_drive_opts); |
| 3017 | qemu_add_drive_opts(&qemu_drive_opts); |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 3018 | qemu_add_opts(&qemu_chardev_opts); |
| 3019 | qemu_add_opts(&qemu_device_opts); |
| 3020 | qemu_add_opts(&qemu_netdev_opts); |
| 3021 | qemu_add_opts(&qemu_net_opts); |
| 3022 | qemu_add_opts(&qemu_rtc_opts); |
| 3023 | qemu_add_opts(&qemu_global_opts); |
| 3024 | qemu_add_opts(&qemu_mon_opts); |
| 3025 | qemu_add_opts(&qemu_trace_opts); |
| 3026 | qemu_add_opts(&qemu_option_rom_opts); |
| 3027 | qemu_add_opts(&qemu_machine_opts); |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 3028 | qemu_add_opts(&qemu_mem_opts); |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 3029 | qemu_add_opts(&qemu_smp_opts); |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 3030 | qemu_add_opts(&qemu_boot_opts); |
| 3031 | qemu_add_opts(&qemu_sandbox_opts); |
| 3032 | qemu_add_opts(&qemu_add_fd_opts); |
| 3033 | qemu_add_opts(&qemu_object_opts); |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 3034 | qemu_add_opts(&qemu_tpmdev_opts); |
Satoru Moriya | 888a6bc | 2013-04-19 16:42:06 +0200 | [diff] [blame] | 3035 | qemu_add_opts(&qemu_realtime_opts); |
Seiji Aguchi | 5e2ac51 | 2013-07-03 23:02:46 -0400 | [diff] [blame] | 3036 | qemu_add_opts(&qemu_msg_opts); |
Dr. David Alan Gilbert | 5d12f96 | 2014-01-30 10:20:30 +0000 | [diff] [blame] | 3037 | qemu_add_opts(&qemu_name_opts); |
Paolo Bonzini | 4d45457 | 2012-11-26 16:03:42 +0100 | [diff] [blame] | 3038 | |
Luiz Capitulino | 5db9d4d | 2011-09-05 16:36:31 -0300 | [diff] [blame] | 3039 | runstate_init(); |
| 3040 | |
Alex Bligh | 884f17c | 2013-08-21 16:03:04 +0100 | [diff] [blame] | 3041 | rtc_clock = QEMU_CLOCK_HOST; |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3042 | |
Richard Henderson | b6a3e69 | 2013-06-04 11:24:49 -0700 | [diff] [blame] | 3043 | qemu_init_auxval(envp); |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 3044 | qemu_cache_utils_init(); |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 3045 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 3046 | QLIST_INIT (&vm_change_state_head); |
Jes Sorensen | fe98ac1 | 2010-06-10 11:42:21 +0200 | [diff] [blame] | 3047 | os_setup_early_signal_handling(); |
bellard | be995c2 | 2006-06-25 16:25:21 +0000 | [diff] [blame] | 3048 | |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 3049 | module_call_init(MODULE_INIT_MACHINE); |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 3050 | machine_class = find_default_machine(); |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 3051 | cpu_model = NULL; |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 3052 | ram_size = default_ram_size; |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 3053 | snapshot = 0; |
malc | 9f227bc | 2012-08-27 18:33:22 +0400 | [diff] [blame] | 3054 | cyls = heads = secs = 0; |
| 3055 | translation = BIOS_ATA_TRANSLATION_AUTO; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 3056 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3057 | for (i = 0; i < MAX_NODES; i++) { |
| 3058 | node_mem[i] = 0; |
Chegu Vinod | ee785fe | 2012-07-16 21:31:30 -0700 | [diff] [blame] | 3059 | node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3060 | } |
| 3061 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3062 | nb_numa_nodes = 0; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 3063 | nb_nics = 0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3064 | |
Peter Lieven | 142c6b1 | 2013-03-21 13:07:10 +0100 | [diff] [blame] | 3065 | bdrv_init_with_whitelist(); |
| 3066 | |
Kewei Yu | 2c02d1a | 2013-12-31 18:36:08 +0800 | [diff] [blame] | 3067 | autostart = 1; |
blueswir1 | 41bd639 | 2008-10-05 09:56:21 +0000 | [diff] [blame] | 3068 | |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 3069 | /* first pass of option parsing */ |
| 3070 | optind = 1; |
| 3071 | while (optind < argc) { |
| 3072 | if (argv[optind][0] != '-') { |
| 3073 | /* disk image */ |
Anthony Liguori | 28e68d6 | 2010-01-27 10:46:00 -0600 | [diff] [blame] | 3074 | optind++; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 3075 | } else { |
| 3076 | const QEMUOption *popt; |
| 3077 | |
| 3078 | popt = lookup_opt(argc, argv, &optarg, &optind); |
| 3079 | switch (popt->index) { |
| 3080 | case QEMU_OPTION_nodefconfig: |
Eduardo Habkost | 3ed2d9e | 2012-05-02 13:07:28 -0300 | [diff] [blame] | 3081 | defconfig = false; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 3082 | break; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 3083 | case QEMU_OPTION_nouserconfig: |
| 3084 | userconfig = false; |
| 3085 | break; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 3086 | } |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | if (defconfig) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 3091 | int ret; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 3092 | ret = qemu_read_default_config_files(userconfig); |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 3093 | if (ret < 0) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 3094 | exit(1); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | /* second pass of option parsing */ |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3099 | optind = 1; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 3100 | for(;;) { |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3101 | if (optind >= argc) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 3102 | break; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 3103 | if (argv[optind][0] != '-') { |
malc | 9f227bc | 2012-08-27 18:33:22 +0400 | [diff] [blame] | 3104 | hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3105 | } else { |
| 3106 | const QEMUOption *popt; |
| 3107 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 3108 | popt = lookup_opt(argc, argv, &optarg, &optind); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 3109 | if (!(popt->arch_mask & arch_type)) { |
| 3110 | printf("Option %s not supported for this target\n", popt->name); |
| 3111 | exit(1); |
| 3112 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3113 | switch(popt->index) { |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 3114 | case QEMU_OPTION_M: |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 3115 | machine_class = machine_parse(optarg); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 3116 | break; |
Jan Kiszka | e43d594 | 2012-10-05 14:51:40 -0300 | [diff] [blame] | 3117 | case QEMU_OPTION_no_kvm_irqchip: { |
| 3118 | olist = qemu_find_opts("machine"); |
| 3119 | qemu_opts_parse(olist, "kernel_irqchip=off", 0); |
| 3120 | break; |
| 3121 | } |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 3122 | case QEMU_OPTION_cpu: |
| 3123 | /* hw initialization will check this */ |
Eduardo Habkost | ecf40be | 2012-03-09 16:19:07 -0300 | [diff] [blame] | 3124 | cpu_model = optarg; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 3125 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3126 | case QEMU_OPTION_hda: |
malc | 9f227bc | 2012-08-27 18:33:22 +0400 | [diff] [blame] | 3127 | { |
| 3128 | char buf[256]; |
| 3129 | if (cyls == 0) |
| 3130 | snprintf(buf, sizeof(buf), "%s", HD_OPTS); |
| 3131 | else |
| 3132 | snprintf(buf, sizeof(buf), |
| 3133 | "%s,cyls=%d,heads=%d,secs=%d%s", |
| 3134 | HD_OPTS , cyls, heads, secs, |
| 3135 | translation == BIOS_ATA_TRANSLATION_LBA ? |
| 3136 | ",trans=lba" : |
| 3137 | translation == BIOS_ATA_TRANSLATION_NONE ? |
| 3138 | ",trans=none" : ""); |
| 3139 | drive_add(IF_DEFAULT, 0, optarg, buf); |
| 3140 | break; |
| 3141 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3142 | case QEMU_OPTION_hdb: |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 3143 | case QEMU_OPTION_hdc: |
| 3144 | case QEMU_OPTION_hdd: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 3145 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
| 3146 | HD_OPTS); |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 3147 | break; |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 3148 | case QEMU_OPTION_drive: |
Michael Tokarev | e2982c3 | 2011-03-30 16:31:05 +0400 | [diff] [blame] | 3149 | if (drive_def(optarg) == NULL) { |
| 3150 | exit(1); |
| 3151 | } |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 3152 | break; |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 3153 | case QEMU_OPTION_set: |
| 3154 | if (qemu_set_option(optarg) != 0) |
| 3155 | exit(1); |
| 3156 | break; |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 3157 | case QEMU_OPTION_global: |
| 3158 | if (qemu_global_option(optarg) != 0) |
| 3159 | exit(1); |
| 3160 | break; |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 3161 | case QEMU_OPTION_mtdblock: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 3162 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 3163 | break; |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 3164 | case QEMU_OPTION_sd: |
Peter Crosthwaite | 80f4d9f | 2013-02-28 18:23:14 +0000 | [diff] [blame] | 3165 | drive_add(IF_SD, -1, optarg, SD_OPTS); |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 3166 | break; |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 3167 | case QEMU_OPTION_pflash: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 3168 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 3169 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3170 | case QEMU_OPTION_snapshot: |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 3171 | snapshot = 1; |
| 3172 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3173 | case QEMU_OPTION_hdachs: |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 3174 | { |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 3175 | const char *p; |
| 3176 | p = optarg; |
| 3177 | cyls = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3178 | if (cyls < 1 || cyls > 16383) |
| 3179 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 3180 | if (*p != ',') |
| 3181 | goto chs_fail; |
| 3182 | p++; |
| 3183 | heads = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3184 | if (heads < 1 || heads > 16) |
| 3185 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 3186 | if (*p != ',') |
| 3187 | goto chs_fail; |
| 3188 | p++; |
| 3189 | secs = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3190 | if (secs < 1 || secs > 63) |
| 3191 | goto chs_fail; |
| 3192 | if (*p == ',') { |
| 3193 | p++; |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3194 | if (!strcmp(p, "large")) { |
| 3195 | translation = BIOS_ATA_TRANSLATION_LARGE; |
| 3196 | } else if (!strcmp(p, "rechs")) { |
| 3197 | translation = BIOS_ATA_TRANSLATION_RECHS; |
| 3198 | } else if (!strcmp(p, "none")) { |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3199 | translation = BIOS_ATA_TRANSLATION_NONE; |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3200 | } else if (!strcmp(p, "lba")) { |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3201 | translation = BIOS_ATA_TRANSLATION_LBA; |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3202 | } else if (!strcmp(p, "auto")) { |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3203 | translation = BIOS_ATA_TRANSLATION_AUTO; |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3204 | } else { |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3205 | goto chs_fail; |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3206 | } |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3207 | } else if (*p != '\0') { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 3208 | chs_fail: |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 3209 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
| 3210 | exit(1); |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 3211 | } |
malc | 9f227bc | 2012-08-27 18:33:22 +0400 | [diff] [blame] | 3212 | if (hda_opts != NULL) { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 3213 | char num[16]; |
| 3214 | snprintf(num, sizeof(num), "%d", cyls); |
| 3215 | qemu_opt_set(hda_opts, "cyls", num); |
| 3216 | snprintf(num, sizeof(num), "%d", heads); |
| 3217 | qemu_opt_set(hda_opts, "heads", num); |
| 3218 | snprintf(num, sizeof(num), "%d", secs); |
| 3219 | qemu_opt_set(hda_opts, "secs", num); |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3220 | if (translation == BIOS_ATA_TRANSLATION_LARGE) { |
| 3221 | qemu_opt_set(hda_opts, "trans", "large"); |
| 3222 | } else if (translation == BIOS_ATA_TRANSLATION_RECHS) { |
| 3223 | qemu_opt_set(hda_opts, "trans", "rechs"); |
| 3224 | } else if (translation == BIOS_ATA_TRANSLATION_LBA) { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 3225 | qemu_opt_set(hda_opts, "trans", "lba"); |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3226 | } else if (translation == BIOS_ATA_TRANSLATION_NONE) { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 3227 | qemu_opt_set(hda_opts, "trans", "none"); |
Paolo Bonzini | f31c41f | 2014-02-08 11:01:54 +0100 | [diff] [blame] | 3228 | } |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 3229 | } |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 3230 | } |
| 3231 | break; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3232 | case QEMU_OPTION_numa: |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 3233 | numa_add(optarg); |
| 3234 | break; |
Jes Sorensen | 1472a95 | 2011-03-16 13:33:31 +0100 | [diff] [blame] | 3235 | case QEMU_OPTION_display: |
| 3236 | display_type = select_display(optarg); |
| 3237 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3238 | case QEMU_OPTION_nographic: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3239 | display_type = DT_NOGRAPHIC; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 3240 | break; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 3241 | case QEMU_OPTION_curses: |
Jes Sorensen | 47b0536 | 2011-03-16 13:33:35 +0100 | [diff] [blame] | 3242 | #ifdef CONFIG_CURSES |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3243 | display_type = DT_CURSES; |
Jes Sorensen | 47b0536 | 2011-03-16 13:33:35 +0100 | [diff] [blame] | 3244 | #else |
| 3245 | fprintf(stderr, "Curses support is disabled\n"); |
| 3246 | exit(1); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 3247 | #endif |
Jes Sorensen | 47b0536 | 2011-03-16 13:33:35 +0100 | [diff] [blame] | 3248 | break; |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 3249 | case QEMU_OPTION_portrait: |
Vasily Khoruzhick | 9312805 | 2011-06-17 13:04:36 +0300 | [diff] [blame] | 3250 | graphic_rotate = 90; |
| 3251 | break; |
| 3252 | case QEMU_OPTION_rotate: |
| 3253 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); |
| 3254 | if (graphic_rotate != 0 && graphic_rotate != 90 && |
| 3255 | graphic_rotate != 180 && graphic_rotate != 270) { |
| 3256 | fprintf(stderr, |
| 3257 | "qemu: only 90, 180, 270 deg rotation is available\n"); |
| 3258 | exit(1); |
| 3259 | } |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 3260 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3261 | case QEMU_OPTION_kernel: |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 3262 | qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg); |
| 3263 | break; |
| 3264 | case QEMU_OPTION_initrd: |
| 3265 | qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg); |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 3266 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3267 | case QEMU_OPTION_append: |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 3268 | qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg); |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 3269 | break; |
Grant Likely | 412beee | 2012-03-02 11:56:38 +0000 | [diff] [blame] | 3270 | case QEMU_OPTION_dtb: |
| 3271 | qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg); |
| 3272 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3273 | case QEMU_OPTION_cdrom: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 3274 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 3275 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3276 | case QEMU_OPTION_boot: |
Markus Armbruster | 8281abd | 2013-06-14 13:15:03 +0200 | [diff] [blame] | 3277 | opts = qemu_opts_parse(qemu_find_opts("boot-opts"), optarg, 1); |
| 3278 | if (!opts) { |
| 3279 | exit(1); |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 3280 | } |
| 3281 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3282 | case QEMU_OPTION_fda: |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3283 | case QEMU_OPTION_fdb: |
Markus Armbruster | 2292dda | 2011-01-28 11:21:41 +0100 | [diff] [blame] | 3284 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
| 3285 | optarg, FD_OPTS); |
bellard | c45886d | 2004-01-05 00:02:06 +0000 | [diff] [blame] | 3286 | break; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 3287 | case QEMU_OPTION_no_fd_bootchk: |
| 3288 | fd_bootchk = 0; |
| 3289 | break; |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 3290 | case QEMU_OPTION_netdev: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3291 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 3292 | exit(1); |
| 3293 | } |
| 3294 | break; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 3295 | case QEMU_OPTION_net: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3296 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 3297 | exit(1); |
| 3298 | } |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 3299 | break; |
Ronnie Sahlberg | f9dadc9 | 2012-01-26 09:39:02 +1100 | [diff] [blame] | 3300 | #ifdef CONFIG_LIBISCSI |
| 3301 | case QEMU_OPTION_iscsi: |
| 3302 | opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0); |
| 3303 | if (!opts) { |
| 3304 | exit(1); |
| 3305 | } |
| 3306 | break; |
| 3307 | #endif |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 3308 | #ifdef CONFIG_SLIRP |
| 3309 | case QEMU_OPTION_tftp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 3310 | legacy_tftp_prefix = optarg; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 3311 | break; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 3312 | case QEMU_OPTION_bootp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 3313 | legacy_bootp_filename = optarg; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 3314 | break; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 3315 | case QEMU_OPTION_redir: |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 3316 | if (net_slirp_redir(optarg) < 0) |
| 3317 | exit(1); |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 3318 | break; |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 3319 | #endif |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 3320 | case QEMU_OPTION_bt: |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 3321 | add_device_config(DEV_BT, optarg); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 3322 | break; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 3323 | case QEMU_OPTION_audio_help: |
| 3324 | AUD_help (); |
| 3325 | exit (0); |
| 3326 | break; |
| 3327 | case QEMU_OPTION_soundhw: |
| 3328 | select_soundhw (optarg); |
| 3329 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3330 | case QEMU_OPTION_h: |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 3331 | help(0); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3332 | break; |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 3333 | case QEMU_OPTION_version: |
| 3334 | version(); |
| 3335 | exit(0); |
| 3336 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 3337 | case QEMU_OPTION_m: { |
Markus Armbruster | ff96101 | 2012-08-15 13:12:19 +0200 | [diff] [blame] | 3338 | uint64_t sz; |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 3339 | const char *mem_str; |
Igor Mammedov | c270fb9 | 2014-06-02 15:25:02 +0200 | [diff] [blame] | 3340 | const char *maxmem_str, *slots_str; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 3341 | |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 3342 | opts = qemu_opts_parse(qemu_find_opts("memory"), |
| 3343 | optarg, 1); |
| 3344 | if (!opts) { |
| 3345 | exit(EXIT_FAILURE); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3346 | } |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 3347 | |
| 3348 | mem_str = qemu_opt_get(opts, "size"); |
| 3349 | if (!mem_str) { |
| 3350 | error_report("invalid -m option, missing 'size' option"); |
| 3351 | exit(EXIT_FAILURE); |
| 3352 | } |
| 3353 | if (!*mem_str) { |
| 3354 | error_report("missing 'size' option value"); |
| 3355 | exit(EXIT_FAILURE); |
| 3356 | } |
| 3357 | |
| 3358 | sz = qemu_opt_get_size(opts, "size", ram_size); |
| 3359 | |
| 3360 | /* Fix up legacy suffix-less format */ |
| 3361 | if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) { |
| 3362 | uint64_t overflow_check = sz; |
| 3363 | |
| 3364 | sz <<= 20; |
| 3365 | if ((sz >> 20) != overflow_check) { |
| 3366 | error_report("too large 'size' option value"); |
| 3367 | exit(EXIT_FAILURE); |
| 3368 | } |
| 3369 | } |
| 3370 | |
| 3371 | /* backward compatibility behaviour for case "-m 0" */ |
| 3372 | if (sz == 0) { |
| 3373 | sz = default_ram_size; |
| 3374 | } |
| 3375 | |
| 3376 | sz = QEMU_ALIGN_UP(sz, 8192); |
Markus Armbruster | ff96101 | 2012-08-15 13:12:19 +0200 | [diff] [blame] | 3377 | ram_size = sz; |
| 3378 | if (ram_size != sz) { |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 3379 | error_report("ram size too large"); |
| 3380 | exit(EXIT_FAILURE); |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 3381 | } |
Igor Mammedov | c270fb9 | 2014-06-02 15:25:02 +0200 | [diff] [blame] | 3382 | |
| 3383 | maxmem_str = qemu_opt_get(opts, "maxmem"); |
| 3384 | slots_str = qemu_opt_get(opts, "slots"); |
| 3385 | if (maxmem_str && slots_str) { |
| 3386 | uint64_t slots; |
| 3387 | |
| 3388 | sz = qemu_opt_get_size(opts, "maxmem", 0); |
| 3389 | if (sz < ram_size) { |
| 3390 | fprintf(stderr, "qemu: invalid -m option value: maxmem " |
| 3391 | "(%" PRIu64 ") <= initial memory (%" |
| 3392 | PRIu64 ")\n", sz, ram_size); |
| 3393 | exit(EXIT_FAILURE); |
| 3394 | } |
| 3395 | |
| 3396 | slots = qemu_opt_get_number(opts, "slots", 0); |
| 3397 | if ((sz > ram_size) && !slots) { |
| 3398 | fprintf(stderr, "qemu: invalid -m option value: maxmem " |
| 3399 | "(%" PRIu64 ") more than initial memory (%" |
| 3400 | PRIu64 ") but no hotplug slots where " |
| 3401 | "specified\n", sz, ram_size); |
| 3402 | exit(EXIT_FAILURE); |
| 3403 | } |
| 3404 | |
| 3405 | if ((sz <= ram_size) && slots) { |
| 3406 | fprintf(stderr, "qemu: invalid -m option value: %" |
| 3407 | PRIu64 " hotplug slots where specified but " |
| 3408 | "maxmem (%" PRIu64 ") <= initial memory (%" |
| 3409 | PRIu64 ")\n", slots, sz, ram_size); |
| 3410 | exit(EXIT_FAILURE); |
| 3411 | } |
| 3412 | maxram_size = sz; |
| 3413 | ram_slots = slots; |
| 3414 | } else if ((!maxmem_str && slots_str) || |
| 3415 | (maxmem_str && !slots_str)) { |
| 3416 | fprintf(stderr, "qemu: invalid -m option value: missing " |
| 3417 | "'%s' option\n", slots_str ? "maxmem" : "slots"); |
| 3418 | exit(EXIT_FAILURE); |
| 3419 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3420 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 3421 | } |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 3422 | #ifdef CONFIG_TPM |
| 3423 | case QEMU_OPTION_tpmdev: |
| 3424 | if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) { |
| 3425 | exit(1); |
| 3426 | } |
| 3427 | break; |
| 3428 | #endif |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 3429 | case QEMU_OPTION_mempath: |
| 3430 | mem_path = optarg; |
| 3431 | break; |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 3432 | case QEMU_OPTION_mem_prealloc: |
| 3433 | mem_prealloc = 1; |
| 3434 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3435 | case QEMU_OPTION_d: |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 3436 | log_mask = optarg; |
| 3437 | break; |
| 3438 | case QEMU_OPTION_D: |
| 3439 | log_file = optarg; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3440 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3441 | case QEMU_OPTION_s: |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 3442 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3443 | break; |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 3444 | case QEMU_OPTION_gdb: |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 3445 | add_device_config(DEV_GDB, optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3446 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3447 | case QEMU_OPTION_L: |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 3448 | if (data_dir_idx < ARRAY_SIZE(data_dir)) { |
| 3449 | data_dir[data_dir_idx++] = optarg; |
| 3450 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3451 | break; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 3452 | case QEMU_OPTION_bios: |
Gerd Hoffmann | 1442d3e | 2013-10-15 16:57:45 +0200 | [diff] [blame] | 3453 | qemu_opts_set(qemu_find_opts("machine"), 0, "firmware", optarg); |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 3454 | break; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 3455 | case QEMU_OPTION_singlestep: |
| 3456 | singlestep = 1; |
| 3457 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3458 | case QEMU_OPTION_S: |
pbrook | 3c07f8e | 2007-01-21 16:47:01 +0000 | [diff] [blame] | 3459 | autostart = 0; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 3460 | break; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 3461 | case QEMU_OPTION_k: |
| 3462 | keyboard_layout = optarg; |
| 3463 | break; |
bellard | ee22c2f | 2004-06-03 12:49:50 +0000 | [diff] [blame] | 3464 | case QEMU_OPTION_localtime: |
| 3465 | rtc_utc = 0; |
| 3466 | break; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 3467 | case QEMU_OPTION_vga: |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 3468 | vga_model = optarg; |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 3469 | default_vga = 0; |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 3470 | break; |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 3471 | case QEMU_OPTION_g: |
| 3472 | { |
| 3473 | const char *p; |
| 3474 | int w, h, depth; |
| 3475 | p = optarg; |
| 3476 | w = strtol(p, (char **)&p, 10); |
| 3477 | if (w <= 0) { |
| 3478 | graphic_error: |
| 3479 | fprintf(stderr, "qemu: invalid resolution or depth\n"); |
| 3480 | exit(1); |
| 3481 | } |
| 3482 | if (*p != 'x') |
| 3483 | goto graphic_error; |
| 3484 | p++; |
| 3485 | h = strtol(p, (char **)&p, 10); |
| 3486 | if (h <= 0) |
| 3487 | goto graphic_error; |
| 3488 | if (*p == 'x') { |
| 3489 | p++; |
| 3490 | depth = strtol(p, (char **)&p, 10); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3491 | if (depth != 8 && depth != 15 && depth != 16 && |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 3492 | depth != 24 && depth != 32) |
| 3493 | goto graphic_error; |
| 3494 | } else if (*p == '\0') { |
| 3495 | depth = graphic_depth; |
| 3496 | } else { |
| 3497 | goto graphic_error; |
| 3498 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 3499 | |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 3500 | graphic_width = w; |
| 3501 | graphic_height = h; |
| 3502 | graphic_depth = depth; |
| 3503 | } |
| 3504 | break; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 3505 | case QEMU_OPTION_echr: |
| 3506 | { |
| 3507 | char *r; |
| 3508 | term_escape_char = strtol(optarg, &r, 0); |
| 3509 | if (r == optarg) |
| 3510 | printf("Bad argument to echr\n"); |
| 3511 | break; |
| 3512 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 3513 | case QEMU_OPTION_monitor: |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 3514 | default_monitor = 0; |
Luiz Capitulino | 70e098a | 2013-05-16 12:02:55 -0400 | [diff] [blame] | 3515 | if (strncmp(optarg, "none", 4)) { |
| 3516 | monitor_parse(optarg, "readline"); |
| 3517 | } |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 3518 | break; |
| 3519 | case QEMU_OPTION_qmp: |
| 3520 | monitor_parse(optarg, "control"); |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 3521 | default_monitor = 0; |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 3522 | break; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 3523 | case QEMU_OPTION_mon: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3524 | opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 3525 | if (!opts) { |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 3526 | exit(1); |
| 3527 | } |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 3528 | default_monitor = 0; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 3529 | break; |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 3530 | case QEMU_OPTION_chardev: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3531 | opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 3532 | if (!opts) { |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 3533 | exit(1); |
| 3534 | } |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 3535 | break; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 3536 | case QEMU_OPTION_fsdev: |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 3537 | olist = qemu_find_opts("fsdev"); |
| 3538 | if (!olist) { |
| 3539 | fprintf(stderr, "fsdev is not supported by this qemu build.\n"); |
| 3540 | exit(1); |
| 3541 | } |
| 3542 | opts = qemu_opts_parse(olist, optarg, 1); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 3543 | if (!opts) { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 3544 | exit(1); |
| 3545 | } |
| 3546 | break; |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 3547 | case QEMU_OPTION_virtfs: { |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 3548 | QemuOpts *fsdev; |
| 3549 | QemuOpts *device; |
M. Mohan Kumar | 84a87cc | 2011-12-14 13:58:47 +0530 | [diff] [blame] | 3550 | const char *writeout, *sock_fd, *socket; |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 3551 | |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 3552 | olist = qemu_find_opts("virtfs"); |
| 3553 | if (!olist) { |
| 3554 | fprintf(stderr, "virtfs is not supported by this qemu build.\n"); |
| 3555 | exit(1); |
| 3556 | } |
| 3557 | opts = qemu_opts_parse(olist, optarg, 1); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 3558 | if (!opts) { |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 3559 | exit(1); |
| 3560 | } |
| 3561 | |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 3562 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
Aneesh Kumar K.V | 99519f0 | 2011-12-14 13:48:59 +0530 | [diff] [blame] | 3563 | qemu_opt_get(opts, "mount_tag") == NULL) { |
| 3564 | fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n"); |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 3565 | exit(1); |
| 3566 | } |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 3567 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
Luiz Capitulino | 8be7e7e | 2012-03-20 15:51:57 -0300 | [diff] [blame] | 3568 | qemu_opt_get(opts, "mount_tag"), |
| 3569 | 1, NULL); |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 3570 | if (!fsdev) { |
| 3571 | fprintf(stderr, "duplicate fsdev id: %s\n", |
| 3572 | qemu_opt_get(opts, "mount_tag")); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 3573 | exit(1); |
| 3574 | } |
Aneesh Kumar K.V | d3ab98e | 2011-10-12 19:11:23 +0530 | [diff] [blame] | 3575 | |
| 3576 | writeout = qemu_opt_get(opts, "writeout"); |
| 3577 | if (writeout) { |
| 3578 | #ifdef CONFIG_SYNC_FILE_RANGE |
| 3579 | qemu_opt_set(fsdev, "writeout", writeout); |
| 3580 | #else |
| 3581 | fprintf(stderr, "writeout=immediate not supported on " |
| 3582 | "this platform\n"); |
| 3583 | exit(1); |
| 3584 | #endif |
| 3585 | } |
Aneesh Kumar K.V | fbcbf10 | 2011-10-13 12:28:04 +0530 | [diff] [blame] | 3586 | qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver")); |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 3587 | qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); |
| 3588 | qemu_opt_set(fsdev, "security_model", |
| 3589 | qemu_opt_get(opts, "security_model")); |
M. Mohan Kumar | 84a87cc | 2011-12-14 13:58:47 +0530 | [diff] [blame] | 3590 | socket = qemu_opt_get(opts, "socket"); |
| 3591 | if (socket) { |
| 3592 | qemu_opt_set(fsdev, "socket", socket); |
| 3593 | } |
M. Mohan Kumar | 4c793dd | 2011-12-14 13:49:28 +0530 | [diff] [blame] | 3594 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
| 3595 | if (sock_fd) { |
| 3596 | qemu_opt_set(fsdev, "sock_fd", sock_fd); |
| 3597 | } |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 3598 | |
M. Mohan Kumar | 2c74c2c | 2011-10-25 12:10:39 +0530 | [diff] [blame] | 3599 | qemu_opt_set_bool(fsdev, "readonly", |
| 3600 | qemu_opt_get_bool(opts, "readonly", 0)); |
Peter Crosthwaite | 87ea75d | 2014-01-01 18:49:17 -0800 | [diff] [blame] | 3601 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
| 3602 | &error_abort); |
Stefan Hajnoczi | e14ea47 | 2011-03-16 08:31:43 +0000 | [diff] [blame] | 3603 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
| 3604 | qemu_opt_set(device, "fsdev", |
| 3605 | qemu_opt_get(opts, "mount_tag")); |
| 3606 | qemu_opt_set(device, "mount_tag", |
| 3607 | qemu_opt_get(opts, "mount_tag")); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 3608 | break; |
| 3609 | } |
Aneesh Kumar K.V | 9db221a | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 3610 | case QEMU_OPTION_virtfs_synth: { |
| 3611 | QemuOpts *fsdev; |
| 3612 | QemuOpts *device; |
| 3613 | |
Luiz Capitulino | 8be7e7e | 2012-03-20 15:51:57 -0300 | [diff] [blame] | 3614 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth", |
| 3615 | 1, NULL); |
Aneesh Kumar K.V | 9db221a | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 3616 | if (!fsdev) { |
| 3617 | fprintf(stderr, "duplicate option: %s\n", "virtfs_synth"); |
| 3618 | exit(1); |
| 3619 | } |
| 3620 | qemu_opt_set(fsdev, "fsdriver", "synth"); |
Aneesh Kumar K.V | 9db221a | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 3621 | |
Peter Crosthwaite | 87ea75d | 2014-01-01 18:49:17 -0800 | [diff] [blame] | 3622 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
| 3623 | &error_abort); |
Aneesh Kumar K.V | 9db221a | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 3624 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
| 3625 | qemu_opt_set(device, "fsdev", "v_synth"); |
| 3626 | qemu_opt_set(device, "mount_tag", "v_synth"); |
| 3627 | break; |
| 3628 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 3629 | case QEMU_OPTION_serial: |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 3630 | add_device_config(DEV_SERIAL, optarg); |
| 3631 | default_serial = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 3632 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 3633 | default_monitor = 0; |
| 3634 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 3635 | break; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 3636 | case QEMU_OPTION_watchdog: |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 3637 | if (watchdog) { |
| 3638 | fprintf(stderr, |
| 3639 | "qemu: only one watchdog option may be given\n"); |
| 3640 | return 1; |
| 3641 | } |
| 3642 | watchdog = optarg; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 3643 | break; |
| 3644 | case QEMU_OPTION_watchdog_action: |
| 3645 | if (select_watchdog_action(optarg) == -1) { |
| 3646 | fprintf(stderr, "Unknown -watchdog-action parameter\n"); |
| 3647 | exit(1); |
| 3648 | } |
| 3649 | break; |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 3650 | case QEMU_OPTION_virtiocon: |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 3651 | add_device_config(DEV_VIRTCON, optarg); |
| 3652 | default_virtcon = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 3653 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 3654 | default_monitor = 0; |
| 3655 | } |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 3656 | break; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 3657 | case QEMU_OPTION_parallel: |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 3658 | add_device_config(DEV_PARALLEL, optarg); |
| 3659 | default_parallel = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 3660 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 3661 | default_monitor = 0; |
| 3662 | } |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 3663 | break; |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 3664 | case QEMU_OPTION_debugcon: |
| 3665 | add_device_config(DEV_DEBUGCON, optarg); |
| 3666 | break; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 3667 | case QEMU_OPTION_loadvm: |
| 3668 | loadvm = optarg; |
| 3669 | break; |
| 3670 | case QEMU_OPTION_full_screen: |
| 3671 | full_screen = 1; |
| 3672 | break; |
ths | 43523e9 | 2007-02-18 18:19:32 +0000 | [diff] [blame] | 3673 | case QEMU_OPTION_no_frame: |
| 3674 | no_frame = 1; |
| 3675 | break; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 3676 | case QEMU_OPTION_alt_grab: |
| 3677 | alt_grab = 1; |
| 3678 | break; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 3679 | case QEMU_OPTION_ctrl_grab: |
| 3680 | ctrl_grab = 1; |
| 3681 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 3682 | case QEMU_OPTION_no_quit: |
| 3683 | no_quit = 1; |
| 3684 | break; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 3685 | case QEMU_OPTION_sdl: |
Michael Tokarev | 24f6ff8 | 2013-06-15 14:44:20 +0400 | [diff] [blame] | 3686 | #ifdef CONFIG_SDL |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 3687 | display_type = DT_SDL; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 3688 | break; |
Jes Sorensen | 58fc096 | 2011-03-16 13:33:34 +0100 | [diff] [blame] | 3689 | #else |
Jes Sorensen | 58fc096 | 2011-03-16 13:33:34 +0100 | [diff] [blame] | 3690 | fprintf(stderr, "SDL support is disabled\n"); |
| 3691 | exit(1); |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 3692 | #endif |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 3693 | case QEMU_OPTION_pidfile: |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 3694 | pid_file = optarg; |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 3695 | break; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 3696 | case QEMU_OPTION_win2k_hack: |
| 3697 | win2k_install_hack = 1; |
| 3698 | break; |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 3699 | case QEMU_OPTION_rtc_td_hack: { |
| 3700 | static GlobalProperty slew_lost_ticks[] = { |
| 3701 | { |
| 3702 | .driver = "mc146818rtc", |
| 3703 | .property = "lost_tick_policy", |
| 3704 | .value = "slew", |
| 3705 | }, |
| 3706 | { /* end of list */ } |
| 3707 | }; |
| 3708 | |
| 3709 | qdev_prop_register_global_list(slew_lost_ticks); |
aliguori | 73822ec | 2009-01-15 20:11:34 +0000 | [diff] [blame] | 3710 | break; |
Jan Kiszka | 433acf0 | 2012-01-23 20:15:12 +0100 | [diff] [blame] | 3711 | } |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 3712 | case QEMU_OPTION_acpitable: |
Laszlo Ersek | 0c764a9 | 2013-03-21 00:23:17 +0100 | [diff] [blame] | 3713 | opts = qemu_opts_parse(qemu_find_opts("acpi"), optarg, 1); |
Laszlo Ersek | f46e720 | 2013-11-28 18:12:59 +0100 | [diff] [blame] | 3714 | if (!opts) { |
| 3715 | exit(1); |
| 3716 | } |
Laszlo Ersek | 0c764a9 | 2013-03-21 00:23:17 +0100 | [diff] [blame] | 3717 | do_acpitable_option(opts); |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 3718 | break; |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 3719 | case QEMU_OPTION_smbios: |
Markus Armbruster | 4f953d2 | 2013-08-16 15:18:29 +0200 | [diff] [blame] | 3720 | opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0); |
Laszlo Ersek | f46e720 | 2013-11-28 18:12:59 +0100 | [diff] [blame] | 3721 | if (!opts) { |
| 3722 | exit(1); |
| 3723 | } |
Markus Armbruster | 4f953d2 | 2013-08-16 15:18:29 +0200 | [diff] [blame] | 3724 | do_smbios_option(opts); |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 3725 | break; |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 3726 | case QEMU_OPTION_enable_kvm: |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 3727 | olist = qemu_find_opts("machine"); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 3728 | qemu_opts_parse(olist, "accel=kvm", 0); |
| 3729 | break; |
| 3730 | case QEMU_OPTION_machine: |
| 3731 | olist = qemu_find_opts("machine"); |
Jan Kiszka | 9052ea6 | 2011-07-23 12:38:37 +0200 | [diff] [blame] | 3732 | opts = qemu_opts_parse(olist, optarg, 1); |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 3733 | if (!opts) { |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 3734 | exit(1); |
| 3735 | } |
Jan Kiszka | 2645c6d | 2011-07-25 18:11:20 +0200 | [diff] [blame] | 3736 | optarg = qemu_opt_get(opts, "type"); |
| 3737 | if (optarg) { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 3738 | machine_class = machine_parse(optarg); |
Jan Kiszka | 2645c6d | 2011-07-25 18:11:20 +0200 | [diff] [blame] | 3739 | } |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 3740 | break; |
Jan Kiszka | a0dac02 | 2012-10-05 14:51:45 -0300 | [diff] [blame] | 3741 | case QEMU_OPTION_no_kvm: |
| 3742 | olist = qemu_find_opts("machine"); |
| 3743 | qemu_opts_parse(olist, "accel=tcg", 0); |
| 3744 | break; |
Jan Kiszka | 4086bde | 2012-10-05 14:51:41 -0300 | [diff] [blame] | 3745 | case QEMU_OPTION_no_kvm_pit: { |
| 3746 | fprintf(stderr, "Warning: KVM PIT can no longer be disabled " |
| 3747 | "separately.\n"); |
| 3748 | break; |
| 3749 | } |
Jan Kiszka | c21fb4f | 2012-10-05 14:51:42 -0300 | [diff] [blame] | 3750 | case QEMU_OPTION_no_kvm_pit_reinjection: { |
| 3751 | static GlobalProperty kvm_pit_lost_tick_policy[] = { |
| 3752 | { |
| 3753 | .driver = "kvm-pit", |
| 3754 | .property = "lost_tick_policy", |
| 3755 | .value = "discard", |
| 3756 | }, |
| 3757 | { /* end of list */ } |
| 3758 | }; |
| 3759 | |
| 3760 | fprintf(stderr, "Warning: option deprecated, use " |
| 3761 | "lost_tick_policy property of kvm-pit instead.\n"); |
| 3762 | qdev_prop_register_global_list(kvm_pit_lost_tick_policy); |
| 3763 | break; |
| 3764 | } |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 3765 | case QEMU_OPTION_usb: |
Peter Maydell | fa5358c | 2012-11-22 16:48:45 +0000 | [diff] [blame] | 3766 | olist = qemu_find_opts("machine"); |
| 3767 | qemu_opts_parse(olist, "usb=on", 0); |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 3768 | break; |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 3769 | case QEMU_OPTION_usbdevice: |
Peter Maydell | fa5358c | 2012-11-22 16:48:45 +0000 | [diff] [blame] | 3770 | olist = qemu_find_opts("machine"); |
| 3771 | qemu_opts_parse(olist, "usb=on", 0); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 3772 | add_device_config(DEV_USB, optarg); |
| 3773 | break; |
| 3774 | case QEMU_OPTION_device: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3775 | if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 3776 | exit(1); |
| 3777 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 3778 | break; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3779 | case QEMU_OPTION_smp: |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 3780 | if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) { |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 3781 | exit(1); |
| 3782 | } |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 3783 | break; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 3784 | case QEMU_OPTION_vnc: |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3785 | #ifdef CONFIG_VNC |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 3786 | display_remote++; |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 3787 | vnc_display = optarg; |
| 3788 | #else |
| 3789 | fprintf(stderr, "VNC support is disabled\n"); |
| 3790 | exit(1); |
| 3791 | #endif |
| 3792 | break; |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 3793 | case QEMU_OPTION_no_acpi: |
| 3794 | acpi_enabled = 0; |
| 3795 | break; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 3796 | case QEMU_OPTION_no_hpet: |
| 3797 | no_hpet = 1; |
| 3798 | break; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 3799 | case QEMU_OPTION_balloon: |
| 3800 | if (balloon_parse(optarg) < 0) { |
| 3801 | fprintf(stderr, "Unknown -balloon argument %s\n", optarg); |
| 3802 | exit(1); |
| 3803 | } |
Eduardo Habkost | df97b92 | 2009-06-10 16:34:08 -0300 | [diff] [blame] | 3804 | break; |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 3805 | case QEMU_OPTION_no_reboot: |
| 3806 | no_reboot = 1; |
| 3807 | break; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 3808 | case QEMU_OPTION_no_shutdown: |
| 3809 | no_shutdown = 1; |
| 3810 | break; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 3811 | case QEMU_OPTION_show_cursor: |
| 3812 | cursor_hide = 0; |
| 3813 | break; |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 3814 | case QEMU_OPTION_uuid: |
| 3815 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { |
| 3816 | fprintf(stderr, "Fail to parse UUID string." |
| 3817 | " Wrong format.\n"); |
| 3818 | exit(1); |
| 3819 | } |
Markus Armbruster | fc3b329 | 2013-08-16 15:18:31 +0200 | [diff] [blame] | 3820 | qemu_uuid_set = true; |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 3821 | break; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 3822 | case QEMU_OPTION_option_rom: |
| 3823 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
| 3824 | fprintf(stderr, "Too many option ROMs\n"); |
| 3825 | exit(1); |
| 3826 | } |
Gleb Natapov | 2e55e84 | 2010-12-08 13:35:07 +0200 | [diff] [blame] | 3827 | opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); |
Markus Armbruster | 49295eb | 2013-02-08 21:22:19 +0100 | [diff] [blame] | 3828 | if (!opts) { |
| 3829 | exit(1); |
| 3830 | } |
Gleb Natapov | 2e55e84 | 2010-12-08 13:35:07 +0200 | [diff] [blame] | 3831 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); |
| 3832 | option_rom[nb_option_roms].bootindex = |
| 3833 | qemu_opt_get_number(opts, "bootindex", -1); |
| 3834 | if (!option_rom[nb_option_roms].name) { |
| 3835 | fprintf(stderr, "Option ROM file is not specified\n"); |
| 3836 | exit(1); |
| 3837 | } |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 3838 | nb_option_roms++; |
| 3839 | break; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 3840 | case QEMU_OPTION_semihosting: |
| 3841 | semihosting_enabled = 1; |
| 3842 | break; |
Jan Kiszka | 88eed34 | 2012-10-05 14:51:44 -0300 | [diff] [blame] | 3843 | case QEMU_OPTION_tdf: |
| 3844 | fprintf(stderr, "Warning: user space PIT time drift fix " |
| 3845 | "is no longer supported.\n"); |
| 3846 | break; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 3847 | case QEMU_OPTION_name: |
Dr. David Alan Gilbert | 5d12f96 | 2014-01-30 10:20:30 +0000 | [diff] [blame] | 3848 | opts = qemu_opts_parse(qemu_find_opts("name"), optarg, 1); |
| 3849 | if (!opts) { |
| 3850 | exit(1); |
| 3851 | } |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 3852 | break; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 3853 | case QEMU_OPTION_prom_env: |
| 3854 | if (nb_prom_envs >= MAX_PROM_ENVS) { |
| 3855 | fprintf(stderr, "Too many prom variables\n"); |
| 3856 | exit(1); |
| 3857 | } |
| 3858 | prom_envs[nb_prom_envs] = optarg; |
| 3859 | nb_prom_envs++; |
| 3860 | break; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 3861 | case QEMU_OPTION_old_param: |
| 3862 | old_param = 1; |
ths | 05ebd53 | 2008-01-08 19:32:16 +0000 | [diff] [blame] | 3863 | break; |
ths | f3dcfad | 2007-08-24 01:26:02 +0000 | [diff] [blame] | 3864 | case QEMU_OPTION_clock: |
Alex Bligh | 6d32717 | 2013-08-21 16:02:59 +0100 | [diff] [blame] | 3865 | /* Clock options no longer exist. Keep this option for |
| 3866 | * backward compatibility. |
| 3867 | */ |
ths | f3dcfad | 2007-08-24 01:26:02 +0000 | [diff] [blame] | 3868 | break; |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 3869 | case QEMU_OPTION_startdate: |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3870 | configure_rtc_date_offset(optarg, 1); |
| 3871 | break; |
| 3872 | case QEMU_OPTION_rtc: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 3873 | opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3874 | if (!opts) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3875 | exit(1); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 3876 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 3877 | configure_rtc(opts); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 3878 | break; |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 3879 | case QEMU_OPTION_tb_size: |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 3880 | tcg_tb_size = strtol(optarg, NULL, 0); |
| 3881 | if (tcg_tb_size < 0) { |
| 3882 | tcg_tb_size = 0; |
| 3883 | } |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 3884 | break; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 3885 | case QEMU_OPTION_icount: |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 3886 | icount_option = optarg; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 3887 | break; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 3888 | case QEMU_OPTION_incoming: |
| 3889 | incoming = optarg; |
Stefano Stabellini | 81323a6 | 2012-01-18 12:23:13 +0000 | [diff] [blame] | 3890 | runstate_set(RUN_STATE_INMIGRATE); |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 3891 | break; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 3892 | case QEMU_OPTION_nodefaults: |
Mark Wu | d44229c | 2014-03-10 22:37:40 +0800 | [diff] [blame] | 3893 | has_defaults = 0; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 3894 | break; |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3895 | case QEMU_OPTION_xen_domid: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 3896 | if (!(xen_available())) { |
| 3897 | printf("Option %s not supported for this target\n", popt->name); |
| 3898 | exit(1); |
| 3899 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3900 | xen_domid = atoi(optarg); |
| 3901 | break; |
| 3902 | case QEMU_OPTION_xen_create: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 3903 | if (!(xen_available())) { |
| 3904 | printf("Option %s not supported for this target\n", popt->name); |
| 3905 | exit(1); |
| 3906 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3907 | xen_mode = XEN_CREATE; |
| 3908 | break; |
| 3909 | case QEMU_OPTION_xen_attach: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 3910 | if (!(xen_available())) { |
| 3911 | printf("Option %s not supported for this target\n", popt->name); |
| 3912 | exit(1); |
| 3913 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 3914 | xen_mode = XEN_ATTACH; |
| 3915 | break; |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3916 | case QEMU_OPTION_trace: |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3917 | { |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3918 | opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3919 | if (!opts) { |
| 3920 | exit(1); |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3921 | } |
Lluís | 23d15e8 | 2011-08-31 20:31:31 +0200 | [diff] [blame] | 3922 | trace_events = qemu_opt_get(opts, "events"); |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3923 | trace_file = qemu_opt_get(opts, "file"); |
Prerna Saxena | ab6540d | 2010-08-09 11:48:32 +0100 | [diff] [blame] | 3924 | break; |
Lluís | e485897 | 2011-08-31 20:31:03 +0200 | [diff] [blame] | 3925 | } |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3926 | case QEMU_OPTION_readconfig: |
| 3927 | { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 3928 | int ret = qemu_read_config_file(optarg); |
| 3929 | if (ret < 0) { |
| 3930 | fprintf(stderr, "read config %s: %s\n", optarg, |
| 3931 | strerror(-ret)); |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3932 | exit(1); |
| 3933 | } |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3934 | break; |
| 3935 | } |
Gerd Hoffmann | 29b0040 | 2010-03-11 11:13:27 -0300 | [diff] [blame] | 3936 | case QEMU_OPTION_spice: |
| 3937 | olist = qemu_find_opts("spice"); |
| 3938 | if (!olist) { |
| 3939 | fprintf(stderr, "spice is not supported by this qemu build.\n"); |
| 3940 | exit(1); |
| 3941 | } |
| 3942 | opts = qemu_opts_parse(olist, optarg, 0); |
| 3943 | if (!opts) { |
Gerd Hoffmann | 29b0040 | 2010-03-11 11:13:27 -0300 | [diff] [blame] | 3944 | exit(1); |
| 3945 | } |
Gerd Hoffmann | f963e4d | 2013-02-25 16:02:30 +0100 | [diff] [blame] | 3946 | display_remote++; |
Gerd Hoffmann | 29b0040 | 2010-03-11 11:13:27 -0300 | [diff] [blame] | 3947 | break; |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3948 | case QEMU_OPTION_writeconfig: |
| 3949 | { |
| 3950 | FILE *fp; |
| 3951 | if (strcmp(optarg, "-") == 0) { |
| 3952 | fp = stdout; |
| 3953 | } else { |
| 3954 | fp = fopen(optarg, "w"); |
| 3955 | if (fp == NULL) { |
| 3956 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); |
| 3957 | exit(1); |
| 3958 | } |
| 3959 | } |
| 3960 | qemu_config_write(fp); |
Chen Gang | 7fb8b5d | 2014-04-22 09:12:34 +0800 | [diff] [blame] | 3961 | if (fp != stdout) { |
| 3962 | fclose(fp); |
| 3963 | } |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 3964 | break; |
| 3965 | } |
Anthony Liguori | c7f0f3b | 2012-03-28 15:42:02 +0200 | [diff] [blame] | 3966 | case QEMU_OPTION_qtest: |
| 3967 | qtest_chrdev = optarg; |
| 3968 | break; |
| 3969 | case QEMU_OPTION_qtest_log: |
| 3970 | qtest_log = optarg; |
| 3971 | break; |
Eduardo Otubo | 7d76ad4 | 2012-08-14 18:44:08 -0300 | [diff] [blame] | 3972 | case QEMU_OPTION_sandbox: |
| 3973 | opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1); |
| 3974 | if (!opts) { |
Markus Armbruster | 49295eb | 2013-02-08 21:22:19 +0100 | [diff] [blame] | 3975 | exit(1); |
Eduardo Otubo | 7d76ad4 | 2012-08-14 18:44:08 -0300 | [diff] [blame] | 3976 | } |
| 3977 | break; |
Corey Bryant | 587ed6b | 2012-10-18 15:19:34 -0400 | [diff] [blame] | 3978 | case QEMU_OPTION_add_fd: |
| 3979 | #ifndef _WIN32 |
| 3980 | opts = qemu_opts_parse(qemu_find_opts("add-fd"), optarg, 0); |
| 3981 | if (!opts) { |
Markus Armbruster | 49295eb | 2013-02-08 21:22:19 +0100 | [diff] [blame] | 3982 | exit(1); |
Corey Bryant | 587ed6b | 2012-10-18 15:19:34 -0400 | [diff] [blame] | 3983 | } |
| 3984 | #else |
| 3985 | error_report("File descriptor passing is disabled on this " |
| 3986 | "platform"); |
| 3987 | exit(1); |
| 3988 | #endif |
| 3989 | break; |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 3990 | case QEMU_OPTION_object: |
| 3991 | opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); |
Markus Armbruster | 49295eb | 2013-02-08 21:22:19 +0100 | [diff] [blame] | 3992 | if (!opts) { |
| 3993 | exit(1); |
| 3994 | } |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 3995 | break; |
Satoru Moriya | 888a6bc | 2013-04-19 16:42:06 +0200 | [diff] [blame] | 3996 | case QEMU_OPTION_realtime: |
| 3997 | opts = qemu_opts_parse(qemu_find_opts("realtime"), optarg, 0); |
| 3998 | if (!opts) { |
| 3999 | exit(1); |
| 4000 | } |
| 4001 | configure_realtime(opts); |
| 4002 | break; |
Seiji Aguchi | 5e2ac51 | 2013-07-03 23:02:46 -0400 | [diff] [blame] | 4003 | case QEMU_OPTION_msg: |
| 4004 | opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0); |
| 4005 | if (!opts) { |
| 4006 | exit(1); |
| 4007 | } |
| 4008 | configure_msg(opts); |
| 4009 | break; |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 4010 | default: |
| 4011 | os_parse_cmd_args(popt->index, optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 4012 | } |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 4013 | } |
| 4014 | } |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 4015 | loc_set_none(); |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 4016 | |
Igor Mammedov | 2d9c272 | 2014-06-02 15:25:00 +0200 | [diff] [blame] | 4017 | os_daemonize(); |
| 4018 | |
Paolo Bonzini | 1c53786 | 2012-10-30 00:17:12 +0100 | [diff] [blame] | 4019 | if (qemu_init_main_loop()) { |
| 4020 | fprintf(stderr, "qemu_init_main_loop failed\n"); |
| 4021 | exit(1); |
| 4022 | } |
| 4023 | |
Eduardo Otubo | 7d76ad4 | 2012-08-14 18:44:08 -0300 | [diff] [blame] | 4024 | if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) { |
| 4025 | exit(1); |
| 4026 | } |
| 4027 | |
Dr. David Alan Gilbert | 5b9d313 | 2014-05-06 12:15:55 +0100 | [diff] [blame] | 4028 | if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) { |
| 4029 | exit(1); |
| 4030 | } |
| 4031 | |
Corey Bryant | 587ed6b | 2012-10-18 15:19:34 -0400 | [diff] [blame] | 4032 | #ifndef _WIN32 |
| 4033 | if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) { |
| 4034 | exit(1); |
| 4035 | } |
| 4036 | |
| 4037 | if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NULL, 1)) { |
| 4038 | exit(1); |
| 4039 | } |
| 4040 | #endif |
| 4041 | |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 4042 | if (machine_class == NULL) { |
Peter Maydell | a7a5544 | 2014-03-27 14:00:52 +0000 | [diff] [blame] | 4043 | fprintf(stderr, "No machine specified, and there is no default.\n" |
| 4044 | "Use -machine help to list supported machines!\n"); |
Dunrong Huang | fb7c269 | 2012-07-24 00:42:20 +0800 | [diff] [blame] | 4045 | exit(1); |
| 4046 | } |
| 4047 | |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 4048 | current_machine = MACHINE(object_new(object_class_get_name( |
| 4049 | OBJECT_CLASS(machine_class)))); |
| 4050 | object_property_add_child(object_get_root(), "machine", |
| 4051 | OBJECT(current_machine), &error_abort); |
| 4052 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4053 | if (machine_class->hw_version) { |
| 4054 | qemu_set_version(machine_class->hw_version); |
Crístian Viana | 93bfef4 | 2012-05-30 00:35:51 -0300 | [diff] [blame] | 4055 | } |
| 4056 | |
Anthony Liguori | 68d98d3 | 2012-06-25 14:36:33 -0500 | [diff] [blame] | 4057 | if (qemu_opts_foreach(qemu_find_opts("object"), |
| 4058 | object_create, NULL, 0) != 0) { |
| 4059 | exit(1); |
| 4060 | } |
| 4061 | |
Eduardo Habkost | ecf40be | 2012-03-09 16:19:07 -0300 | [diff] [blame] | 4062 | /* Init CPU def lists, based on config |
| 4063 | * - Must be called after all the qemu_read_config_file() calls |
| 4064 | * - Must be called before list_cpus() |
| 4065 | * - Must be called before machine->init() |
| 4066 | */ |
| 4067 | cpudef_init(); |
| 4068 | |
Peter Maydell | c8057f9 | 2012-08-02 13:45:54 +0100 | [diff] [blame] | 4069 | if (cpu_model && is_help_option(cpu_model)) { |
Eduardo Habkost | 1d6528a | 2012-03-21 09:33:40 -0300 | [diff] [blame] | 4070 | list_cpus(stdout, &fprintf, cpu_model); |
Eduardo Habkost | ecf40be | 2012-03-09 16:19:07 -0300 | [diff] [blame] | 4071 | exit(0); |
| 4072 | } |
| 4073 | |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 4074 | /* Open the logfile at this point, if necessary. We can't open the logfile |
| 4075 | * when encountering either of the logging options (-d or -D) because the |
| 4076 | * other one may be encountered later on the command line, changing the |
| 4077 | * location or level of logging. |
| 4078 | */ |
| 4079 | if (log_mask) { |
Peter Maydell | b946bff | 2013-02-11 16:41:24 +0000 | [diff] [blame] | 4080 | int mask; |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 4081 | if (log_file) { |
Peter Maydell | 9a7e542 | 2013-02-11 16:41:20 +0000 | [diff] [blame] | 4082 | qemu_set_log_filename(log_file); |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 4083 | } |
Peter Maydell | b946bff | 2013-02-11 16:41:24 +0000 | [diff] [blame] | 4084 | |
| 4085 | mask = qemu_str_to_log_mask(log_mask); |
| 4086 | if (!mask) { |
| 4087 | qemu_print_log_usage(stdout); |
| 4088 | exit(1); |
| 4089 | } |
| 4090 | qemu_set_log(mask); |
Matthew Fernandez | c235d73 | 2011-06-07 16:32:40 +0000 | [diff] [blame] | 4091 | } |
| 4092 | |
Michael Mueller | 8a745f2 | 2013-09-23 16:36:54 +0200 | [diff] [blame] | 4093 | if (!is_daemonized()) { |
Lluís Vilanova | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 4094 | if (!trace_init_backends(trace_events, trace_file)) { |
Michael Mueller | 8a745f2 | 2013-09-23 16:36:54 +0200 | [diff] [blame] | 4095 | exit(1); |
| 4096 | } |
Stefan Hajnoczi | 31d3c9b | 2011-03-13 20:14:30 +0000 | [diff] [blame] | 4097 | } |
Stefan Hajnoczi | 0b5538c | 2011-02-26 18:38:39 +0000 | [diff] [blame] | 4098 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 4099 | /* If no data_dir is specified then try to find it relative to the |
| 4100 | executable path. */ |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 4101 | if (data_dir_idx < ARRAY_SIZE(data_dir)) { |
Fam Zheng | 10f5bff | 2014-02-10 14:48:51 +0800 | [diff] [blame] | 4102 | data_dir[data_dir_idx] = os_find_datadir(); |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 4103 | if (data_dir[data_dir_idx] != NULL) { |
| 4104 | data_dir_idx++; |
| 4105 | } |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 4106 | } |
Stefan Weil | 60474fb | 2011-09-04 15:17:46 +0200 | [diff] [blame] | 4107 | /* If all else fails use the install path specified when building. */ |
Gerd Hoffmann | 4524051 | 2013-03-08 11:42:24 +0100 | [diff] [blame] | 4108 | if (data_dir_idx < ARRAY_SIZE(data_dir)) { |
| 4109 | data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 4110 | } |
| 4111 | |
Michael Tokarev | 12b7f57 | 2013-06-24 15:06:52 +0400 | [diff] [blame] | 4112 | smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 4113 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4114 | machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */ |
| 4115 | if (smp_cpus > machine_class->max_cpus) { |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 4116 | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4117 | "supported by machine `%s' (%d)\n", smp_cpus, |
| 4118 | machine_class->name, machine_class->max_cpus); |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 4119 | exit(1); |
| 4120 | } |
| 4121 | |
Anthony PERARD | 67b724e | 2010-11-22 15:44:15 +0000 | [diff] [blame] | 4122 | /* |
| 4123 | * Get the default machine options from the machine if it is not already |
| 4124 | * specified either by the configuration file or by the command line. |
| 4125 | */ |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4126 | if (machine_class->default_machine_opts) { |
Jan Kiszka | 25de593 | 2012-01-27 19:55:43 +0100 | [diff] [blame] | 4127 | qemu_opts_set_defaults(qemu_find_opts("machine"), |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4128 | machine_class->default_machine_opts, 0); |
Anthony PERARD | 67b724e | 2010-11-22 15:44:15 +0000 | [diff] [blame] | 4129 | } |
| 4130 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 4131 | qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0); |
| 4132 | qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0); |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 4133 | |
Mark Wu | d44229c | 2014-03-10 22:37:40 +0800 | [diff] [blame] | 4134 | if (!vga_model && !default_vga) { |
| 4135 | vga_interface_type = VGA_DEVICE; |
| 4136 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4137 | if (!has_defaults || machine_class->no_serial) { |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 4138 | default_serial = 0; |
| 4139 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4140 | if (!has_defaults || machine_class->no_parallel) { |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 4141 | default_parallel = 0; |
| 4142 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4143 | if (!has_defaults || !machine_class->use_virtcon) { |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 4144 | default_virtcon = 0; |
| 4145 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4146 | if (!has_defaults || !machine_class->use_sclp) { |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 4147 | default_sclp = 0; |
| 4148 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4149 | if (!has_defaults || machine_class->no_floppy) { |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 4150 | default_floppy = 0; |
| 4151 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4152 | if (!has_defaults || machine_class->no_cdrom) { |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 4153 | default_cdrom = 0; |
| 4154 | } |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4155 | if (!has_defaults || machine_class->no_sdcard) { |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 4156 | default_sdcard = 0; |
| 4157 | } |
Mark Wu | d44229c | 2014-03-10 22:37:40 +0800 | [diff] [blame] | 4158 | if (!has_defaults) { |
| 4159 | default_monitor = 0; |
| 4160 | default_net = 0; |
| 4161 | default_vga = 0; |
| 4162 | } |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 4163 | |
Michael Tokarev | ab51b1d | 2012-12-30 12:48:14 +0400 | [diff] [blame] | 4164 | if (is_daemonized()) { |
| 4165 | /* According to documentation and historically, -nographic redirects |
| 4166 | * serial port, parallel port and monitor to stdio, which does not work |
| 4167 | * with -daemonize. We can redirect these to null instead, but since |
| 4168 | * -nographic is legacy, let's just error out. |
| 4169 | * We disallow -nographic only if all other ports are not redirected |
| 4170 | * explicitly, to not break existing legacy setups which uses |
| 4171 | * -nographic _and_ redirects all ports explicitly - this is valid |
| 4172 | * usage, -nographic is just a no-op in this case. |
| 4173 | */ |
| 4174 | if (display_type == DT_NOGRAPHIC |
| 4175 | && (default_parallel || default_serial |
| 4176 | || default_monitor || default_virtcon)) { |
| 4177 | fprintf(stderr, "-nographic can not be used with -daemonize\n"); |
| 4178 | exit(1); |
| 4179 | } |
| 4180 | #ifdef CONFIG_CURSES |
| 4181 | if (display_type == DT_CURSES) { |
| 4182 | fprintf(stderr, "curses display can not be used with -daemonize\n"); |
| 4183 | exit(1); |
| 4184 | } |
| 4185 | #endif |
| 4186 | } |
| 4187 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4188 | if (display_type == DT_NOGRAPHIC) { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 4189 | if (default_parallel) |
| 4190 | add_device_config(DEV_PARALLEL, "null"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 4191 | if (default_serial && default_monitor) { |
| 4192 | add_device_config(DEV_SERIAL, "mon:stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 4193 | } else if (default_virtcon && default_monitor) { |
| 4194 | add_device_config(DEV_VIRTCON, "mon:stdio"); |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 4195 | } else if (default_sclp && default_monitor) { |
| 4196 | add_device_config(DEV_SCLP, "mon:stdio"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 4197 | } else { |
| 4198 | if (default_serial) |
| 4199 | add_device_config(DEV_SERIAL, "stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 4200 | if (default_virtcon) |
| 4201 | add_device_config(DEV_VIRTCON, "stdio"); |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 4202 | if (default_sclp) { |
| 4203 | add_device_config(DEV_SCLP, "stdio"); |
| 4204 | } |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 4205 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 4206 | monitor_parse("stdio", "readline"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 4207 | } |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 4208 | } else { |
| 4209 | if (default_serial) |
| 4210 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 4211 | if (default_parallel) |
| 4212 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 4213 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 4214 | monitor_parse("vc:80Cx24C", "readline"); |
Alexander Graf | 38536da | 2009-12-17 13:06:08 +0100 | [diff] [blame] | 4215 | if (default_virtcon) |
| 4216 | add_device_config(DEV_VIRTCON, "vc:80Cx24C"); |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 4217 | if (default_sclp) { |
| 4218 | add_device_config(DEV_SCLP, "vc:80Cx24C"); |
| 4219 | } |
aliguori | bc0129d | 2008-08-01 15:12:34 +0000 | [diff] [blame] | 4220 | } |
| 4221 | |
Anthony Liguori | 1554642 | 2013-02-20 07:43:25 -0600 | [diff] [blame] | 4222 | if (display_type == DT_DEFAULT && !display_remote) { |
| 4223 | #if defined(CONFIG_GTK) |
| 4224 | display_type = DT_GTK; |
| 4225 | #elif defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
| 4226 | display_type = DT_SDL; |
| 4227 | #elif defined(CONFIG_VNC) |
| 4228 | vnc_display = "localhost:0,to=99"; |
| 4229 | show_vnc_port = 1; |
| 4230 | #else |
| 4231 | display_type = DT_NONE; |
| 4232 | #endif |
| 4233 | } |
| 4234 | |
Peter Wu | 047d4e1 | 2013-06-11 10:55:08 +0200 | [diff] [blame] | 4235 | if ((no_frame || alt_grab || ctrl_grab) && display_type != DT_SDL) { |
| 4236 | fprintf(stderr, "-no-frame, -alt-grab and -ctrl-grab are only valid " |
| 4237 | "for SDL, ignoring option\n"); |
| 4238 | } |
| 4239 | if (no_quit && (display_type != DT_GTK && display_type != DT_SDL)) { |
| 4240 | fprintf(stderr, "-no-quit is only valid for GTK and SDL, " |
| 4241 | "ignoring option\n"); |
| 4242 | } |
| 4243 | |
Anthony Liguori | 1554642 | 2013-02-20 07:43:25 -0600 | [diff] [blame] | 4244 | #if defined(CONFIG_GTK) |
| 4245 | if (display_type == DT_GTK) { |
| 4246 | early_gtk_display_init(); |
| 4247 | } |
| 4248 | #endif |
| 4249 | |
TeLeMan | a5829fd | 2010-04-15 12:37:55 +0800 | [diff] [blame] | 4250 | socket_init(); |
| 4251 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 4252 | if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 4253 | exit(1); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 4254 | #ifdef CONFIG_VIRTFS |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 4255 | if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) { |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 4256 | exit(1); |
| 4257 | } |
| 4258 | #endif |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 4259 | |
ths | aa26bb2 | 2007-03-25 21:33:06 +0000 | [diff] [blame] | 4260 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 4261 | os_pidfile_error(); |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 4262 | exit(1); |
| 4263 | } |
| 4264 | |
Igor Mammedov | 6e1d3c1 | 2013-11-27 01:27:35 +0100 | [diff] [blame] | 4265 | /* store value for the future use */ |
| 4266 | qemu_opt_set_number(qemu_find_opts_singleton("memory"), "size", ram_size); |
Jan Kiszka | 0ac543d | 2011-08-15 16:18:57 -0700 | [diff] [blame] | 4267 | |
Bruce Rogers | 3d1d965 | 2012-08-09 12:47:40 -0600 | [diff] [blame] | 4268 | if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) |
| 4269 | != 0) { |
| 4270 | exit(0); |
| 4271 | } |
| 4272 | |
Marcel Apfelbaum | 6b1b144 | 2014-05-26 15:40:58 +0300 | [diff] [blame] | 4273 | machine_opts = qemu_get_machine_opts(); |
| 4274 | if (qemu_opt_foreach(machine_opts, object_set_property, current_machine, |
| 4275 | 1) < 0) { |
| 4276 | object_unref(OBJECT(current_machine)); |
| 4277 | exit(1); |
| 4278 | } |
| 4279 | |
Marcel Apfelbaum | f1e2987 | 2014-04-09 20:34:52 +0300 | [diff] [blame] | 4280 | configure_accelerator(machine_class); |
Marcelo Tosatti | 214910a | 2009-09-18 02:41:23 -0300 | [diff] [blame] | 4281 | |
Paolo Bonzini | d4fce24 | 2013-10-18 13:51:11 +0200 | [diff] [blame] | 4282 | if (qtest_chrdev) { |
Fam Zheng | 23802b4 | 2014-02-10 09:28:02 +0800 | [diff] [blame] | 4283 | Error *local_err = NULL; |
| 4284 | qtest_init(qtest_chrdev, qtest_log, &local_err); |
| 4285 | if (local_err) { |
| 4286 | error_report("%s", error_get_pretty(local_err)); |
| 4287 | error_free(local_err); |
| 4288 | exit(1); |
| 4289 | } |
Edgar E. Iglesias | a907cf5 | 2013-04-15 21:28:17 +0200 | [diff] [blame] | 4290 | } |
| 4291 | |
Markus Armbruster | 2ff3de6 | 2013-07-04 15:09:22 +0200 | [diff] [blame] | 4292 | machine_opts = qemu_get_machine_opts(); |
| 4293 | kernel_filename = qemu_opt_get(machine_opts, "kernel"); |
| 4294 | initrd_filename = qemu_opt_get(machine_opts, "initrd"); |
| 4295 | kernel_cmdline = qemu_opt_get(machine_opts, "append"); |
Gerd Hoffmann | 1442d3e | 2013-10-15 16:57:45 +0200 | [diff] [blame] | 4296 | bios_name = qemu_opt_get(machine_opts, "firmware"); |
Peter Maydell | 967c0da | 2012-02-22 22:40:00 +0000 | [diff] [blame] | 4297 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4298 | boot_order = machine_class->default_boot_order; |
Markus Armbruster | 8281abd | 2013-06-14 13:15:03 +0200 | [diff] [blame] | 4299 | opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL); |
| 4300 | if (opts) { |
| 4301 | char *normal_boot_order; |
| 4302 | const char *order, *once; |
| 4303 | |
| 4304 | order = qemu_opt_get(opts, "order"); |
| 4305 | if (order) { |
| 4306 | validate_bootdevices(order); |
| 4307 | boot_order = order; |
| 4308 | } |
| 4309 | |
| 4310 | once = qemu_opt_get(opts, "once"); |
| 4311 | if (once) { |
| 4312 | validate_bootdevices(once); |
| 4313 | normal_boot_order = g_strdup(boot_order); |
| 4314 | boot_order = once; |
Markus Armbruster | 083b79c | 2013-06-14 13:15:04 +0200 | [diff] [blame] | 4315 | qemu_register_reset(restore_boot_order, normal_boot_order); |
Markus Armbruster | 8281abd | 2013-06-14 13:15:03 +0200 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu); |
Amos Kong | e5187b5 | 2013-12-09 19:53:15 +0800 | [diff] [blame] | 4319 | boot_strict = qemu_opt_get_bool(opts, "strict", false); |
Markus Armbruster | 8281abd | 2013-06-14 13:15:03 +0200 | [diff] [blame] | 4320 | } |
| 4321 | |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 4322 | if (!kernel_cmdline) { |
| 4323 | kernel_cmdline = ""; |
Marcel Apfelbaum | 6b1b144 | 2014-05-26 15:40:58 +0300 | [diff] [blame] | 4324 | current_machine->kernel_cmdline = (char *)kernel_cmdline; |
Peter Maydell | a0abe47 | 2012-02-08 05:41:39 +0000 | [diff] [blame] | 4325 | } |
| 4326 | |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 4327 | linux_boot = (kernel_filename != NULL); |
balrog | 6c41b27 | 2007-11-17 12:12:29 +0000 | [diff] [blame] | 4328 | |
ths | f8d39c0 | 2008-07-03 10:01:15 +0000 | [diff] [blame] | 4329 | if (!linux_boot && *kernel_cmdline != '\0') { |
| 4330 | fprintf(stderr, "-append only allowed with -kernel option\n"); |
| 4331 | exit(1); |
| 4332 | } |
| 4333 | |
| 4334 | if (!linux_boot && initrd_filename != NULL) { |
| 4335 | fprintf(stderr, "-initrd only allowed with -kernel option\n"); |
| 4336 | exit(1); |
| 4337 | } |
| 4338 | |
Markus Armbruster | 2ff3de6 | 2013-07-04 15:09:22 +0200 | [diff] [blame] | 4339 | if (!linux_boot && qemu_opt_get(machine_opts, "dtb")) { |
Grant Likely | 412beee | 2012-03-02 11:56:38 +0000 | [diff] [blame] | 4340 | fprintf(stderr, "-dtb only allowed with -kernel option\n"); |
| 4341 | exit(1); |
| 4342 | } |
| 4343 | |
Jes Sorensen | 9156d76 | 2010-06-10 11:42:30 +0200 | [diff] [blame] | 4344 | os_set_line_buffering(); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4345 | |
Paolo Bonzini | 49cf572 | 2012-11-02 15:43:24 +0100 | [diff] [blame] | 4346 | qemu_init_cpu_loop(); |
| 4347 | qemu_mutex_lock_iothread(); |
| 4348 | |
Alon Levy | ad1be89 | 2012-03-14 20:33:37 +0200 | [diff] [blame] | 4349 | #ifdef CONFIG_SPICE |
| 4350 | /* spice needs the timers to be initialized by this point */ |
| 4351 | qemu_spice_init(); |
| 4352 | #endif |
| 4353 | |
Max Filippov | 0abe905 | 2011-11-10 15:38:42 +0400 | [diff] [blame] | 4354 | if (icount_option && (kvm_enabled() || xen_enabled())) { |
| 4355 | fprintf(stderr, "-icount is not allowed with kvm or xen\n"); |
| 4356 | exit(1); |
| 4357 | } |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 4358 | configure_icount(icount_option); |
pbrook | 634fce9 | 2006-07-15 17:40:09 +0000 | [diff] [blame] | 4359 | |
Amos Kong | f30dbae | 2012-12-11 22:20:15 +0800 | [diff] [blame] | 4360 | /* clean up network at qemu process termination */ |
| 4361 | atexit(&net_cleanup); |
| 4362 | |
Mark McLoughlin | dc1c9fe | 2009-10-06 12:17:16 +0100 | [diff] [blame] | 4363 | if (net_init_clients() < 0) { |
| 4364 | exit(1); |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 4365 | } |
bellard | f1510b2 | 2003-06-25 00:07:40 +0000 | [diff] [blame] | 4366 | |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 4367 | #ifdef CONFIG_TPM |
| 4368 | if (tpm_init() < 0) { |
| 4369 | exit(1); |
| 4370 | } |
| 4371 | #endif |
| 4372 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 4373 | /* init the bluetooth world */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 4374 | if (foreach_device_config(DEV_BT, bt_parse)) |
| 4375 | exit(1); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 4376 | |
Anthony PERARD | 834e76e | 2011-07-20 08:17:44 +0000 | [diff] [blame] | 4377 | if (!xen_enabled()) { |
| 4378 | /* On 32-bit hosts, QEMU is limited by virtual address space */ |
| 4379 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { |
| 4380 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n"); |
| 4381 | exit(1); |
| 4382 | } |
| 4383 | } |
balrog | 7fb4fdc | 2008-04-24 17:59:27 +0000 | [diff] [blame] | 4384 | |
Jan Kiszka | d5ab971 | 2011-08-02 16:10:21 +0200 | [diff] [blame] | 4385 | cpu_exec_init_all(); |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 4386 | |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 4387 | blk_mig_init(); |
Dr. David Alan Gilbert | 0d6ab3a | 2014-03-19 18:32:30 +0000 | [diff] [blame] | 4388 | ram_mig_init(); |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 4389 | |
ths | 96d30e4 | 2007-01-07 20:42:14 +0000 | [diff] [blame] | 4390 | /* open the virtual block devices */ |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 4391 | if (snapshot) |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 4392 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
Christian Borntraeger | 2d0d283 | 2012-11-20 15:30:34 +0100 | [diff] [blame] | 4393 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4394 | &machine_class->block_default_type, 1) != 0) { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 4395 | exit(1); |
Christian Borntraeger | 2d0d283 | 2012-11-20 15:30:34 +0100 | [diff] [blame] | 4396 | } |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 4397 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4398 | default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2, |
Christian Borntraeger | 3c42ea6 | 2012-11-22 21:02:55 +0100 | [diff] [blame] | 4399 | CDROM_OPTS); |
| 4400 | default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS); |
| 4401 | default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS); |
Markus Armbruster | 4e5d9b5 | 2011-01-28 11:21:45 +0100 | [diff] [blame] | 4402 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 4403 | if (nb_numa_nodes > 0) { |
| 4404 | int i; |
| 4405 | |
Sasha Levin | ea0e541 | 2011-06-29 23:29:39 -0400 | [diff] [blame] | 4406 | if (nb_numa_nodes > MAX_NODES) { |
| 4407 | nb_numa_nodes = MAX_NODES; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | /* If no memory size if given for any node, assume the default case |
| 4411 | * and distribute the available memory equally across all nodes |
| 4412 | */ |
| 4413 | for (i = 0; i < nb_numa_nodes; i++) { |
| 4414 | if (node_mem[i] != 0) |
| 4415 | break; |
| 4416 | } |
| 4417 | if (i == nb_numa_nodes) { |
| 4418 | uint64_t usedmem = 0; |
| 4419 | |
| 4420 | /* On Linux, the each node's border has to be 8MB aligned, |
| 4421 | * the final node gets the rest. |
| 4422 | */ |
| 4423 | for (i = 0; i < nb_numa_nodes - 1; i++) { |
| 4424 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); |
| 4425 | usedmem += node_mem[i]; |
| 4426 | } |
| 4427 | node_mem[i] = ram_size - usedmem; |
| 4428 | } |
| 4429 | |
| 4430 | for (i = 0; i < nb_numa_nodes; i++) { |
Chegu Vinod | ee785fe | 2012-07-16 21:31:30 -0700 | [diff] [blame] | 4431 | if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) { |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 4432 | break; |
Chegu Vinod | ee785fe | 2012-07-16 21:31:30 -0700 | [diff] [blame] | 4433 | } |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 4434 | } |
| 4435 | /* assigning the VCPUs round-robin is easier to implement, guest OSes |
| 4436 | * must cope with this anyway, because there are BIOSes out there in |
| 4437 | * real machines which also use this scheme. |
| 4438 | */ |
| 4439 | if (i == nb_numa_nodes) { |
Vasilis Liaskovitis | 991dfef | 2011-10-26 14:19:00 +0200 | [diff] [blame] | 4440 | for (i = 0; i < max_cpus; i++) { |
Chegu Vinod | ee785fe | 2012-07-16 21:31:30 -0700 | [diff] [blame] | 4441 | set_bit(i, node_cpumask[i % nb_numa_nodes]); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 4442 | } |
| 4443 | } |
| 4444 | } |
| 4445 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 4446 | if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) { |
Jan Kiszka | 157b931 | 2010-04-06 16:55:53 +0200 | [diff] [blame] | 4447 | exit(1); |
| 4448 | } |
| 4449 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 4450 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
| 4451 | exit(1); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 4452 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
| 4453 | exit(1); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 4454 | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
| 4455 | exit(1); |
Alexander Graf | 3ef669e | 2013-01-24 12:18:52 +0100 | [diff] [blame] | 4456 | if (foreach_device_config(DEV_SCLP, sclp_parse) < 0) { |
| 4457 | exit(1); |
| 4458 | } |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 4459 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
| 4460 | exit(1); |
aliguori | 2796dae | 2009-01-16 20:23:27 +0000 | [diff] [blame] | 4461 | |
Paolo Bonzini | 7f1b17f | 2012-05-10 09:39:17 +0200 | [diff] [blame] | 4462 | /* If no default VGA is requested, the default is "none". */ |
Aurelien Jarno | 3605ded | 2012-09-10 01:01:44 +0200 | [diff] [blame] | 4463 | if (default_vga) { |
| 4464 | if (cirrus_vga_available()) { |
| 4465 | vga_model = "cirrus"; |
| 4466 | } else if (vga_available()) { |
| 4467 | vga_model = "std"; |
| 4468 | } |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 4469 | } |
Mark Wu | d44229c | 2014-03-10 22:37:40 +0800 | [diff] [blame] | 4470 | if (vga_model) { |
| 4471 | select_vgahw(vga_model); |
| 4472 | } |
Blue Swirl | a369da5 | 2011-09-27 19:15:42 +0000 | [diff] [blame] | 4473 | |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 4474 | if (watchdog) { |
| 4475 | i = select_watchdog(watchdog); |
| 4476 | if (i > 0) |
| 4477 | exit (i == 1 ? 1 : 0); |
| 4478 | } |
| 4479 | |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 4480 | if (machine_class->compat_props) { |
| 4481 | qdev_prop_register_global_list(machine_class->compat_props); |
Gerd Hoffmann | b6b6114 | 2009-07-15 13:48:21 +0200 | [diff] [blame] | 4482 | } |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 4483 | qemu_add_globals(); |
| 4484 | |
Anthony Liguori | 1de81d2 | 2011-12-19 16:37:46 -0600 | [diff] [blame] | 4485 | qdev_machine_init(); |
| 4486 | |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 4487 | current_machine->ram_size = ram_size; |
Igor Mammedov | c270fb9 | 2014-06-02 15:25:02 +0200 | [diff] [blame] | 4488 | current_machine->maxram_size = maxram_size; |
| 4489 | current_machine->ram_slots = ram_slots; |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 4490 | current_machine->boot_order = boot_order; |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 4491 | current_machine->cpu_model = cpu_model; |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 4492 | |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 4493 | machine_class->init(current_machine); |
aliguori | 3023f332 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 4494 | |
Paolo Bonzini | b3e6d59 | 2013-04-18 18:44:04 +0200 | [diff] [blame] | 4495 | audio_init(); |
| 4496 | |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 4497 | cpu_synchronize_all_post_init(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 4498 | |
Blue Swirl | 87d0a28 | 2010-03-27 18:24:45 +0000 | [diff] [blame] | 4499 | set_numa_modes(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 4500 | |
aliguori | 3023f332 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 4501 | /* init USB devices */ |
zhlcindy@gmail.com | 094b287 | 2012-09-02 19:25:28 +0000 | [diff] [blame] | 4502 | if (usb_enabled(false)) { |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 4503 | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
| 4504 | exit(1); |
aliguori | 3023f332 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 4507 | /* init generic devices */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 4508 | if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 4509 | exit(1); |
| 4510 | |
Markus Armbruster | 668680f | 2010-02-11 14:44:58 +0100 | [diff] [blame] | 4511 | net_check_clients(); |
| 4512 | |
Gerd Hoffmann | 64840c6 | 2013-03-07 17:08:29 +0100 | [diff] [blame] | 4513 | ds = init_displaystate(); |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4514 | |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 4515 | /* init local displays */ |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4516 | switch (display_type) { |
| 4517 | case DT_NOGRAPHIC: |
Antony Pavlov | 8111d02 | 2013-10-29 08:36:31 +0400 | [diff] [blame] | 4518 | (void)ds; /* avoid warning if no display is configured */ |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4519 | break; |
| 4520 | #if defined(CONFIG_CURSES) |
| 4521 | case DT_CURSES: |
Michael Tokarev | ab51b1d | 2012-12-30 12:48:14 +0400 | [diff] [blame] | 4522 | curses_display_init(ds, full_screen); |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4523 | break; |
| 4524 | #endif |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 4525 | #if defined(CONFIG_SDL) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4526 | case DT_SDL: |
| 4527 | sdl_display_init(ds, full_screen, no_frame); |
| 4528 | break; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 4529 | #elif defined(CONFIG_COCOA) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4530 | case DT_SDL: |
| 4531 | cocoa_display_init(ds, full_screen); |
| 4532 | break; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 4533 | #endif |
Anthony Liguori | 1554642 | 2013-02-20 07:43:25 -0600 | [diff] [blame] | 4534 | #if defined(CONFIG_GTK) |
| 4535 | case DT_GTK: |
Jan Kiszka | 881249c | 2014-03-12 08:33:50 +0100 | [diff] [blame] | 4536 | gtk_display_init(ds, full_screen, grab_on_hover); |
Anthony Liguori | 1554642 | 2013-02-20 07:43:25 -0600 | [diff] [blame] | 4537 | break; |
| 4538 | #endif |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 4539 | default: |
| 4540 | break; |
| 4541 | } |
| 4542 | |
Gleb Natapov | 0ce235a | 2011-03-31 11:27:23 +0200 | [diff] [blame] | 4543 | /* must be after terminal init, SDL library changes signal handlers */ |
| 4544 | os_setup_signal_handling(); |
| 4545 | |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 4546 | #ifdef CONFIG_VNC |
Gerd Hoffmann | 6b62dc2 | 2010-08-25 10:51:06 +0200 | [diff] [blame] | 4547 | /* init remote displays */ |
| 4548 | if (vnc_display) { |
Paolo Bonzini | 2d55f0e | 2012-10-02 10:17:21 +0200 | [diff] [blame] | 4549 | Error *local_err = NULL; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4550 | vnc_display_init(ds); |
Paolo Bonzini | 2d55f0e | 2012-10-02 10:17:21 +0200 | [diff] [blame] | 4551 | vnc_display_open(ds, vnc_display, &local_err); |
| 4552 | if (local_err != NULL) { |
Seiji Aguchi | 4a44d85 | 2013-08-05 15:40:44 -0400 | [diff] [blame] | 4553 | error_report("Failed to start VNC server on `%s': %s", |
| 4554 | vnc_display, error_get_pretty(local_err)); |
Paolo Bonzini | 2d55f0e | 2012-10-02 10:17:21 +0200 | [diff] [blame] | 4555 | error_free(local_err); |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4556 | exit(1); |
Amos Kong | 94b204c | 2012-06-30 10:02:20 +0800 | [diff] [blame] | 4557 | } |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 4558 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 4559 | if (show_vnc_port) { |
| 4560 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 4561 | } |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 4562 | } |
Jes Sorensen | 821601e | 2011-03-16 13:33:36 +0100 | [diff] [blame] | 4563 | #endif |
Gerd Hoffmann | a3e2226 | 2010-08-25 15:32:06 +0200 | [diff] [blame] | 4564 | #ifdef CONFIG_SPICE |
Gerd Hoffmann | 9fa0328 | 2013-10-11 22:39:59 +0200 | [diff] [blame] | 4565 | if (using_spice) { |
| 4566 | qemu_spice_display_init(); |
Gerd Hoffmann | a3e2226 | 2010-08-25 15:32:06 +0200 | [diff] [blame] | 4567 | } |
| 4568 | #endif |
aliguori | 5b08fc1 | 2008-08-21 20:08:03 +0000 | [diff] [blame] | 4569 | |
Markus Armbruster | ef0c4a0 | 2012-02-07 15:09:13 +0100 | [diff] [blame] | 4570 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 4571 | exit(1); |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 4572 | } |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 4573 | |
Gerd Hoffmann | 3418bd2 | 2009-09-25 21:42:41 +0200 | [diff] [blame] | 4574 | qdev_machine_creation_done(); |
| 4575 | |
Gerd Hoffmann | 15ff770 | 2009-12-14 16:07:35 +0100 | [diff] [blame] | 4576 | if (rom_load_all() != 0) { |
| 4577 | fprintf(stderr, "rom loading failed\n"); |
| 4578 | exit(1); |
| 4579 | } |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 4580 | |
Isaku Yamahata | 80376c3 | 2010-12-20 14:33:35 +0900 | [diff] [blame] | 4581 | /* TODO: once all bus devices are qdevified, this should be done |
| 4582 | * when bus is created by qdev.c */ |
| 4583 | qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); |
Gleb Natapov | 4cab946 | 2010-12-08 13:35:08 +0200 | [diff] [blame] | 4584 | qemu_run_machine_init_done_notifiers(); |
| 4585 | |
Michael S. Tsirkin | d916b46 | 2013-07-24 18:56:08 +0300 | [diff] [blame] | 4586 | /* Done notifiers can load ROMs */ |
| 4587 | rom_load_done(); |
| 4588 | |
Jan Kiszka | e063eb1 | 2011-06-14 18:29:43 +0200 | [diff] [blame] | 4589 | qemu_system_reset(VMRESET_SILENT); |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 4590 | if (loadvm) { |
Markus Armbruster | 03cd465 | 2010-02-17 16:24:10 +0100 | [diff] [blame] | 4591 | if (load_vmstate(loadvm) < 0) { |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 4592 | autostart = 0; |
| 4593 | } |
| 4594 | } |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 4595 | |
Don Slutz | 9f9260a | 2014-05-05 14:03:06 -0400 | [diff] [blame] | 4596 | qdev_prop_check_global(); |
| 4597 | |
Glauber Costa | 2bb8c10 | 2009-07-24 16:20:23 -0400 | [diff] [blame] | 4598 | if (incoming) { |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 4599 | Error *local_err = NULL; |
| 4600 | qemu_start_incoming_migration(incoming, &local_err); |
| 4601 | if (local_err) { |
Seiji Aguchi | 4a44d85 | 2013-08-05 15:40:44 -0400 | [diff] [blame] | 4602 | error_report("-incoming %s: %s", incoming, |
| 4603 | error_get_pretty(local_err)); |
Paolo Bonzini | 43eaae2 | 2012-10-02 18:21:18 +0200 | [diff] [blame] | 4604 | error_free(local_err); |
| 4605 | exit(1); |
Juan Quintela | 8ca5e80 | 2010-06-09 14:10:54 +0200 | [diff] [blame] | 4606 | } |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 4607 | } else if (autostart) { |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 4608 | vm_start(); |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 4609 | } |
ths | ffd843b | 2006-12-21 19:46:43 +0000 | [diff] [blame] | 4610 | |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 4611 | os_setup_post(); |
ths | 71e3ceb | 2006-12-22 02:11:31 +0000 | [diff] [blame] | 4612 | |
Michael Mueller | 8a745f2 | 2013-09-23 16:36:54 +0200 | [diff] [blame] | 4613 | if (is_daemonized()) { |
Lluís Vilanova | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 4614 | if (!trace_init_backends(trace_events, trace_file)) { |
Michael Mueller | 8a745f2 | 2013-09-23 16:36:54 +0200 | [diff] [blame] | 4615 | exit(1); |
| 4616 | } |
| 4617 | } |
| 4618 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 4619 | main_loop(); |
Paolo Bonzini | 9943590 | 2011-09-12 14:03:13 +0200 | [diff] [blame] | 4620 | bdrv_close_all(); |
| 4621 | pause_all_vcpus(); |
wayne | 3d3b830 | 2011-07-27 18:04:55 +0800 | [diff] [blame] | 4622 | res_free(); |
Stefan Berger | d1a0cf7 | 2013-02-27 12:47:49 -0500 | [diff] [blame] | 4623 | #ifdef CONFIG_TPM |
| 4624 | tpm_cleanup(); |
| 4625 | #endif |
ths | b46a890 | 2007-10-21 23:20:45 +0000 | [diff] [blame] | 4626 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 4627 | return 0; |
| 4628 | } |