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> |
Juan Quintela | 71e72a1 | 2009-07-27 16:12:56 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_BSD |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 51 | #include <sys/stat.h> |
Aurelien Jarno | a167ba5 | 2009-11-29 18:00:41 +0100 | [diff] [blame] | 52 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 53 | #include <libutil.h> |
Juergen Lock | 92c0e65 | 2010-03-25 22:07:12 +0100 | [diff] [blame] | 54 | #include <sys/sysctl.h> |
blueswir1 | 24646c7 | 2008-11-07 16:55:48 +0000 | [diff] [blame] | 55 | #else |
| 56 | #include <util.h> |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 57 | #endif |
Aurelien Jarno | bbe813a | 2009-11-30 15:42:59 +0100 | [diff] [blame] | 58 | #else |
blueswir1 | 223f0d7 | 2008-09-30 18:12:18 +0000 | [diff] [blame] | 59 | #ifdef __linux__ |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 60 | #include <pty.h> |
| 61 | #include <malloc.h> |
ths | bd494f4 | 2007-09-16 20:03:23 +0000 | [diff] [blame] | 62 | |
bellard | e57a8c0 | 2005-11-10 23:58:52 +0000 | [diff] [blame] | 63 | #include <linux/ppdev.h> |
ths | 5867c88 | 2007-02-17 23:44:43 +0000 | [diff] [blame] | 64 | #include <linux/parport.h> |
blueswir1 | 223f0d7 | 2008-09-30 18:12:18 +0000 | [diff] [blame] | 65 | #endif |
| 66 | #ifdef __sun__ |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 67 | #include <sys/stat.h> |
| 68 | #include <sys/ethernet.h> |
| 69 | #include <sys/sockio.h> |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 70 | #include <netinet/arp.h> |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 71 | #include <netinet/in_systm.h> |
| 72 | #include <netinet/ip.h> |
| 73 | #include <netinet/ip_icmp.h> // must come after ip.h |
| 74 | #include <netinet/udp.h> |
| 75 | #include <netinet/tcp.h> |
| 76 | #include <net/if.h> |
| 77 | #include <syslog.h> |
| 78 | #include <stropts.h> |
Blue Swirl | 8d32cf0 | 2009-10-02 19:32:12 +0000 | [diff] [blame] | 79 | /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for |
| 80 | discussion about Solaris header problems */ |
| 81 | extern int madvise(caddr_t, size_t, int); |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 82 | #endif |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 83 | #endif |
bellard | ec530c8 | 2006-04-25 22:36:06 +0000 | [diff] [blame] | 84 | #endif |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 85 | |
blueswir1 | 9892fbf | 2008-08-24 10:34:20 +0000 | [diff] [blame] | 86 | #if defined(__OpenBSD__) |
| 87 | #include <util.h> |
| 88 | #endif |
| 89 | |
ths | 8a16d27 | 2008-07-19 09:56:24 +0000 | [diff] [blame] | 90 | #if defined(CONFIG_VDE) |
| 91 | #include <libvdeplug.h> |
| 92 | #endif |
| 93 | |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 94 | #ifdef _WIN32 |
aliguori | 49dc768 | 2009-03-08 16:26:59 +0000 | [diff] [blame] | 95 | #include <windows.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 96 | #endif |
| 97 | |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 98 | #ifdef CONFIG_SDL |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 99 | #if defined(__APPLE__) || defined(main) |
Stefan Weil | 6693665 | 2009-06-13 13:19:11 +0200 | [diff] [blame] | 100 | #include <SDL.h> |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 101 | int qemu_main(int argc, char **argv, char **envp); |
| 102 | int main(int argc, char **argv) |
| 103 | { |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 104 | return qemu_main(argc, argv, NULL); |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 105 | } |
| 106 | #undef main |
| 107 | #define main qemu_main |
bellard | 96bcd4f | 2004-07-10 16:26:15 +0000 | [diff] [blame] | 108 | #endif |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 109 | #endif /* CONFIG_SDL */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 110 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 111 | #ifdef CONFIG_COCOA |
| 112 | #undef main |
| 113 | #define main qemu_main |
| 114 | #endif /* CONFIG_COCOA */ |
| 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" |
Kevin Wolf | d3f2436 | 2009-05-18 16:42:09 +0200 | [diff] [blame] | 146 | #include "qemu-option.h" |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 147 | #include "qemu-config.h" |
Luiz Capitulino | e78c48e | 2009-12-10 17:16:04 -0200 | [diff] [blame] | 148 | #include "qemu-objects.h" |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 149 | #include "qemu-options.h" |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 150 | #ifdef CONFIG_LINUX |
| 151 | #include "fsdev/qemu-fsdev.h" |
| 152 | #endif |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 153 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 154 | #include "disas.h" |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 155 | |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 156 | #include "qemu_socket.h" |
| 157 | |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 158 | #include "slirp/libslirp.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 159 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 160 | #include "qemu-queue.h" |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 161 | #include "cpus.h" |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 162 | #include "arch_init.h" |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 163 | |
blueswir1 | 9dc63a1 | 2008-10-04 07:25:46 +0000 | [diff] [blame] | 164 | //#define DEBUG_NET |
| 165 | //#define DEBUG_SLIRP |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 166 | |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 167 | #define DEFAULT_RAM_SIZE 128 |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 168 | |
Amit Shah | 98b1925 | 2010-01-20 00:36:52 +0530 | [diff] [blame] | 169 | #define MAX_VIRTIO_CONSOLES 1 |
| 170 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 171 | static const char *data_dir; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 172 | const char *bios_name = NULL; |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 173 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 174 | DisplayType display_type = DT_DEFAULT; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 175 | const char* keyboard_layout = NULL; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 176 | ram_addr_t ram_size; |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 177 | const char *mem_path = NULL; |
| 178 | #ifdef MAP_POPULATE |
| 179 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
| 180 | #endif |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 181 | int nb_nics; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 182 | NICInfo nd_table[MAX_NICS]; |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 183 | int vm_running; |
Paolo Bonzini | d399f67 | 2009-07-27 23:17:51 +0200 | [diff] [blame] | 184 | int autostart; |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 185 | static int rtc_utc = 1; |
| 186 | static int rtc_date_offset = -1; /* -1 means no change */ |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 187 | QEMUClock *rtc_clock; |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 188 | int vga_interface_type = VGA_NONE; |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 189 | static int full_screen = 0; |
blueswir1 | 634a21f | 2008-11-16 11:34:07 +0000 | [diff] [blame] | 190 | #ifdef CONFIG_SDL |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 191 | static int no_frame = 0; |
blueswir1 | 634a21f | 2008-11-16 11:34:07 +0000 | [diff] [blame] | 192 | #endif |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 193 | int no_quit = 0; |
bellard | 8d11df9 | 2004-08-24 21:13:40 +0000 | [diff] [blame] | 194 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 195 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
aliguori | 9ede2fd | 2009-01-15 20:05:25 +0000 | [diff] [blame] | 196 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 197 | int win2k_install_hack = 0; |
aliguori | 73822ec | 2009-01-15 20:11:34 +0000 | [diff] [blame] | 198 | int rtc_td_hack = 0; |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 199 | int usb_enabled = 0; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 200 | int singlestep = 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 201 | int smp_cpus = 1; |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 202 | int max_cpus = 0; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 203 | int smp_cores = 1; |
| 204 | int smp_threads = 1; |
ths | 73fc974 | 2006-12-22 02:09:07 +0000 | [diff] [blame] | 205 | const char *vnc_display; |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 206 | int acpi_enabled = 1; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 207 | int no_hpet = 0; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 208 | int fd_bootchk = 1; |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 209 | int no_reboot = 0; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 210 | int no_shutdown = 0; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 211 | int cursor_hide = 1; |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 212 | int graphic_rotate = 0; |
Jes Sorensen | 6b35e7b | 2009-08-06 16:25:50 +0200 | [diff] [blame] | 213 | uint8_t irq0override = 1; |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 214 | const char *watchdog; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 215 | const char *option_rom[MAX_OPTION_ROMS]; |
| 216 | int nb_option_roms; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 217 | int semihosting_enabled = 0; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 218 | int old_param = 0; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 219 | const char *qemu_name; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 220 | int alt_grab = 0; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 221 | int ctrl_grab = 0; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 222 | unsigned int nb_prom_envs = 0; |
| 223 | const char *prom_envs[MAX_PROM_ENVS]; |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 224 | int boot_menu; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 225 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 226 | int nb_numa_nodes; |
| 227 | uint64_t node_mem[MAX_NODES]; |
| 228 | uint64_t node_cpumask[MAX_NODES]; |
| 229 | |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 230 | static QEMUTimer *nographic_timer; |
balrog | ee5605e | 2007-12-03 03:01:40 +0000 | [diff] [blame] | 231 | |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 232 | uint8_t qemu_uuid[16]; |
| 233 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 234 | static QEMUBootSetHandler *boot_set_handler; |
| 235 | static void *boot_set_opaque; |
| 236 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame^] | 237 | static NotifierList exit_notifiers = |
| 238 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); |
| 239 | |
Blue Swirl | d745bef | 2010-03-29 19:23:49 +0000 | [diff] [blame] | 240 | int kvm_allowed = 0; |
| 241 | uint32_t xen_domid; |
| 242 | enum xen_mode xen_mode = XEN_EMULATE; |
| 243 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 244 | static int default_serial = 1; |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 245 | static int default_parallel = 1; |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 246 | static int default_virtcon = 1; |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 247 | static int default_monitor = 1; |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 248 | static int default_vga = 1; |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 249 | static int default_floppy = 1; |
| 250 | static int default_cdrom = 1; |
| 251 | static int default_sdcard = 1; |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 252 | |
| 253 | static struct { |
| 254 | const char *driver; |
| 255 | int *flag; |
| 256 | } default_list[] = { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 257 | { .driver = "isa-serial", .flag = &default_serial }, |
| 258 | { .driver = "isa-parallel", .flag = &default_parallel }, |
Gerd Hoffmann | d8bcbab | 2009-12-16 14:25:40 +0100 | [diff] [blame] | 259 | { .driver = "isa-fdc", .flag = &default_floppy }, |
| 260 | { .driver = "ide-drive", .flag = &default_cdrom }, |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 261 | { .driver = "virtio-serial-pci", .flag = &default_virtcon }, |
| 262 | { .driver = "virtio-serial-s390", .flag = &default_virtcon }, |
| 263 | { .driver = "virtio-serial", .flag = &default_virtcon }, |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 264 | { .driver = "VGA", .flag = &default_vga }, |
Gerd Hoffmann | 69fd02e | 2009-12-16 13:35:19 +0100 | [diff] [blame] | 265 | { .driver = "cirrus-vga", .flag = &default_vga }, |
| 266 | { .driver = "vmware-svga", .flag = &default_vga }, |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | static int default_driver_check(QemuOpts *opts, void *opaque) |
| 270 | { |
| 271 | const char *driver = qemu_opt_get(opts, "driver"); |
| 272 | int i; |
| 273 | |
| 274 | if (!driver) |
| 275 | return 0; |
| 276 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { |
| 277 | if (strcmp(default_list[i].driver, driver) != 0) |
| 278 | continue; |
| 279 | *(default_list[i].flag) = 0; |
| 280 | } |
| 281 | return 0; |
| 282 | } |
| 283 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 284 | /***********************************************************/ |
Paolo Bonzini | 8f0056b | 2010-01-13 14:05:34 +0100 | [diff] [blame] | 285 | /* real time host monotonic timer */ |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 286 | |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 287 | /* compute with 96 bit intermediate result: (a*b)/c */ |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 288 | uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 289 | { |
| 290 | union { |
| 291 | uint64_t ll; |
| 292 | struct { |
Juan Quintela | e2542fe | 2009-07-27 16:13:06 +0200 | [diff] [blame] | 293 | #ifdef HOST_WORDS_BIGENDIAN |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 294 | uint32_t high, low; |
| 295 | #else |
| 296 | uint32_t low, high; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 297 | #endif |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 298 | } l; |
| 299 | } u, res; |
| 300 | uint64_t rl, rh; |
| 301 | |
| 302 | u.ll = a; |
| 303 | rl = (uint64_t)u.l.low * (uint64_t)b; |
| 304 | rh = (uint64_t)u.l.high * (uint64_t)b; |
| 305 | rh += (rl >> 32); |
| 306 | res.l.high = rh / c; |
| 307 | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; |
| 308 | return res.ll; |
| 309 | } |
| 310 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 311 | /***********************************************************/ |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 312 | /* host time/date access */ |
| 313 | void qemu_get_timedate(struct tm *tm, int offset) |
| 314 | { |
| 315 | time_t ti; |
| 316 | struct tm *ret; |
| 317 | |
| 318 | time(&ti); |
| 319 | ti += offset; |
| 320 | if (rtc_date_offset == -1) { |
| 321 | if (rtc_utc) |
| 322 | ret = gmtime(&ti); |
| 323 | else |
| 324 | ret = localtime(&ti); |
| 325 | } else { |
| 326 | ti -= rtc_date_offset; |
| 327 | ret = gmtime(&ti); |
| 328 | } |
| 329 | |
| 330 | memcpy(tm, ret, sizeof(struct tm)); |
| 331 | } |
| 332 | |
| 333 | int qemu_timedate_diff(struct tm *tm) |
| 334 | { |
| 335 | time_t seconds; |
| 336 | |
| 337 | if (rtc_date_offset == -1) |
| 338 | if (rtc_utc) |
| 339 | seconds = mktimegm(tm); |
| 340 | else |
| 341 | seconds = mktime(tm); |
| 342 | else |
| 343 | seconds = mktimegm(tm) + rtc_date_offset; |
| 344 | |
| 345 | return seconds - time(NULL); |
| 346 | } |
| 347 | |
Luiz Capitulino | 80cd347 | 2010-02-25 12:11:44 -0300 | [diff] [blame] | 348 | void rtc_change_mon_event(struct tm *tm) |
| 349 | { |
| 350 | QObject *data; |
| 351 | |
| 352 | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); |
| 353 | monitor_protocol_event(QEVENT_RTC_CHANGE, data); |
| 354 | qobject_decref(data); |
| 355 | } |
| 356 | |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 357 | static void configure_rtc_date_offset(const char *startdate, int legacy) |
| 358 | { |
| 359 | time_t rtc_start_date; |
| 360 | struct tm tm; |
| 361 | |
| 362 | if (!strcmp(startdate, "now") && legacy) { |
| 363 | rtc_date_offset = -1; |
| 364 | } else { |
| 365 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", |
| 366 | &tm.tm_year, |
| 367 | &tm.tm_mon, |
| 368 | &tm.tm_mday, |
| 369 | &tm.tm_hour, |
| 370 | &tm.tm_min, |
| 371 | &tm.tm_sec) == 6) { |
| 372 | /* OK */ |
| 373 | } else if (sscanf(startdate, "%d-%d-%d", |
| 374 | &tm.tm_year, |
| 375 | &tm.tm_mon, |
| 376 | &tm.tm_mday) == 3) { |
| 377 | tm.tm_hour = 0; |
| 378 | tm.tm_min = 0; |
| 379 | tm.tm_sec = 0; |
| 380 | } else { |
| 381 | goto date_fail; |
| 382 | } |
| 383 | tm.tm_year -= 1900; |
| 384 | tm.tm_mon--; |
| 385 | rtc_start_date = mktimegm(&tm); |
| 386 | if (rtc_start_date == -1) { |
| 387 | date_fail: |
| 388 | fprintf(stderr, "Invalid date format. Valid formats are:\n" |
| 389 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); |
| 390 | exit(1); |
| 391 | } |
| 392 | rtc_date_offset = time(NULL) - rtc_start_date; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | static void configure_rtc(QemuOpts *opts) |
| 397 | { |
| 398 | const char *value; |
| 399 | |
| 400 | value = qemu_opt_get(opts, "base"); |
| 401 | if (value) { |
| 402 | if (!strcmp(value, "utc")) { |
| 403 | rtc_utc = 1; |
| 404 | } else if (!strcmp(value, "localtime")) { |
| 405 | rtc_utc = 0; |
| 406 | } else { |
| 407 | configure_rtc_date_offset(value, 0); |
| 408 | } |
| 409 | } |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 410 | value = qemu_opt_get(opts, "clock"); |
| 411 | if (value) { |
| 412 | if (!strcmp(value, "host")) { |
| 413 | rtc_clock = host_clock; |
| 414 | } else if (!strcmp(value, "vm")) { |
| 415 | rtc_clock = vm_clock; |
| 416 | } else { |
| 417 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 418 | exit(1); |
| 419 | } |
| 420 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 421 | value = qemu_opt_get(opts, "driftfix"); |
| 422 | if (value) { |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 423 | if (!strcmp(value, "slew")) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 424 | rtc_td_hack = 1; |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 425 | } else if (!strcmp(value, "none")) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 426 | rtc_td_hack = 0; |
| 427 | } else { |
| 428 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 429 | exit(1); |
| 430 | } |
| 431 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 432 | } |
| 433 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 434 | /***********************************************************/ |
| 435 | /* Bluetooth support */ |
| 436 | static int nb_hcis; |
| 437 | static int cur_hci; |
| 438 | static struct HCIInfo *hci_table[MAX_NICS]; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 439 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 440 | static struct bt_vlan_s { |
| 441 | struct bt_scatternet_s net; |
| 442 | int id; |
| 443 | struct bt_vlan_s *next; |
| 444 | } *first_bt_vlan; |
| 445 | |
| 446 | /* find or alloc a new bluetooth "VLAN" */ |
blueswir1 | 674bb26 | 2008-09-30 18:18:27 +0000 | [diff] [blame] | 447 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 448 | { |
| 449 | struct bt_vlan_s **pvlan, *vlan; |
| 450 | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { |
| 451 | if (vlan->id == id) |
| 452 | return &vlan->net; |
| 453 | } |
| 454 | vlan = qemu_mallocz(sizeof(struct bt_vlan_s)); |
| 455 | vlan->id = id; |
| 456 | pvlan = &first_bt_vlan; |
| 457 | while (*pvlan != NULL) |
| 458 | pvlan = &(*pvlan)->next; |
| 459 | *pvlan = vlan; |
| 460 | return &vlan->net; |
| 461 | } |
| 462 | |
| 463 | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) |
| 464 | { |
| 465 | } |
| 466 | |
| 467 | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) |
| 468 | { |
| 469 | return -ENOTSUP; |
| 470 | } |
| 471 | |
| 472 | static struct HCIInfo null_hci = { |
| 473 | .cmd_send = null_hci_send, |
| 474 | .sco_send = null_hci_send, |
| 475 | .acl_send = null_hci_send, |
| 476 | .bdaddr_set = null_hci_addr_set, |
| 477 | }; |
| 478 | |
| 479 | struct HCIInfo *qemu_next_hci(void) |
| 480 | { |
| 481 | if (cur_hci == nb_hcis) |
| 482 | return &null_hci; |
| 483 | |
| 484 | return hci_table[cur_hci++]; |
| 485 | } |
| 486 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 487 | static struct HCIInfo *hci_init(const char *str) |
| 488 | { |
| 489 | char *endp; |
| 490 | struct bt_scatternet_s *vlan = 0; |
| 491 | |
| 492 | if (!strcmp(str, "null")) |
| 493 | /* null */ |
| 494 | return &null_hci; |
| 495 | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) |
| 496 | /* host[:hciN] */ |
| 497 | return bt_host_hci(str[4] ? str + 5 : "hci0"); |
| 498 | else if (!strncmp(str, "hci", 3)) { |
| 499 | /* hci[,vlan=n] */ |
| 500 | if (str[3]) { |
| 501 | if (!strncmp(str + 3, ",vlan=", 6)) { |
| 502 | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); |
| 503 | if (*endp) |
| 504 | vlan = 0; |
| 505 | } |
| 506 | } else |
| 507 | vlan = qemu_find_bt_vlan(0); |
| 508 | if (vlan) |
| 509 | return bt_new_hci(vlan); |
| 510 | } |
| 511 | |
| 512 | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | static int bt_hci_parse(const char *str) |
| 518 | { |
| 519 | struct HCIInfo *hci; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 520 | bdaddr_t bdaddr; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 521 | |
| 522 | if (nb_hcis >= MAX_NICS) { |
| 523 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); |
| 524 | return -1; |
| 525 | } |
| 526 | |
| 527 | hci = hci_init(str); |
| 528 | if (!hci) |
| 529 | return -1; |
| 530 | |
| 531 | bdaddr.b[0] = 0x52; |
| 532 | bdaddr.b[1] = 0x54; |
| 533 | bdaddr.b[2] = 0x00; |
| 534 | bdaddr.b[3] = 0x12; |
| 535 | bdaddr.b[4] = 0x34; |
| 536 | bdaddr.b[5] = 0x56 + nb_hcis; |
| 537 | hci->bdaddr_set(hci, bdaddr.b); |
| 538 | |
| 539 | hci_table[nb_hcis++] = hci; |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static void bt_vhci_add(int vlan_id) |
| 545 | { |
| 546 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); |
| 547 | |
| 548 | if (!vlan->slave) |
| 549 | fprintf(stderr, "qemu: warning: adding a VHCI to " |
| 550 | "an empty scatternet %i\n", vlan_id); |
| 551 | |
| 552 | bt_vhci_init(bt_new_hci(vlan)); |
| 553 | } |
| 554 | |
| 555 | static struct bt_device_s *bt_device_add(const char *opt) |
| 556 | { |
| 557 | struct bt_scatternet_s *vlan; |
| 558 | int vlan_id = 0; |
| 559 | char *endp = strstr(opt, ",vlan="); |
| 560 | int len = (endp ? endp - opt : strlen(opt)) + 1; |
| 561 | char devname[10]; |
| 562 | |
| 563 | pstrcpy(devname, MIN(sizeof(devname), len), opt); |
| 564 | |
| 565 | if (endp) { |
| 566 | vlan_id = strtol(endp + 6, &endp, 0); |
| 567 | if (*endp) { |
| 568 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); |
| 569 | return 0; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | vlan = qemu_find_bt_vlan(vlan_id); |
| 574 | |
| 575 | if (!vlan->slave) |
| 576 | fprintf(stderr, "qemu: warning: adding a slave device to " |
| 577 | "an empty scatternet %i\n", vlan_id); |
| 578 | |
| 579 | if (!strcmp(devname, "keyboard")) |
| 580 | return bt_keyboard_init(vlan); |
| 581 | |
| 582 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | static int bt_parse(const char *opt) |
| 587 | { |
| 588 | const char *endp, *p; |
| 589 | int vlan; |
| 590 | |
| 591 | if (strstart(opt, "hci", &endp)) { |
| 592 | if (!*endp || *endp == ',') { |
| 593 | if (*endp) |
| 594 | if (!strstart(endp, ",vlan=", 0)) |
| 595 | opt = endp + 1; |
| 596 | |
| 597 | return bt_hci_parse(opt); |
| 598 | } |
| 599 | } else if (strstart(opt, "vhci", &endp)) { |
| 600 | if (!*endp || *endp == ',') { |
| 601 | if (*endp) { |
| 602 | if (strstart(endp, ",vlan=", &p)) { |
| 603 | vlan = strtol(p, (char **) &endp, 0); |
| 604 | if (*endp) { |
| 605 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); |
| 606 | return 1; |
| 607 | } |
| 608 | } else { |
| 609 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); |
| 610 | return 1; |
| 611 | } |
| 612 | } else |
| 613 | vlan = 0; |
| 614 | |
| 615 | bt_vhci_add(vlan); |
| 616 | return 0; |
| 617 | } |
| 618 | } else if (strstart(opt, "device:", &endp)) |
| 619 | return !bt_device_add(endp); |
| 620 | |
| 621 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); |
| 622 | return 1; |
| 623 | } |
| 624 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 625 | /***********************************************************/ |
| 626 | /* QEMU Block devices */ |
| 627 | |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 628 | #define HD_ALIAS "index=%d,media=disk" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 629 | #define CDROM_ALIAS "index=2,media=cdrom" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 630 | #define FD_ALIAS "index=%d,if=floppy" |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 631 | #define PFLASH_ALIAS "if=pflash" |
| 632 | #define MTD_ALIAS "if=mtd" |
balrog | 9d413d1 | 2007-12-04 00:10:34 +0000 | [diff] [blame] | 633 | #define SD_ALIAS "index=0,if=sd" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 634 | |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 635 | static int drive_init_func(QemuOpts *opts, void *opaque) |
| 636 | { |
Markus Armbruster | a803cb8 | 2010-06-02 13:31:55 +0200 | [diff] [blame] | 637 | int *use_scsi = opaque; |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 638 | int fatal_error = 0; |
| 639 | |
Markus Armbruster | a803cb8 | 2010-06-02 13:31:55 +0200 | [diff] [blame] | 640 | if (drive_init(opts, *use_scsi, &fatal_error) == NULL) { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 641 | if (fatal_error) |
| 642 | return 1; |
| 643 | } |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) |
| 648 | { |
| 649 | if (NULL == qemu_opt_get(opts, "snapshot")) { |
| 650 | qemu_opt_set(opts, "snapshot", "on"); |
| 651 | } |
| 652 | return 0; |
| 653 | } |
| 654 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 655 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
| 656 | { |
| 657 | boot_set_handler = func; |
| 658 | boot_set_opaque = opaque; |
| 659 | } |
| 660 | |
| 661 | int qemu_boot_set(const char *boot_devices) |
| 662 | { |
| 663 | if (!boot_set_handler) { |
| 664 | return -EINVAL; |
| 665 | } |
| 666 | return boot_set_handler(boot_set_opaque, boot_devices); |
| 667 | } |
| 668 | |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 669 | static void validate_bootdevices(char *devices) |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 670 | { |
| 671 | /* We just do some generic consistency checks */ |
| 672 | const char *p; |
| 673 | int bitmap = 0; |
| 674 | |
| 675 | for (p = devices; *p != '\0'; p++) { |
| 676 | /* Allowed boot devices are: |
| 677 | * a-b: floppy disk drives |
| 678 | * c-f: IDE disk drives |
| 679 | * g-m: machine implementation dependant drives |
| 680 | * n-p: network devices |
| 681 | * It's up to each machine implementation to check if the given boot |
| 682 | * devices match the actual hardware implementation and firmware |
| 683 | * features. |
| 684 | */ |
| 685 | if (*p < 'a' || *p > 'p') { |
| 686 | fprintf(stderr, "Invalid boot device '%c'\n", *p); |
| 687 | exit(1); |
| 688 | } |
| 689 | if (bitmap & (1 << (*p - 'a'))) { |
| 690 | fprintf(stderr, "Boot device '%c' was given twice\n", *p); |
| 691 | exit(1); |
| 692 | } |
| 693 | bitmap |= 1 << (*p - 'a'); |
| 694 | } |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 695 | } |
| 696 | |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 697 | static void restore_boot_devices(void *opaque) |
| 698 | { |
| 699 | char *standard_boot_devices = opaque; |
Alex Williamson | 37905d6 | 2010-04-30 15:21:11 -0600 | [diff] [blame] | 700 | static int first = 1; |
| 701 | |
| 702 | /* Restore boot order and remove ourselves after the first boot */ |
| 703 | if (first) { |
| 704 | first = 0; |
| 705 | return; |
| 706 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 707 | |
| 708 | qemu_boot_set(standard_boot_devices); |
| 709 | |
| 710 | qemu_unregister_reset(restore_boot_devices, standard_boot_devices); |
| 711 | qemu_free(standard_boot_devices); |
| 712 | } |
| 713 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 714 | static void numa_add(const char *optarg) |
| 715 | { |
| 716 | char option[128]; |
| 717 | char *endptr; |
| 718 | unsigned long long value, endvalue; |
| 719 | int nodenr; |
| 720 | |
| 721 | optarg = get_opt_name(option, 128, optarg, ',') + 1; |
| 722 | if (!strcmp(option, "node")) { |
| 723 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
| 724 | nodenr = nb_numa_nodes; |
| 725 | } else { |
| 726 | nodenr = strtoull(option, NULL, 10); |
| 727 | } |
| 728 | |
| 729 | if (get_param_value(option, 128, "mem", optarg) == 0) { |
| 730 | node_mem[nodenr] = 0; |
| 731 | } else { |
| 732 | value = strtoull(option, &endptr, 0); |
| 733 | switch (*endptr) { |
| 734 | case 0: case 'M': case 'm': |
| 735 | value <<= 20; |
| 736 | break; |
| 737 | case 'G': case 'g': |
| 738 | value <<= 30; |
| 739 | break; |
| 740 | } |
| 741 | node_mem[nodenr] = value; |
| 742 | } |
| 743 | if (get_param_value(option, 128, "cpus", optarg) == 0) { |
| 744 | node_cpumask[nodenr] = 0; |
| 745 | } else { |
| 746 | value = strtoull(option, &endptr, 10); |
| 747 | if (value >= 64) { |
| 748 | value = 63; |
| 749 | fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n"); |
| 750 | } else { |
| 751 | if (*endptr == '-') { |
| 752 | endvalue = strtoull(endptr+1, &endptr, 10); |
| 753 | if (endvalue >= 63) { |
| 754 | endvalue = 62; |
| 755 | fprintf(stderr, |
| 756 | "only 63 CPUs in NUMA mode supported.\n"); |
| 757 | } |
Paolo Bonzini | 0dfbd51 | 2010-02-04 14:31:50 +0100 | [diff] [blame] | 758 | value = (2ULL << endvalue) - (1ULL << value); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 759 | } else { |
Paolo Bonzini | 0dfbd51 | 2010-02-04 14:31:50 +0100 | [diff] [blame] | 760 | value = 1ULL << value; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | node_cpumask[nodenr] = value; |
| 764 | } |
| 765 | nb_numa_nodes++; |
| 766 | } |
| 767 | return; |
| 768 | } |
| 769 | |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 770 | static void smp_parse(const char *optarg) |
| 771 | { |
| 772 | int smp, sockets = 0, threads = 0, cores = 0; |
| 773 | char *endptr; |
| 774 | char option[128]; |
| 775 | |
| 776 | smp = strtoul(optarg, &endptr, 10); |
| 777 | if (endptr != optarg) { |
| 778 | if (*endptr == ',') { |
| 779 | endptr++; |
| 780 | } |
| 781 | } |
| 782 | if (get_param_value(option, 128, "sockets", endptr) != 0) |
| 783 | sockets = strtoull(option, NULL, 10); |
| 784 | if (get_param_value(option, 128, "cores", endptr) != 0) |
| 785 | cores = strtoull(option, NULL, 10); |
| 786 | if (get_param_value(option, 128, "threads", endptr) != 0) |
| 787 | threads = strtoull(option, NULL, 10); |
| 788 | if (get_param_value(option, 128, "maxcpus", endptr) != 0) |
| 789 | max_cpus = strtoull(option, NULL, 10); |
| 790 | |
| 791 | /* compute missing values, prefer sockets over cores over threads */ |
| 792 | if (smp == 0 || sockets == 0) { |
| 793 | sockets = sockets > 0 ? sockets : 1; |
| 794 | cores = cores > 0 ? cores : 1; |
| 795 | threads = threads > 0 ? threads : 1; |
| 796 | if (smp == 0) { |
| 797 | smp = cores * threads * sockets; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 798 | } |
| 799 | } else { |
| 800 | if (cores == 0) { |
| 801 | threads = threads > 0 ? threads : 1; |
| 802 | cores = smp / (sockets * threads); |
| 803 | } else { |
Amit Shah | 5cdc9b7 | 2010-01-13 16:24:42 +0530 | [diff] [blame] | 804 | if (sockets) { |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 805 | threads = smp / (cores * sockets); |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | smp_cpus = smp; |
| 810 | smp_cores = cores > 0 ? cores : 1; |
| 811 | smp_threads = threads > 0 ? threads : 1; |
| 812 | if (max_cpus == 0) |
| 813 | max_cpus = smp_cpus; |
| 814 | } |
| 815 | |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 816 | /***********************************************************/ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 817 | /* USB devices */ |
| 818 | |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 819 | static int usb_device_add(const char *devname) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 820 | { |
| 821 | const char *p; |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 822 | USBDevice *dev = NULL; |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 823 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 824 | if (!usb_enabled) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 825 | return -1; |
| 826 | |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 827 | /* drivers with .usbdevice_name entry in USBDeviceInfo */ |
| 828 | dev = usbdevice_create(devname); |
| 829 | if (dev) |
| 830 | goto done; |
| 831 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 832 | /* the other ones */ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 833 | if (strstart(devname, "host:", &p)) { |
| 834 | dev = usb_host_device_open(p); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 835 | } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { |
| 836 | dev = usb_bt_init(devname[2] ? hci_init(p) : |
| 837 | bt_new_hci(qemu_find_bt_vlan(0))); |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 838 | } else { |
| 839 | return -1; |
| 840 | } |
pbrook | 0d92ed3 | 2006-05-21 16:30:15 +0000 | [diff] [blame] | 841 | if (!dev) |
| 842 | return -1; |
| 843 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 844 | done: |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 845 | return 0; |
| 846 | } |
| 847 | |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 848 | static int usb_device_del(const char *devname) |
| 849 | { |
| 850 | int bus_num, addr; |
| 851 | const char *p; |
| 852 | |
aliguori | 5d0c575 | 2008-09-14 01:07:41 +0000 | [diff] [blame] | 853 | if (strstart(devname, "host:", &p)) |
| 854 | return usb_host_device_close(p); |
| 855 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 856 | if (!usb_enabled) |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 857 | return -1; |
| 858 | |
| 859 | p = strchr(devname, '.'); |
| 860 | if (!p) |
| 861 | return -1; |
| 862 | bus_num = strtoul(devname, NULL, 0); |
| 863 | addr = strtoul(p + 1, NULL, 0); |
| 864 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 865 | return usb_device_delete_addr(bus_num, addr); |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 866 | } |
| 867 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 868 | static int usb_parse(const char *cmdline) |
| 869 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 870 | int r; |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 871 | r = usb_device_add(cmdline); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 872 | if (r < 0) { |
| 873 | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline); |
| 874 | } |
| 875 | return r; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 876 | } |
| 877 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 878 | void do_usb_add(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 879 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 880 | const char *devname = qdict_get_str(qdict, "devname"); |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 881 | if (usb_device_add(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 882 | error_report("could not add USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 883 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 886 | void do_usb_del(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 887 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 888 | const char *devname = qdict_get_str(qdict, "devname"); |
| 889 | if (usb_device_del(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 890 | error_report("could not delete USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 891 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 892 | } |
| 893 | |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 894 | /***********************************************************/ |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 895 | /* PCMCIA/Cardbus */ |
| 896 | |
| 897 | static struct pcmcia_socket_entry_s { |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 898 | PCMCIASocket *socket; |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 899 | struct pcmcia_socket_entry_s *next; |
| 900 | } *pcmcia_sockets = 0; |
| 901 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 902 | void pcmcia_socket_register(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 903 | { |
| 904 | struct pcmcia_socket_entry_s *entry; |
| 905 | |
| 906 | entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s)); |
| 907 | entry->socket = socket; |
| 908 | entry->next = pcmcia_sockets; |
| 909 | pcmcia_sockets = entry; |
| 910 | } |
| 911 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 912 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 913 | { |
| 914 | struct pcmcia_socket_entry_s *entry, **ptr; |
| 915 | |
| 916 | ptr = &pcmcia_sockets; |
| 917 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) |
| 918 | if (entry->socket == socket) { |
| 919 | *ptr = entry->next; |
| 920 | qemu_free(entry); |
| 921 | } |
| 922 | } |
| 923 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 924 | void pcmcia_info(Monitor *mon) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 925 | { |
| 926 | struct pcmcia_socket_entry_s *iter; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 927 | |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 928 | if (!pcmcia_sockets) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 929 | monitor_printf(mon, "No PCMCIA sockets\n"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 930 | |
| 931 | for (iter = pcmcia_sockets; iter; iter = iter->next) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 932 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
| 933 | iter->socket->attached ? iter->socket->card_string : |
| 934 | "Empty"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | /***********************************************************/ |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 938 | /* I/O handling */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 939 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 940 | typedef struct IOHandlerRecord { |
| 941 | int fd; |
Juan Quintela | 7b27a76 | 2010-03-11 17:55:39 +0100 | [diff] [blame] | 942 | IOCanReadHandler *fd_read_poll; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 943 | IOHandler *fd_read; |
| 944 | IOHandler *fd_write; |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 945 | int deleted; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 946 | void *opaque; |
| 947 | /* temporary data */ |
| 948 | struct pollfd *ufd; |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 949 | QLIST_ENTRY(IOHandlerRecord) next; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 950 | } IOHandlerRecord; |
| 951 | |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 952 | static QLIST_HEAD(, IOHandlerRecord) io_handlers = |
| 953 | QLIST_HEAD_INITIALIZER(io_handlers); |
| 954 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 955 | |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 956 | /* XXX: fd_read_poll should be suppressed, but an API change is |
| 957 | necessary in the character devices to suppress fd_can_read(). */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 958 | int qemu_set_fd_handler2(int fd, |
Juan Quintela | 7b27a76 | 2010-03-11 17:55:39 +0100 | [diff] [blame] | 959 | IOCanReadHandler *fd_read_poll, |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 960 | IOHandler *fd_read, |
| 961 | IOHandler *fd_write, |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 962 | void *opaque) |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 963 | { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 964 | IOHandlerRecord *ioh; |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 965 | |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 966 | if (!fd_read && !fd_write) { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 967 | QLIST_FOREACH(ioh, &io_handlers, next) { |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 968 | if (ioh->fd == fd) { |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 969 | ioh->deleted = 1; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 970 | break; |
| 971 | } |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 972 | } |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 973 | } else { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 974 | QLIST_FOREACH(ioh, &io_handlers, next) { |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 975 | if (ioh->fd == fd) |
| 976 | goto found; |
| 977 | } |
| 978 | ioh = qemu_mallocz(sizeof(IOHandlerRecord)); |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 979 | QLIST_INSERT_HEAD(&io_handlers, ioh, next); |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 980 | found: |
| 981 | ioh->fd = fd; |
| 982 | ioh->fd_read_poll = fd_read_poll; |
| 983 | ioh->fd_read = fd_read; |
| 984 | ioh->fd_write = fd_write; |
| 985 | ioh->opaque = opaque; |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 986 | ioh->deleted = 0; |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 987 | } |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 988 | return 0; |
| 989 | } |
| 990 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 991 | int qemu_set_fd_handler(int fd, |
| 992 | IOHandler *fd_read, |
| 993 | IOHandler *fd_write, |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 994 | void *opaque) |
| 995 | { |
| 996 | return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque); |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 997 | } |
| 998 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 999 | /***********************************************************/ |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1000 | /* machine registration */ |
| 1001 | |
blueswir1 | bdaf78e | 2008-10-04 07:24:27 +0000 | [diff] [blame] | 1002 | static QEMUMachine *first_machine = NULL; |
aliguori | 6f338c3 | 2009-02-11 15:21:54 +0000 | [diff] [blame] | 1003 | QEMUMachine *current_machine = NULL; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1004 | |
| 1005 | int qemu_register_machine(QEMUMachine *m) |
| 1006 | { |
| 1007 | QEMUMachine **pm; |
| 1008 | pm = &first_machine; |
| 1009 | while (*pm != NULL) |
| 1010 | pm = &(*pm)->next; |
| 1011 | m->next = NULL; |
| 1012 | *pm = m; |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 1016 | static QEMUMachine *find_machine(const char *name) |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1017 | { |
| 1018 | QEMUMachine *m; |
| 1019 | |
| 1020 | for(m = first_machine; m != NULL; m = m->next) { |
| 1021 | if (!strcmp(m->name, name)) |
| 1022 | return m; |
Mark McLoughlin | 3f6599e | 2009-07-22 10:02:50 +0100 | [diff] [blame] | 1023 | if (m->alias && !strcmp(m->alias, name)) |
| 1024 | return m; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1025 | } |
| 1026 | return NULL; |
| 1027 | } |
| 1028 | |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1029 | static QEMUMachine *find_default_machine(void) |
| 1030 | { |
| 1031 | QEMUMachine *m; |
| 1032 | |
| 1033 | for(m = first_machine; m != NULL; m = m->next) { |
| 1034 | if (m->is_default) { |
| 1035 | return m; |
| 1036 | } |
| 1037 | } |
| 1038 | return NULL; |
| 1039 | } |
| 1040 | |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1041 | /***********************************************************/ |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1042 | /* main execution loop */ |
| 1043 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 1044 | static void gui_update(void *opaque) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1045 | { |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1046 | uint64_t interval = GUI_REFRESH_INTERVAL; |
ths | 740733b | 2007-06-08 01:57:56 +0000 | [diff] [blame] | 1047 | DisplayState *ds = opaque; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1048 | DisplayChangeListener *dcl = ds->listeners; |
| 1049 | |
Sheng Yang | 62a2744 | 2010-01-26 19:21:16 +0800 | [diff] [blame] | 1050 | qemu_flush_coalesced_mmio_buffer(); |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1051 | dpy_refresh(ds); |
| 1052 | |
| 1053 | while (dcl != NULL) { |
| 1054 | if (dcl->gui_timer_interval && |
| 1055 | dcl->gui_timer_interval < interval) |
| 1056 | interval = dcl->gui_timer_interval; |
| 1057 | dcl = dcl->next; |
| 1058 | } |
| 1059 | qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock)); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 1062 | static void nographic_update(void *opaque) |
| 1063 | { |
| 1064 | uint64_t interval = GUI_REFRESH_INTERVAL; |
| 1065 | |
Sheng Yang | 62a2744 | 2010-01-26 19:21:16 +0800 | [diff] [blame] | 1066 | qemu_flush_coalesced_mmio_buffer(); |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 1067 | qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock)); |
| 1068 | } |
| 1069 | |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1070 | struct vm_change_state_entry { |
| 1071 | VMChangeStateHandler *cb; |
| 1072 | void *opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1073 | QLIST_ENTRY (vm_change_state_entry) entries; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1074 | }; |
| 1075 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1076 | 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] | 1077 | |
| 1078 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
| 1079 | void *opaque) |
| 1080 | { |
| 1081 | VMChangeStateEntry *e; |
| 1082 | |
| 1083 | e = qemu_mallocz(sizeof (*e)); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1084 | |
| 1085 | e->cb = cb; |
| 1086 | e->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1087 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1088 | return e; |
| 1089 | } |
| 1090 | |
| 1091 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) |
| 1092 | { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1093 | QLIST_REMOVE (e, entries); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1094 | qemu_free (e); |
| 1095 | } |
| 1096 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 1097 | void vm_state_notify(int running, int reason) |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1098 | { |
| 1099 | VMChangeStateEntry *e; |
| 1100 | |
| 1101 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
aliguori | 9781e04 | 2009-01-22 17:15:29 +0000 | [diff] [blame] | 1102 | e->cb(e->opaque, running, reason); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1103 | } |
| 1104 | } |
| 1105 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1106 | void vm_start(void) |
| 1107 | { |
| 1108 | if (!vm_running) { |
| 1109 | cpu_enable_ticks(); |
| 1110 | vm_running = 1; |
aliguori | 9781e04 | 2009-01-22 17:15:29 +0000 | [diff] [blame] | 1111 | vm_state_notify(1, 0); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1112 | resume_all_vcpus(); |
Luiz Capitulino | 6ed2c48 | 2010-04-27 20:35:59 -0300 | [diff] [blame] | 1113 | monitor_protocol_event(QEVENT_RESUME, NULL); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1117 | /* reset/shutdown handler */ |
| 1118 | |
| 1119 | typedef struct QEMUResetEntry { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1120 | QTAILQ_ENTRY(QEMUResetEntry) entry; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1121 | QEMUResetHandler *func; |
| 1122 | void *opaque; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1123 | } QEMUResetEntry; |
| 1124 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1125 | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = |
| 1126 | QTAILQ_HEAD_INITIALIZER(reset_handlers); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1127 | static int reset_requested; |
| 1128 | static int shutdown_requested; |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1129 | static int powerdown_requested; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 1130 | int debug_requested; |
Blue Swirl | 7277e02 | 2010-04-12 17:19:06 +0000 | [diff] [blame] | 1131 | int vmstop_requested; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1132 | |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1133 | int qemu_shutdown_requested(void) |
| 1134 | { |
| 1135 | int r = shutdown_requested; |
| 1136 | shutdown_requested = 0; |
| 1137 | return r; |
| 1138 | } |
| 1139 | |
| 1140 | int qemu_reset_requested(void) |
| 1141 | { |
| 1142 | int r = reset_requested; |
| 1143 | reset_requested = 0; |
| 1144 | return r; |
| 1145 | } |
| 1146 | |
| 1147 | int qemu_powerdown_requested(void) |
| 1148 | { |
| 1149 | int r = powerdown_requested; |
| 1150 | powerdown_requested = 0; |
| 1151 | return r; |
| 1152 | } |
| 1153 | |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1154 | static int qemu_debug_requested(void) |
| 1155 | { |
| 1156 | int r = debug_requested; |
| 1157 | debug_requested = 0; |
| 1158 | return r; |
| 1159 | } |
| 1160 | |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1161 | static int qemu_vmstop_requested(void) |
| 1162 | { |
| 1163 | int r = vmstop_requested; |
| 1164 | vmstop_requested = 0; |
| 1165 | return r; |
| 1166 | } |
| 1167 | |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 1168 | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1169 | { |
Jan Kiszka | 55ddfe8 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1170 | QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry)); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1171 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1172 | re->func = func; |
| 1173 | re->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1174 | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1177 | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1178 | { |
| 1179 | QEMUResetEntry *re; |
| 1180 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1181 | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1182 | if (re->func == func && re->opaque == opaque) { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1183 | QTAILQ_REMOVE(&reset_handlers, re, entry); |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1184 | qemu_free(re); |
| 1185 | return; |
| 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | void qemu_system_reset(void) |
| 1191 | { |
| 1192 | QEMUResetEntry *re, *nre; |
| 1193 | |
| 1194 | /* reset all devices */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1195 | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1196 | re->func(re->opaque); |
| 1197 | } |
Luiz Capitulino | 81d9b78 | 2010-03-10 09:06:34 -0600 | [diff] [blame] | 1198 | monitor_protocol_event(QEVENT_RESET, NULL); |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 1199 | cpu_synchronize_all_post_reset(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | void qemu_system_reset_request(void) |
| 1203 | { |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 1204 | if (no_reboot) { |
| 1205 | shutdown_requested = 1; |
| 1206 | } else { |
| 1207 | reset_requested = 1; |
| 1208 | } |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1209 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | void qemu_system_shutdown_request(void) |
| 1213 | { |
| 1214 | shutdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1215 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1218 | void qemu_system_powerdown_request(void) |
| 1219 | { |
| 1220 | powerdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1221 | qemu_notify_event(); |
| 1222 | } |
| 1223 | |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1224 | void main_loop_wait(int nonblocking) |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1225 | { |
| 1226 | IOHandlerRecord *ioh; |
| 1227 | fd_set rfds, wfds, xfds; |
| 1228 | int ret, nfds; |
| 1229 | struct timeval tv; |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1230 | int timeout; |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1231 | |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1232 | if (nonblocking) |
| 1233 | timeout = 0; |
| 1234 | else { |
| 1235 | timeout = qemu_calculate_timeout(); |
| 1236 | qemu_bh_update_timeout(&timeout); |
| 1237 | } |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1238 | |
Jes Sorensen | 0d93ca7 | 2010-06-10 11:42:18 +0200 | [diff] [blame] | 1239 | os_host_main_loop_wait(&timeout); |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1240 | |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1241 | /* poll any events */ |
| 1242 | /* XXX: separate device handlers from system ones */ |
aliguori | 6abfbd7 | 2008-11-05 20:49:37 +0000 | [diff] [blame] | 1243 | nfds = -1; |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1244 | FD_ZERO(&rfds); |
| 1245 | FD_ZERO(&wfds); |
bellard | e035649 | 2006-05-01 13:33:02 +0000 | [diff] [blame] | 1246 | FD_ZERO(&xfds); |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1247 | QLIST_FOREACH(ioh, &io_handlers, next) { |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1248 | if (ioh->deleted) |
| 1249 | continue; |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1250 | if (ioh->fd_read && |
| 1251 | (!ioh->fd_read_poll || |
| 1252 | ioh->fd_read_poll(ioh->opaque) != 0)) { |
| 1253 | FD_SET(ioh->fd, &rfds); |
| 1254 | if (ioh->fd > nfds) |
| 1255 | nfds = ioh->fd; |
| 1256 | } |
| 1257 | if (ioh->fd_write) { |
| 1258 | FD_SET(ioh->fd, &wfds); |
| 1259 | if (ioh->fd > nfds) |
| 1260 | nfds = ioh->fd; |
| 1261 | } |
| 1262 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1263 | |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1264 | tv.tv_sec = timeout / 1000; |
| 1265 | tv.tv_usec = (timeout % 1000) * 1000; |
| 1266 | |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 1267 | slirp_select_fill(&nfds, &rfds, &wfds, &xfds); |
| 1268 | |
aliguori | 4870852 | 2009-04-24 18:03:49 +0000 | [diff] [blame] | 1269 | qemu_mutex_unlock_iothread(); |
bellard | e035649 | 2006-05-01 13:33:02 +0000 | [diff] [blame] | 1270 | ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); |
aliguori | 4870852 | 2009-04-24 18:03:49 +0000 | [diff] [blame] | 1271 | qemu_mutex_lock_iothread(); |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1272 | if (ret > 0) { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1273 | IOHandlerRecord *pioh; |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1274 | |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1275 | QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1276 | if (ioh->deleted) { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1277 | QLIST_REMOVE(ioh, next); |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1278 | qemu_free(ioh); |
Juan Quintela | 4bed983 | 2010-03-11 17:55:41 +0100 | [diff] [blame] | 1279 | continue; |
| 1280 | } |
| 1281 | if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { |
| 1282 | ioh->fd_read(ioh->opaque); |
| 1283 | } |
| 1284 | if (ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) { |
| 1285 | ioh->fd_write(ioh->opaque); |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1286 | } |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1287 | } |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1288 | } |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 1289 | |
| 1290 | slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0)); |
bellard | c20709a | 2004-04-21 23:27:19 +0000 | [diff] [blame] | 1291 | |
Paolo Bonzini | b696482 | 2010-03-10 11:38:45 +0100 | [diff] [blame] | 1292 | qemu_run_all_timers(); |
Jan Kiszka | 21d5d12 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 1293 | |
pbrook | 423f074 | 2007-05-23 00:06:54 +0000 | [diff] [blame] | 1294 | /* Check bottom-halves last in case any of the earlier events triggered |
| 1295 | them. */ |
| 1296 | qemu_bh_poll(); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1297 | |
bellard | 5905b2e | 2004-08-01 21:53:26 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1300 | static int vm_can_run(void) |
| 1301 | { |
| 1302 | if (powerdown_requested) |
| 1303 | return 0; |
| 1304 | if (reset_requested) |
| 1305 | return 0; |
| 1306 | if (shutdown_requested) |
| 1307 | return 0; |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1308 | if (debug_requested) |
| 1309 | return 0; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1310 | return 1; |
| 1311 | } |
| 1312 | |
Blue Swirl | d9c3231 | 2009-08-09 08:42:19 +0000 | [diff] [blame] | 1313 | qemu_irq qemu_system_powerdown; |
| 1314 | |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1315 | static void main_loop(void) |
| 1316 | { |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1317 | int r; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1318 | |
Blue Swirl | 7277e02 | 2010-04-12 17:19:06 +0000 | [diff] [blame] | 1319 | qemu_main_loop_start(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1320 | |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1321 | for (;;) { |
aliguori | e6e35b1 | 2009-04-24 18:03:57 +0000 | [diff] [blame] | 1322 | do { |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1323 | bool nonblocking = false; |
aliguori | e6e35b1 | 2009-04-24 18:03:57 +0000 | [diff] [blame] | 1324 | #ifdef CONFIG_PROFILER |
| 1325 | int64_t ti; |
| 1326 | #endif |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1327 | #ifndef CONFIG_IOTHREAD |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1328 | nonblocking = tcg_cpu_exec(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1329 | #endif |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1330 | #ifdef CONFIG_PROFILER |
| 1331 | ti = profile_getclock(); |
| 1332 | #endif |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1333 | main_loop_wait(nonblocking); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1334 | #ifdef CONFIG_PROFILER |
| 1335 | dev_time += profile_getclock() - ti; |
| 1336 | #endif |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1337 | } while (vm_can_run()); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1338 | |
Blue Swirl | 54fc6ea | 2010-03-29 19:23:46 +0000 | [diff] [blame] | 1339 | if ((r = qemu_debug_requested())) { |
| 1340 | vm_stop(r); |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 1341 | } |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1342 | if (qemu_shutdown_requested()) { |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 1343 | monitor_protocol_event(QEVENT_SHUTDOWN, NULL); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1344 | if (no_shutdown) { |
| 1345 | vm_stop(0); |
| 1346 | no_shutdown = 0; |
| 1347 | } else |
| 1348 | break; |
| 1349 | } |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1350 | if (qemu_reset_requested()) { |
| 1351 | pause_all_vcpus(); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1352 | qemu_system_reset(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1353 | resume_all_vcpus(); |
| 1354 | } |
Blue Swirl | d9c3231 | 2009-08-09 08:42:19 +0000 | [diff] [blame] | 1355 | if (qemu_powerdown_requested()) { |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 1356 | monitor_protocol_event(QEVENT_POWERDOWN, NULL); |
Blue Swirl | d9c3231 | 2009-08-09 08:42:19 +0000 | [diff] [blame] | 1357 | qemu_irq_raise(qemu_system_powerdown); |
| 1358 | } |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 1359 | if ((r = qemu_vmstop_requested())) { |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1360 | vm_stop(r); |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 1361 | } |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1362 | } |
MORITA Kazutaka | 2bc93fe | 2010-05-28 11:44:57 +0900 | [diff] [blame] | 1363 | bdrv_close_all(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1364 | pause_all_vcpus(); |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 1367 | static void version(void) |
| 1368 | { |
Thomas Monjalon | f75ca1a | 2010-04-28 14:42:01 +0200 | [diff] [blame] | 1369 | 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] | 1370 | } |
| 1371 | |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1372 | static void help(int exitcode) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1373 | { |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1374 | const char *options_help = |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1375 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ |
| 1376 | opt_help |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1377 | #define DEFHEADING(text) stringify(text) "\n" |
Jes Sorensen | 9f16732 | 2010-06-10 11:42:24 +0200 | [diff] [blame] | 1378 | #include "qemu-options.def" |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1379 | #undef DEF |
| 1380 | #undef DEFHEADING |
| 1381 | #undef GEN_DOCS |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1382 | ; |
| 1383 | version(); |
| 1384 | printf("usage: %s [options] [disk_image]\n" |
malc | 3f020d7 | 2010-02-08 12:04:56 +0300 | [diff] [blame] | 1385 | "\n" |
Thomas Monjalon | f75ca1a | 2010-04-28 14:42:01 +0200 | [diff] [blame] | 1386 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n" |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1387 | "\n" |
| 1388 | "%s\n" |
malc | 3f020d7 | 2010-02-08 12:04:56 +0300 | [diff] [blame] | 1389 | "During emulation, the following keys are useful:\n" |
| 1390 | "ctrl-alt-f toggle full screen\n" |
| 1391 | "ctrl-alt-n switch to virtual console 'n'\n" |
| 1392 | "ctrl-alt toggle mouse and keyboard grab\n" |
| 1393 | "\n" |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1394 | "When using -nographic, press 'ctrl-a h' to get some help.\n", |
| 1395 | "qemu", |
| 1396 | options_help); |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1397 | exit(exitcode); |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1400 | #define HAS_ARG 0x0001 |
| 1401 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1402 | typedef struct QEMUOption { |
| 1403 | const char *name; |
| 1404 | int flags; |
| 1405 | int index; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1406 | uint32_t arch_mask; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1407 | } QEMUOption; |
| 1408 | |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 1409 | static const QEMUOption qemu_options[] = { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1410 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
| 1411 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ |
| 1412 | { option, opt_arg, opt_enum, arch_mask }, |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1413 | #define DEFHEADING(text) |
Jes Sorensen | 9f16732 | 2010-06-10 11:42:24 +0200 | [diff] [blame] | 1414 | #include "qemu-options.def" |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1415 | #undef DEF |
| 1416 | #undef DEFHEADING |
| 1417 | #undef GEN_DOCS |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1418 | { NULL }, |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1419 | }; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1420 | static void select_vgahw (const char *p) |
| 1421 | { |
| 1422 | const char *opts; |
| 1423 | |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 1424 | default_vga = 0; |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1425 | vga_interface_type = VGA_NONE; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1426 | if (strstart(p, "std", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1427 | vga_interface_type = VGA_STD; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1428 | } else if (strstart(p, "cirrus", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1429 | vga_interface_type = VGA_CIRRUS; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1430 | } else if (strstart(p, "vmware", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1431 | vga_interface_type = VGA_VMWARE; |
aliguori | 94909d9 | 2009-04-22 15:19:53 +0000 | [diff] [blame] | 1432 | } else if (strstart(p, "xenfb", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1433 | vga_interface_type = VGA_XENFB; |
aliguori | 28b85ed | 2009-04-22 15:19:48 +0000 | [diff] [blame] | 1434 | } else if (!strstart(p, "none", &opts)) { |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1435 | invalid_vga: |
| 1436 | fprintf(stderr, "Unknown vga type: %s\n", p); |
| 1437 | exit(1); |
| 1438 | } |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 1439 | while (*opts) { |
| 1440 | const char *nextopt; |
| 1441 | |
| 1442 | if (strstart(opts, ",retrace=", &nextopt)) { |
| 1443 | opts = nextopt; |
| 1444 | if (strstart(opts, "dumb", &nextopt)) |
| 1445 | vga_retrace_method = VGA_RETRACE_DUMB; |
| 1446 | else if (strstart(opts, "precise", &nextopt)) |
| 1447 | vga_retrace_method = VGA_RETRACE_PRECISE; |
| 1448 | else goto invalid_vga; |
| 1449 | } else goto invalid_vga; |
| 1450 | opts = nextopt; |
| 1451 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1454 | static int balloon_parse(const char *arg) |
| 1455 | { |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1456 | QemuOpts *opts; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1457 | |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1458 | if (strcmp(arg, "none") == 0) { |
| 1459 | return 0; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1460 | } |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1461 | |
| 1462 | if (!strncmp(arg, "virtio", 6)) { |
| 1463 | if (arg[6] == ',') { |
| 1464 | /* have params -> parse them */ |
Markus Armbruster | 8212c64 | 2010-02-10 19:52:18 +0100 | [diff] [blame] | 1465 | opts = qemu_opts_parse(&qemu_device_opts, arg+7, 0); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1466 | if (!opts) |
| 1467 | return -1; |
| 1468 | } else { |
| 1469 | /* create empty opts */ |
| 1470 | opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
| 1471 | } |
| 1472 | qemu_opt_set(opts, "driver", "virtio-balloon-pci"); |
| 1473 | return 0; |
| 1474 | } |
| 1475 | |
| 1476 | return -1; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1477 | } |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1478 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1479 | char *qemu_find_file(int type, const char *name) |
| 1480 | { |
| 1481 | int len; |
| 1482 | const char *subdir; |
| 1483 | char *buf; |
| 1484 | |
| 1485 | /* If name contains path separators then try it as a straight path. */ |
| 1486 | if ((strchr(name, '/') || strchr(name, '\\')) |
| 1487 | && access(name, R_OK) == 0) { |
Jean-Christophe DUBOIS | 73ffc80 | 2009-09-02 23:59:06 +0200 | [diff] [blame] | 1488 | return qemu_strdup(name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1489 | } |
| 1490 | switch (type) { |
| 1491 | case QEMU_FILE_TYPE_BIOS: |
| 1492 | subdir = ""; |
| 1493 | break; |
| 1494 | case QEMU_FILE_TYPE_KEYMAP: |
| 1495 | subdir = "keymaps/"; |
| 1496 | break; |
| 1497 | default: |
| 1498 | abort(); |
| 1499 | } |
| 1500 | len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; |
| 1501 | buf = qemu_mallocz(len); |
Blue Swirl | 3a41759 | 2009-06-09 19:12:21 +0000 | [diff] [blame] | 1502 | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1503 | if (access(buf, R_OK)) { |
| 1504 | qemu_free(buf); |
| 1505 | return NULL; |
| 1506 | } |
| 1507 | return buf; |
| 1508 | } |
| 1509 | |
Markus Armbruster | ff952ba | 2010-01-29 19:48:57 +0100 | [diff] [blame] | 1510 | static int device_help_func(QemuOpts *opts, void *opaque) |
| 1511 | { |
| 1512 | return qdev_device_help(opts); |
| 1513 | } |
| 1514 | |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 1515 | static int device_init_func(QemuOpts *opts, void *opaque) |
| 1516 | { |
| 1517 | DeviceState *dev; |
| 1518 | |
| 1519 | dev = qdev_device_add(opts); |
| 1520 | if (!dev) |
| 1521 | return -1; |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 1525 | static int chardev_init_func(QemuOpts *opts, void *opaque) |
| 1526 | { |
| 1527 | CharDriverState *chr; |
| 1528 | |
| 1529 | chr = qemu_chr_open_opts(opts, NULL); |
| 1530 | if (!chr) |
| 1531 | return -1; |
| 1532 | return 0; |
| 1533 | } |
| 1534 | |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 1535 | #ifdef CONFIG_LINUX |
| 1536 | static int fsdev_init_func(QemuOpts *opts, void *opaque) |
| 1537 | { |
| 1538 | int ret; |
| 1539 | ret = qemu_fsdev_add(opts); |
| 1540 | |
| 1541 | return ret; |
| 1542 | } |
| 1543 | #endif |
| 1544 | |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1545 | static int mon_init_func(QemuOpts *opts, void *opaque) |
| 1546 | { |
| 1547 | CharDriverState *chr; |
| 1548 | const char *chardev; |
| 1549 | const char *mode; |
| 1550 | int flags; |
| 1551 | |
| 1552 | mode = qemu_opt_get(opts, "mode"); |
| 1553 | if (mode == NULL) { |
| 1554 | mode = "readline"; |
| 1555 | } |
| 1556 | if (strcmp(mode, "readline") == 0) { |
| 1557 | flags = MONITOR_USE_READLINE; |
| 1558 | } else if (strcmp(mode, "control") == 0) { |
| 1559 | flags = MONITOR_USE_CONTROL; |
| 1560 | } else { |
| 1561 | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); |
| 1562 | exit(1); |
| 1563 | } |
| 1564 | |
| 1565 | if (qemu_opt_get_bool(opts, "default", 0)) |
| 1566 | flags |= MONITOR_IS_DEFAULT; |
| 1567 | |
| 1568 | chardev = qemu_opt_get(opts, "chardev"); |
| 1569 | chr = qemu_chr_find(chardev); |
| 1570 | if (chr == NULL) { |
| 1571 | fprintf(stderr, "chardev \"%s\" not found\n", chardev); |
| 1572 | exit(1); |
| 1573 | } |
| 1574 | |
| 1575 | monitor_init(chr, flags); |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 1579 | static void monitor_parse(const char *optarg, const char *mode) |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1580 | { |
| 1581 | static int monitor_device_index = 0; |
| 1582 | QemuOpts *opts; |
| 1583 | const char *p; |
| 1584 | char label[32]; |
| 1585 | int def = 0; |
| 1586 | |
| 1587 | if (strstart(optarg, "chardev:", &p)) { |
| 1588 | snprintf(label, sizeof(label), "%s", p); |
| 1589 | } else { |
Jan Kiszka | 140e065 | 2010-04-06 16:55:52 +0200 | [diff] [blame] | 1590 | snprintf(label, sizeof(label), "compat_monitor%d", |
| 1591 | monitor_device_index); |
| 1592 | if (monitor_device_index == 0) { |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1593 | def = 1; |
| 1594 | } |
| 1595 | opts = qemu_chr_parse_compat(label, optarg); |
| 1596 | if (!opts) { |
| 1597 | fprintf(stderr, "parse error: %s\n", optarg); |
| 1598 | exit(1); |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | opts = qemu_opts_create(&qemu_mon_opts, label, 1); |
| 1603 | if (!opts) { |
| 1604 | fprintf(stderr, "duplicate chardev: %s\n", label); |
| 1605 | exit(1); |
| 1606 | } |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 1607 | qemu_opt_set(opts, "mode", mode); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1608 | qemu_opt_set(opts, "chardev", label); |
| 1609 | if (def) |
| 1610 | qemu_opt_set(opts, "default", "on"); |
| 1611 | monitor_device_index++; |
| 1612 | } |
| 1613 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1614 | struct device_config { |
| 1615 | enum { |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1616 | DEV_USB, /* -usbdevice */ |
| 1617 | DEV_BT, /* -bt */ |
| 1618 | DEV_SERIAL, /* -serial */ |
| 1619 | DEV_PARALLEL, /* -parallel */ |
| 1620 | DEV_VIRTCON, /* -virtioconsole */ |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 1621 | DEV_DEBUGCON, /* -debugcon */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1622 | } type; |
| 1623 | const char *cmdline; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1624 | QTAILQ_ENTRY(device_config) next; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1625 | }; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1626 | QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1627 | |
| 1628 | static void add_device_config(int type, const char *cmdline) |
| 1629 | { |
| 1630 | struct device_config *conf; |
| 1631 | |
| 1632 | conf = qemu_mallocz(sizeof(*conf)); |
| 1633 | conf->type = type; |
| 1634 | conf->cmdline = cmdline; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1635 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) |
| 1639 | { |
| 1640 | struct device_config *conf; |
| 1641 | int rc; |
| 1642 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1643 | QTAILQ_FOREACH(conf, &device_configs, next) { |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1644 | if (conf->type != type) |
| 1645 | continue; |
| 1646 | rc = func(conf->cmdline); |
| 1647 | if (0 != rc) |
| 1648 | return rc; |
| 1649 | } |
| 1650 | return 0; |
| 1651 | } |
| 1652 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 1653 | static int serial_parse(const char *devname) |
| 1654 | { |
| 1655 | static int index = 0; |
| 1656 | char label[32]; |
| 1657 | |
| 1658 | if (strcmp(devname, "none") == 0) |
| 1659 | return 0; |
| 1660 | if (index == MAX_SERIAL_PORTS) { |
| 1661 | fprintf(stderr, "qemu: too many serial ports\n"); |
| 1662 | exit(1); |
| 1663 | } |
| 1664 | snprintf(label, sizeof(label), "serial%d", index); |
| 1665 | serial_hds[index] = qemu_chr_open(label, devname, NULL); |
| 1666 | if (!serial_hds[index]) { |
| 1667 | fprintf(stderr, "qemu: could not open serial device '%s': %s\n", |
| 1668 | devname, strerror(errno)); |
| 1669 | return -1; |
| 1670 | } |
| 1671 | index++; |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 1675 | static int parallel_parse(const char *devname) |
| 1676 | { |
| 1677 | static int index = 0; |
| 1678 | char label[32]; |
| 1679 | |
| 1680 | if (strcmp(devname, "none") == 0) |
| 1681 | return 0; |
| 1682 | if (index == MAX_PARALLEL_PORTS) { |
| 1683 | fprintf(stderr, "qemu: too many parallel ports\n"); |
| 1684 | exit(1); |
| 1685 | } |
| 1686 | snprintf(label, sizeof(label), "parallel%d", index); |
| 1687 | parallel_hds[index] = qemu_chr_open(label, devname, NULL); |
| 1688 | if (!parallel_hds[index]) { |
| 1689 | fprintf(stderr, "qemu: could not open parallel device '%s': %s\n", |
| 1690 | devname, strerror(errno)); |
| 1691 | return -1; |
| 1692 | } |
| 1693 | index++; |
| 1694 | return 0; |
| 1695 | } |
| 1696 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1697 | static int virtcon_parse(const char *devname) |
| 1698 | { |
| 1699 | static int index = 0; |
| 1700 | char label[32]; |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1701 | QemuOpts *bus_opts, *dev_opts; |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1702 | |
| 1703 | if (strcmp(devname, "none") == 0) |
| 1704 | return 0; |
| 1705 | if (index == MAX_VIRTIO_CONSOLES) { |
| 1706 | fprintf(stderr, "qemu: too many virtio consoles\n"); |
| 1707 | exit(1); |
| 1708 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1709 | |
| 1710 | bus_opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
| 1711 | qemu_opt_set(bus_opts, "driver", "virtio-serial"); |
| 1712 | |
| 1713 | dev_opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
| 1714 | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
| 1715 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1716 | snprintf(label, sizeof(label), "virtcon%d", index); |
| 1717 | virtcon_hds[index] = qemu_chr_open(label, devname, NULL); |
| 1718 | if (!virtcon_hds[index]) { |
| 1719 | fprintf(stderr, "qemu: could not open virtio console '%s': %s\n", |
| 1720 | devname, strerror(errno)); |
| 1721 | return -1; |
| 1722 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1723 | qemu_opt_set(dev_opts, "chardev", label); |
| 1724 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1725 | index++; |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 1729 | static int debugcon_parse(const char *devname) |
| 1730 | { |
| 1731 | QemuOpts *opts; |
| 1732 | |
| 1733 | if (!qemu_chr_open("debugcon", devname, NULL)) { |
| 1734 | exit(1); |
| 1735 | } |
| 1736 | opts = qemu_opts_create(&qemu_device_opts, "debugcon", 1); |
| 1737 | if (!opts) { |
| 1738 | fprintf(stderr, "qemu: already have a debugcon device\n"); |
| 1739 | exit(1); |
| 1740 | } |
| 1741 | qemu_opt_set(opts, "driver", "isa-debugcon"); |
| 1742 | qemu_opt_set(opts, "chardev", "debugcon"); |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame^] | 1746 | void qemu_add_exit_notifier(Notifier *notify) |
| 1747 | { |
| 1748 | notifier_list_add(&exit_notifiers, notify); |
| 1749 | } |
| 1750 | |
| 1751 | void qemu_remove_exit_notifier(Notifier *notify) |
| 1752 | { |
| 1753 | notifier_list_remove(&exit_notifiers, notify); |
| 1754 | } |
| 1755 | |
| 1756 | static void qemu_run_exit_notifiers(void) |
| 1757 | { |
| 1758 | notifier_list_notify(&exit_notifiers); |
| 1759 | } |
| 1760 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1761 | static const QEMUOption *lookup_opt(int argc, char **argv, |
| 1762 | const char **poptarg, int *poptind) |
| 1763 | { |
| 1764 | const QEMUOption *popt; |
| 1765 | int optind = *poptind; |
| 1766 | char *r = argv[optind]; |
| 1767 | const char *optarg; |
| 1768 | |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1769 | loc_set_cmdline(argv, optind, 1); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1770 | optind++; |
| 1771 | /* Treat --foo the same as -foo. */ |
| 1772 | if (r[1] == '-') |
| 1773 | r++; |
| 1774 | popt = qemu_options; |
| 1775 | for(;;) { |
| 1776 | if (!popt->name) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1777 | error_report("invalid option"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1778 | exit(1); |
| 1779 | } |
| 1780 | if (!strcmp(popt->name, r + 1)) |
| 1781 | break; |
| 1782 | popt++; |
| 1783 | } |
| 1784 | if (popt->flags & HAS_ARG) { |
| 1785 | if (optind >= argc) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1786 | error_report("requires an argument"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1787 | exit(1); |
| 1788 | } |
| 1789 | optarg = argv[optind++]; |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1790 | loc_set_cmdline(argv, optind - 2, 2); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1791 | } else { |
| 1792 | optarg = NULL; |
| 1793 | } |
| 1794 | |
| 1795 | *poptarg = optarg; |
| 1796 | *poptind = optind; |
| 1797 | |
| 1798 | return popt; |
| 1799 | } |
| 1800 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 1801 | int main(int argc, char **argv, char **envp) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1802 | { |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 1803 | const char *gdbstub_dev = NULL; |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1804 | int i; |
Eduardo Habkost | da1fcfd | 2010-04-06 19:22:07 -0300 | [diff] [blame] | 1805 | int snapshot, linux_boot; |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 1806 | const char *icount_option = NULL; |
bellard | 7f7f987 | 2003-10-30 01:11:23 +0000 | [diff] [blame] | 1807 | const char *initrd_filename; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 1808 | const char *kernel_filename, *kernel_cmdline; |
Anthony Liguori | 195325a | 2009-10-30 12:42:29 -0500 | [diff] [blame] | 1809 | char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 1810 | DisplayState *ds; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1811 | DisplayChangeListener *dcl; |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1812 | int cyls, heads, secs, translation; |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 1813 | QemuOpts *hda_opts = NULL, *opts; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1814 | int optind; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1815 | const char *optarg; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 1816 | const char *loadvm = NULL; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1817 | QEMUMachine *machine; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1818 | const char *cpu_model; |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 1819 | int tb_size; |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 1820 | const char *pid_file = NULL; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 1821 | const char *incoming = NULL; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 1822 | int show_vnc_port = 0; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1823 | int defconfig = 1; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1824 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame^] | 1825 | atexit(qemu_run_exit_notifiers); |
Markus Armbruster | 65abca0 | 2010-02-24 14:37:14 +0100 | [diff] [blame] | 1826 | error_set_progname(argv[0]); |
| 1827 | |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 1828 | init_clocks(); |
| 1829 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 1830 | qemu_cache_utils_init(envp); |
| 1831 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1832 | QLIST_INIT (&vm_change_state_head); |
Jes Sorensen | fe98ac1 | 2010-06-10 11:42:21 +0200 | [diff] [blame] | 1833 | os_setup_early_signal_handling(); |
bellard | be995c2 | 2006-06-25 16:25:21 +0000 | [diff] [blame] | 1834 | |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 1835 | module_call_init(MODULE_INIT_MACHINE); |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1836 | machine = find_default_machine(); |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1837 | cpu_model = NULL; |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1838 | initrd_filename = NULL; |
aurel32 | 4fc5d07 | 2008-04-27 21:39:40 +0000 | [diff] [blame] | 1839 | ram_size = 0; |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 1840 | snapshot = 0; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 1841 | kernel_filename = NULL; |
| 1842 | kernel_cmdline = ""; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 1843 | cyls = heads = secs = 0; |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1844 | translation = BIOS_ATA_TRANSLATION_AUTO; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 1845 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1846 | for (i = 0; i < MAX_NODES; i++) { |
| 1847 | node_mem[i] = 0; |
| 1848 | node_cpumask[i] = 0; |
| 1849 | } |
| 1850 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1851 | nb_numa_nodes = 0; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 1852 | nb_nics = 0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1853 | |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 1854 | tb_size = 0; |
blueswir1 | 41bd639 | 2008-10-05 09:56:21 +0000 | [diff] [blame] | 1855 | autostart= 1; |
| 1856 | |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1857 | /* first pass of option parsing */ |
| 1858 | optind = 1; |
| 1859 | while (optind < argc) { |
| 1860 | if (argv[optind][0] != '-') { |
| 1861 | /* disk image */ |
Anthony Liguori | 28e68d6 | 2010-01-27 10:46:00 -0600 | [diff] [blame] | 1862 | optind++; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1863 | continue; |
| 1864 | } else { |
| 1865 | const QEMUOption *popt; |
| 1866 | |
| 1867 | popt = lookup_opt(argc, argv, &optarg, &optind); |
| 1868 | switch (popt->index) { |
| 1869 | case QEMU_OPTION_nodefconfig: |
| 1870 | defconfig=0; |
| 1871 | break; |
| 1872 | } |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | if (defconfig) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1877 | int ret; |
Markus Armbruster | cf5a65a | 2010-02-18 19:48:33 +0100 | [diff] [blame] | 1878 | |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1879 | ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); |
Kevin Wolf | 019e78b | 2010-05-17 10:36:47 +0200 | [diff] [blame] | 1880 | if (ret < 0 && ret != -ENOENT) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1881 | exit(1); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1882 | } |
| 1883 | |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1884 | ret = qemu_read_config_file(arch_config_name); |
Kevin Wolf | 019e78b | 2010-05-17 10:36:47 +0200 | [diff] [blame] | 1885 | if (ret < 0 && ret != -ENOENT) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1886 | exit(1); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1887 | } |
| 1888 | } |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 1889 | cpudef_init(); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1890 | |
| 1891 | /* second pass of option parsing */ |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1892 | optind = 1; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1893 | for(;;) { |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1894 | if (optind >= argc) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1895 | break; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1896 | if (argv[optind][0] != '-') { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1897 | hda_opts = drive_add(argv[optind++], HD_ALIAS, 0); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1898 | } else { |
| 1899 | const QEMUOption *popt; |
| 1900 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1901 | popt = lookup_opt(argc, argv, &optarg, &optind); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1902 | if (!(popt->arch_mask & arch_type)) { |
| 1903 | printf("Option %s not supported for this target\n", popt->name); |
| 1904 | exit(1); |
| 1905 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1906 | switch(popt->index) { |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1907 | case QEMU_OPTION_M: |
| 1908 | machine = find_machine(optarg); |
| 1909 | if (!machine) { |
| 1910 | QEMUMachine *m; |
| 1911 | printf("Supported machines are:\n"); |
| 1912 | for(m = first_machine; m != NULL; m = m->next) { |
Mark McLoughlin | 3f6599e | 2009-07-22 10:02:50 +0100 | [diff] [blame] | 1913 | if (m->alias) |
| 1914 | printf("%-10s %s (alias of %s)\n", |
| 1915 | m->alias, m->desc, m->name); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1916 | printf("%-10s %s%s\n", |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1917 | m->name, m->desc, |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1918 | m->is_default ? " (default)" : ""); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1919 | } |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1920 | exit(*optarg != '?'); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1921 | } |
| 1922 | break; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1923 | case QEMU_OPTION_cpu: |
| 1924 | /* hw initialization will check this */ |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1925 | if (*optarg == '?') { |
Blue Swirl | 262353c | 2010-05-04 19:55:35 +0000 | [diff] [blame] | 1926 | list_cpus(stdout, &fprintf, optarg); |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1927 | exit(0); |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1928 | } else { |
| 1929 | cpu_model = optarg; |
| 1930 | } |
| 1931 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1932 | case QEMU_OPTION_initrd: |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1933 | initrd_filename = optarg; |
| 1934 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1935 | case QEMU_OPTION_hda: |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1936 | if (cyls == 0) |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1937 | hda_opts = drive_add(optarg, HD_ALIAS, 0); |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1938 | else |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1939 | hda_opts = drive_add(optarg, HD_ALIAS |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1940 | ",cyls=%d,heads=%d,secs=%d%s", |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1941 | 0, cyls, heads, secs, |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1942 | translation == BIOS_ATA_TRANSLATION_LBA ? |
| 1943 | ",trans=lba" : |
| 1944 | translation == BIOS_ATA_TRANSLATION_NONE ? |
| 1945 | ",trans=none" : ""); |
| 1946 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1947 | case QEMU_OPTION_hdb: |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1948 | case QEMU_OPTION_hdc: |
| 1949 | case QEMU_OPTION_hdd: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1950 | drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda); |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1951 | break; |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1952 | case QEMU_OPTION_drive: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1953 | drive_add(NULL, "%s", optarg); |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1954 | break; |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 1955 | case QEMU_OPTION_set: |
| 1956 | if (qemu_set_option(optarg) != 0) |
| 1957 | exit(1); |
| 1958 | break; |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 1959 | case QEMU_OPTION_global: |
| 1960 | if (qemu_global_option(optarg) != 0) |
| 1961 | exit(1); |
| 1962 | break; |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 1963 | case QEMU_OPTION_mtdblock: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1964 | drive_add(optarg, MTD_ALIAS); |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 1965 | break; |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 1966 | case QEMU_OPTION_sd: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1967 | drive_add(optarg, SD_ALIAS); |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 1968 | break; |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 1969 | case QEMU_OPTION_pflash: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1970 | drive_add(optarg, PFLASH_ALIAS); |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 1971 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1972 | case QEMU_OPTION_snapshot: |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 1973 | snapshot = 1; |
| 1974 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1975 | case QEMU_OPTION_hdachs: |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1976 | { |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1977 | const char *p; |
| 1978 | p = optarg; |
| 1979 | cyls = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1980 | if (cyls < 1 || cyls > 16383) |
| 1981 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1982 | if (*p != ',') |
| 1983 | goto chs_fail; |
| 1984 | p++; |
| 1985 | heads = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1986 | if (heads < 1 || heads > 16) |
| 1987 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1988 | if (*p != ',') |
| 1989 | goto chs_fail; |
| 1990 | p++; |
| 1991 | secs = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1992 | if (secs < 1 || secs > 63) |
| 1993 | goto chs_fail; |
| 1994 | if (*p == ',') { |
| 1995 | p++; |
| 1996 | if (!strcmp(p, "none")) |
| 1997 | translation = BIOS_ATA_TRANSLATION_NONE; |
| 1998 | else if (!strcmp(p, "lba")) |
| 1999 | translation = BIOS_ATA_TRANSLATION_LBA; |
| 2000 | else if (!strcmp(p, "auto")) |
| 2001 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2002 | else |
| 2003 | goto chs_fail; |
| 2004 | } else if (*p != '\0') { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2005 | chs_fail: |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2006 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
| 2007 | exit(1); |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2008 | } |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 2009 | if (hda_opts != NULL) { |
| 2010 | char num[16]; |
| 2011 | snprintf(num, sizeof(num), "%d", cyls); |
| 2012 | qemu_opt_set(hda_opts, "cyls", num); |
| 2013 | snprintf(num, sizeof(num), "%d", heads); |
| 2014 | qemu_opt_set(hda_opts, "heads", num); |
| 2015 | snprintf(num, sizeof(num), "%d", secs); |
| 2016 | qemu_opt_set(hda_opts, "secs", num); |
| 2017 | if (translation == BIOS_ATA_TRANSLATION_LBA) |
| 2018 | qemu_opt_set(hda_opts, "trans", "lba"); |
| 2019 | if (translation == BIOS_ATA_TRANSLATION_NONE) |
| 2020 | qemu_opt_set(hda_opts, "trans", "none"); |
| 2021 | } |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2022 | } |
| 2023 | break; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2024 | case QEMU_OPTION_numa: |
| 2025 | if (nb_numa_nodes >= MAX_NODES) { |
| 2026 | fprintf(stderr, "qemu: too many NUMA nodes\n"); |
| 2027 | exit(1); |
| 2028 | } |
| 2029 | numa_add(optarg); |
| 2030 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2031 | case QEMU_OPTION_nographic: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2032 | display_type = DT_NOGRAPHIC; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2033 | break; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 2034 | #ifdef CONFIG_CURSES |
| 2035 | case QEMU_OPTION_curses: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2036 | display_type = DT_CURSES; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 2037 | break; |
| 2038 | #endif |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 2039 | case QEMU_OPTION_portrait: |
| 2040 | graphic_rotate = 1; |
| 2041 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2042 | case QEMU_OPTION_kernel: |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2043 | kernel_filename = optarg; |
| 2044 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2045 | case QEMU_OPTION_append: |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2046 | kernel_cmdline = optarg; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 2047 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2048 | case QEMU_OPTION_cdrom: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 2049 | drive_add(optarg, CDROM_ALIAS); |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 2050 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2051 | case QEMU_OPTION_boot: |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 2052 | { |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2053 | static const char * const params[] = { |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2054 | "order", "once", "menu", NULL |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2055 | }; |
| 2056 | char buf[sizeof(boot_devices)]; |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2057 | char *standard_boot_devices; |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2058 | int legacy = 0; |
| 2059 | |
| 2060 | if (!strchr(optarg, '=')) { |
| 2061 | legacy = 1; |
| 2062 | pstrcpy(buf, sizeof(buf), optarg); |
| 2063 | } else if (check_params(buf, sizeof(buf), params, optarg) < 0) { |
| 2064 | fprintf(stderr, |
| 2065 | "qemu: unknown boot parameter '%s' in '%s'\n", |
| 2066 | buf, optarg); |
| 2067 | exit(1); |
| 2068 | } |
| 2069 | |
| 2070 | if (legacy || |
| 2071 | get_param_value(buf, sizeof(buf), "order", optarg)) { |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 2072 | validate_bootdevices(buf); |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2073 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 2074 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2075 | if (!legacy) { |
| 2076 | if (get_param_value(buf, sizeof(buf), |
| 2077 | "once", optarg)) { |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 2078 | validate_bootdevices(buf); |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2079 | standard_boot_devices = qemu_strdup(boot_devices); |
| 2080 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
| 2081 | qemu_register_reset(restore_boot_devices, |
| 2082 | standard_boot_devices); |
| 2083 | } |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2084 | if (get_param_value(buf, sizeof(buf), |
| 2085 | "menu", optarg)) { |
| 2086 | if (!strcmp(buf, "on")) { |
| 2087 | boot_menu = 1; |
| 2088 | } else if (!strcmp(buf, "off")) { |
| 2089 | boot_menu = 0; |
| 2090 | } else { |
| 2091 | fprintf(stderr, |
| 2092 | "qemu: invalid option value '%s'\n", |
| 2093 | buf); |
| 2094 | exit(1); |
| 2095 | } |
| 2096 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2097 | } |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 2098 | } |
| 2099 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2100 | case QEMU_OPTION_fda: |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2101 | case QEMU_OPTION_fdb: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 2102 | drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda); |
bellard | c45886d | 2004-01-05 00:02:06 +0000 | [diff] [blame] | 2103 | break; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 2104 | case QEMU_OPTION_no_fd_bootchk: |
| 2105 | fd_bootchk = 0; |
| 2106 | break; |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 2107 | case QEMU_OPTION_netdev: |
| 2108 | if (net_client_parse(&qemu_netdev_opts, optarg) == -1) { |
| 2109 | exit(1); |
| 2110 | } |
| 2111 | break; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 2112 | case QEMU_OPTION_net: |
Mark McLoughlin | 7f161aa | 2009-10-08 19:58:25 +0100 | [diff] [blame] | 2113 | if (net_client_parse(&qemu_net_opts, optarg) == -1) { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2114 | exit(1); |
| 2115 | } |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 2116 | break; |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 2117 | #ifdef CONFIG_SLIRP |
| 2118 | case QEMU_OPTION_tftp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 2119 | legacy_tftp_prefix = optarg; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2120 | break; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 2121 | case QEMU_OPTION_bootp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 2122 | legacy_bootp_filename = optarg; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 2123 | break; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2124 | case QEMU_OPTION_redir: |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 2125 | if (net_slirp_redir(optarg) < 0) |
| 2126 | exit(1); |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2127 | break; |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 2128 | #endif |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2129 | case QEMU_OPTION_bt: |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2130 | add_device_config(DEV_BT, optarg); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2131 | break; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2132 | case QEMU_OPTION_audio_help: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2133 | if (!(audio_available())) { |
| 2134 | printf("Option %s not supported for this target\n", popt->name); |
| 2135 | exit(1); |
| 2136 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2137 | AUD_help (); |
| 2138 | exit (0); |
| 2139 | break; |
| 2140 | case QEMU_OPTION_soundhw: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2141 | if (!(audio_available())) { |
| 2142 | printf("Option %s not supported for this target\n", popt->name); |
| 2143 | exit(1); |
| 2144 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2145 | select_soundhw (optarg); |
| 2146 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2147 | case QEMU_OPTION_h: |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 2148 | help(0); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2149 | break; |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 2150 | case QEMU_OPTION_version: |
| 2151 | version(); |
| 2152 | exit(0); |
| 2153 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2154 | case QEMU_OPTION_m: { |
| 2155 | uint64_t value; |
| 2156 | char *ptr; |
| 2157 | |
| 2158 | value = strtoul(optarg, &ptr, 10); |
| 2159 | switch (*ptr) { |
| 2160 | case 0: case 'M': case 'm': |
| 2161 | value <<= 20; |
| 2162 | break; |
| 2163 | case 'G': case 'g': |
| 2164 | value <<= 30; |
| 2165 | break; |
| 2166 | default: |
| 2167 | fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2168 | exit(1); |
| 2169 | } |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2170 | |
| 2171 | /* On 32-bit hosts, QEMU is limited by virtual address space */ |
Anthony Liguori | 4a1418e | 2009-08-10 17:07:24 -0500 | [diff] [blame] | 2172 | if (value > (2047 << 20) && HOST_LONG_BITS == 32) { |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2173 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n"); |
| 2174 | exit(1); |
| 2175 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2176 | if (value != (uint64_t)(ram_addr_t)value) { |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2177 | fprintf(stderr, "qemu: ram size too large\n"); |
| 2178 | exit(1); |
| 2179 | } |
| 2180 | ram_size = value; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2181 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2182 | } |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 2183 | case QEMU_OPTION_mempath: |
| 2184 | mem_path = optarg; |
| 2185 | break; |
| 2186 | #ifdef MAP_POPULATE |
| 2187 | case QEMU_OPTION_mem_prealloc: |
| 2188 | mem_prealloc = 1; |
| 2189 | break; |
| 2190 | #endif |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2191 | case QEMU_OPTION_d: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2192 | set_cpu_log(optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2193 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2194 | case QEMU_OPTION_s: |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 2195 | gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2196 | break; |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 2197 | case QEMU_OPTION_gdb: |
| 2198 | gdbstub_dev = optarg; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2199 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2200 | case QEMU_OPTION_L: |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2201 | data_dir = optarg; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2202 | break; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 2203 | case QEMU_OPTION_bios: |
| 2204 | bios_name = optarg; |
| 2205 | break; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 2206 | case QEMU_OPTION_singlestep: |
| 2207 | singlestep = 1; |
| 2208 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2209 | case QEMU_OPTION_S: |
pbrook | 3c07f8e | 2007-01-21 16:47:01 +0000 | [diff] [blame] | 2210 | autostart = 0; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2211 | break; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 2212 | case QEMU_OPTION_k: |
| 2213 | keyboard_layout = optarg; |
| 2214 | break; |
bellard | ee22c2f | 2004-06-03 12:49:50 +0000 | [diff] [blame] | 2215 | case QEMU_OPTION_localtime: |
| 2216 | rtc_utc = 0; |
| 2217 | break; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2218 | case QEMU_OPTION_vga: |
| 2219 | select_vgahw (optarg); |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 2220 | break; |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2221 | case QEMU_OPTION_g: |
| 2222 | { |
| 2223 | const char *p; |
| 2224 | int w, h, depth; |
| 2225 | p = optarg; |
| 2226 | w = strtol(p, (char **)&p, 10); |
| 2227 | if (w <= 0) { |
| 2228 | graphic_error: |
| 2229 | fprintf(stderr, "qemu: invalid resolution or depth\n"); |
| 2230 | exit(1); |
| 2231 | } |
| 2232 | if (*p != 'x') |
| 2233 | goto graphic_error; |
| 2234 | p++; |
| 2235 | h = strtol(p, (char **)&p, 10); |
| 2236 | if (h <= 0) |
| 2237 | goto graphic_error; |
| 2238 | if (*p == 'x') { |
| 2239 | p++; |
| 2240 | depth = strtol(p, (char **)&p, 10); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2241 | if (depth != 8 && depth != 15 && depth != 16 && |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2242 | depth != 24 && depth != 32) |
| 2243 | goto graphic_error; |
| 2244 | } else if (*p == '\0') { |
| 2245 | depth = graphic_depth; |
| 2246 | } else { |
| 2247 | goto graphic_error; |
| 2248 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2249 | |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2250 | graphic_width = w; |
| 2251 | graphic_height = h; |
| 2252 | graphic_depth = depth; |
| 2253 | } |
| 2254 | break; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 2255 | case QEMU_OPTION_echr: |
| 2256 | { |
| 2257 | char *r; |
| 2258 | term_escape_char = strtol(optarg, &r, 0); |
| 2259 | if (r == optarg) |
| 2260 | printf("Bad argument to echr\n"); |
| 2261 | break; |
| 2262 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2263 | case QEMU_OPTION_monitor: |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2264 | monitor_parse(optarg, "readline"); |
| 2265 | default_monitor = 0; |
| 2266 | break; |
| 2267 | case QEMU_OPTION_qmp: |
| 2268 | monitor_parse(optarg, "control"); |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 2269 | default_monitor = 0; |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2270 | break; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2271 | case QEMU_OPTION_mon: |
Markus Armbruster | 8212c64 | 2010-02-10 19:52:18 +0100 | [diff] [blame] | 2272 | opts = qemu_opts_parse(&qemu_mon_opts, optarg, 1); |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2273 | if (!opts) { |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2274 | exit(1); |
| 2275 | } |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 2276 | default_monitor = 0; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2277 | break; |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2278 | case QEMU_OPTION_chardev: |
Markus Armbruster | 8212c64 | 2010-02-10 19:52:18 +0100 | [diff] [blame] | 2279 | opts = qemu_opts_parse(&qemu_chardev_opts, optarg, 1); |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2280 | if (!opts) { |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2281 | exit(1); |
| 2282 | } |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2283 | break; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2284 | #ifdef CONFIG_LINUX |
| 2285 | case QEMU_OPTION_fsdev: |
| 2286 | opts = qemu_opts_parse(&qemu_fsdev_opts, optarg, 1); |
| 2287 | if (!opts) { |
| 2288 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2289 | exit(1); |
| 2290 | } |
| 2291 | break; |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2292 | case QEMU_OPTION_virtfs: { |
| 2293 | char *arg_fsdev = NULL; |
| 2294 | char *arg_9p = NULL; |
| 2295 | int len = 0; |
| 2296 | |
| 2297 | opts = qemu_opts_parse(&qemu_virtfs_opts, optarg, 1); |
| 2298 | if (!opts) { |
| 2299 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2300 | exit(1); |
| 2301 | } |
| 2302 | |
| 2303 | len = strlen(",id=,path="); |
| 2304 | len += strlen(qemu_opt_get(opts, "fstype")); |
| 2305 | len += strlen(qemu_opt_get(opts, "mount_tag")); |
| 2306 | len += strlen(qemu_opt_get(opts, "path")); |
| 2307 | arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev)); |
| 2308 | |
| 2309 | if (!arg_fsdev) { |
| 2310 | fprintf(stderr, "No memory to parse -fsdev for %s\n", |
| 2311 | optarg); |
| 2312 | exit(1); |
| 2313 | } |
| 2314 | |
| 2315 | sprintf(arg_fsdev, "%s,id=%s,path=%s", |
| 2316 | qemu_opt_get(opts, "fstype"), |
| 2317 | qemu_opt_get(opts, "mount_tag"), |
| 2318 | qemu_opt_get(opts, "path")); |
| 2319 | |
| 2320 | len = strlen("virtio-9p-pci,fsdev=,mount_tag="); |
| 2321 | len += 2*strlen(qemu_opt_get(opts, "mount_tag")); |
| 2322 | arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p)); |
| 2323 | |
| 2324 | if (!arg_9p) { |
| 2325 | fprintf(stderr, "No memory to parse -device for %s\n", |
| 2326 | optarg); |
| 2327 | exit(1); |
| 2328 | } |
| 2329 | |
| 2330 | sprintf(arg_9p, "virtio-9p-pci,fsdev=%s,mount_tag=%s", |
| 2331 | qemu_opt_get(opts, "mount_tag"), |
| 2332 | qemu_opt_get(opts, "mount_tag")); |
| 2333 | |
| 2334 | if (!qemu_opts_parse(&qemu_fsdev_opts, arg_fsdev, 1)) { |
| 2335 | fprintf(stderr, "parse error [fsdev]: %s\n", optarg); |
| 2336 | exit(1); |
| 2337 | } |
| 2338 | |
| 2339 | if (!qemu_opts_parse(&qemu_device_opts, arg_9p, 1)) { |
| 2340 | fprintf(stderr, "parse error [device]: %s\n", optarg); |
| 2341 | exit(1); |
| 2342 | } |
| 2343 | |
| 2344 | qemu_free(arg_fsdev); |
| 2345 | qemu_free(arg_9p); |
| 2346 | break; |
| 2347 | } |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2348 | #endif |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2349 | case QEMU_OPTION_serial: |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2350 | add_device_config(DEV_SERIAL, optarg); |
| 2351 | default_serial = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2352 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2353 | default_monitor = 0; |
| 2354 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2355 | break; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 2356 | case QEMU_OPTION_watchdog: |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 2357 | if (watchdog) { |
| 2358 | fprintf(stderr, |
| 2359 | "qemu: only one watchdog option may be given\n"); |
| 2360 | return 1; |
| 2361 | } |
| 2362 | watchdog = optarg; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 2363 | break; |
| 2364 | case QEMU_OPTION_watchdog_action: |
| 2365 | if (select_watchdog_action(optarg) == -1) { |
| 2366 | fprintf(stderr, "Unknown -watchdog-action parameter\n"); |
| 2367 | exit(1); |
| 2368 | } |
| 2369 | break; |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 2370 | case QEMU_OPTION_virtiocon: |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2371 | add_device_config(DEV_VIRTCON, optarg); |
| 2372 | default_virtcon = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2373 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2374 | default_monitor = 0; |
| 2375 | } |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 2376 | break; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 2377 | case QEMU_OPTION_parallel: |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2378 | add_device_config(DEV_PARALLEL, optarg); |
| 2379 | default_parallel = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2380 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2381 | default_monitor = 0; |
| 2382 | } |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 2383 | break; |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2384 | case QEMU_OPTION_debugcon: |
| 2385 | add_device_config(DEV_DEBUGCON, optarg); |
| 2386 | break; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 2387 | case QEMU_OPTION_loadvm: |
| 2388 | loadvm = optarg; |
| 2389 | break; |
| 2390 | case QEMU_OPTION_full_screen: |
| 2391 | full_screen = 1; |
| 2392 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2393 | #ifdef CONFIG_SDL |
ths | 43523e9 | 2007-02-18 18:19:32 +0000 | [diff] [blame] | 2394 | case QEMU_OPTION_no_frame: |
| 2395 | no_frame = 1; |
| 2396 | break; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 2397 | case QEMU_OPTION_alt_grab: |
| 2398 | alt_grab = 1; |
| 2399 | break; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 2400 | case QEMU_OPTION_ctrl_grab: |
| 2401 | ctrl_grab = 1; |
| 2402 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2403 | case QEMU_OPTION_no_quit: |
| 2404 | no_quit = 1; |
| 2405 | break; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2406 | case QEMU_OPTION_sdl: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2407 | display_type = DT_SDL; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2408 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2409 | #endif |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 2410 | case QEMU_OPTION_pidfile: |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 2411 | pid_file = optarg; |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 2412 | break; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 2413 | case QEMU_OPTION_win2k_hack: |
| 2414 | win2k_install_hack = 1; |
| 2415 | break; |
aliguori | 73822ec | 2009-01-15 20:11:34 +0000 | [diff] [blame] | 2416 | case QEMU_OPTION_rtc_td_hack: |
| 2417 | rtc_td_hack = 1; |
| 2418 | break; |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 2419 | case QEMU_OPTION_acpitable: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2420 | do_acpitable_option(optarg); |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 2421 | break; |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 2422 | case QEMU_OPTION_smbios: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2423 | do_smbios_option(optarg); |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 2424 | break; |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2425 | case QEMU_OPTION_enable_kvm: |
| 2426 | kvm_allowed = 1; |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2427 | break; |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 2428 | case QEMU_OPTION_usb: |
| 2429 | usb_enabled = 1; |
| 2430 | break; |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 2431 | case QEMU_OPTION_usbdevice: |
| 2432 | usb_enabled = 1; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2433 | add_device_config(DEV_USB, optarg); |
| 2434 | break; |
| 2435 | case QEMU_OPTION_device: |
Markus Armbruster | 8212c64 | 2010-02-10 19:52:18 +0100 | [diff] [blame] | 2436 | if (!qemu_opts_parse(&qemu_device_opts, optarg, 1)) { |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 2437 | exit(1); |
| 2438 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 2439 | break; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2440 | case QEMU_OPTION_smp: |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 2441 | smp_parse(optarg); |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 2442 | if (smp_cpus < 1) { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2443 | fprintf(stderr, "Invalid number of CPUs\n"); |
| 2444 | exit(1); |
| 2445 | } |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 2446 | if (max_cpus < smp_cpus) { |
| 2447 | fprintf(stderr, "maxcpus must be equal to or greater than " |
| 2448 | "smp\n"); |
| 2449 | exit(1); |
| 2450 | } |
| 2451 | if (max_cpus > 255) { |
| 2452 | fprintf(stderr, "Unsupported number of maxcpus\n"); |
| 2453 | exit(1); |
| 2454 | } |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2455 | break; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 2456 | case QEMU_OPTION_vnc: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2457 | display_type = DT_VNC; |
ths | 73fc974 | 2006-12-22 02:09:07 +0000 | [diff] [blame] | 2458 | vnc_display = optarg; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 2459 | break; |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 2460 | case QEMU_OPTION_no_acpi: |
| 2461 | acpi_enabled = 0; |
| 2462 | break; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 2463 | case QEMU_OPTION_no_hpet: |
| 2464 | no_hpet = 1; |
| 2465 | break; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 2466 | case QEMU_OPTION_balloon: |
| 2467 | if (balloon_parse(optarg) < 0) { |
| 2468 | fprintf(stderr, "Unknown -balloon argument %s\n", optarg); |
| 2469 | exit(1); |
| 2470 | } |
Eduardo Habkost | df97b92 | 2009-06-10 16:34:08 -0300 | [diff] [blame] | 2471 | break; |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 2472 | case QEMU_OPTION_no_reboot: |
| 2473 | no_reboot = 1; |
| 2474 | break; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 2475 | case QEMU_OPTION_no_shutdown: |
| 2476 | no_shutdown = 1; |
| 2477 | break; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 2478 | case QEMU_OPTION_show_cursor: |
| 2479 | cursor_hide = 0; |
| 2480 | break; |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 2481 | case QEMU_OPTION_uuid: |
| 2482 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { |
| 2483 | fprintf(stderr, "Fail to parse UUID string." |
| 2484 | " Wrong format.\n"); |
| 2485 | exit(1); |
| 2486 | } |
| 2487 | break; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 2488 | case QEMU_OPTION_option_rom: |
| 2489 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
| 2490 | fprintf(stderr, "Too many option ROMs\n"); |
| 2491 | exit(1); |
| 2492 | } |
| 2493 | option_rom[nb_option_roms] = optarg; |
| 2494 | nb_option_roms++; |
| 2495 | break; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 2496 | case QEMU_OPTION_semihosting: |
| 2497 | semihosting_enabled = 1; |
| 2498 | break; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 2499 | case QEMU_OPTION_name: |
Andi Kleen | 1889465 | 2009-07-02 09:34:17 +0200 | [diff] [blame] | 2500 | qemu_name = qemu_strdup(optarg); |
| 2501 | { |
| 2502 | char *p = strchr(qemu_name, ','); |
| 2503 | if (p != NULL) { |
| 2504 | *p++ = 0; |
| 2505 | if (strncmp(p, "process=", 8)) { |
| 2506 | fprintf(stderr, "Unknown subargument %s to -name", p); |
| 2507 | exit(1); |
| 2508 | } |
| 2509 | p += 8; |
Jes Sorensen | ce798cf | 2010-06-10 11:42:31 +0200 | [diff] [blame] | 2510 | os_set_proc_name(p); |
Andi Kleen | 1889465 | 2009-07-02 09:34:17 +0200 | [diff] [blame] | 2511 | } |
| 2512 | } |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 2513 | break; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 2514 | case QEMU_OPTION_prom_env: |
| 2515 | if (nb_prom_envs >= MAX_PROM_ENVS) { |
| 2516 | fprintf(stderr, "Too many prom variables\n"); |
| 2517 | exit(1); |
| 2518 | } |
| 2519 | prom_envs[nb_prom_envs] = optarg; |
| 2520 | nb_prom_envs++; |
| 2521 | break; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 2522 | case QEMU_OPTION_old_param: |
| 2523 | old_param = 1; |
ths | 05ebd53 | 2008-01-08 19:32:16 +0000 | [diff] [blame] | 2524 | break; |
ths | f3dcfad | 2007-08-24 01:26:02 +0000 | [diff] [blame] | 2525 | case QEMU_OPTION_clock: |
| 2526 | configure_alarms(optarg); |
| 2527 | break; |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 2528 | case QEMU_OPTION_startdate: |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2529 | configure_rtc_date_offset(optarg, 1); |
| 2530 | break; |
| 2531 | case QEMU_OPTION_rtc: |
Markus Armbruster | 8212c64 | 2010-02-10 19:52:18 +0100 | [diff] [blame] | 2532 | opts = qemu_opts_parse(&qemu_rtc_opts, optarg, 0); |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2533 | if (!opts) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2534 | exit(1); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 2535 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2536 | configure_rtc(opts); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 2537 | break; |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 2538 | case QEMU_OPTION_tb_size: |
| 2539 | tb_size = strtol(optarg, NULL, 0); |
| 2540 | if (tb_size < 0) |
| 2541 | tb_size = 0; |
| 2542 | break; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 2543 | case QEMU_OPTION_icount: |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 2544 | icount_option = optarg; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 2545 | break; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 2546 | case QEMU_OPTION_incoming: |
| 2547 | incoming = optarg; |
| 2548 | break; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 2549 | case QEMU_OPTION_nodefaults: |
| 2550 | default_serial = 0; |
| 2551 | default_parallel = 0; |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2552 | default_virtcon = 0; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 2553 | default_monitor = 0; |
| 2554 | default_vga = 0; |
Gerd Hoffmann | cb4522c | 2009-12-08 13:11:47 +0100 | [diff] [blame] | 2555 | default_net = 0; |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2556 | default_floppy = 0; |
| 2557 | default_cdrom = 0; |
| 2558 | default_sdcard = 0; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 2559 | break; |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2560 | case QEMU_OPTION_xen_domid: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2561 | if (!(xen_available())) { |
| 2562 | printf("Option %s not supported for this target\n", popt->name); |
| 2563 | exit(1); |
| 2564 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2565 | xen_domid = atoi(optarg); |
| 2566 | break; |
| 2567 | case QEMU_OPTION_xen_create: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2568 | if (!(xen_available())) { |
| 2569 | printf("Option %s not supported for this target\n", popt->name); |
| 2570 | exit(1); |
| 2571 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2572 | xen_mode = XEN_CREATE; |
| 2573 | break; |
| 2574 | case QEMU_OPTION_xen_attach: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2575 | if (!(xen_available())) { |
| 2576 | printf("Option %s not supported for this target\n", popt->name); |
| 2577 | exit(1); |
| 2578 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2579 | xen_mode = XEN_ATTACH; |
| 2580 | break; |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 2581 | case QEMU_OPTION_readconfig: |
| 2582 | { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 2583 | int ret = qemu_read_config_file(optarg); |
| 2584 | if (ret < 0) { |
| 2585 | fprintf(stderr, "read config %s: %s\n", optarg, |
| 2586 | strerror(-ret)); |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 2587 | exit(1); |
| 2588 | } |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 2589 | break; |
| 2590 | } |
| 2591 | case QEMU_OPTION_writeconfig: |
| 2592 | { |
| 2593 | FILE *fp; |
| 2594 | if (strcmp(optarg, "-") == 0) { |
| 2595 | fp = stdout; |
| 2596 | } else { |
| 2597 | fp = fopen(optarg, "w"); |
| 2598 | if (fp == NULL) { |
| 2599 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); |
| 2600 | exit(1); |
| 2601 | } |
| 2602 | } |
| 2603 | qemu_config_write(fp); |
| 2604 | fclose(fp); |
| 2605 | break; |
| 2606 | } |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 2607 | default: |
| 2608 | os_parse_cmd_args(popt->index, optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2609 | } |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2610 | } |
| 2611 | } |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2612 | loc_set_none(); |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2613 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2614 | /* If no data_dir is specified then try to find it relative to the |
| 2615 | executable path. */ |
| 2616 | if (!data_dir) { |
Jes Sorensen | 6170540 | 2010-06-10 11:42:23 +0200 | [diff] [blame] | 2617 | data_dir = os_find_datadir(argv[0]); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2618 | } |
| 2619 | /* If all else fails use the install patch specified when building. */ |
| 2620 | if (!data_dir) { |
Paolo Bonzini | 1dabe05 | 2010-05-26 16:08:25 +0200 | [diff] [blame] | 2621 | data_dir = CONFIG_QEMU_DATADIR; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2622 | } |
| 2623 | |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 2624 | /* |
| 2625 | * Default to max_cpus = smp_cpus, in case the user doesn't |
| 2626 | * specify a max_cpus value. |
| 2627 | */ |
| 2628 | if (!max_cpus) |
| 2629 | max_cpus = smp_cpus; |
| 2630 | |
balrog | 3d878ca | 2008-10-28 10:59:59 +0000 | [diff] [blame] | 2631 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 2632 | if (smp_cpus > machine->max_cpus) { |
| 2633 | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " |
| 2634 | "supported by machine `%s' (%d)\n", smp_cpus, machine->name, |
| 2635 | machine->max_cpus); |
| 2636 | exit(1); |
| 2637 | } |
| 2638 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2639 | qemu_opts_foreach(&qemu_device_opts, default_driver_check, NULL, 0); |
Gerd Hoffmann | d8bcbab | 2009-12-16 14:25:40 +0100 | [diff] [blame] | 2640 | qemu_opts_foreach(&qemu_global_opts, default_driver_check, NULL, 0); |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2641 | |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2642 | if (machine->no_serial) { |
| 2643 | default_serial = 0; |
| 2644 | } |
| 2645 | if (machine->no_parallel) { |
| 2646 | default_parallel = 0; |
| 2647 | } |
| 2648 | if (!machine->use_virtcon) { |
| 2649 | default_virtcon = 0; |
| 2650 | } |
| 2651 | if (machine->no_vga) { |
| 2652 | default_vga = 0; |
| 2653 | } |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2654 | if (machine->no_floppy) { |
| 2655 | default_floppy = 0; |
| 2656 | } |
| 2657 | if (machine->no_cdrom) { |
| 2658 | default_cdrom = 0; |
| 2659 | } |
| 2660 | if (machine->no_sdcard) { |
| 2661 | default_sdcard = 0; |
| 2662 | } |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2663 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2664 | if (display_type == DT_NOGRAPHIC) { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2665 | if (default_parallel) |
| 2666 | add_device_config(DEV_PARALLEL, "null"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2667 | if (default_serial && default_monitor) { |
| 2668 | add_device_config(DEV_SERIAL, "mon:stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2669 | } else if (default_virtcon && default_monitor) { |
| 2670 | add_device_config(DEV_VIRTCON, "mon:stdio"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2671 | } else { |
| 2672 | if (default_serial) |
| 2673 | add_device_config(DEV_SERIAL, "stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2674 | if (default_virtcon) |
| 2675 | add_device_config(DEV_VIRTCON, "stdio"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2676 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2677 | monitor_parse("stdio", "readline"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2678 | } |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2679 | } else { |
| 2680 | if (default_serial) |
| 2681 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2682 | if (default_parallel) |
| 2683 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 2684 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2685 | monitor_parse("vc:80Cx24C", "readline"); |
Alexander Graf | 38536da | 2009-12-17 13:06:08 +0100 | [diff] [blame] | 2686 | if (default_virtcon) |
| 2687 | add_device_config(DEV_VIRTCON, "vc:80Cx24C"); |
aliguori | bc0129d | 2008-08-01 15:12:34 +0000 | [diff] [blame] | 2688 | } |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 2689 | if (default_vga) |
| 2690 | vga_interface_type = VGA_CIRRUS; |
aliguori | bc0129d | 2008-08-01 15:12:34 +0000 | [diff] [blame] | 2691 | |
TeLeMan | a5829fd | 2010-04-15 12:37:55 +0800 | [diff] [blame] | 2692 | socket_init(); |
| 2693 | |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 2694 | if (qemu_opts_foreach(&qemu_chardev_opts, chardev_init_func, NULL, 1) != 0) |
| 2695 | exit(1); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2696 | #ifdef CONFIG_LINUX |
| 2697 | if (qemu_opts_foreach(&qemu_fsdev_opts, fsdev_init_func, NULL, 1) != 0) { |
| 2698 | exit(1); |
| 2699 | } |
| 2700 | #endif |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 2701 | |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 2702 | os_daemonize(); |
ths | 71e3ceb | 2006-12-22 02:11:31 +0000 | [diff] [blame] | 2703 | |
ths | aa26bb2 | 2007-03-25 21:33:06 +0000 | [diff] [blame] | 2704 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 2705 | os_pidfile_error(); |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 2706 | exit(1); |
| 2707 | } |
| 2708 | |
Paolo Bonzini | 98c8573 | 2010-04-19 18:59:30 +0000 | [diff] [blame] | 2709 | if (kvm_allowed) { |
| 2710 | int ret = kvm_init(smp_cpus); |
Marcelo Tosatti | 214910a | 2009-09-18 02:41:23 -0300 | [diff] [blame] | 2711 | if (ret < 0) { |
Paolo Bonzini | 98c8573 | 2010-04-19 18:59:30 +0000 | [diff] [blame] | 2712 | if (!kvm_available()) { |
| 2713 | printf("KVM not supported for this target\n"); |
| 2714 | } else { |
| 2715 | fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret)); |
| 2716 | } |
Marcelo Tosatti | 214910a | 2009-09-18 02:41:23 -0300 | [diff] [blame] | 2717 | exit(1); |
| 2718 | } |
| 2719 | } |
| 2720 | |
aliguori | 3fcf7b6 | 2009-04-24 18:03:25 +0000 | [diff] [blame] | 2721 | if (qemu_init_main_loop()) { |
| 2722 | fprintf(stderr, "qemu_init_main_loop failed\n"); |
| 2723 | exit(1); |
| 2724 | } |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2725 | linux_boot = (kernel_filename != NULL); |
balrog | 6c41b27 | 2007-11-17 12:12:29 +0000 | [diff] [blame] | 2726 | |
ths | f8d39c0 | 2008-07-03 10:01:15 +0000 | [diff] [blame] | 2727 | if (!linux_boot && *kernel_cmdline != '\0') { |
| 2728 | fprintf(stderr, "-append only allowed with -kernel option\n"); |
| 2729 | exit(1); |
| 2730 | } |
| 2731 | |
| 2732 | if (!linux_boot && initrd_filename != NULL) { |
| 2733 | fprintf(stderr, "-initrd only allowed with -kernel option\n"); |
| 2734 | exit(1); |
| 2735 | } |
| 2736 | |
Jes Sorensen | 9156d76 | 2010-06-10 11:42:30 +0200 | [diff] [blame] | 2737 | os_set_line_buffering(); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2738 | |
aliguori | 7183b4b | 2008-11-05 20:40:18 +0000 | [diff] [blame] | 2739 | if (init_timer_alarm() < 0) { |
| 2740 | fprintf(stderr, "could not initialize alarm timer\n"); |
| 2741 | exit(1); |
| 2742 | } |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 2743 | configure_icount(icount_option); |
pbrook | 634fce9 | 2006-07-15 17:40:09 +0000 | [diff] [blame] | 2744 | |
Mark McLoughlin | dc1c9fe | 2009-10-06 12:17:16 +0100 | [diff] [blame] | 2745 | if (net_init_clients() < 0) { |
| 2746 | exit(1); |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 2747 | } |
bellard | f1510b2 | 2003-06-25 00:07:40 +0000 | [diff] [blame] | 2748 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2749 | /* init the bluetooth world */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2750 | if (foreach_device_config(DEV_BT, bt_parse)) |
| 2751 | exit(1); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2752 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2753 | /* init the memory */ |
pbrook | 94a6b54 | 2009-04-11 17:15:54 +0000 | [diff] [blame] | 2754 | if (ram_size == 0) |
| 2755 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; |
balrog | 7fb4fdc | 2008-04-24 17:59:27 +0000 | [diff] [blame] | 2756 | |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 2757 | /* init the dynamic translator */ |
| 2758 | cpu_exec_init_all(tb_size * 1024 * 1024); |
| 2759 | |
Markus Armbruster | eb85201 | 2009-10-27 18:41:44 +0100 | [diff] [blame] | 2760 | bdrv_init_with_whitelist(); |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2761 | |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 2762 | blk_mig_init(); |
| 2763 | |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2764 | if (default_cdrom) { |
Gerd Hoffmann | aa40fc9 | 2009-12-08 13:11:48 +0100 | [diff] [blame] | 2765 | /* we always create the cdrom drive, even if no disk is there */ |
| 2766 | drive_add(NULL, CDROM_ALIAS); |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2767 | } |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2768 | |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2769 | if (default_floppy) { |
Gerd Hoffmann | aa40fc9 | 2009-12-08 13:11:48 +0100 | [diff] [blame] | 2770 | /* we always create at least one floppy */ |
| 2771 | drive_add(NULL, FD_ALIAS, 0); |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2772 | } |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2773 | |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2774 | if (default_sdcard) { |
Gerd Hoffmann | aa40fc9 | 2009-12-08 13:11:48 +0100 | [diff] [blame] | 2775 | /* we always create one sd slot, even if no card is in it */ |
| 2776 | drive_add(NULL, SD_ALIAS); |
| 2777 | } |
balrog | 9d413d1 | 2007-12-04 00:10:34 +0000 | [diff] [blame] | 2778 | |
ths | 96d30e4 | 2007-01-07 20:42:14 +0000 | [diff] [blame] | 2779 | /* open the virtual block devices */ |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 2780 | if (snapshot) |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 2781 | qemu_opts_foreach(&qemu_drive_opts, drive_enable_snapshot, NULL, 0); |
Markus Armbruster | a803cb8 | 2010-06-02 13:31:55 +0200 | [diff] [blame] | 2782 | if (qemu_opts_foreach(&qemu_drive_opts, drive_init_func, &machine->use_scsi, 1) != 0) |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 2783 | exit(1); |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 2784 | |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 2785 | register_savevm_live("ram", 0, 3, NULL, ram_save_live, NULL, |
| 2786 | ram_load, NULL); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 2787 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2788 | if (nb_numa_nodes > 0) { |
| 2789 | int i; |
| 2790 | |
| 2791 | if (nb_numa_nodes > smp_cpus) { |
| 2792 | nb_numa_nodes = smp_cpus; |
| 2793 | } |
| 2794 | |
| 2795 | /* If no memory size if given for any node, assume the default case |
| 2796 | * and distribute the available memory equally across all nodes |
| 2797 | */ |
| 2798 | for (i = 0; i < nb_numa_nodes; i++) { |
| 2799 | if (node_mem[i] != 0) |
| 2800 | break; |
| 2801 | } |
| 2802 | if (i == nb_numa_nodes) { |
| 2803 | uint64_t usedmem = 0; |
| 2804 | |
| 2805 | /* On Linux, the each node's border has to be 8MB aligned, |
| 2806 | * the final node gets the rest. |
| 2807 | */ |
| 2808 | for (i = 0; i < nb_numa_nodes - 1; i++) { |
| 2809 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); |
| 2810 | usedmem += node_mem[i]; |
| 2811 | } |
| 2812 | node_mem[i] = ram_size - usedmem; |
| 2813 | } |
| 2814 | |
| 2815 | for (i = 0; i < nb_numa_nodes; i++) { |
| 2816 | if (node_cpumask[i] != 0) |
| 2817 | break; |
| 2818 | } |
| 2819 | /* assigning the VCPUs round-robin is easier to implement, guest OSes |
| 2820 | * must cope with this anyway, because there are BIOSes out there in |
| 2821 | * real machines which also use this scheme. |
| 2822 | */ |
| 2823 | if (i == nb_numa_nodes) { |
| 2824 | for (i = 0; i < smp_cpus; i++) { |
| 2825 | node_cpumask[i % nb_numa_nodes] |= 1 << i; |
| 2826 | } |
| 2827 | } |
| 2828 | } |
| 2829 | |
Jan Kiszka | 157b931 | 2010-04-06 16:55:53 +0200 | [diff] [blame] | 2830 | if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0) { |
| 2831 | exit(1); |
| 2832 | } |
| 2833 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2834 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
| 2835 | exit(1); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2836 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
| 2837 | exit(1); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2838 | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
| 2839 | exit(1); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2840 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
| 2841 | exit(1); |
aliguori | 2796dae | 2009-01-16 20:23:27 +0000 | [diff] [blame] | 2842 | |
Paul Brook | aae9460 | 2009-05-14 22:35:06 +0100 | [diff] [blame] | 2843 | module_call_init(MODULE_INIT_DEVICE); |
| 2844 | |
Markus Armbruster | ff952ba | 2010-01-29 19:48:57 +0100 | [diff] [blame] | 2845 | if (qemu_opts_foreach(&qemu_device_opts, device_help_func, NULL, 0) != 0) |
| 2846 | exit(0); |
| 2847 | |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 2848 | if (watchdog) { |
| 2849 | i = select_watchdog(watchdog); |
| 2850 | if (i > 0) |
| 2851 | exit (i == 1 ? 1 : 0); |
| 2852 | } |
| 2853 | |
Gerd Hoffmann | b6b6114 | 2009-07-15 13:48:21 +0200 | [diff] [blame] | 2854 | if (machine->compat_props) { |
Gerd Hoffmann | 458fb67 | 2009-12-08 13:11:33 +0100 | [diff] [blame] | 2855 | qdev_prop_register_global_list(machine->compat_props); |
Gerd Hoffmann | b6b6114 | 2009-07-15 13:48:21 +0200 | [diff] [blame] | 2856 | } |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 2857 | qemu_add_globals(); |
| 2858 | |
Paul Brook | fbe1b59 | 2009-05-13 17:56:25 +0100 | [diff] [blame] | 2859 | machine->init(ram_size, boot_devices, |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2860 | kernel_filename, kernel_cmdline, initrd_filename, cpu_model); |
| 2861 | |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 2862 | cpu_synchronize_all_post_init(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2863 | |
Juan Quintela | 67b3b71 | 2009-08-28 19:25:15 +0200 | [diff] [blame] | 2864 | /* must be after terminal init, SDL library changes signal handlers */ |
Jes Sorensen | 8d963e6 | 2010-06-10 11:42:22 +0200 | [diff] [blame] | 2865 | os_setup_signal_handling(); |
Juan Quintela | 67b3b71 | 2009-08-28 19:25:15 +0200 | [diff] [blame] | 2866 | |
Blue Swirl | 87d0a28 | 2010-03-27 18:24:45 +0000 | [diff] [blame] | 2867 | set_numa_modes(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2868 | |
aliguori | 6f338c3 | 2009-02-11 15:21:54 +0000 | [diff] [blame] | 2869 | current_machine = machine; |
| 2870 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2871 | /* init USB devices */ |
| 2872 | if (usb_enabled) { |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 2873 | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
| 2874 | exit(1); |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2877 | /* init generic devices */ |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 2878 | if (qemu_opts_foreach(&qemu_device_opts, device_init_func, NULL, 1) != 0) |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2879 | exit(1); |
| 2880 | |
Markus Armbruster | 668680f | 2010-02-11 14:44:58 +0100 | [diff] [blame] | 2881 | net_check_clients(); |
| 2882 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2883 | /* just use the first displaystate for the moment */ |
Paolo Bonzini | b473df6 | 2010-02-11 00:29:55 +0100 | [diff] [blame] | 2884 | ds = get_displaystate(); |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2885 | |
| 2886 | if (display_type == DT_DEFAULT) { |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 2887 | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2888 | display_type = DT_SDL; |
| 2889 | #else |
| 2890 | display_type = DT_VNC; |
| 2891 | vnc_display = "localhost:0,to=99"; |
| 2892 | show_vnc_port = 1; |
| 2893 | #endif |
| 2894 | } |
| 2895 | |
| 2896 | |
| 2897 | switch (display_type) { |
| 2898 | case DT_NOGRAPHIC: |
| 2899 | break; |
| 2900 | #if defined(CONFIG_CURSES) |
| 2901 | case DT_CURSES: |
| 2902 | curses_display_init(ds, full_screen); |
| 2903 | break; |
| 2904 | #endif |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 2905 | #if defined(CONFIG_SDL) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2906 | case DT_SDL: |
| 2907 | sdl_display_init(ds, full_screen, no_frame); |
| 2908 | break; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 2909 | #elif defined(CONFIG_COCOA) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2910 | case DT_SDL: |
| 2911 | cocoa_display_init(ds, full_screen); |
| 2912 | break; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 2913 | #endif |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2914 | case DT_VNC: |
| 2915 | vnc_display_init(ds); |
| 2916 | if (vnc_display_open(ds, vnc_display) < 0) |
| 2917 | exit(1); |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 2918 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2919 | if (show_vnc_port) { |
| 2920 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 2921 | } |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2922 | break; |
| 2923 | default: |
| 2924 | break; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 2925 | } |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2926 | dpy_resize(ds); |
aliguori | 5b08fc1 | 2008-08-21 20:08:03 +0000 | [diff] [blame] | 2927 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2928 | dcl = ds->listeners; |
| 2929 | while (dcl != NULL) { |
| 2930 | if (dcl->dpy_refresh != NULL) { |
| 2931 | ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds); |
| 2932 | qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock)); |
Isaku Yamahata | 0f2ad63 | 2010-05-27 14:38:47 +0900 | [diff] [blame] | 2933 | break; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 2934 | } |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2935 | dcl = dcl->next; |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2936 | } |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2937 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2938 | if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) { |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 2939 | nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL); |
| 2940 | qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock)); |
| 2941 | } |
| 2942 | |
Paolo Bonzini | b473df6 | 2010-02-11 00:29:55 +0100 | [diff] [blame] | 2943 | text_consoles_set_display(ds); |
aliguori | 2796dae | 2009-01-16 20:23:27 +0000 | [diff] [blame] | 2944 | |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 2945 | if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) { |
| 2946 | fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n", |
| 2947 | gdbstub_dev); |
| 2948 | exit(1); |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 2949 | } |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 2950 | |
Gerd Hoffmann | 3418bd2 | 2009-09-25 21:42:41 +0200 | [diff] [blame] | 2951 | qdev_machine_creation_done(); |
| 2952 | |
Gerd Hoffmann | 15ff770 | 2009-12-14 16:07:35 +0100 | [diff] [blame] | 2953 | if (rom_load_all() != 0) { |
| 2954 | fprintf(stderr, "rom loading failed\n"); |
| 2955 | exit(1); |
| 2956 | } |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 2957 | |
Juan Quintela | 504c294 | 2009-11-12 00:39:13 +0100 | [diff] [blame] | 2958 | qemu_system_reset(); |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 2959 | if (loadvm) { |
Markus Armbruster | 03cd465 | 2010-02-17 16:24:10 +0100 | [diff] [blame] | 2960 | if (load_vmstate(loadvm) < 0) { |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 2961 | autostart = 0; |
| 2962 | } |
| 2963 | } |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 2964 | |
Glauber Costa | 2bb8c10 | 2009-07-24 16:20:23 -0400 | [diff] [blame] | 2965 | if (incoming) { |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 2966 | qemu_start_incoming_migration(incoming); |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 2967 | } else if (autostart) { |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 2968 | vm_start(); |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 2969 | } |
ths | ffd843b | 2006-12-21 19:46:43 +0000 | [diff] [blame] | 2970 | |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 2971 | os_setup_post(); |
ths | 71e3ceb | 2006-12-22 02:11:31 +0000 | [diff] [blame] | 2972 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 2973 | main_loop(); |
bellard | 40c3bac | 2004-04-04 12:56:28 +0000 | [diff] [blame] | 2974 | quit_timers(); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 2975 | net_cleanup(); |
ths | b46a890 | 2007-10-21 23:20:45 +0000 | [diff] [blame] | 2976 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2977 | return 0; |
| 2978 | } |