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