David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QEMU System Emulator |
| 3 | * |
| 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
| 5 | * |
| 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. |
| 23 | */ |
| 24 | |
| 25 | /* the following is needed on Linux to define ptsname() in stdlib.h */ |
| 26 | #if defined(__linux__) |
| 27 | #define _GNU_SOURCE 1 |
| 28 | #endif |
| 29 | |
| 30 | #include "qemu-common.h" |
| 31 | #include "hw/hw.h" |
| 32 | #include "hw/boards.h" |
| 33 | #include "hw/usb.h" |
| 34 | #include "hw/pcmcia.h" |
David 'Digit' Turner | 2ec695a | 2013-12-17 10:03:39 +0100 | [diff] [blame] | 35 | #include "hw/i386/pc.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 36 | #include "hw/audiodev.h" |
David 'Digit' Turner | 2ec695a | 2013-12-17 10:03:39 +0100 | [diff] [blame] | 37 | #include "hw/isa/isa.h" |
David 'Digit' Turner | 1365eb2 | 2014-02-16 22:23:26 +0100 | [diff] [blame] | 38 | #include "hw/loader.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 39 | #include "hw/baum.h" |
David 'Digit' Turner | f066542 | 2013-12-17 10:47:09 +0100 | [diff] [blame] | 40 | #include "hw/android/goldfish/nand.h" |
David 'Digit' Turner | cc330d4 | 2013-12-14 23:26:42 +0100 | [diff] [blame] | 41 | #include "net/net.h" |
David 'Digit' Turner | 1c31e3e | 2013-12-14 20:07:17 +0100 | [diff] [blame] | 42 | #include "ui/console.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 43 | #include "sysemu/sysemu.h" |
David 'Digit' Turner | 852088c | 2013-12-14 23:04:12 +0100 | [diff] [blame] | 44 | #include "exec/gdbstub.h" |
David 'Digit' Turner | 7e9f6c1 | 2014-01-22 18:42:40 +0100 | [diff] [blame] | 45 | #include "qemu/log.h" |
David 'Digit' Turner | 7a78db7 | 2013-12-14 11:46:01 +0100 | [diff] [blame] | 46 | #include "qemu/timer.h" |
David 'Digit' Turner | e7216d8 | 2013-12-15 00:51:13 +0100 | [diff] [blame] | 47 | #include "sysemu/char.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 48 | #include "sysemu/blockdev.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 49 | #include "audio/audio.h" |
| 50 | |
David 'Digit' Turner | 28a09b6 | 2013-12-15 00:16:00 +0100 | [diff] [blame] | 51 | #include "migration/qemu-file.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 52 | #include "android/android.h" |
David 'Digit' Turner | e1e03df | 2013-12-15 00:42:21 +0100 | [diff] [blame] | 53 | #include "android/charpipe.h" |
David 'Digit' Turner | f9077a8 | 2014-02-10 23:10:47 +0100 | [diff] [blame] | 54 | #include "android/log-rotate.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 55 | #include "modem_driver.h" |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 56 | #include "android/filesystems/ext4_utils.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 57 | #include "android/gps.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 58 | #include "android/hw-kmsg.h" |
David 'Digit' Turner | c0ac733 | 2011-05-02 15:05:35 +0200 | [diff] [blame] | 59 | #include "android/hw-pipe-net.h" |
| 60 | #include "android/hw-qemud.h" |
Vladimir Chtchetkine | c646f5e | 2011-09-03 15:17:13 -0700 | [diff] [blame] | 61 | #include "android/camera/camera-service.h" |
Vladimir Chtchetkine | 8dd31e8 | 2012-02-15 17:16:04 -0800 | [diff] [blame] | 62 | #include "android/multitouch-port.h" |
Vladimir Chtchetkine | eb83825 | 2010-07-15 12:27:56 -0700 | [diff] [blame] | 63 | #include "android/charmap.h" |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 64 | #include "android/globals.h" |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 65 | #include "android/utils/bufprint.h" |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 66 | #include "android/utils/debug.h" |
David 'Digit' Turner | 48a3c66 | 2011-03-01 14:03:20 +0100 | [diff] [blame] | 67 | #include "android/utils/filelock.h" |
| 68 | #include "android/utils/path.h" |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 69 | #include "android/utils/stralloc.h" |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 70 | #include "android/utils/tempfile.h" |
Vladimir Chtchetkine | 72d83df | 2010-12-14 09:24:02 -0800 | [diff] [blame] | 71 | #include "android/display-core.h" |
Vladimir Chtchetkine | 90c6235 | 2011-01-13 11:24:07 -0800 | [diff] [blame] | 72 | #include "android/utils/timezone.h" |
David 'Digit' Turner | bdb6f2d | 2011-02-23 15:57:25 +0100 | [diff] [blame] | 73 | #include "android/snapshot.h" |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 74 | #include "android/opengles.h" |
Vladimir Chtchetkine | 1a820e9 | 2012-04-11 13:22:48 -0700 | [diff] [blame] | 75 | #include "android/multitouch-screen.h" |
David 'Digit' Turner | bcde109 | 2014-01-09 23:19:19 +0100 | [diff] [blame] | 76 | #include "exec/hwaddr.h" |
David 'Digit' Turner | 6e2eb78 | 2013-12-15 00:54:21 +0100 | [diff] [blame] | 77 | #include "android/tcpdump.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 78 | |
David 'Digit' Turner | 5bb450e | 2014-03-14 17:19:45 +0100 | [diff] [blame] | 79 | #ifdef CONFIG_ANDROID_MEMCHECK |
David 'Digit' Turner | 96e493a | 2014-03-14 17:17:26 +0100 | [diff] [blame] | 80 | #include "android/qemu/memcheck/memcheck.h" |
David 'Digit' Turner | 5bb450e | 2014-03-14 17:19:45 +0100 | [diff] [blame] | 81 | #endif // CONFIG_ANDROID_MEMCHECK |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 82 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 83 | #include <unistd.h> |
| 84 | #include <fcntl.h> |
| 85 | #include <signal.h> |
| 86 | #include <time.h> |
| 87 | #include <errno.h> |
| 88 | #include <sys/time.h> |
| 89 | #include <zlib.h> |
| 90 | |
David 'Digit' Turner | 2c538c8 | 2010-05-10 16:48:20 -0700 | [diff] [blame] | 91 | /* Needed early for CONFIG_BSD etc. */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 92 | #include "config-host.h" |
| 93 | |
| 94 | #ifndef _WIN32 |
| 95 | #include <libgen.h> |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 96 | #include <sys/times.h> |
| 97 | #include <sys/wait.h> |
| 98 | #include <termios.h> |
| 99 | #include <sys/mman.h> |
| 100 | #include <sys/ioctl.h> |
| 101 | #include <sys/resource.h> |
| 102 | #include <sys/socket.h> |
| 103 | #include <netinet/in.h> |
| 104 | #include <net/if.h> |
| 105 | #if defined(__NetBSD__) |
| 106 | #include <net/if_tap.h> |
| 107 | #endif |
| 108 | #ifdef __linux__ |
| 109 | #include <linux/if_tun.h> |
| 110 | #endif |
| 111 | #include <arpa/inet.h> |
| 112 | #include <dirent.h> |
| 113 | #include <netdb.h> |
| 114 | #include <sys/select.h> |
David 'Digit' Turner | 2c538c8 | 2010-05-10 16:48:20 -0700 | [diff] [blame] | 115 | #ifdef CONFIG_BSD |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 116 | #include <sys/stat.h> |
| 117 | #if defined(__FreeBSD__) || defined(__DragonFly__) |
| 118 | #include <libutil.h> |
| 119 | #else |
| 120 | #include <util.h> |
| 121 | #endif |
| 122 | #elif defined (__GLIBC__) && defined (__FreeBSD_kernel__) |
| 123 | #include <freebsd/stdlib.h> |
| 124 | #else |
| 125 | #ifdef __linux__ |
| 126 | #include <pty.h> |
| 127 | #include <malloc.h> |
| 128 | #include <linux/rtc.h> |
| 129 | |
| 130 | /* For the benefit of older linux systems which don't supply it, |
| 131 | we use a local copy of hpet.h. */ |
| 132 | /* #include <linux/hpet.h> */ |
David 'Digit' Turner | 2dbdad5 | 2013-12-17 09:24:18 +0100 | [diff] [blame] | 133 | #include "hw/timer/hpet.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 134 | |
| 135 | #include <linux/ppdev.h> |
| 136 | #include <linux/parport.h> |
| 137 | #endif |
| 138 | #ifdef __sun__ |
| 139 | #include <sys/stat.h> |
| 140 | #include <sys/ethernet.h> |
| 141 | #include <sys/sockio.h> |
| 142 | #include <netinet/arp.h> |
| 143 | #include <netinet/in.h> |
| 144 | #include <netinet/in_systm.h> |
| 145 | #include <netinet/ip.h> |
| 146 | #include <netinet/ip_icmp.h> // must come after ip.h |
| 147 | #include <netinet/udp.h> |
| 148 | #include <netinet/tcp.h> |
| 149 | #include <net/if.h> |
| 150 | #include <syslog.h> |
| 151 | #include <stropts.h> |
| 152 | #endif |
| 153 | #endif |
| 154 | #endif |
| 155 | |
| 156 | #if defined(__OpenBSD__) |
| 157 | #include <util.h> |
| 158 | #endif |
| 159 | |
| 160 | #if defined(CONFIG_VDE) |
| 161 | #include <libvdeplug.h> |
| 162 | #endif |
| 163 | |
| 164 | #ifdef _WIN32 |
| 165 | #include <windows.h> |
| 166 | #include <malloc.h> |
| 167 | #include <sys/timeb.h> |
| 168 | #include <mmsystem.h> |
| 169 | #define getopt_long_only getopt_long |
| 170 | #define memalign(align, size) malloc(size) |
| 171 | #endif |
| 172 | |
David 'Digit' Turner | 1182284 | 2013-12-17 09:16:47 +0100 | [diff] [blame] | 173 | #include "sysemu/cpus.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 174 | #include "sysemu/arch_init.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 175 | |
| 176 | #ifdef CONFIG_COCOA |
David 'Digit' Turner | ae3098a | 2011-05-11 16:01:57 +0200 | [diff] [blame] | 177 | int qemu_main(int argc, char **argv, char **envp); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 178 | #undef main |
| 179 | #define main qemu_main |
| 180 | #endif /* CONFIG_COCOA */ |
| 181 | |
| 182 | #include "hw/hw.h" |
| 183 | #include "hw/boards.h" |
| 184 | #include "hw/usb.h" |
| 185 | #include "hw/pcmcia.h" |
David 'Digit' Turner | 2ec695a | 2013-12-17 10:03:39 +0100 | [diff] [blame] | 186 | #include "hw/i386/pc.h" |
| 187 | #include "hw/isa/isa.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 188 | #include "hw/baum.h" |
| 189 | #include "hw/bt.h" |
David 'Digit' Turner | 7821d63 | 2013-12-17 11:27:50 +0100 | [diff] [blame] | 190 | #include "sysemu/watchdog.h" |
David 'Digit' Turner | 73a93a1 | 2013-12-17 11:26:01 +0100 | [diff] [blame] | 191 | #include "hw/i386/smbios.h" |
David 'Digit' Turner | 5031918 | 2013-12-17 11:28:54 +0100 | [diff] [blame] | 192 | #include "hw/xen/xen.h" |
David 'Digit' Turner | 6800f0a | 2013-12-17 09:12:54 +0100 | [diff] [blame] | 193 | #include "sysemu/bt.h" |
David 'Digit' Turner | cc330d4 | 2013-12-14 23:26:42 +0100 | [diff] [blame] | 194 | #include "net/net.h" |
David 'Digit' Turner | 6af6765 | 2013-12-14 23:49:32 +0100 | [diff] [blame] | 195 | #include "monitor/monitor.h" |
David 'Digit' Turner | 1c31e3e | 2013-12-14 20:07:17 +0100 | [diff] [blame] | 196 | #include "ui/console.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 197 | #include "sysemu/sysemu.h" |
David 'Digit' Turner | 852088c | 2013-12-14 23:04:12 +0100 | [diff] [blame] | 198 | #include "exec/gdbstub.h" |
David 'Digit' Turner | 7a78db7 | 2013-12-14 11:46:01 +0100 | [diff] [blame] | 199 | #include "qemu/timer.h" |
David 'Digit' Turner | e7216d8 | 2013-12-15 00:51:13 +0100 | [diff] [blame] | 200 | #include "sysemu/char.h" |
David 'Digit' Turner | 37dc41a | 2013-12-14 14:45:51 +0100 | [diff] [blame] | 201 | #include "qemu/cache-utils.h" |
David 'Digit' Turner | e1e03df | 2013-12-15 00:42:21 +0100 | [diff] [blame] | 202 | #include "block/block.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 203 | #include "sysemu/dma.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 204 | #include "audio/audio.h" |
David 'Digit' Turner | 28a09b6 | 2013-12-15 00:16:00 +0100 | [diff] [blame] | 205 | #include "migration/migration.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 206 | #include "sysemu/kvm.h" |
David 'Digit' Turner | e1e03df | 2013-12-15 00:42:21 +0100 | [diff] [blame] | 207 | #include "exec/hax.h" |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 208 | #ifdef CONFIG_KVM |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 209 | #include "android/kvm.h" |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 210 | #endif |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 211 | #include "sysemu/balloon.h" |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 212 | #include "android/hw-lcd.h" |
| 213 | #include "android/boot-properties.h" |
David 'Digit' Turner | ca95059 | 2011-04-27 12:26:15 +0200 | [diff] [blame] | 214 | #include "android/hw-control.h" |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 215 | #include "android/core-init-utils.h" |
David 'Digit' Turner | ca29fbb | 2011-01-02 13:17:22 +0100 | [diff] [blame] | 216 | #include "android/audio-test.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 217 | |
Vladimir Chtchetkine | db450d7 | 2012-01-12 13:37:40 -0800 | [diff] [blame] | 218 | #include "android/snaphost-android.h" |
| 219 | |
Vladimir Chtchetkine | 5758404 | 2011-01-20 16:15:30 -0800 | [diff] [blame] | 220 | #if !defined(CONFIG_STANDALONE_CORE) |
| 221 | /* in android/qemulator.c */ |
| 222 | extern void android_emulator_set_base_port(int port); |
| 223 | #endif |
| 224 | |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 225 | #if defined(CONFIG_SKINS) && !defined(CONFIG_STANDALONE_CORE) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 226 | #undef main |
| 227 | #define main qemu_main |
| 228 | #endif |
| 229 | |
David 'Digit' Turner | cc33b2d | 2013-12-15 00:09:42 +0100 | [diff] [blame] | 230 | #include "disas/disas.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 231 | |
David 'Digit' Turner | d0edecb | 2013-12-17 09:32:26 +0100 | [diff] [blame] | 232 | #include "qemu/sockets.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 233 | |
| 234 | #if defined(CONFIG_SLIRP) |
| 235 | #include "libslirp.h" |
| 236 | #endif |
| 237 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 238 | #define DEFAULT_RAM_SIZE 128 |
| 239 | |
| 240 | /* Max number of USB devices that can be specified on the commandline. */ |
| 241 | #define MAX_USB_CMDLINE 8 |
| 242 | |
| 243 | /* Max number of bluetooth switches on the commandline. */ |
| 244 | #define MAX_BT_CMDLINE 10 |
| 245 | |
| 246 | /* XXX: use a two level table to limit memory usage */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 247 | |
| 248 | static const char *data_dir; |
| 249 | const char *bios_name = NULL; |
| 250 | static void *ioport_opaque[MAX_IOPORTS]; |
| 251 | static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; |
| 252 | static IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 253 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 254 | /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available |
| 255 | to store the VM snapshots */ |
| 256 | DriveInfo drives_table[MAX_DRIVES+1]; |
| 257 | int nb_drives; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 258 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 259 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 260 | DisplayType display_type = DT_DEFAULT; |
| 261 | const char* keyboard_layout = NULL; |
| 262 | int64_t ticks_per_sec; |
| 263 | ram_addr_t ram_size; |
David 'Digit' Turner | 0e8e748 | 2014-02-17 20:25:52 +0100 | [diff] [blame] | 264 | bool xen_allowed; |
David 'Digit' Turner | 280afa0 | 2011-05-11 17:37:44 +0200 | [diff] [blame] | 265 | const char *mem_path = NULL; |
| 266 | #ifdef MAP_POPULATE |
| 267 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
| 268 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 269 | int nb_nics; |
| 270 | NICInfo nd_table[MAX_NICS]; |
| 271 | int vm_running; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 272 | int autostart; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 273 | static int rtc_utc = 1; |
| 274 | static int rtc_date_offset = -1; /* -1 means no change */ |
| 275 | int cirrus_vga_enabled = 1; |
| 276 | int std_vga_enabled = 0; |
| 277 | int vmsvga_enabled = 0; |
| 278 | int xenfb_enabled = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 279 | static int full_screen = 0; |
| 280 | #ifdef CONFIG_SDL |
| 281 | static int no_frame = 0; |
| 282 | #endif |
| 283 | int no_quit = 0; |
| 284 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 285 | int serial_hds_count; |
| 286 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 287 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
| 288 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
| 289 | #ifdef TARGET_I386 |
| 290 | int win2k_install_hack = 0; |
| 291 | int rtc_td_hack = 0; |
| 292 | #endif |
| 293 | int usb_enabled = 0; |
| 294 | int singlestep = 0; |
| 295 | int smp_cpus = 1; |
| 296 | const char *vnc_display; |
| 297 | int acpi_enabled = 1; |
| 298 | int no_hpet = 0; |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 299 | int hax_disabled = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 300 | int no_virtio_balloon = 0; |
| 301 | int fd_bootchk = 1; |
| 302 | int no_reboot = 0; |
| 303 | int no_shutdown = 0; |
| 304 | int cursor_hide = 1; |
| 305 | int graphic_rotate = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 306 | WatchdogTimerModel *watchdog = NULL; |
| 307 | int watchdog_action = WDT_RESET; |
| 308 | const char *option_rom[MAX_OPTION_ROMS]; |
| 309 | int nb_option_roms; |
| 310 | int semihosting_enabled = 0; |
| 311 | #ifdef TARGET_ARM |
| 312 | int old_param = 0; |
| 313 | #endif |
| 314 | const char *qemu_name; |
| 315 | int alt_grab = 0; |
| 316 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) |
| 317 | unsigned int nb_prom_envs = 0; |
| 318 | const char *prom_envs[MAX_PROM_ENVS]; |
| 319 | #endif |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 320 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 321 | int nb_drives_opt; |
| 322 | struct drive_opt drives_opt[MAX_DRIVES]; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 323 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 324 | int nb_numa_nodes; |
| 325 | uint64_t node_mem[MAX_NODES]; |
| 326 | uint64_t node_cpumask[MAX_NODES]; |
| 327 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 328 | static QEMUTimer *nographic_timer; |
| 329 | |
| 330 | uint8_t qemu_uuid[16]; |
| 331 | |
| 332 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 333 | int qemu_cpu_delay; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 334 | extern char* audio_input_source; |
| 335 | |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 336 | extern char* android_op_ports; |
| 337 | extern char* android_op_port; |
| 338 | extern char* android_op_report_console; |
| 339 | extern char* op_http_proxy; |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 340 | // Path to the file containing specific key character map. |
| 341 | char* op_charmap_file = NULL; |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 342 | |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 343 | /* Path to hardware initialization file passed with -android-hw option. */ |
| 344 | char* android_op_hwini = NULL; |
| 345 | |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 346 | /* Memory checker options. */ |
| 347 | char* android_op_memcheck = NULL; |
| 348 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 349 | /* -dns-server option value. */ |
| 350 | char* android_op_dns_server = NULL; |
| 351 | |
Vladimir Chtchetkine | 13f3b6c | 2010-08-25 09:49:25 -0700 | [diff] [blame] | 352 | /* -radio option value. */ |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 353 | char* android_op_radio = NULL; |
| 354 | |
| 355 | /* -gps option value. */ |
| 356 | char* android_op_gps = NULL; |
| 357 | |
| 358 | /* -audio option value. */ |
| 359 | char* android_op_audio = NULL; |
| 360 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 361 | /* -cpu-delay option value. */ |
| 362 | char* android_op_cpu_delay = NULL; |
| 363 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 364 | #ifdef CONFIG_NAND_LIMITS |
| 365 | /* -nand-limits option value. */ |
| 366 | char* android_op_nand_limits = NULL; |
| 367 | #endif // CONFIG_NAND_LIMITS |
| 368 | |
| 369 | /* -netspeed option value. */ |
| 370 | char* android_op_netspeed = NULL; |
| 371 | |
| 372 | /* -netdelay option value. */ |
| 373 | char* android_op_netdelay = NULL; |
| 374 | |
| 375 | /* -netfast option value. */ |
| 376 | int android_op_netfast = 0; |
| 377 | |
Vladimir Chtchetkine | 318f17a | 2010-08-27 09:09:45 -0700 | [diff] [blame] | 378 | /* -tcpdump option value. */ |
| 379 | char* android_op_tcpdump = NULL; |
| 380 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 381 | /* -lcd-density option value. */ |
| 382 | char* android_op_lcd_density = NULL; |
| 383 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 384 | /* -ui-port option value. This port will be used to report the core |
| 385 | * initialization completion. |
| 386 | */ |
| 387 | char* android_op_ui_port = NULL; |
| 388 | |
| 389 | /* -ui-settings option value. This value will be passed to the UI when new UI |
| 390 | * process is attaching to the core. |
| 391 | */ |
| 392 | char* android_op_ui_settings = NULL; |
| 393 | |
Vladimir Chtchetkine | 90c6235 | 2011-01-13 11:24:07 -0800 | [diff] [blame] | 394 | /* -android-avdname option value. */ |
| 395 | char* android_op_avd_name = "unknown"; |
| 396 | |
Vladimir Chtchetkine | dd50f7d | 2010-07-30 09:16:41 -0700 | [diff] [blame] | 397 | extern int android_display_width; |
| 398 | extern int android_display_height; |
| 399 | extern int android_display_bpp; |
| 400 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 401 | extern void dprint( const char* format, ... ); |
| 402 | |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 403 | const char* dns_log_filename = NULL; |
| 404 | const char* drop_log_filename = NULL; |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 405 | |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 406 | const char* savevm_on_exit = NULL; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 407 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 408 | #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) |
| 409 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 410 | /* Reports the core initialization failure to the error stdout and to the UI |
| 411 | * socket before exiting the application. |
| 412 | * Parameters that are passed to this macro are used to format the error |
| 413 | * mesage using sprintf routine. |
| 414 | */ |
| 415 | #ifdef CONFIG_ANDROID |
| 416 | #define PANIC(...) android_core_init_failure(__VA_ARGS__) |
| 417 | #else |
| 418 | #define PANIC(...) do { fprintf(stderr, __VA_ARGS__); \ |
| 419 | exit(1); \ |
| 420 | } while (0) |
| 421 | #endif // CONFIG_ANDROID |
| 422 | |
| 423 | /* Exits the core during initialization. */ |
| 424 | #ifdef CONFIG_ANDROID |
| 425 | #define QEMU_EXIT(exit_code) android_core_init_exit(exit_code) |
| 426 | #else |
| 427 | #define QEMU_EXIT(exit_code) exit(exit_code) |
| 428 | #endif // CONFIG_ANDROID |
| 429 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 430 | /***********************************************************/ |
| 431 | /* x86 ISA bus support */ |
| 432 | |
David 'Digit' Turner | bcde109 | 2014-01-09 23:19:19 +0100 | [diff] [blame] | 433 | hwaddr isa_mem_base = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 434 | PicState2 *isa_pic; |
| 435 | |
| 436 | static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl; |
| 437 | static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel; |
| 438 | |
| 439 | static uint32_t ioport_read(int index, uint32_t address) |
| 440 | { |
| 441 | static IOPortReadFunc *default_func[3] = { |
| 442 | default_ioport_readb, |
| 443 | default_ioport_readw, |
| 444 | default_ioport_readl |
| 445 | }; |
| 446 | IOPortReadFunc *func = ioport_read_table[index][address]; |
| 447 | if (!func) |
| 448 | func = default_func[index]; |
| 449 | return func(ioport_opaque[address], address); |
| 450 | } |
| 451 | |
| 452 | static void ioport_write(int index, uint32_t address, uint32_t data) |
| 453 | { |
| 454 | static IOPortWriteFunc *default_func[3] = { |
| 455 | default_ioport_writeb, |
| 456 | default_ioport_writew, |
| 457 | default_ioport_writel |
| 458 | }; |
| 459 | IOPortWriteFunc *func = ioport_write_table[index][address]; |
| 460 | if (!func) |
| 461 | func = default_func[index]; |
| 462 | func(ioport_opaque[address], address, data); |
| 463 | } |
| 464 | |
| 465 | static uint32_t default_ioport_readb(void *opaque, uint32_t address) |
| 466 | { |
| 467 | #ifdef DEBUG_UNUSED_IOPORT |
| 468 | fprintf(stderr, "unused inb: port=0x%04x\n", address); |
| 469 | #endif |
| 470 | return 0xff; |
| 471 | } |
| 472 | |
| 473 | static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data) |
| 474 | { |
| 475 | #ifdef DEBUG_UNUSED_IOPORT |
| 476 | fprintf(stderr, "unused outb: port=0x%04x data=0x%02x\n", address, data); |
| 477 | #endif |
| 478 | } |
| 479 | |
| 480 | /* default is to make two byte accesses */ |
| 481 | static uint32_t default_ioport_readw(void *opaque, uint32_t address) |
| 482 | { |
| 483 | uint32_t data; |
| 484 | data = ioport_read(0, address); |
| 485 | address = (address + 1) & (MAX_IOPORTS - 1); |
| 486 | data |= ioport_read(0, address) << 8; |
| 487 | return data; |
| 488 | } |
| 489 | |
| 490 | static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) |
| 491 | { |
| 492 | ioport_write(0, address, data & 0xff); |
| 493 | address = (address + 1) & (MAX_IOPORTS - 1); |
| 494 | ioport_write(0, address, (data >> 8) & 0xff); |
| 495 | } |
| 496 | |
| 497 | static uint32_t default_ioport_readl(void *opaque, uint32_t address) |
| 498 | { |
| 499 | #ifdef DEBUG_UNUSED_IOPORT |
| 500 | fprintf(stderr, "unused inl: port=0x%04x\n", address); |
| 501 | #endif |
| 502 | return 0xffffffff; |
| 503 | } |
| 504 | |
| 505 | static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data) |
| 506 | { |
| 507 | #ifdef DEBUG_UNUSED_IOPORT |
| 508 | fprintf(stderr, "unused outl: port=0x%04x data=0x%02x\n", address, data); |
| 509 | #endif |
| 510 | } |
| 511 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 512 | /***************/ |
| 513 | /* ballooning */ |
| 514 | |
| 515 | static QEMUBalloonEvent *qemu_balloon_event; |
| 516 | void *qemu_balloon_event_opaque; |
| 517 | |
| 518 | void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) |
| 519 | { |
| 520 | qemu_balloon_event = func; |
| 521 | qemu_balloon_event_opaque = opaque; |
| 522 | } |
| 523 | |
| 524 | void qemu_balloon(ram_addr_t target) |
| 525 | { |
| 526 | if (qemu_balloon_event) |
| 527 | qemu_balloon_event(qemu_balloon_event_opaque, target); |
| 528 | } |
| 529 | |
| 530 | ram_addr_t qemu_balloon_status(void) |
| 531 | { |
| 532 | if (qemu_balloon_event) |
| 533 | return qemu_balloon_event(qemu_balloon_event_opaque, 0); |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | /***********************************************************/ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 538 | /* host time/date access */ |
| 539 | void qemu_get_timedate(struct tm *tm, int offset) |
| 540 | { |
| 541 | time_t ti; |
| 542 | struct tm *ret; |
| 543 | |
| 544 | time(&ti); |
| 545 | ti += offset; |
| 546 | if (rtc_date_offset == -1) { |
| 547 | if (rtc_utc) |
| 548 | ret = gmtime(&ti); |
| 549 | else |
| 550 | ret = localtime(&ti); |
| 551 | } else { |
| 552 | ti -= rtc_date_offset; |
| 553 | ret = gmtime(&ti); |
| 554 | } |
| 555 | |
| 556 | memcpy(tm, ret, sizeof(struct tm)); |
| 557 | } |
| 558 | |
| 559 | int qemu_timedate_diff(struct tm *tm) |
| 560 | { |
| 561 | time_t seconds; |
| 562 | |
| 563 | if (rtc_date_offset == -1) |
| 564 | if (rtc_utc) |
| 565 | seconds = mktimegm(tm); |
| 566 | else |
| 567 | seconds = mktime(tm); |
| 568 | else |
| 569 | seconds = mktimegm(tm) + rtc_date_offset; |
| 570 | |
| 571 | return seconds - time(NULL); |
| 572 | } |
| 573 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 574 | /***********************************************************/ |
| 575 | /* Bluetooth support */ |
| 576 | static int nb_hcis; |
| 577 | static int cur_hci; |
| 578 | static struct HCIInfo *hci_table[MAX_NICS]; |
| 579 | |
| 580 | static struct bt_vlan_s { |
| 581 | struct bt_scatternet_s net; |
| 582 | int id; |
| 583 | struct bt_vlan_s *next; |
| 584 | } *first_bt_vlan; |
| 585 | |
| 586 | /* find or alloc a new bluetooth "VLAN" */ |
| 587 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
| 588 | { |
| 589 | struct bt_vlan_s **pvlan, *vlan; |
| 590 | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { |
| 591 | if (vlan->id == id) |
| 592 | return &vlan->net; |
| 593 | } |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 594 | vlan = g_malloc0(sizeof(struct bt_vlan_s)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 595 | vlan->id = id; |
| 596 | pvlan = &first_bt_vlan; |
| 597 | while (*pvlan != NULL) |
| 598 | pvlan = &(*pvlan)->next; |
| 599 | *pvlan = vlan; |
| 600 | return &vlan->net; |
| 601 | } |
| 602 | |
| 603 | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) |
| 604 | { |
| 605 | } |
| 606 | |
| 607 | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) |
| 608 | { |
| 609 | return -ENOTSUP; |
| 610 | } |
| 611 | |
| 612 | static struct HCIInfo null_hci = { |
| 613 | .cmd_send = null_hci_send, |
| 614 | .sco_send = null_hci_send, |
| 615 | .acl_send = null_hci_send, |
| 616 | .bdaddr_set = null_hci_addr_set, |
| 617 | }; |
| 618 | |
| 619 | struct HCIInfo *qemu_next_hci(void) |
| 620 | { |
| 621 | if (cur_hci == nb_hcis) |
| 622 | return &null_hci; |
| 623 | |
| 624 | return hci_table[cur_hci++]; |
| 625 | } |
| 626 | |
| 627 | static struct HCIInfo *hci_init(const char *str) |
| 628 | { |
| 629 | char *endp; |
| 630 | struct bt_scatternet_s *vlan = 0; |
| 631 | |
| 632 | if (!strcmp(str, "null")) |
| 633 | /* null */ |
| 634 | return &null_hci; |
| 635 | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) |
| 636 | /* host[:hciN] */ |
| 637 | return bt_host_hci(str[4] ? str + 5 : "hci0"); |
| 638 | else if (!strncmp(str, "hci", 3)) { |
| 639 | /* hci[,vlan=n] */ |
| 640 | if (str[3]) { |
| 641 | if (!strncmp(str + 3, ",vlan=", 6)) { |
| 642 | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); |
| 643 | if (*endp) |
| 644 | vlan = 0; |
| 645 | } |
| 646 | } else |
| 647 | vlan = qemu_find_bt_vlan(0); |
| 648 | if (vlan) |
| 649 | return bt_new_hci(vlan); |
| 650 | } |
| 651 | |
| 652 | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static int bt_hci_parse(const char *str) |
| 658 | { |
| 659 | struct HCIInfo *hci; |
| 660 | bdaddr_t bdaddr; |
| 661 | |
| 662 | if (nb_hcis >= MAX_NICS) { |
| 663 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); |
| 664 | return -1; |
| 665 | } |
| 666 | |
| 667 | hci = hci_init(str); |
| 668 | if (!hci) |
| 669 | return -1; |
| 670 | |
| 671 | bdaddr.b[0] = 0x52; |
| 672 | bdaddr.b[1] = 0x54; |
| 673 | bdaddr.b[2] = 0x00; |
| 674 | bdaddr.b[3] = 0x12; |
| 675 | bdaddr.b[4] = 0x34; |
| 676 | bdaddr.b[5] = 0x56 + nb_hcis; |
| 677 | hci->bdaddr_set(hci, bdaddr.b); |
| 678 | |
| 679 | hci_table[nb_hcis++] = hci; |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | static void bt_vhci_add(int vlan_id) |
| 685 | { |
| 686 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); |
| 687 | |
| 688 | if (!vlan->slave) |
| 689 | fprintf(stderr, "qemu: warning: adding a VHCI to " |
| 690 | "an empty scatternet %i\n", vlan_id); |
| 691 | |
| 692 | bt_vhci_init(bt_new_hci(vlan)); |
| 693 | } |
| 694 | |
| 695 | static struct bt_device_s *bt_device_add(const char *opt) |
| 696 | { |
| 697 | struct bt_scatternet_s *vlan; |
| 698 | int vlan_id = 0; |
| 699 | char *endp = strstr(opt, ",vlan="); |
| 700 | int len = (endp ? endp - opt : strlen(opt)) + 1; |
| 701 | char devname[10]; |
| 702 | |
| 703 | pstrcpy(devname, MIN(sizeof(devname), len), opt); |
| 704 | |
| 705 | if (endp) { |
| 706 | vlan_id = strtol(endp + 6, &endp, 0); |
| 707 | if (*endp) { |
| 708 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); |
| 709 | return 0; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | vlan = qemu_find_bt_vlan(vlan_id); |
| 714 | |
| 715 | if (!vlan->slave) |
| 716 | fprintf(stderr, "qemu: warning: adding a slave device to " |
| 717 | "an empty scatternet %i\n", vlan_id); |
| 718 | |
| 719 | if (!strcmp(devname, "keyboard")) |
| 720 | return bt_keyboard_init(vlan); |
| 721 | |
| 722 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | static int bt_parse(const char *opt) |
| 727 | { |
| 728 | const char *endp, *p; |
| 729 | int vlan; |
| 730 | |
| 731 | if (strstart(opt, "hci", &endp)) { |
| 732 | if (!*endp || *endp == ',') { |
| 733 | if (*endp) |
| 734 | if (!strstart(endp, ",vlan=", 0)) |
| 735 | opt = endp + 1; |
| 736 | |
| 737 | return bt_hci_parse(opt); |
| 738 | } |
| 739 | } else if (strstart(opt, "vhci", &endp)) { |
| 740 | if (!*endp || *endp == ',') { |
| 741 | if (*endp) { |
| 742 | if (strstart(endp, ",vlan=", &p)) { |
| 743 | vlan = strtol(p, (char **) &endp, 0); |
| 744 | if (*endp) { |
| 745 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); |
| 746 | return 1; |
| 747 | } |
| 748 | } else { |
| 749 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); |
| 750 | return 1; |
| 751 | } |
| 752 | } else |
| 753 | vlan = 0; |
| 754 | |
| 755 | bt_vhci_add(vlan); |
| 756 | return 0; |
| 757 | } |
| 758 | } else if (strstart(opt, "device:", &endp)) |
| 759 | return !bt_device_add(endp); |
| 760 | |
| 761 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); |
| 762 | return 1; |
| 763 | } |
| 764 | |
| 765 | /***********************************************************/ |
| 766 | /* QEMU Block devices */ |
| 767 | |
| 768 | #define HD_ALIAS "index=%d,media=disk" |
| 769 | #define CDROM_ALIAS "index=2,media=cdrom" |
| 770 | #define FD_ALIAS "index=%d,if=floppy" |
| 771 | #define PFLASH_ALIAS "if=pflash" |
| 772 | #define MTD_ALIAS "if=mtd" |
| 773 | #define SD_ALIAS "index=0,if=sd" |
| 774 | |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 775 | static int drive_init_func(QemuOpts *opts, void *opaque) |
| 776 | { |
| 777 | int *use_scsi = opaque; |
| 778 | int fatal_error = 0; |
| 779 | |
| 780 | if (drive_init(opts, *use_scsi, &fatal_error) == NULL) { |
| 781 | if (fatal_error) |
| 782 | return 1; |
| 783 | } |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) |
| 788 | { |
| 789 | if (NULL == qemu_opt_get(opts, "snapshot")) { |
| 790 | qemu_opt_set(opts, "snapshot", "on"); |
| 791 | } |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 796 | static int drive_opt_get_free_idx(void) |
| 797 | { |
| 798 | int index; |
| 799 | |
| 800 | for (index = 0; index < MAX_DRIVES; index++) |
| 801 | if (!drives_opt[index].used) { |
| 802 | drives_opt[index].used = 1; |
| 803 | return index; |
| 804 | } |
| 805 | |
| 806 | return -1; |
| 807 | } |
| 808 | |
| 809 | static int drive_get_free_idx(void) |
| 810 | { |
| 811 | int index; |
| 812 | |
| 813 | for (index = 0; index < MAX_DRIVES; index++) |
| 814 | if (!drives_table[index].used) { |
| 815 | drives_table[index].used = 1; |
| 816 | return index; |
| 817 | } |
| 818 | |
| 819 | return -1; |
| 820 | } |
| 821 | |
| 822 | int drive_add(const char *file, const char *fmt, ...) |
| 823 | { |
| 824 | va_list ap; |
| 825 | int index = drive_opt_get_free_idx(); |
| 826 | |
| 827 | if (nb_drives_opt >= MAX_DRIVES || index == -1) { |
| 828 | fprintf(stderr, "qemu: too many drives\n"); |
| 829 | return -1; |
| 830 | } |
| 831 | |
| 832 | drives_opt[index].file = file; |
| 833 | va_start(ap, fmt); |
| 834 | vsnprintf(drives_opt[index].opt, |
| 835 | sizeof(drives_opt[0].opt), fmt, ap); |
| 836 | va_end(ap); |
David 'Digit' Turner | 9256895 | 2010-04-15 15:04:16 -0700 | [diff] [blame] | 837 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 838 | nb_drives_opt++; |
| 839 | return index; |
| 840 | } |
| 841 | |
| 842 | void drive_remove(int index) |
| 843 | { |
| 844 | drives_opt[index].used = 0; |
| 845 | nb_drives_opt--; |
| 846 | } |
| 847 | |
| 848 | int drive_get_index(BlockInterfaceType type, int bus, int unit) |
| 849 | { |
| 850 | int index; |
| 851 | |
| 852 | /* seek interface, bus and unit */ |
| 853 | |
| 854 | for (index = 0; index < MAX_DRIVES; index++) |
| 855 | if (drives_table[index].type == type && |
| 856 | drives_table[index].bus == bus && |
| 857 | drives_table[index].unit == unit && |
| 858 | drives_table[index].used) |
| 859 | return index; |
| 860 | |
| 861 | return -1; |
| 862 | } |
| 863 | |
| 864 | int drive_get_max_bus(BlockInterfaceType type) |
| 865 | { |
| 866 | int max_bus; |
| 867 | int index; |
| 868 | |
| 869 | max_bus = -1; |
| 870 | for (index = 0; index < nb_drives; index++) { |
| 871 | if(drives_table[index].type == type && |
| 872 | drives_table[index].bus > max_bus) |
| 873 | max_bus = drives_table[index].bus; |
| 874 | } |
| 875 | return max_bus; |
| 876 | } |
| 877 | |
| 878 | const char *drive_get_serial(BlockDriverState *bdrv) |
| 879 | { |
| 880 | int index; |
| 881 | |
| 882 | for (index = 0; index < nb_drives; index++) |
| 883 | if (drives_table[index].bdrv == bdrv) |
| 884 | return drives_table[index].serial; |
| 885 | |
| 886 | return "\0"; |
| 887 | } |
| 888 | |
| 889 | BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv) |
| 890 | { |
| 891 | int index; |
| 892 | |
| 893 | for (index = 0; index < nb_drives; index++) |
| 894 | if (drives_table[index].bdrv == bdrv) |
| 895 | return drives_table[index].onerror; |
| 896 | |
| 897 | return BLOCK_ERR_STOP_ENOSPC; |
| 898 | } |
| 899 | |
| 900 | static void bdrv_format_print(void *opaque, const char *name) |
| 901 | { |
| 902 | fprintf(stderr, " %s", name); |
| 903 | } |
| 904 | |
| 905 | void drive_uninit(BlockDriverState *bdrv) |
| 906 | { |
| 907 | int i; |
| 908 | |
| 909 | for (i = 0; i < MAX_DRIVES; i++) |
| 910 | if (drives_table[i].bdrv == bdrv) { |
| 911 | drives_table[i].bdrv = NULL; |
| 912 | drives_table[i].used = 0; |
| 913 | drive_remove(drives_table[i].drive_opt_idx); |
| 914 | nb_drives--; |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | int drive_init(struct drive_opt *arg, int snapshot, void *opaque) |
| 920 | { |
| 921 | char buf[128]; |
| 922 | char file[1024]; |
| 923 | char devname[128]; |
| 924 | char serial[21]; |
| 925 | const char *mediastr = ""; |
| 926 | BlockInterfaceType type; |
| 927 | enum { MEDIA_DISK, MEDIA_CDROM } media; |
| 928 | int bus_id, unit_id; |
| 929 | int cyls, heads, secs, translation; |
| 930 | BlockDriverState *bdrv; |
| 931 | BlockDriver *drv = NULL; |
| 932 | QEMUMachine *machine = opaque; |
| 933 | int max_devs; |
| 934 | int index; |
| 935 | int cache; |
| 936 | int bdrv_flags, onerror; |
| 937 | int drives_table_idx; |
| 938 | char *str = arg->opt; |
| 939 | static const char * const params[] = { "bus", "unit", "if", "index", |
| 940 | "cyls", "heads", "secs", "trans", |
| 941 | "media", "snapshot", "file", |
| 942 | "cache", "format", "serial", "werror", |
| 943 | NULL }; |
| 944 | |
| 945 | if (check_params(buf, sizeof(buf), params, str) < 0) { |
| 946 | fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n", |
| 947 | buf, str); |
| 948 | return -1; |
| 949 | } |
| 950 | |
| 951 | file[0] = 0; |
| 952 | cyls = heads = secs = 0; |
| 953 | bus_id = 0; |
| 954 | unit_id = -1; |
| 955 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 956 | index = -1; |
| 957 | cache = 3; |
| 958 | |
| 959 | if (machine->use_scsi) { |
| 960 | type = IF_SCSI; |
| 961 | max_devs = MAX_SCSI_DEVS; |
| 962 | pstrcpy(devname, sizeof(devname), "scsi"); |
| 963 | } else { |
| 964 | type = IF_IDE; |
| 965 | max_devs = MAX_IDE_DEVS; |
| 966 | pstrcpy(devname, sizeof(devname), "ide"); |
| 967 | } |
| 968 | media = MEDIA_DISK; |
| 969 | |
| 970 | /* extract parameters */ |
| 971 | |
| 972 | if (get_param_value(buf, sizeof(buf), "bus", str)) { |
| 973 | bus_id = strtol(buf, NULL, 0); |
| 974 | if (bus_id < 0) { |
| 975 | fprintf(stderr, "qemu: '%s' invalid bus id\n", str); |
| 976 | return -1; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | if (get_param_value(buf, sizeof(buf), "unit", str)) { |
| 981 | unit_id = strtol(buf, NULL, 0); |
| 982 | if (unit_id < 0) { |
| 983 | fprintf(stderr, "qemu: '%s' invalid unit id\n", str); |
| 984 | return -1; |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | if (get_param_value(buf, sizeof(buf), "if", str)) { |
| 989 | pstrcpy(devname, sizeof(devname), buf); |
| 990 | if (!strcmp(buf, "ide")) { |
| 991 | type = IF_IDE; |
| 992 | max_devs = MAX_IDE_DEVS; |
| 993 | } else if (!strcmp(buf, "scsi")) { |
| 994 | type = IF_SCSI; |
| 995 | max_devs = MAX_SCSI_DEVS; |
| 996 | } else if (!strcmp(buf, "floppy")) { |
| 997 | type = IF_FLOPPY; |
| 998 | max_devs = 0; |
| 999 | } else if (!strcmp(buf, "pflash")) { |
| 1000 | type = IF_PFLASH; |
| 1001 | max_devs = 0; |
| 1002 | } else if (!strcmp(buf, "mtd")) { |
| 1003 | type = IF_MTD; |
| 1004 | max_devs = 0; |
| 1005 | } else if (!strcmp(buf, "sd")) { |
| 1006 | type = IF_SD; |
| 1007 | max_devs = 0; |
| 1008 | } else if (!strcmp(buf, "virtio")) { |
| 1009 | type = IF_VIRTIO; |
| 1010 | max_devs = 0; |
| 1011 | } else if (!strcmp(buf, "xen")) { |
| 1012 | type = IF_XEN; |
| 1013 | max_devs = 0; |
| 1014 | } else { |
| 1015 | fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf); |
| 1016 | return -1; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | if (get_param_value(buf, sizeof(buf), "index", str)) { |
| 1021 | index = strtol(buf, NULL, 0); |
| 1022 | if (index < 0) { |
| 1023 | fprintf(stderr, "qemu: '%s' invalid index\n", str); |
| 1024 | return -1; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | if (get_param_value(buf, sizeof(buf), "cyls", str)) { |
| 1029 | cyls = strtol(buf, NULL, 0); |
| 1030 | } |
| 1031 | |
| 1032 | if (get_param_value(buf, sizeof(buf), "heads", str)) { |
| 1033 | heads = strtol(buf, NULL, 0); |
| 1034 | } |
| 1035 | |
| 1036 | if (get_param_value(buf, sizeof(buf), "secs", str)) { |
| 1037 | secs = strtol(buf, NULL, 0); |
| 1038 | } |
| 1039 | |
| 1040 | if (cyls || heads || secs) { |
| 1041 | if (cyls < 1 || cyls > 16383) { |
| 1042 | fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", str); |
| 1043 | return -1; |
| 1044 | } |
| 1045 | if (heads < 1 || heads > 16) { |
| 1046 | fprintf(stderr, "qemu: '%s' invalid physical heads number\n", str); |
| 1047 | return -1; |
| 1048 | } |
| 1049 | if (secs < 1 || secs > 63) { |
| 1050 | fprintf(stderr, "qemu: '%s' invalid physical secs number\n", str); |
| 1051 | return -1; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | if (get_param_value(buf, sizeof(buf), "trans", str)) { |
| 1056 | if (!cyls) { |
| 1057 | fprintf(stderr, |
| 1058 | "qemu: '%s' trans must be used with cyls,heads and secs\n", |
| 1059 | str); |
| 1060 | return -1; |
| 1061 | } |
| 1062 | if (!strcmp(buf, "none")) |
| 1063 | translation = BIOS_ATA_TRANSLATION_NONE; |
| 1064 | else if (!strcmp(buf, "lba")) |
| 1065 | translation = BIOS_ATA_TRANSLATION_LBA; |
| 1066 | else if (!strcmp(buf, "auto")) |
| 1067 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 1068 | else { |
| 1069 | fprintf(stderr, "qemu: '%s' invalid translation type\n", str); |
| 1070 | return -1; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | if (get_param_value(buf, sizeof(buf), "media", str)) { |
| 1075 | if (!strcmp(buf, "disk")) { |
| 1076 | media = MEDIA_DISK; |
| 1077 | } else if (!strcmp(buf, "cdrom")) { |
| 1078 | if (cyls || secs || heads) { |
| 1079 | fprintf(stderr, |
| 1080 | "qemu: '%s' invalid physical CHS format\n", str); |
| 1081 | return -1; |
| 1082 | } |
| 1083 | media = MEDIA_CDROM; |
| 1084 | } else { |
| 1085 | fprintf(stderr, "qemu: '%s' invalid media\n", str); |
| 1086 | return -1; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | if (get_param_value(buf, sizeof(buf), "snapshot", str)) { |
| 1091 | if (!strcmp(buf, "on")) |
| 1092 | snapshot = 1; |
| 1093 | else if (!strcmp(buf, "off")) |
| 1094 | snapshot = 0; |
| 1095 | else { |
| 1096 | fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str); |
| 1097 | return -1; |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | if (get_param_value(buf, sizeof(buf), "cache", str)) { |
| 1102 | if (!strcmp(buf, "off") || !strcmp(buf, "none")) |
| 1103 | cache = 0; |
| 1104 | else if (!strcmp(buf, "writethrough")) |
| 1105 | cache = 1; |
| 1106 | else if (!strcmp(buf, "writeback")) |
| 1107 | cache = 2; |
| 1108 | else { |
| 1109 | fprintf(stderr, "qemu: invalid cache option\n"); |
| 1110 | return -1; |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | if (get_param_value(buf, sizeof(buf), "format", str)) { |
| 1115 | if (strcmp(buf, "?") == 0) { |
| 1116 | fprintf(stderr, "qemu: Supported formats:"); |
| 1117 | bdrv_iterate_format(bdrv_format_print, NULL); |
| 1118 | fprintf(stderr, "\n"); |
| 1119 | return -1; |
| 1120 | } |
| 1121 | drv = bdrv_find_format(buf); |
| 1122 | if (!drv) { |
| 1123 | fprintf(stderr, "qemu: '%s' invalid format\n", buf); |
| 1124 | return -1; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | if (arg->file == NULL) |
| 1129 | get_param_value(file, sizeof(file), "file", str); |
| 1130 | else |
| 1131 | pstrcpy(file, sizeof(file), arg->file); |
| 1132 | |
| 1133 | if (!get_param_value(serial, sizeof(serial), "serial", str)) |
| 1134 | memset(serial, 0, sizeof(serial)); |
| 1135 | |
| 1136 | onerror = BLOCK_ERR_STOP_ENOSPC; |
| 1137 | if (get_param_value(buf, sizeof(serial), "werror", str)) { |
| 1138 | if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) { |
| 1139 | fprintf(stderr, "werror is no supported by this format\n"); |
| 1140 | return -1; |
| 1141 | } |
| 1142 | if (!strcmp(buf, "ignore")) |
| 1143 | onerror = BLOCK_ERR_IGNORE; |
| 1144 | else if (!strcmp(buf, "enospc")) |
| 1145 | onerror = BLOCK_ERR_STOP_ENOSPC; |
| 1146 | else if (!strcmp(buf, "stop")) |
| 1147 | onerror = BLOCK_ERR_STOP_ANY; |
| 1148 | else if (!strcmp(buf, "report")) |
| 1149 | onerror = BLOCK_ERR_REPORT; |
| 1150 | else { |
| 1151 | fprintf(stderr, "qemu: '%s' invalid write error action\n", buf); |
| 1152 | return -1; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | /* compute bus and unit according index */ |
| 1157 | |
| 1158 | if (index != -1) { |
| 1159 | if (bus_id != 0 || unit_id != -1) { |
| 1160 | fprintf(stderr, |
| 1161 | "qemu: '%s' index cannot be used with bus and unit\n", str); |
| 1162 | return -1; |
| 1163 | } |
| 1164 | if (max_devs == 0) |
| 1165 | { |
| 1166 | unit_id = index; |
| 1167 | bus_id = 0; |
| 1168 | } else { |
| 1169 | unit_id = index % max_devs; |
| 1170 | bus_id = index / max_devs; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | /* if user doesn't specify a unit_id, |
| 1175 | * try to find the first free |
| 1176 | */ |
| 1177 | |
| 1178 | if (unit_id == -1) { |
| 1179 | unit_id = 0; |
| 1180 | while (drive_get_index(type, bus_id, unit_id) != -1) { |
| 1181 | unit_id++; |
| 1182 | if (max_devs && unit_id >= max_devs) { |
| 1183 | unit_id -= max_devs; |
| 1184 | bus_id++; |
| 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | /* check unit id */ |
| 1190 | |
| 1191 | if (max_devs && unit_id >= max_devs) { |
| 1192 | fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n", |
| 1193 | str, unit_id, max_devs - 1); |
| 1194 | return -1; |
| 1195 | } |
| 1196 | |
| 1197 | /* |
| 1198 | * ignore multiple definitions |
| 1199 | */ |
| 1200 | |
| 1201 | if (drive_get_index(type, bus_id, unit_id) != -1) |
| 1202 | return -2; |
| 1203 | |
| 1204 | /* init */ |
| 1205 | |
| 1206 | if (type == IF_IDE || type == IF_SCSI) |
| 1207 | mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; |
| 1208 | if (max_devs) |
| 1209 | snprintf(buf, sizeof(buf), "%s%i%s%i", |
| 1210 | devname, bus_id, mediastr, unit_id); |
| 1211 | else |
| 1212 | snprintf(buf, sizeof(buf), "%s%s%i", |
| 1213 | devname, mediastr, unit_id); |
| 1214 | bdrv = bdrv_new(buf); |
| 1215 | drives_table_idx = drive_get_free_idx(); |
| 1216 | drives_table[drives_table_idx].bdrv = bdrv; |
| 1217 | drives_table[drives_table_idx].type = type; |
| 1218 | drives_table[drives_table_idx].bus = bus_id; |
| 1219 | drives_table[drives_table_idx].unit = unit_id; |
| 1220 | drives_table[drives_table_idx].onerror = onerror; |
| 1221 | drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt; |
| 1222 | strncpy(drives_table[drives_table_idx].serial, serial, sizeof(serial)); |
| 1223 | nb_drives++; |
| 1224 | |
| 1225 | switch(type) { |
| 1226 | case IF_IDE: |
| 1227 | case IF_SCSI: |
| 1228 | case IF_XEN: |
| 1229 | switch(media) { |
| 1230 | case MEDIA_DISK: |
| 1231 | if (cyls != 0) { |
| 1232 | bdrv_set_geometry_hint(bdrv, cyls, heads, secs); |
| 1233 | bdrv_set_translation_hint(bdrv, translation); |
| 1234 | } |
| 1235 | break; |
| 1236 | case MEDIA_CDROM: |
| 1237 | bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM); |
| 1238 | break; |
| 1239 | } |
| 1240 | break; |
| 1241 | case IF_SD: |
| 1242 | /* FIXME: This isn't really a floppy, but it's a reasonable |
| 1243 | approximation. */ |
| 1244 | case IF_FLOPPY: |
| 1245 | bdrv_set_type_hint(bdrv, BDRV_TYPE_FLOPPY); |
| 1246 | break; |
| 1247 | case IF_PFLASH: |
| 1248 | case IF_MTD: |
| 1249 | case IF_VIRTIO: |
| 1250 | break; |
| 1251 | case IF_COUNT: |
David 'Digit' Turner | c34e8dc | 2010-09-13 02:47:01 -0700 | [diff] [blame] | 1252 | case IF_NONE: |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1253 | abort(); |
| 1254 | } |
| 1255 | if (!file[0]) |
| 1256 | return -2; |
| 1257 | bdrv_flags = 0; |
| 1258 | if (snapshot) { |
| 1259 | bdrv_flags |= BDRV_O_SNAPSHOT; |
| 1260 | cache = 2; /* always use write-back with snapshot */ |
| 1261 | } |
| 1262 | if (cache == 0) /* no caching */ |
| 1263 | bdrv_flags |= BDRV_O_NOCACHE; |
| 1264 | else if (cache == 2) /* write-back */ |
| 1265 | bdrv_flags |= BDRV_O_CACHE_WB; |
| 1266 | else if (cache == 3) /* not specified */ |
| 1267 | bdrv_flags |= BDRV_O_CACHE_DEF; |
| 1268 | if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) { |
| 1269 | fprintf(stderr, "qemu: could not open disk image %s\n", |
| 1270 | file); |
| 1271 | return -1; |
| 1272 | } |
| 1273 | if (bdrv_key_required(bdrv)) |
| 1274 | autostart = 0; |
| 1275 | return drives_table_idx; |
| 1276 | } |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 1277 | #endif /* MAX_DRIVES */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1278 | |
| 1279 | static void numa_add(const char *optarg) |
| 1280 | { |
| 1281 | char option[128]; |
| 1282 | char *endptr; |
| 1283 | unsigned long long value, endvalue; |
| 1284 | int nodenr; |
| 1285 | |
| 1286 | optarg = get_opt_name(option, 128, optarg, ',') + 1; |
| 1287 | if (!strcmp(option, "node")) { |
| 1288 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
| 1289 | nodenr = nb_numa_nodes; |
| 1290 | } else { |
| 1291 | nodenr = strtoull(option, NULL, 10); |
| 1292 | } |
| 1293 | |
| 1294 | if (get_param_value(option, 128, "mem", optarg) == 0) { |
| 1295 | node_mem[nodenr] = 0; |
| 1296 | } else { |
| 1297 | value = strtoull(option, &endptr, 0); |
| 1298 | switch (*endptr) { |
| 1299 | case 0: case 'M': case 'm': |
| 1300 | value <<= 20; |
| 1301 | break; |
| 1302 | case 'G': case 'g': |
| 1303 | value <<= 30; |
| 1304 | break; |
| 1305 | } |
| 1306 | node_mem[nodenr] = value; |
| 1307 | } |
| 1308 | if (get_param_value(option, 128, "cpus", optarg) == 0) { |
| 1309 | node_cpumask[nodenr] = 0; |
| 1310 | } else { |
| 1311 | value = strtoull(option, &endptr, 10); |
| 1312 | if (value >= 64) { |
| 1313 | value = 63; |
| 1314 | fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n"); |
| 1315 | } else { |
| 1316 | if (*endptr == '-') { |
| 1317 | endvalue = strtoull(endptr+1, &endptr, 10); |
| 1318 | if (endvalue >= 63) { |
| 1319 | endvalue = 62; |
| 1320 | fprintf(stderr, |
| 1321 | "only 63 CPUs in NUMA mode supported.\n"); |
| 1322 | } |
| 1323 | value = (1 << (endvalue + 1)) - (1 << value); |
| 1324 | } else { |
| 1325 | value = 1 << value; |
| 1326 | } |
| 1327 | } |
| 1328 | node_cpumask[nodenr] = value; |
| 1329 | } |
| 1330 | nb_numa_nodes++; |
| 1331 | } |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | /***********************************************************/ |
| 1336 | /* USB devices */ |
| 1337 | |
| 1338 | static USBPort *used_usb_ports; |
| 1339 | static USBPort *free_usb_ports; |
| 1340 | |
| 1341 | /* ??? Maybe change this to register a hub to keep track of the topology. */ |
| 1342 | void qemu_register_usb_port(USBPort *port, void *opaque, int index, |
| 1343 | usb_attachfn attach) |
| 1344 | { |
| 1345 | port->opaque = opaque; |
| 1346 | port->index = index; |
| 1347 | port->attach = attach; |
| 1348 | port->next = free_usb_ports; |
| 1349 | free_usb_ports = port; |
| 1350 | } |
| 1351 | |
| 1352 | int usb_device_add_dev(USBDevice *dev) |
| 1353 | { |
| 1354 | USBPort *port; |
| 1355 | |
| 1356 | /* Find a USB port to add the device to. */ |
| 1357 | port = free_usb_ports; |
Manuel Francisco Naranjo | 58ecd74 | 2012-07-18 11:22:09 -0300 | [diff] [blame] | 1358 | if (!port){ |
| 1359 | USBDevice *hub = usb_hub_init(VM_USB_HUB_SIZE); |
| 1360 | port = free_usb_ports; |
| 1361 | usb_attach(port, hub); |
| 1362 | } |
| 1363 | else if (!port->next){ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1364 | USBDevice *hub; |
| 1365 | |
| 1366 | /* Create a new hub and chain it on. */ |
| 1367 | free_usb_ports = NULL; |
| 1368 | port->next = used_usb_ports; |
| 1369 | used_usb_ports = port; |
| 1370 | |
| 1371 | hub = usb_hub_init(VM_USB_HUB_SIZE); |
| 1372 | usb_attach(port, hub); |
| 1373 | port = free_usb_ports; |
| 1374 | } |
| 1375 | |
| 1376 | free_usb_ports = port->next; |
| 1377 | port->next = used_usb_ports; |
| 1378 | used_usb_ports = port; |
| 1379 | usb_attach(port, dev); |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
David 'Digit' Turner | 3266b51 | 2010-05-10 18:44:56 -0700 | [diff] [blame] | 1383 | #if 0 |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1384 | static void usb_msd_password_cb(void *opaque, int err) |
| 1385 | { |
| 1386 | USBDevice *dev = opaque; |
| 1387 | |
| 1388 | if (!err) |
| 1389 | usb_device_add_dev(dev); |
| 1390 | else |
| 1391 | dev->handle_destroy(dev); |
| 1392 | } |
David 'Digit' Turner | 3266b51 | 2010-05-10 18:44:56 -0700 | [diff] [blame] | 1393 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1394 | |
| 1395 | static int usb_device_add(const char *devname, int is_hotplug) |
| 1396 | { |
| 1397 | const char *p; |
| 1398 | USBDevice *dev; |
| 1399 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1400 | if (strstart(devname, "host:", &p)) { |
| 1401 | dev = usb_host_device_open(p); |
| 1402 | } else if (!strcmp(devname, "mouse")) { |
| 1403 | dev = usb_mouse_init(); |
| 1404 | } else if (!strcmp(devname, "tablet")) { |
| 1405 | dev = usb_tablet_init(); |
| 1406 | } else if (!strcmp(devname, "keyboard")) { |
| 1407 | dev = usb_keyboard_init(); |
| 1408 | } else if (strstart(devname, "disk:", &p)) { |
| 1409 | #if 0 |
| 1410 | BlockDriverState *bs; |
| 1411 | #endif |
| 1412 | dev = usb_msd_init(p); |
| 1413 | if (!dev) |
| 1414 | return -1; |
| 1415 | #if 0 |
| 1416 | bs = usb_msd_get_bdrv(dev); |
| 1417 | if (bdrv_key_required(bs)) { |
| 1418 | autostart = 0; |
| 1419 | if (is_hotplug) { |
| 1420 | monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb, |
| 1421 | dev); |
| 1422 | return 0; |
| 1423 | } |
| 1424 | } |
| 1425 | } else if (!strcmp(devname, "wacom-tablet")) { |
| 1426 | dev = usb_wacom_init(); |
| 1427 | } else if (strstart(devname, "serial:", &p)) { |
| 1428 | dev = usb_serial_init(p); |
| 1429 | #ifdef CONFIG_BRLAPI |
| 1430 | } else if (!strcmp(devname, "braille")) { |
| 1431 | dev = usb_baum_init(); |
| 1432 | #endif |
| 1433 | } else if (strstart(devname, "net:", &p)) { |
| 1434 | int nic = nb_nics; |
| 1435 | |
| 1436 | if (net_client_init("nic", p) < 0) |
| 1437 | return -1; |
| 1438 | nd_table[nic].model = "usb"; |
| 1439 | dev = usb_net_init(&nd_table[nic]); |
| 1440 | } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { |
| 1441 | dev = usb_bt_init(devname[2] ? hci_init(p) : |
| 1442 | bt_new_hci(qemu_find_bt_vlan(0))); |
| 1443 | #endif |
| 1444 | } else { |
| 1445 | return -1; |
| 1446 | } |
| 1447 | if (!dev) |
| 1448 | return -1; |
| 1449 | |
| 1450 | return usb_device_add_dev(dev); |
| 1451 | } |
| 1452 | |
| 1453 | int usb_device_del_addr(int bus_num, int addr) |
| 1454 | { |
| 1455 | USBPort *port; |
| 1456 | USBPort **lastp; |
| 1457 | USBDevice *dev; |
| 1458 | |
| 1459 | if (!used_usb_ports) |
| 1460 | return -1; |
| 1461 | |
| 1462 | if (bus_num != 0) |
| 1463 | return -1; |
| 1464 | |
| 1465 | lastp = &used_usb_ports; |
| 1466 | port = used_usb_ports; |
| 1467 | while (port && port->dev->addr != addr) { |
| 1468 | lastp = &port->next; |
| 1469 | port = port->next; |
| 1470 | } |
| 1471 | |
| 1472 | if (!port) |
| 1473 | return -1; |
| 1474 | |
| 1475 | dev = port->dev; |
| 1476 | *lastp = port->next; |
| 1477 | usb_attach(port, NULL); |
| 1478 | dev->handle_destroy(dev); |
| 1479 | port->next = free_usb_ports; |
| 1480 | free_usb_ports = port; |
| 1481 | return 0; |
| 1482 | } |
| 1483 | |
| 1484 | static int usb_device_del(const char *devname) |
| 1485 | { |
| 1486 | int bus_num, addr; |
| 1487 | const char *p; |
| 1488 | |
| 1489 | if (strstart(devname, "host:", &p)) |
| 1490 | return usb_host_device_close(p); |
| 1491 | |
| 1492 | if (!used_usb_ports) |
| 1493 | return -1; |
| 1494 | |
| 1495 | p = strchr(devname, '.'); |
| 1496 | if (!p) |
| 1497 | return -1; |
| 1498 | bus_num = strtoul(devname, NULL, 0); |
| 1499 | addr = strtoul(p + 1, NULL, 0); |
| 1500 | |
| 1501 | return usb_device_del_addr(bus_num, addr); |
| 1502 | } |
| 1503 | |
| 1504 | void do_usb_add(Monitor *mon, const char *devname) |
| 1505 | { |
| 1506 | usb_device_add(devname, 1); |
| 1507 | } |
| 1508 | |
| 1509 | void do_usb_del(Monitor *mon, const char *devname) |
| 1510 | { |
| 1511 | usb_device_del(devname); |
| 1512 | } |
| 1513 | |
| 1514 | void usb_info(Monitor *mon) |
| 1515 | { |
| 1516 | USBDevice *dev; |
| 1517 | USBPort *port; |
| 1518 | const char *speed_str; |
| 1519 | |
| 1520 | if (!usb_enabled) { |
| 1521 | monitor_printf(mon, "USB support not enabled\n"); |
| 1522 | return; |
| 1523 | } |
| 1524 | |
| 1525 | for (port = used_usb_ports; port; port = port->next) { |
| 1526 | dev = port->dev; |
| 1527 | if (!dev) |
| 1528 | continue; |
| 1529 | switch(dev->speed) { |
| 1530 | case USB_SPEED_LOW: |
| 1531 | speed_str = "1.5"; |
| 1532 | break; |
| 1533 | case USB_SPEED_FULL: |
| 1534 | speed_str = "12"; |
| 1535 | break; |
| 1536 | case USB_SPEED_HIGH: |
| 1537 | speed_str = "480"; |
| 1538 | break; |
| 1539 | default: |
| 1540 | speed_str = "?"; |
| 1541 | break; |
| 1542 | } |
| 1543 | monitor_printf(mon, " Device %d.%d, Speed %s Mb/s, Product %s\n", |
| 1544 | 0, dev->addr, speed_str, dev->devname); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | /***********************************************************/ |
| 1549 | /* PCMCIA/Cardbus */ |
| 1550 | |
| 1551 | static struct pcmcia_socket_entry_s { |
| 1552 | PCMCIASocket *socket; |
| 1553 | struct pcmcia_socket_entry_s *next; |
| 1554 | } *pcmcia_sockets = 0; |
| 1555 | |
| 1556 | void pcmcia_socket_register(PCMCIASocket *socket) |
| 1557 | { |
| 1558 | struct pcmcia_socket_entry_s *entry; |
| 1559 | |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1560 | entry = g_malloc(sizeof(struct pcmcia_socket_entry_s)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1561 | entry->socket = socket; |
| 1562 | entry->next = pcmcia_sockets; |
| 1563 | pcmcia_sockets = entry; |
| 1564 | } |
| 1565 | |
| 1566 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
| 1567 | { |
| 1568 | struct pcmcia_socket_entry_s *entry, **ptr; |
| 1569 | |
| 1570 | ptr = &pcmcia_sockets; |
| 1571 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) |
| 1572 | if (entry->socket == socket) { |
| 1573 | *ptr = entry->next; |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1574 | g_free(entry); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | void pcmcia_info(Monitor *mon) |
| 1579 | { |
| 1580 | struct pcmcia_socket_entry_s *iter; |
| 1581 | |
| 1582 | if (!pcmcia_sockets) |
| 1583 | monitor_printf(mon, "No PCMCIA sockets\n"); |
| 1584 | |
| 1585 | for (iter = pcmcia_sockets; iter; iter = iter->next) |
| 1586 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
| 1587 | iter->socket->attached ? iter->socket->card_string : |
| 1588 | "Empty"); |
| 1589 | } |
| 1590 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1591 | /***********************************************************/ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1592 | /* machine registration */ |
| 1593 | |
| 1594 | static QEMUMachine *first_machine = NULL; |
| 1595 | QEMUMachine *current_machine = NULL; |
| 1596 | |
| 1597 | int qemu_register_machine(QEMUMachine *m) |
| 1598 | { |
| 1599 | QEMUMachine **pm; |
| 1600 | pm = &first_machine; |
| 1601 | while (*pm != NULL) |
| 1602 | pm = &(*pm)->next; |
| 1603 | m->next = NULL; |
| 1604 | *pm = m; |
| 1605 | return 0; |
| 1606 | } |
| 1607 | |
| 1608 | static QEMUMachine *find_machine(const char *name) |
| 1609 | { |
| 1610 | QEMUMachine *m; |
| 1611 | |
| 1612 | for(m = first_machine; m != NULL; m = m->next) { |
| 1613 | if (!strcmp(m->name, name)) |
| 1614 | return m; |
| 1615 | } |
| 1616 | return NULL; |
| 1617 | } |
| 1618 | |
| 1619 | static QEMUMachine *find_default_machine(void) |
| 1620 | { |
| 1621 | QEMUMachine *m; |
| 1622 | |
| 1623 | for(m = first_machine; m != NULL; m = m->next) { |
| 1624 | if (m->is_default) { |
| 1625 | return m; |
| 1626 | } |
| 1627 | } |
| 1628 | return NULL; |
| 1629 | } |
| 1630 | |
| 1631 | /***********************************************************/ |
| 1632 | /* main execution loop */ |
| 1633 | |
| 1634 | static void gui_update(void *opaque) |
| 1635 | { |
| 1636 | uint64_t interval = GUI_REFRESH_INTERVAL; |
| 1637 | DisplayState *ds = opaque; |
| 1638 | DisplayChangeListener *dcl = ds->listeners; |
| 1639 | |
| 1640 | dpy_refresh(ds); |
| 1641 | |
| 1642 | while (dcl != NULL) { |
| 1643 | if (dcl->gui_timer_interval && |
| 1644 | dcl->gui_timer_interval < interval) |
| 1645 | interval = dcl->gui_timer_interval; |
| 1646 | dcl = dcl->next; |
| 1647 | } |
David 'Digit' Turner | dcda949 | 2014-02-16 15:13:55 +0100 | [diff] [blame] | 1648 | timer_mod(ds->gui_timer, interval + qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | static void nographic_update(void *opaque) |
| 1652 | { |
| 1653 | uint64_t interval = GUI_REFRESH_INTERVAL; |
| 1654 | |
David 'Digit' Turner | dcda949 | 2014-02-16 15:13:55 +0100 | [diff] [blame] | 1655 | timer_mod(nographic_timer, interval + qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | struct vm_change_state_entry { |
| 1659 | VMChangeStateHandler *cb; |
| 1660 | void *opaque; |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1661 | QLIST_ENTRY (vm_change_state_entry) entries; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1662 | }; |
| 1663 | |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1664 | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1665 | |
| 1666 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
| 1667 | void *opaque) |
| 1668 | { |
| 1669 | VMChangeStateEntry *e; |
| 1670 | |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1671 | e = g_malloc0(sizeof (*e)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1672 | |
| 1673 | e->cb = cb; |
| 1674 | e->opaque = opaque; |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1675 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1676 | return e; |
| 1677 | } |
| 1678 | |
| 1679 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) |
| 1680 | { |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1681 | QLIST_REMOVE (e, entries); |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1682 | g_free (e); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
David 'Digit' Turner | 23ca2ae | 2011-06-01 16:14:53 +0200 | [diff] [blame] | 1685 | void vm_state_notify(int running, int reason) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1686 | { |
| 1687 | VMChangeStateEntry *e; |
| 1688 | |
| 1689 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
| 1690 | e->cb(e->opaque, running, reason); |
| 1691 | } |
| 1692 | } |
| 1693 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1694 | void vm_start(void) |
| 1695 | { |
| 1696 | if (!vm_running) { |
| 1697 | cpu_enable_ticks(); |
| 1698 | vm_running = 1; |
| 1699 | vm_state_notify(1, 0); |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 1700 | //qemu_rearm_alarm_timer(alarm_timer); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1701 | resume_all_vcpus(); |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | /* reset/shutdown handler */ |
| 1706 | |
| 1707 | typedef struct QEMUResetEntry { |
| 1708 | QEMUResetHandler *func; |
| 1709 | void *opaque; |
| 1710 | int order; |
| 1711 | struct QEMUResetEntry *next; |
| 1712 | } QEMUResetEntry; |
| 1713 | |
| 1714 | static QEMUResetEntry *first_reset_entry; |
| 1715 | static int reset_requested; |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 1716 | static int shutdown_requested, shutdown_signal = -1; |
| 1717 | static pid_t shutdown_pid; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1718 | static int powerdown_requested; |
David 'Digit' Turner | 23ca2ae | 2011-06-01 16:14:53 +0200 | [diff] [blame] | 1719 | int debug_requested; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1720 | static int vmstop_requested; |
| 1721 | |
| 1722 | int qemu_shutdown_requested(void) |
| 1723 | { |
| 1724 | int r = shutdown_requested; |
| 1725 | shutdown_requested = 0; |
| 1726 | return r; |
| 1727 | } |
| 1728 | |
| 1729 | int qemu_reset_requested(void) |
| 1730 | { |
| 1731 | int r = reset_requested; |
| 1732 | reset_requested = 0; |
| 1733 | return r; |
| 1734 | } |
| 1735 | |
| 1736 | int qemu_powerdown_requested(void) |
| 1737 | { |
| 1738 | int r = powerdown_requested; |
| 1739 | powerdown_requested = 0; |
| 1740 | return r; |
| 1741 | } |
| 1742 | |
David 'Digit' Turner | f9077a8 | 2014-02-10 23:10:47 +0100 | [diff] [blame] | 1743 | int qemu_debug_requested(void) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1744 | { |
| 1745 | int r = debug_requested; |
| 1746 | debug_requested = 0; |
| 1747 | return r; |
| 1748 | } |
| 1749 | |
David 'Digit' Turner | f9077a8 | 2014-02-10 23:10:47 +0100 | [diff] [blame] | 1750 | int qemu_vmstop_requested(void) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1751 | { |
| 1752 | int r = vmstop_requested; |
| 1753 | vmstop_requested = 0; |
| 1754 | return r; |
| 1755 | } |
| 1756 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1757 | void qemu_register_reset(QEMUResetHandler *func, int order, void *opaque) |
| 1758 | { |
| 1759 | QEMUResetEntry **pre, *re; |
| 1760 | |
| 1761 | pre = &first_reset_entry; |
| 1762 | while (*pre != NULL && (*pre)->order >= order) { |
| 1763 | pre = &(*pre)->next; |
| 1764 | } |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1765 | re = g_malloc0(sizeof(QEMUResetEntry)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1766 | re->func = func; |
| 1767 | re->opaque = opaque; |
| 1768 | re->order = order; |
| 1769 | re->next = NULL; |
| 1770 | *pre = re; |
| 1771 | } |
| 1772 | |
| 1773 | void qemu_system_reset(void) |
| 1774 | { |
| 1775 | QEMUResetEntry *re; |
| 1776 | |
| 1777 | /* reset all devices */ |
| 1778 | for(re = first_reset_entry; re != NULL; re = re->next) { |
| 1779 | re->func(re->opaque); |
| 1780 | } |
| 1781 | } |
| 1782 | |
| 1783 | void qemu_system_reset_request(void) |
| 1784 | { |
| 1785 | if (no_reboot) { |
| 1786 | shutdown_requested = 1; |
| 1787 | } else { |
| 1788 | reset_requested = 1; |
| 1789 | } |
| 1790 | qemu_notify_event(); |
| 1791 | } |
| 1792 | |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 1793 | void qemu_system_killed(int signal, pid_t pid) |
| 1794 | { |
| 1795 | shutdown_signal = signal; |
| 1796 | shutdown_pid = pid; |
| 1797 | qemu_system_shutdown_request(); |
| 1798 | } |
| 1799 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1800 | void qemu_system_shutdown_request(void) |
| 1801 | { |
| 1802 | shutdown_requested = 1; |
| 1803 | qemu_notify_event(); |
| 1804 | } |
| 1805 | |
| 1806 | void qemu_system_powerdown_request(void) |
| 1807 | { |
| 1808 | powerdown_requested = 1; |
| 1809 | qemu_notify_event(); |
| 1810 | } |
| 1811 | |
David 'Digit' Turner | f9077a8 | 2014-02-10 23:10:47 +0100 | [diff] [blame] | 1812 | int vm_can_run(void) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1813 | { |
| 1814 | if (powerdown_requested) |
| 1815 | return 0; |
| 1816 | if (reset_requested) |
| 1817 | return 0; |
| 1818 | if (shutdown_requested) |
| 1819 | return 0; |
| 1820 | if (debug_requested) |
| 1821 | return 0; |
| 1822 | return 1; |
| 1823 | } |
| 1824 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 1825 | void version(void) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1826 | { |
| 1827 | printf("QEMU PC emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
| 1828 | } |
| 1829 | |
| 1830 | void qemu_help(int exitcode) |
| 1831 | { |
| 1832 | version(); |
| 1833 | printf("usage: %s [options] [disk_image]\n" |
| 1834 | "\n" |
| 1835 | "'disk_image' is a raw hard image image for IDE hard disk 0\n" |
| 1836 | "\n" |
| 1837 | #define DEF(option, opt_arg, opt_enum, opt_help) \ |
| 1838 | opt_help |
| 1839 | #define DEFHEADING(text) stringify(text) "\n" |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 1840 | #include "qemu-options.def" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1841 | #undef DEF |
| 1842 | #undef DEFHEADING |
| 1843 | #undef GEN_DOCS |
| 1844 | "\n" |
| 1845 | "During emulation, the following keys are useful:\n" |
| 1846 | "ctrl-alt-f toggle full screen\n" |
| 1847 | "ctrl-alt-n switch to virtual console 'n'\n" |
| 1848 | "ctrl-alt toggle mouse and keyboard grab\n" |
| 1849 | "\n" |
| 1850 | "When using -nographic, press 'ctrl-a h' to get some help.\n" |
| 1851 | , |
| 1852 | "qemu", |
| 1853 | DEFAULT_RAM_SIZE, |
| 1854 | #ifndef _WIN32 |
| 1855 | DEFAULT_NETWORK_SCRIPT, |
| 1856 | DEFAULT_NETWORK_DOWN_SCRIPT, |
| 1857 | #endif |
| 1858 | DEFAULT_GDBSTUB_PORT, |
| 1859 | "/tmp/qemu.log"); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 1860 | QEMU_EXIT(exitcode); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | #define HAS_ARG 0x0001 |
| 1864 | |
| 1865 | enum { |
| 1866 | #define DEF(option, opt_arg, opt_enum, opt_help) \ |
| 1867 | opt_enum, |
| 1868 | #define DEFHEADING(text) |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 1869 | #include "qemu-options.def" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1870 | #undef DEF |
| 1871 | #undef DEFHEADING |
| 1872 | #undef GEN_DOCS |
| 1873 | }; |
| 1874 | |
| 1875 | typedef struct QEMUOption { |
| 1876 | const char *name; |
| 1877 | int flags; |
| 1878 | int index; |
| 1879 | } QEMUOption; |
| 1880 | |
| 1881 | static const QEMUOption qemu_options[] = { |
| 1882 | { "h", 0, QEMU_OPTION_h }, |
| 1883 | #define DEF(option, opt_arg, opt_enum, opt_help) \ |
| 1884 | { option, opt_arg, opt_enum }, |
| 1885 | #define DEFHEADING(text) |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 1886 | #include "qemu-options.def" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1887 | #undef DEF |
| 1888 | #undef DEFHEADING |
| 1889 | #undef GEN_DOCS |
| 1890 | { NULL, 0, 0 }, |
| 1891 | }; |
| 1892 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1893 | static void select_vgahw (const char *p) |
| 1894 | { |
| 1895 | const char *opts; |
| 1896 | |
| 1897 | cirrus_vga_enabled = 0; |
| 1898 | std_vga_enabled = 0; |
| 1899 | vmsvga_enabled = 0; |
| 1900 | xenfb_enabled = 0; |
| 1901 | if (strstart(p, "std", &opts)) { |
| 1902 | std_vga_enabled = 1; |
| 1903 | } else if (strstart(p, "cirrus", &opts)) { |
| 1904 | cirrus_vga_enabled = 1; |
| 1905 | } else if (strstart(p, "vmware", &opts)) { |
| 1906 | vmsvga_enabled = 1; |
| 1907 | } else if (strstart(p, "xenfb", &opts)) { |
| 1908 | xenfb_enabled = 1; |
| 1909 | } else if (!strstart(p, "none", &opts)) { |
| 1910 | invalid_vga: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 1911 | PANIC("Unknown vga type: %s", p); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1912 | } |
| 1913 | while (*opts) { |
| 1914 | const char *nextopt; |
| 1915 | |
| 1916 | if (strstart(opts, ",retrace=", &nextopt)) { |
| 1917 | opts = nextopt; |
| 1918 | if (strstart(opts, "dumb", &nextopt)) |
| 1919 | vga_retrace_method = VGA_RETRACE_DUMB; |
| 1920 | else if (strstart(opts, "precise", &nextopt)) |
| 1921 | vga_retrace_method = VGA_RETRACE_PRECISE; |
| 1922 | else goto invalid_vga; |
| 1923 | } else goto invalid_vga; |
| 1924 | opts = nextopt; |
| 1925 | } |
| 1926 | } |
| 1927 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1928 | #define MAX_NET_CLIENTS 32 |
| 1929 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1930 | #ifdef _WIN32 |
| 1931 | /* Look for support files in the same directory as the executable. */ |
| 1932 | static char *find_datadir(const char *argv0) |
| 1933 | { |
| 1934 | char *p; |
| 1935 | char buf[MAX_PATH]; |
| 1936 | DWORD len; |
| 1937 | |
| 1938 | len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); |
| 1939 | if (len == 0) { |
| 1940 | return NULL; |
| 1941 | } |
| 1942 | |
| 1943 | buf[len] = 0; |
| 1944 | p = buf + len - 1; |
| 1945 | while (p != buf && *p != '\\') |
| 1946 | p--; |
| 1947 | *p = 0; |
| 1948 | if (access(buf, R_OK) == 0) { |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1949 | return g_strdup(buf); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1950 | } |
| 1951 | return NULL; |
| 1952 | } |
| 1953 | #else /* !_WIN32 */ |
| 1954 | |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 1955 | /* Similarly, return the location of the executable */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1956 | static char *find_datadir(const char *argv0) |
| 1957 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1958 | char *p = NULL; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1959 | char buf[PATH_MAX]; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1960 | |
| 1961 | #if defined(__linux__) |
| 1962 | { |
| 1963 | int len; |
| 1964 | len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); |
| 1965 | if (len > 0) { |
| 1966 | buf[len] = 0; |
| 1967 | p = buf; |
| 1968 | } |
| 1969 | } |
| 1970 | #elif defined(__FreeBSD__) |
| 1971 | { |
| 1972 | int len; |
| 1973 | len = readlink("/proc/curproc/file", buf, sizeof(buf) - 1); |
| 1974 | if (len > 0) { |
| 1975 | buf[len] = 0; |
| 1976 | p = buf; |
| 1977 | } |
| 1978 | } |
| 1979 | #endif |
| 1980 | /* If we don't have any way of figuring out the actual executable |
| 1981 | location then try argv[0]. */ |
| 1982 | if (!p) { |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 1983 | p = realpath(argv0, buf); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1984 | if (!p) { |
| 1985 | return NULL; |
| 1986 | } |
| 1987 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1988 | |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1989 | return g_strdup(dirname(buf)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1990 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1991 | #endif |
| 1992 | |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 1993 | static char* |
| 1994 | qemu_find_file_with_subdir(const char* data_dir, const char* subdir, const char* name) |
| 1995 | { |
| 1996 | int len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1997 | char* buf = g_malloc0(len); |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 1998 | |
| 1999 | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); |
| 2000 | VERBOSE_PRINT(init," trying to find: %s\n", buf); |
| 2001 | if (access(buf, R_OK)) { |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 2002 | g_free(buf); |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2003 | return NULL; |
| 2004 | } |
| 2005 | return buf; |
| 2006 | } |
| 2007 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2008 | char *qemu_find_file(int type, const char *name) |
| 2009 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2010 | const char *subdir; |
| 2011 | char *buf; |
| 2012 | |
| 2013 | /* If name contains path separators then try it as a straight path. */ |
| 2014 | if ((strchr(name, '/') || strchr(name, '\\')) |
| 2015 | && access(name, R_OK) == 0) { |
| 2016 | return strdup(name); |
| 2017 | } |
| 2018 | switch (type) { |
| 2019 | case QEMU_FILE_TYPE_BIOS: |
| 2020 | subdir = ""; |
| 2021 | break; |
| 2022 | case QEMU_FILE_TYPE_KEYMAP: |
| 2023 | subdir = "keymaps/"; |
| 2024 | break; |
| 2025 | default: |
| 2026 | abort(); |
| 2027 | } |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2028 | buf = qemu_find_file_with_subdir(data_dir, subdir, name); |
| 2029 | #ifdef CONFIG_ANDROID |
| 2030 | if (type == QEMU_FILE_TYPE_BIOS) { |
| 2031 | /* This case corresponds to the emulator being used as part of an |
| 2032 | * SDK installation. NOTE: data_dir is really $bindir. */ |
| 2033 | if (buf == NULL) |
| 2034 | buf = qemu_find_file_with_subdir(data_dir, "lib/pc-bios/", name); |
| 2035 | /* This case corresponds to platform builds. */ |
| 2036 | if (buf == NULL) |
| 2037 | buf = qemu_find_file_with_subdir(data_dir, "../usr/share/pc-bios/", name); |
| 2038 | /* Finally, try this for standalone builds under external/qemu */ |
| 2039 | if (buf == NULL) |
Andrew Hsieh | 3d89428 | 2012-05-02 12:06:12 +0800 | [diff] [blame] | 2040 | buf = qemu_find_file_with_subdir(data_dir, "../../../prebuilts/qemu-kernel/x86/pc-bios/", name); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2041 | } |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2042 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2043 | return buf; |
| 2044 | } |
| 2045 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 2046 | static int |
| 2047 | add_dns_server( const char* server_name ) |
| 2048 | { |
| 2049 | SockAddress addr; |
| 2050 | |
| 2051 | if (sock_address_init_resolve( &addr, server_name, 55, 0 ) < 0) { |
| 2052 | fprintf(stdout, |
| 2053 | "### WARNING: can't resolve DNS server name '%s'\n", |
| 2054 | server_name ); |
| 2055 | return -1; |
| 2056 | } |
| 2057 | |
| 2058 | fprintf(stderr, |
| 2059 | "DNS server name '%s' resolved to %s\n", server_name, sock_address_to_string(&addr) ); |
| 2060 | |
| 2061 | if ( slirp_add_dns_server( &addr ) < 0 ) { |
| 2062 | fprintf(stderr, |
| 2063 | "### WARNING: could not add DNS server '%s' to the network stack\n", server_name); |
| 2064 | return -1; |
| 2065 | } |
| 2066 | return 0; |
| 2067 | } |
| 2068 | |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2069 | /* Parses an integer |
| 2070 | * Pararm: |
| 2071 | * str String containing a number to be parsed. |
| 2072 | * result Passes the parsed integer in this argument |
| 2073 | * returns 0 if ok, -1 if failed |
| 2074 | */ |
| 2075 | int |
| 2076 | parse_int(const char *str, int *result) |
| 2077 | { |
| 2078 | char* r; |
| 2079 | *result = strtol(str, &r, 0); |
| 2080 | if (r == NULL || *r != '\0') |
| 2081 | return -1; |
| 2082 | |
| 2083 | return 0; |
| 2084 | } |
| 2085 | |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2086 | /* parses a null-terminated string specifying a network port (e.g., "80") or |
| 2087 | * port range (e.g., "[6666-7000]"). In case of a single port, lport and hport |
| 2088 | * are the same. Returns 0 on success, -1 on error. */ |
| 2089 | |
| 2090 | int parse_port_range(const char *str, unsigned short *lport, |
| 2091 | unsigned short *hport) { |
| 2092 | |
| 2093 | unsigned int low = 0, high = 0; |
| 2094 | char *p, *arg = strdup(str); |
| 2095 | |
| 2096 | if ((*arg == '[') && ((p = strrchr(arg, ']')) != NULL)) { |
| 2097 | p = arg + 1; /* skip '[' */ |
| 2098 | low = atoi(strtok(p, "-")); |
| 2099 | high = atoi(strtok(NULL, "-")); |
| 2100 | if ((low > 0) && (high > 0) && (low < high) && (high < 65535)) { |
| 2101 | *lport = low; |
| 2102 | *hport = high; |
| 2103 | } |
| 2104 | } |
| 2105 | else { |
| 2106 | low = atoi(arg); |
| 2107 | if ((0 < low) && (low < 65535)) { |
| 2108 | *lport = low; |
| 2109 | *hport = low; |
| 2110 | } |
| 2111 | } |
| 2112 | free(arg); |
| 2113 | if (low != 0) |
| 2114 | return 0; |
| 2115 | return -1; |
| 2116 | } |
| 2117 | |
| 2118 | /* |
| 2119 | * Implements the generic port forwarding option |
| 2120 | */ |
| 2121 | void |
| 2122 | net_slirp_forward(const char *optarg) |
| 2123 | { |
| 2124 | /* |
| 2125 | * we expect the following format: |
| 2126 | * dst_net:dst_mask:dst_port:redirect_ip:redirect_port OR |
| 2127 | * dst_net:dst_mask:[dp_range_start-dp_range_end]:redirect_ip:redirect_port |
| 2128 | */ |
| 2129 | char *argument = strdup(optarg), *p = argument; |
| 2130 | char *dst_net, *dst_mask, *dst_port; |
| 2131 | char *redirect_ip, *redirect_port; |
| 2132 | uint32_t dnet, dmask, rip; |
Vladimir Chtchetkine | b557e9f | 2012-03-22 15:38:08 -0700 | [diff] [blame] | 2133 | unsigned short dlport = 0, dhport = 0, rport; |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2134 | |
| 2135 | |
| 2136 | dst_net = strtok(p, ":"); |
| 2137 | dst_mask = strtok(NULL, ":"); |
| 2138 | dst_port = strtok(NULL, ":"); |
| 2139 | redirect_ip = strtok(NULL, ":"); |
| 2140 | redirect_port = strtok(NULL, ":"); |
| 2141 | |
| 2142 | if (dst_net == NULL || dst_mask == NULL || dst_port == NULL || |
| 2143 | redirect_ip == NULL || redirect_port == NULL) { |
| 2144 | fprintf(stderr, |
| 2145 | "Invalid argument for -net-forward, we expect " |
| 2146 | "dst_net:dst_mask:dst_port:redirect_ip:redirect_port or " |
| 2147 | "dst_net:dst_mask:[dp_range_start-dp_range_end]" |
| 2148 | ":redirect_ip:redirect_port: %s\n", |
| 2149 | optarg); |
| 2150 | exit(1); |
| 2151 | } |
| 2152 | |
| 2153 | /* inet_strtoip converts dotted address to host byte order */ |
| 2154 | if (inet_strtoip(dst_net, &dnet) == -1) { |
| 2155 | fprintf(stderr, "Invalid destination IP net: %s\n", dst_net); |
| 2156 | exit(1); |
| 2157 | } |
| 2158 | if (inet_strtoip(dst_mask, &dmask) == -1) { |
| 2159 | fprintf(stderr, "Invalid destination IP mask: %s\n", dst_mask); |
| 2160 | exit(1); |
| 2161 | } |
| 2162 | if (inet_strtoip(redirect_ip, &rip) == -1) { |
| 2163 | fprintf(stderr, "Invalid redirect IP address: %s\n", redirect_ip); |
| 2164 | exit(1); |
| 2165 | } |
| 2166 | |
| 2167 | if (parse_port_range(dst_port, &dlport, &dhport) == -1) { |
| 2168 | fprintf(stderr, "Invalid destination port or port range\n"); |
| 2169 | exit(1); |
| 2170 | } |
| 2171 | |
| 2172 | rport = atoi(redirect_port); |
| 2173 | if (!rport) { |
| 2174 | fprintf(stderr, "Invalid redirect port: %s\n", redirect_port); |
| 2175 | exit(1); |
| 2176 | } |
| 2177 | |
| 2178 | dnet &= dmask; |
| 2179 | |
| 2180 | slirp_add_net_forward(dnet, dmask, dlport, dhport, |
| 2181 | rip, rport); |
| 2182 | |
| 2183 | free(argument); |
| 2184 | } |
| 2185 | |
| 2186 | |
| 2187 | /* Parses an -allow-tcp or -allow-udp argument and inserts a corresponding |
| 2188 | * entry in the allows list */ |
| 2189 | void |
| 2190 | slirp_allow(const char *optarg, u_int8_t proto) |
| 2191 | { |
| 2192 | /* |
| 2193 | * we expect the following format: |
| 2194 | * dst_ip:dst_port OR dst_ip:[dst_lport-dst_hport] |
| 2195 | */ |
| 2196 | char *argument = strdup(optarg), *p = argument; |
| 2197 | char *dst_ip_str, *dst_port_str; |
| 2198 | uint32_t dst_ip; |
Vladimir Chtchetkine | b557e9f | 2012-03-22 15:38:08 -0700 | [diff] [blame] | 2199 | unsigned short dst_lport = 0, dst_hport = 0; |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2200 | |
| 2201 | dst_ip_str = strtok(p, ":"); |
| 2202 | dst_port_str = strtok(NULL, ":"); |
| 2203 | |
| 2204 | if (dst_ip_str == NULL || dst_port_str == NULL) { |
| 2205 | fprintf(stderr, |
| 2206 | "Invalid argument %s for -allow. We expect " |
| 2207 | "dst_ip:dst_port or dst_ip:[dst_lport-dst_hport]\n", |
| 2208 | optarg); |
| 2209 | exit(1); |
| 2210 | } |
| 2211 | |
| 2212 | if (inet_strtoip(dst_ip_str, &dst_ip) == -1) { |
| 2213 | fprintf(stderr, "Invalid destination IP address: %s\n", dst_ip_str); |
| 2214 | exit(1); |
| 2215 | } |
| 2216 | if (parse_port_range(dst_port_str, &dst_lport, &dst_hport) == -1) { |
| 2217 | fprintf(stderr, "Invalid destination port or port range\n"); |
| 2218 | exit(1); |
| 2219 | } |
| 2220 | |
| 2221 | slirp_add_allow(dst_ip, dst_lport, dst_hport, proto); |
| 2222 | |
| 2223 | free(argument); |
| 2224 | } |
| 2225 | |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 2226 | /* Add a serial device at a given location in the emulated hardware table. |
| 2227 | * On failure, this function aborts the program with an error message. |
| 2228 | */ |
| 2229 | static void |
| 2230 | serial_hds_add_at(int index, const char* devname) |
| 2231 | { |
| 2232 | char label[32]; |
| 2233 | |
| 2234 | if (!devname || !strcmp(devname,"none")) |
| 2235 | return; |
| 2236 | |
| 2237 | if (index >= MAX_SERIAL_PORTS) { |
| 2238 | PANIC("qemu: invalid serial index for %s (%d >= %d)", |
| 2239 | devname, index, MAX_SERIAL_PORTS); |
| 2240 | } |
| 2241 | if (serial_hds[index] != NULL) { |
| 2242 | PANIC("qemu: invalid serial index for %s (%d: already taken!)", |
| 2243 | devname, index); |
| 2244 | } |
| 2245 | snprintf(label, sizeof(label), "serial%d", index); |
| 2246 | serial_hds[index] = qemu_chr_open(label, devname, NULL); |
| 2247 | if (!serial_hds[index]) { |
| 2248 | PANIC("qemu: could not open serial device '%s'", devname); |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | |
| 2253 | /* Find a free slot in the emulated serial device table, and register |
| 2254 | * it. Return the allocated table index. |
| 2255 | */ |
| 2256 | static int |
| 2257 | serial_hds_add(const char* devname) |
| 2258 | { |
| 2259 | int index; |
| 2260 | |
| 2261 | /* Find first free slot */ |
| 2262 | for (index = 0; index < MAX_SERIAL_PORTS; index++) { |
| 2263 | if (serial_hds[index] == NULL) { |
| 2264 | serial_hds_add_at(index, devname); |
| 2265 | return index; |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | PANIC("qemu: too many serial devices registered (%d)", index); |
| 2270 | return -1; /* shouldn't happen */ |
| 2271 | } |
| 2272 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2273 | int main(int argc, char **argv, char **envp) |
| 2274 | { |
| 2275 | const char *gdbstub_dev = NULL; |
| 2276 | uint32_t boot_devices_bitmap = 0; |
| 2277 | int i; |
David 'Digit' Turner | a2c14f9 | 2014-02-04 01:02:30 +0100 | [diff] [blame] | 2278 | int snapshot, linux_boot, __attribute__((unused)) net_boot; |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 2279 | const char *icount_option = NULL; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2280 | const char *initrd_filename; |
| 2281 | const char *kernel_filename, *kernel_cmdline; |
| 2282 | const char *boot_devices = ""; |
| 2283 | DisplayState *ds; |
| 2284 | DisplayChangeListener *dcl; |
| 2285 | int cyls, heads, secs, translation; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2286 | QemuOpts *hda_opts = NULL; |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 2287 | QemuOpts *hdb_opts = NULL; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2288 | const char *net_clients[MAX_NET_CLIENTS]; |
| 2289 | int nb_net_clients; |
| 2290 | const char *bt_opts[MAX_BT_CMDLINE]; |
| 2291 | int nb_bt_opts; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2292 | int optind; |
| 2293 | const char *r, *optarg; |
| 2294 | CharDriverState *monitor_hd = NULL; |
| 2295 | const char *monitor_device; |
| 2296 | const char *serial_devices[MAX_SERIAL_PORTS]; |
| 2297 | int serial_device_index; |
| 2298 | const char *parallel_devices[MAX_PARALLEL_PORTS]; |
| 2299 | int parallel_device_index; |
| 2300 | const char *virtio_consoles[MAX_VIRTIO_CONSOLES]; |
| 2301 | int virtio_console_index; |
| 2302 | const char *loadvm = NULL; |
| 2303 | QEMUMachine *machine; |
| 2304 | const char *cpu_model; |
| 2305 | const char *usb_devices[MAX_USB_CMDLINE]; |
| 2306 | int usb_devices_index; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2307 | int tb_size; |
| 2308 | const char *pid_file = NULL; |
| 2309 | const char *incoming = NULL; |
David 'Digit' Turner | 7e9f6c1 | 2014-01-22 18:42:40 +0100 | [diff] [blame] | 2310 | const char* log_mask = NULL; |
| 2311 | const char* log_file = NULL; |
David 'Digit' Turner | 6657678 | 2014-03-24 16:57:57 +0100 | [diff] [blame^] | 2312 | CPUState *cpu; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2313 | int show_vnc_port = 0; |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 2314 | IniFile* hw_ini = NULL; |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 2315 | STRALLOC_DEFINE(kernel_params); |
| 2316 | STRALLOC_DEFINE(kernel_config); |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 2317 | int dns_count = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2318 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2319 | /* Initialize sockets before anything else, so we can properly report |
| 2320 | * initialization failures back to the UI. */ |
| 2321 | #ifdef _WIN32 |
| 2322 | socket_init(); |
| 2323 | #endif |
| 2324 | |
David 'Digit' Turner | a7fb77d | 2010-05-10 23:50:54 -0700 | [diff] [blame] | 2325 | init_clocks(); |
| 2326 | |
David 'Digit' Turner | 8848f63 | 2014-01-16 18:10:21 +0100 | [diff] [blame] | 2327 | qemu_cache_utils_init(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2328 | |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 2329 | QLIST_INIT (&vm_change_state_head); |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 2330 | os_setup_early_signal_handling(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2331 | |
| 2332 | module_call_init(MODULE_INIT_MACHINE); |
| 2333 | machine = find_default_machine(); |
| 2334 | cpu_model = NULL; |
| 2335 | initrd_filename = NULL; |
| 2336 | ram_size = 0; |
| 2337 | snapshot = 0; |
| 2338 | kernel_filename = NULL; |
| 2339 | kernel_cmdline = ""; |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 2340 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2341 | cyls = heads = secs = 0; |
| 2342 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2343 | monitor_device = "vc:80Cx24C"; |
| 2344 | |
| 2345 | serial_devices[0] = "vc:80Cx24C"; |
| 2346 | for(i = 1; i < MAX_SERIAL_PORTS; i++) |
| 2347 | serial_devices[i] = NULL; |
| 2348 | serial_device_index = 0; |
| 2349 | |
| 2350 | parallel_devices[0] = "vc:80Cx24C"; |
| 2351 | for(i = 1; i < MAX_PARALLEL_PORTS; i++) |
| 2352 | parallel_devices[i] = NULL; |
| 2353 | parallel_device_index = 0; |
| 2354 | |
| 2355 | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) |
| 2356 | virtio_consoles[i] = NULL; |
| 2357 | virtio_console_index = 0; |
| 2358 | |
| 2359 | for (i = 0; i < MAX_NODES; i++) { |
| 2360 | node_mem[i] = 0; |
| 2361 | node_cpumask[i] = 0; |
| 2362 | } |
| 2363 | |
| 2364 | usb_devices_index = 0; |
| 2365 | |
| 2366 | nb_net_clients = 0; |
| 2367 | nb_bt_opts = 0; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2368 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2369 | nb_drives = 0; |
| 2370 | nb_drives_opt = 0; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2371 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2372 | nb_numa_nodes = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2373 | |
| 2374 | nb_nics = 0; |
| 2375 | |
| 2376 | tb_size = 0; |
| 2377 | autostart= 1; |
| 2378 | |
| 2379 | register_watchdogs(); |
| 2380 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 2381 | /* Initialize boot properties. */ |
| 2382 | boot_property_init_service(); |
David 'Digit' Turner | ca95059 | 2011-04-27 12:26:15 +0200 | [diff] [blame] | 2383 | android_hw_control_init(); |
David 'Digit' Turner | d4d688e | 2011-04-26 18:09:17 +0200 | [diff] [blame] | 2384 | android_net_pipes_init(); |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 2385 | |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 2386 | #ifdef CONFIG_KVM |
| 2387 | /* By default, force auto-detection for kvm */ |
| 2388 | kvm_allowed = -1; |
| 2389 | #endif |
| 2390 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2391 | optind = 1; |
| 2392 | for(;;) { |
| 2393 | if (optind >= argc) |
| 2394 | break; |
| 2395 | r = argv[optind]; |
| 2396 | if (r[0] != '-') { |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2397 | hda_opts = drive_add(argv[optind++], HD_ALIAS, 0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2398 | } else { |
| 2399 | const QEMUOption *popt; |
| 2400 | |
| 2401 | optind++; |
| 2402 | /* Treat --foo the same as -foo. */ |
| 2403 | if (r[1] == '-') |
| 2404 | r++; |
| 2405 | popt = qemu_options; |
| 2406 | for(;;) { |
| 2407 | if (!popt->name) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2408 | PANIC("%s: invalid option -- '%s'", |
| 2409 | argv[0], r); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2410 | } |
| 2411 | if (!strcmp(popt->name, r + 1)) |
| 2412 | break; |
| 2413 | popt++; |
| 2414 | } |
| 2415 | if (popt->flags & HAS_ARG) { |
| 2416 | if (optind >= argc) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2417 | PANIC("%s: option '%s' requires an argument", |
| 2418 | argv[0], r); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2419 | } |
| 2420 | optarg = argv[optind++]; |
| 2421 | } else { |
| 2422 | optarg = NULL; |
| 2423 | } |
| 2424 | |
| 2425 | switch(popt->index) { |
| 2426 | case QEMU_OPTION_M: |
| 2427 | machine = find_machine(optarg); |
| 2428 | if (!machine) { |
| 2429 | QEMUMachine *m; |
| 2430 | printf("Supported machines are:\n"); |
| 2431 | for(m = first_machine; m != NULL; m = m->next) { |
| 2432 | printf("%-10s %s%s\n", |
| 2433 | m->name, m->desc, |
| 2434 | m->is_default ? " (default)" : ""); |
| 2435 | } |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2436 | if (*optarg != '?') { |
| 2437 | PANIC("Invalid machine parameter: %s", |
| 2438 | optarg); |
| 2439 | } else { |
| 2440 | QEMU_EXIT(0); |
| 2441 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2442 | } |
| 2443 | break; |
| 2444 | case QEMU_OPTION_cpu: |
| 2445 | /* hw initialization will check this */ |
| 2446 | if (*optarg == '?') { |
| 2447 | /* XXX: implement xxx_cpu_list for targets that still miss it */ |
| 2448 | #if defined(cpu_list) |
| 2449 | cpu_list(stdout, &fprintf); |
| 2450 | #endif |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2451 | QEMU_EXIT(0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2452 | } else { |
| 2453 | cpu_model = optarg; |
| 2454 | } |
| 2455 | break; |
| 2456 | case QEMU_OPTION_initrd: |
| 2457 | initrd_filename = optarg; |
| 2458 | break; |
| 2459 | case QEMU_OPTION_hda: |
| 2460 | if (cyls == 0) |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2461 | hda_opts = drive_add(optarg, HD_ALIAS, 0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2462 | else |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2463 | hda_opts = drive_add(optarg, HD_ALIAS |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2464 | ",cyls=%d,heads=%d,secs=%d%s", |
| 2465 | 0, cyls, heads, secs, |
| 2466 | translation == BIOS_ATA_TRANSLATION_LBA ? |
| 2467 | ",trans=lba" : |
| 2468 | translation == BIOS_ATA_TRANSLATION_NONE ? |
| 2469 | ",trans=none" : ""); |
| 2470 | break; |
| 2471 | case QEMU_OPTION_hdb: |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 2472 | hdb_opts = drive_add(optarg, HD_ALIAS, 1); |
| 2473 | break; |
| 2474 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2475 | case QEMU_OPTION_hdc: |
| 2476 | case QEMU_OPTION_hdd: |
| 2477 | drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda); |
| 2478 | break; |
| 2479 | case QEMU_OPTION_drive: |
| 2480 | drive_add(NULL, "%s", optarg); |
| 2481 | break; |
| 2482 | case QEMU_OPTION_mtdblock: |
| 2483 | drive_add(optarg, MTD_ALIAS); |
| 2484 | break; |
| 2485 | case QEMU_OPTION_sd: |
| 2486 | drive_add(optarg, SD_ALIAS); |
| 2487 | break; |
| 2488 | case QEMU_OPTION_pflash: |
| 2489 | drive_add(optarg, PFLASH_ALIAS); |
| 2490 | break; |
| 2491 | case QEMU_OPTION_snapshot: |
| 2492 | snapshot = 1; |
| 2493 | break; |
| 2494 | case QEMU_OPTION_hdachs: |
| 2495 | { |
| 2496 | const char *p; |
| 2497 | p = optarg; |
| 2498 | cyls = strtol(p, (char **)&p, 0); |
| 2499 | if (cyls < 1 || cyls > 16383) |
| 2500 | goto chs_fail; |
| 2501 | if (*p != ',') |
| 2502 | goto chs_fail; |
| 2503 | p++; |
| 2504 | heads = strtol(p, (char **)&p, 0); |
| 2505 | if (heads < 1 || heads > 16) |
| 2506 | goto chs_fail; |
| 2507 | if (*p != ',') |
| 2508 | goto chs_fail; |
| 2509 | p++; |
| 2510 | secs = strtol(p, (char **)&p, 0); |
| 2511 | if (secs < 1 || secs > 63) |
| 2512 | goto chs_fail; |
| 2513 | if (*p == ',') { |
| 2514 | p++; |
| 2515 | if (!strcmp(p, "none")) |
| 2516 | translation = BIOS_ATA_TRANSLATION_NONE; |
| 2517 | else if (!strcmp(p, "lba")) |
| 2518 | translation = BIOS_ATA_TRANSLATION_LBA; |
| 2519 | else if (!strcmp(p, "auto")) |
| 2520 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2521 | else |
| 2522 | goto chs_fail; |
| 2523 | } else if (*p != '\0') { |
| 2524 | chs_fail: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2525 | PANIC("qemu: invalid physical CHS format"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2526 | } |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2527 | if (hda_opts != NULL) { |
| 2528 | char num[16]; |
| 2529 | snprintf(num, sizeof(num), "%d", cyls); |
| 2530 | qemu_opt_set(hda_opts, "cyls", num); |
| 2531 | snprintf(num, sizeof(num), "%d", heads); |
| 2532 | qemu_opt_set(hda_opts, "heads", num); |
| 2533 | snprintf(num, sizeof(num), "%d", secs); |
| 2534 | qemu_opt_set(hda_opts, "secs", num); |
| 2535 | if (translation == BIOS_ATA_TRANSLATION_LBA) |
| 2536 | qemu_opt_set(hda_opts, "trans", "lba"); |
| 2537 | if (translation == BIOS_ATA_TRANSLATION_NONE) |
| 2538 | qemu_opt_set(hda_opts, "trans", "none"); |
| 2539 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2540 | } |
| 2541 | break; |
| 2542 | case QEMU_OPTION_numa: |
| 2543 | if (nb_numa_nodes >= MAX_NODES) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2544 | PANIC("qemu: too many NUMA nodes"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2545 | } |
| 2546 | numa_add(optarg); |
| 2547 | break; |
| 2548 | case QEMU_OPTION_nographic: |
| 2549 | display_type = DT_NOGRAPHIC; |
| 2550 | break; |
| 2551 | #ifdef CONFIG_CURSES |
| 2552 | case QEMU_OPTION_curses: |
| 2553 | display_type = DT_CURSES; |
| 2554 | break; |
| 2555 | #endif |
| 2556 | case QEMU_OPTION_portrait: |
| 2557 | graphic_rotate = 1; |
| 2558 | break; |
| 2559 | case QEMU_OPTION_kernel: |
| 2560 | kernel_filename = optarg; |
| 2561 | break; |
| 2562 | case QEMU_OPTION_append: |
| 2563 | kernel_cmdline = optarg; |
| 2564 | break; |
| 2565 | case QEMU_OPTION_cdrom: |
| 2566 | drive_add(optarg, CDROM_ALIAS); |
| 2567 | break; |
| 2568 | case QEMU_OPTION_boot: |
| 2569 | boot_devices = optarg; |
| 2570 | /* We just do some generic consistency checks */ |
| 2571 | { |
| 2572 | /* Could easily be extended to 64 devices if needed */ |
| 2573 | const char *p; |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 2574 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2575 | boot_devices_bitmap = 0; |
| 2576 | for (p = boot_devices; *p != '\0'; p++) { |
| 2577 | /* Allowed boot devices are: |
| 2578 | * a b : floppy disk drives |
| 2579 | * c ... f : IDE disk drives |
| 2580 | * g ... m : machine implementation dependant drives |
| 2581 | * n ... p : network devices |
| 2582 | * It's up to each machine implementation to check |
| 2583 | * if the given boot devices match the actual hardware |
| 2584 | * implementation and firmware features. |
| 2585 | */ |
| 2586 | if (*p < 'a' || *p > 'q') { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2587 | PANIC("Invalid boot device '%c'", *p); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2588 | } |
| 2589 | if (boot_devices_bitmap & (1 << (*p - 'a'))) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2590 | PANIC( |
| 2591 | "Boot device '%c' was given twice",*p); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2592 | } |
| 2593 | boot_devices_bitmap |= 1 << (*p - 'a'); |
| 2594 | } |
| 2595 | } |
| 2596 | break; |
| 2597 | case QEMU_OPTION_fda: |
| 2598 | case QEMU_OPTION_fdb: |
| 2599 | drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda); |
| 2600 | break; |
| 2601 | #ifdef TARGET_I386 |
| 2602 | case QEMU_OPTION_no_fd_bootchk: |
| 2603 | fd_bootchk = 0; |
| 2604 | break; |
| 2605 | #endif |
| 2606 | case QEMU_OPTION_net: |
| 2607 | if (nb_net_clients >= MAX_NET_CLIENTS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2608 | PANIC("qemu: too many network clients"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2609 | } |
| 2610 | net_clients[nb_net_clients] = optarg; |
| 2611 | nb_net_clients++; |
| 2612 | break; |
| 2613 | #ifdef CONFIG_SLIRP |
| 2614 | case QEMU_OPTION_tftp: |
| 2615 | tftp_prefix = optarg; |
| 2616 | break; |
| 2617 | case QEMU_OPTION_bootp: |
| 2618 | bootp_filename = optarg; |
| 2619 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2620 | case QEMU_OPTION_redir: |
| 2621 | net_slirp_redir(NULL, optarg, NULL); |
| 2622 | break; |
| 2623 | #endif |
| 2624 | case QEMU_OPTION_bt: |
| 2625 | if (nb_bt_opts >= MAX_BT_CMDLINE) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2626 | PANIC("qemu: too many bluetooth options"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2627 | } |
| 2628 | bt_opts[nb_bt_opts++] = optarg; |
| 2629 | break; |
| 2630 | #ifdef HAS_AUDIO |
| 2631 | case QEMU_OPTION_audio_help: |
| 2632 | AUD_help (); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2633 | QEMU_EXIT(0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2634 | break; |
| 2635 | case QEMU_OPTION_soundhw: |
| 2636 | select_soundhw (optarg); |
| 2637 | break; |
| 2638 | #endif |
| 2639 | case QEMU_OPTION_h: |
| 2640 | qemu_help(0); |
| 2641 | break; |
| 2642 | case QEMU_OPTION_version: |
| 2643 | version(); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2644 | QEMU_EXIT(0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2645 | break; |
| 2646 | case QEMU_OPTION_m: { |
| 2647 | uint64_t value; |
| 2648 | char *ptr; |
| 2649 | |
| 2650 | value = strtoul(optarg, &ptr, 10); |
| 2651 | switch (*ptr) { |
| 2652 | case 0: case 'M': case 'm': |
| 2653 | value <<= 20; |
| 2654 | break; |
| 2655 | case 'G': case 'g': |
| 2656 | value <<= 30; |
| 2657 | break; |
| 2658 | default: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2659 | PANIC("qemu: invalid ram size: %s", optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | /* On 32-bit hosts, QEMU is limited by virtual address space */ |
David 'Digit' Turner | 81911b0 | 2014-02-10 17:53:45 +0100 | [diff] [blame] | 2663 | if (value > (2047 << 20) && HOST_LONG_BITS == 32) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2664 | PANIC("qemu: at most 2047 MB RAM can be simulated"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2665 | } |
| 2666 | if (value != (uint64_t)(ram_addr_t)value) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2667 | PANIC("qemu: ram size too large"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2668 | } |
| 2669 | ram_size = value; |
| 2670 | break; |
| 2671 | } |
| 2672 | case QEMU_OPTION_d: |
David 'Digit' Turner | 7e9f6c1 | 2014-01-22 18:42:40 +0100 | [diff] [blame] | 2673 | log_mask = optarg; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2674 | break; |
| 2675 | case QEMU_OPTION_s: |
| 2676 | gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT; |
| 2677 | break; |
| 2678 | case QEMU_OPTION_gdb: |
| 2679 | gdbstub_dev = optarg; |
| 2680 | break; |
| 2681 | case QEMU_OPTION_L: |
| 2682 | data_dir = optarg; |
| 2683 | break; |
| 2684 | case QEMU_OPTION_bios: |
| 2685 | bios_name = optarg; |
| 2686 | break; |
| 2687 | case QEMU_OPTION_singlestep: |
| 2688 | singlestep = 1; |
| 2689 | break; |
| 2690 | case QEMU_OPTION_S: |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2691 | autostart = 0; |
| 2692 | break; |
| 2693 | #ifndef _WIN32 |
| 2694 | case QEMU_OPTION_k: |
| 2695 | keyboard_layout = optarg; |
| 2696 | break; |
| 2697 | #endif |
| 2698 | case QEMU_OPTION_localtime: |
| 2699 | rtc_utc = 0; |
| 2700 | break; |
| 2701 | case QEMU_OPTION_vga: |
| 2702 | select_vgahw (optarg); |
| 2703 | break; |
| 2704 | #if defined(TARGET_PPC) || defined(TARGET_SPARC) |
| 2705 | case QEMU_OPTION_g: |
| 2706 | { |
| 2707 | const char *p; |
| 2708 | int w, h, depth; |
| 2709 | p = optarg; |
| 2710 | w = strtol(p, (char **)&p, 10); |
| 2711 | if (w <= 0) { |
| 2712 | graphic_error: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2713 | PANIC("qemu: invalid resolution or depth"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2714 | } |
| 2715 | if (*p != 'x') |
| 2716 | goto graphic_error; |
| 2717 | p++; |
| 2718 | h = strtol(p, (char **)&p, 10); |
| 2719 | if (h <= 0) |
| 2720 | goto graphic_error; |
| 2721 | if (*p == 'x') { |
| 2722 | p++; |
| 2723 | depth = strtol(p, (char **)&p, 10); |
| 2724 | if (depth != 8 && depth != 15 && depth != 16 && |
| 2725 | depth != 24 && depth != 32) |
| 2726 | goto graphic_error; |
| 2727 | } else if (*p == '\0') { |
| 2728 | depth = graphic_depth; |
| 2729 | } else { |
| 2730 | goto graphic_error; |
| 2731 | } |
| 2732 | |
| 2733 | graphic_width = w; |
| 2734 | graphic_height = h; |
| 2735 | graphic_depth = depth; |
| 2736 | } |
| 2737 | break; |
| 2738 | #endif |
| 2739 | case QEMU_OPTION_echr: |
| 2740 | { |
| 2741 | char *r; |
| 2742 | term_escape_char = strtol(optarg, &r, 0); |
| 2743 | if (r == optarg) |
| 2744 | printf("Bad argument to echr\n"); |
| 2745 | break; |
| 2746 | } |
| 2747 | case QEMU_OPTION_monitor: |
| 2748 | monitor_device = optarg; |
| 2749 | break; |
| 2750 | case QEMU_OPTION_serial: |
| 2751 | if (serial_device_index >= MAX_SERIAL_PORTS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2752 | PANIC("qemu: too many serial ports"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2753 | } |
| 2754 | serial_devices[serial_device_index] = optarg; |
| 2755 | serial_device_index++; |
| 2756 | break; |
| 2757 | case QEMU_OPTION_watchdog: |
| 2758 | i = select_watchdog(optarg); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2759 | if (i > 0) { |
| 2760 | if (i == 1) { |
| 2761 | PANIC("Invalid watchdog parameter: %s", |
| 2762 | optarg); |
| 2763 | } else { |
| 2764 | QEMU_EXIT(0); |
| 2765 | } |
| 2766 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2767 | break; |
| 2768 | case QEMU_OPTION_watchdog_action: |
| 2769 | if (select_watchdog_action(optarg) == -1) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2770 | PANIC("Unknown -watchdog-action parameter"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2771 | } |
| 2772 | break; |
| 2773 | case QEMU_OPTION_virtiocon: |
| 2774 | if (virtio_console_index >= MAX_VIRTIO_CONSOLES) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2775 | PANIC("qemu: too many virtio consoles"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2776 | } |
| 2777 | virtio_consoles[virtio_console_index] = optarg; |
| 2778 | virtio_console_index++; |
| 2779 | break; |
| 2780 | case QEMU_OPTION_parallel: |
| 2781 | if (parallel_device_index >= MAX_PARALLEL_PORTS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2782 | PANIC("qemu: too many parallel ports"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2783 | } |
| 2784 | parallel_devices[parallel_device_index] = optarg; |
| 2785 | parallel_device_index++; |
| 2786 | break; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 2787 | case QEMU_OPTION_loadvm: |
| 2788 | loadvm = optarg; |
| 2789 | break; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 2790 | case QEMU_OPTION_savevm_on_exit: |
| 2791 | savevm_on_exit = optarg; |
| 2792 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2793 | case QEMU_OPTION_full_screen: |
| 2794 | full_screen = 1; |
| 2795 | break; |
| 2796 | #ifdef CONFIG_SDL |
| 2797 | case QEMU_OPTION_no_frame: |
| 2798 | no_frame = 1; |
| 2799 | break; |
| 2800 | case QEMU_OPTION_alt_grab: |
| 2801 | alt_grab = 1; |
| 2802 | break; |
| 2803 | case QEMU_OPTION_no_quit: |
| 2804 | no_quit = 1; |
| 2805 | break; |
| 2806 | case QEMU_OPTION_sdl: |
| 2807 | display_type = DT_SDL; |
| 2808 | break; |
| 2809 | #endif |
| 2810 | case QEMU_OPTION_pidfile: |
| 2811 | pid_file = optarg; |
| 2812 | break; |
| 2813 | #ifdef TARGET_I386 |
| 2814 | case QEMU_OPTION_win2k_hack: |
| 2815 | win2k_install_hack = 1; |
| 2816 | break; |
| 2817 | case QEMU_OPTION_rtc_td_hack: |
| 2818 | rtc_td_hack = 1; |
| 2819 | break; |
Jun Nakajima | 334ab47 | 2011-02-02 23:49:59 -0800 | [diff] [blame] | 2820 | #ifndef CONFIG_ANDROID |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2821 | case QEMU_OPTION_acpitable: |
| 2822 | if(acpi_table_add(optarg) < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2823 | PANIC("Wrong acpi table provided"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2824 | } |
| 2825 | break; |
Jun Nakajima | 334ab47 | 2011-02-02 23:49:59 -0800 | [diff] [blame] | 2826 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2827 | case QEMU_OPTION_smbios: |
David 'Digit' Turner | ae3098a | 2011-05-11 16:01:57 +0200 | [diff] [blame] | 2828 | do_smbios_option(optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2829 | break; |
| 2830 | #endif |
| 2831 | #ifdef CONFIG_KVM |
| 2832 | case QEMU_OPTION_enable_kvm: |
| 2833 | kvm_allowed = 1; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2834 | break; |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 2835 | case QEMU_OPTION_disable_kvm: |
| 2836 | kvm_allowed = 0; |
| 2837 | break; |
| 2838 | #endif /* CONFIG_KVM */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2839 | case QEMU_OPTION_usb: |
| 2840 | usb_enabled = 1; |
| 2841 | break; |
| 2842 | case QEMU_OPTION_usbdevice: |
| 2843 | usb_enabled = 1; |
| 2844 | if (usb_devices_index >= MAX_USB_CMDLINE) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2845 | PANIC("Too many USB devices"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2846 | } |
| 2847 | usb_devices[usb_devices_index] = optarg; |
| 2848 | usb_devices_index++; |
| 2849 | break; |
| 2850 | case QEMU_OPTION_smp: |
| 2851 | smp_cpus = atoi(optarg); |
| 2852 | if (smp_cpus < 1) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2853 | PANIC("Invalid number of CPUs"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2854 | } |
| 2855 | break; |
| 2856 | case QEMU_OPTION_vnc: |
| 2857 | display_type = DT_VNC; |
| 2858 | vnc_display = optarg; |
| 2859 | break; |
| 2860 | #ifdef TARGET_I386 |
| 2861 | case QEMU_OPTION_no_acpi: |
| 2862 | acpi_enabled = 0; |
| 2863 | break; |
| 2864 | case QEMU_OPTION_no_hpet: |
| 2865 | no_hpet = 1; |
| 2866 | break; |
| 2867 | case QEMU_OPTION_no_virtio_balloon: |
| 2868 | no_virtio_balloon = 1; |
| 2869 | break; |
| 2870 | #endif |
| 2871 | case QEMU_OPTION_no_reboot: |
| 2872 | no_reboot = 1; |
| 2873 | break; |
| 2874 | case QEMU_OPTION_no_shutdown: |
| 2875 | no_shutdown = 1; |
| 2876 | break; |
| 2877 | case QEMU_OPTION_show_cursor: |
| 2878 | cursor_hide = 0; |
| 2879 | break; |
| 2880 | case QEMU_OPTION_uuid: |
| 2881 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2882 | PANIC("Fail to parse UUID string. Wrong format."); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2883 | } |
| 2884 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2885 | case QEMU_OPTION_option_rom: |
| 2886 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2887 | PANIC("Too many option ROMs"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2888 | } |
| 2889 | option_rom[nb_option_roms] = optarg; |
| 2890 | nb_option_roms++; |
| 2891 | break; |
| 2892 | #if defined(TARGET_ARM) || defined(TARGET_M68K) |
| 2893 | case QEMU_OPTION_semihosting: |
| 2894 | semihosting_enabled = 1; |
| 2895 | break; |
| 2896 | #endif |
| 2897 | case QEMU_OPTION_name: |
| 2898 | qemu_name = optarg; |
| 2899 | break; |
| 2900 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) |
| 2901 | case QEMU_OPTION_prom_env: |
| 2902 | if (nb_prom_envs >= MAX_PROM_ENVS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2903 | PANIC("Too many prom variables"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2904 | } |
| 2905 | prom_envs[nb_prom_envs] = optarg; |
| 2906 | nb_prom_envs++; |
| 2907 | break; |
| 2908 | #endif |
| 2909 | #ifdef TARGET_ARM |
| 2910 | case QEMU_OPTION_old_param: |
| 2911 | old_param = 1; |
| 2912 | break; |
| 2913 | #endif |
| 2914 | case QEMU_OPTION_clock: |
| 2915 | configure_alarms(optarg); |
| 2916 | break; |
| 2917 | case QEMU_OPTION_startdate: |
| 2918 | { |
| 2919 | struct tm tm; |
David 'Digit' Turner | dc46820 | 2010-10-27 02:34:46 +0200 | [diff] [blame] | 2920 | time_t rtc_start_date = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2921 | if (!strcmp(optarg, "now")) { |
| 2922 | rtc_date_offset = -1; |
| 2923 | } else { |
| 2924 | if (sscanf(optarg, "%d-%d-%dT%d:%d:%d", |
| 2925 | &tm.tm_year, |
| 2926 | &tm.tm_mon, |
| 2927 | &tm.tm_mday, |
| 2928 | &tm.tm_hour, |
| 2929 | &tm.tm_min, |
| 2930 | &tm.tm_sec) == 6) { |
| 2931 | /* OK */ |
| 2932 | } else if (sscanf(optarg, "%d-%d-%d", |
| 2933 | &tm.tm_year, |
| 2934 | &tm.tm_mon, |
| 2935 | &tm.tm_mday) == 3) { |
| 2936 | tm.tm_hour = 0; |
| 2937 | tm.tm_min = 0; |
| 2938 | tm.tm_sec = 0; |
| 2939 | } else { |
| 2940 | goto date_fail; |
| 2941 | } |
| 2942 | tm.tm_year -= 1900; |
| 2943 | tm.tm_mon--; |
| 2944 | rtc_start_date = mktimegm(&tm); |
| 2945 | if (rtc_start_date == -1) { |
| 2946 | date_fail: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2947 | PANIC("Invalid date format. Valid format are:\n" |
| 2948 | "'now' or '2006-06-17T16:01:21' or '2006-06-17'"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2949 | } |
| 2950 | rtc_date_offset = time(NULL) - rtc_start_date; |
| 2951 | } |
| 2952 | } |
| 2953 | break; |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2954 | |
| 2955 | /* -------------------------------------------------------*/ |
| 2956 | /* User mode network stack restrictions */ |
| 2957 | case QEMU_OPTION_drop_udp: |
| 2958 | slirp_drop_udp(); |
| 2959 | break; |
| 2960 | case QEMU_OPTION_drop_tcp: |
| 2961 | slirp_drop_tcp(); |
| 2962 | break; |
| 2963 | case QEMU_OPTION_allow_tcp: |
| 2964 | slirp_allow(optarg, IPPROTO_TCP); |
| 2965 | break; |
| 2966 | case QEMU_OPTION_allow_udp: |
| 2967 | slirp_allow(optarg, IPPROTO_UDP); |
| 2968 | break; |
| 2969 | case QEMU_OPTION_drop_log: |
| 2970 | { |
| 2971 | FILE* drop_log_fd; |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 2972 | drop_log_filename = optarg; |
| 2973 | drop_log_fd = fopen(optarg, "w+"); |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2974 | |
| 2975 | if (!drop_log_fd) { |
| 2976 | fprintf(stderr, "Cannot open drop log: %s\n", optarg); |
| 2977 | exit(1); |
| 2978 | } |
| 2979 | |
| 2980 | slirp_drop_log_fd(drop_log_fd); |
| 2981 | } |
| 2982 | break; |
| 2983 | |
| 2984 | case QEMU_OPTION_dns_log: |
| 2985 | { |
| 2986 | FILE* dns_log_fd; |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 2987 | dns_log_filename = optarg; |
| 2988 | dns_log_fd = fopen(optarg, "wb+"); |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2989 | |
| 2990 | if (dns_log_fd == NULL) { |
| 2991 | fprintf(stderr, "Cannot open dns log: %s\n", optarg); |
| 2992 | exit(1); |
| 2993 | } |
| 2994 | |
| 2995 | slirp_dns_log_fd(dns_log_fd); |
| 2996 | } |
| 2997 | break; |
| 2998 | |
| 2999 | |
| 3000 | case QEMU_OPTION_max_dns_conns: |
| 3001 | { |
| 3002 | int max_dns_conns = 0; |
| 3003 | if (parse_int(optarg, &max_dns_conns)) { |
| 3004 | fprintf(stderr, |
| 3005 | "qemu: syntax: -max-dns-conns max_connections\n"); |
| 3006 | exit(1); |
| 3007 | } |
| 3008 | if (max_dns_conns <= 0 || max_dns_conns == LONG_MAX) { |
| 3009 | fprintf(stderr, |
| 3010 | "Invalid arg for max dns connections: %s\n", |
| 3011 | optarg); |
| 3012 | exit(1); |
| 3013 | } |
| 3014 | slirp_set_max_dns_conns(max_dns_conns); |
| 3015 | } |
| 3016 | break; |
| 3017 | |
| 3018 | case QEMU_OPTION_net_forward: |
| 3019 | net_slirp_forward(optarg); |
| 3020 | break; |
| 3021 | case QEMU_OPTION_net_forward_tcp2sink: |
| 3022 | { |
| 3023 | SockAddress saddr; |
| 3024 | |
| 3025 | if (parse_host_port(&saddr, optarg)) { |
| 3026 | fprintf(stderr, |
| 3027 | "Invalid ip/port %s for " |
| 3028 | "-forward-dropped-tcp2sink. " |
| 3029 | "We expect 'sink_ip:sink_port'\n", |
| 3030 | optarg); |
| 3031 | exit(1); |
| 3032 | } |
| 3033 | slirp_forward_dropped_tcp2sink(saddr.u.inet.address, |
| 3034 | saddr.u.inet.port); |
| 3035 | } |
| 3036 | break; |
| 3037 | /* -------------------------------------------------------*/ |
| 3038 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3039 | case QEMU_OPTION_tb_size: |
| 3040 | tb_size = strtol(optarg, NULL, 0); |
| 3041 | if (tb_size < 0) |
| 3042 | tb_size = 0; |
| 3043 | break; |
| 3044 | case QEMU_OPTION_icount: |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 3045 | icount_option = optarg; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3046 | break; |
| 3047 | case QEMU_OPTION_incoming: |
| 3048 | incoming = optarg; |
| 3049 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3050 | #ifdef CONFIG_XEN |
| 3051 | case QEMU_OPTION_xen_domid: |
| 3052 | xen_domid = atoi(optarg); |
| 3053 | break; |
| 3054 | case QEMU_OPTION_xen_create: |
| 3055 | xen_mode = XEN_CREATE; |
| 3056 | break; |
| 3057 | case QEMU_OPTION_xen_attach: |
| 3058 | xen_mode = XEN_ATTACH; |
| 3059 | break; |
| 3060 | #endif |
| 3061 | |
| 3062 | |
| 3063 | case QEMU_OPTION_mic: |
| 3064 | audio_input_source = (char*)optarg; |
| 3065 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3066 | #ifdef CONFIG_NAND |
| 3067 | case QEMU_OPTION_nand: |
| 3068 | nand_add_dev(optarg); |
| 3069 | break; |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 3070 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3071 | #endif |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 3072 | case QEMU_OPTION_disable_hax: |
| 3073 | hax_disabled = 1; |
| 3074 | break; |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 3075 | case QEMU_OPTION_android_ports: |
| 3076 | android_op_ports = (char*)optarg; |
| 3077 | break; |
| 3078 | |
| 3079 | case QEMU_OPTION_android_port: |
| 3080 | android_op_port = (char*)optarg; |
| 3081 | break; |
| 3082 | |
| 3083 | case QEMU_OPTION_android_report_console: |
| 3084 | android_op_report_console = (char*)optarg; |
| 3085 | break; |
| 3086 | |
| 3087 | case QEMU_OPTION_http_proxy: |
| 3088 | op_http_proxy = (char*)optarg; |
| 3089 | break; |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3090 | |
| 3091 | case QEMU_OPTION_charmap: |
| 3092 | op_charmap_file = (char*)optarg; |
| 3093 | break; |
Vladimir Chtchetkine | dd50f7d | 2010-07-30 09:16:41 -0700 | [diff] [blame] | 3094 | |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3095 | case QEMU_OPTION_android_hw: |
| 3096 | android_op_hwini = (char*)optarg; |
| 3097 | break; |
Vladimir Chtchetkine | 13f3b6c | 2010-08-25 09:49:25 -0700 | [diff] [blame] | 3098 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3099 | case QEMU_OPTION_dns_server: |
| 3100 | android_op_dns_server = (char*)optarg; |
| 3101 | break; |
| 3102 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3103 | case QEMU_OPTION_radio: |
| 3104 | android_op_radio = (char*)optarg; |
| 3105 | break; |
| 3106 | |
| 3107 | case QEMU_OPTION_gps: |
| 3108 | android_op_gps = (char*)optarg; |
| 3109 | break; |
| 3110 | |
| 3111 | case QEMU_OPTION_audio: |
| 3112 | android_op_audio = (char*)optarg; |
| 3113 | break; |
| 3114 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3115 | case QEMU_OPTION_cpu_delay: |
| 3116 | android_op_cpu_delay = (char*)optarg; |
| 3117 | break; |
| 3118 | |
Vladimir Chtchetkine | 13f3b6c | 2010-08-25 09:49:25 -0700 | [diff] [blame] | 3119 | case QEMU_OPTION_show_kernel: |
| 3120 | android_kmsg_init(ANDROID_KMSG_PRINT_MESSAGES); |
| 3121 | break; |
| 3122 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3123 | #ifdef CONFIG_NAND_LIMITS |
| 3124 | case QEMU_OPTION_nand_limits: |
| 3125 | android_op_nand_limits = (char*)optarg; |
| 3126 | break; |
| 3127 | #endif // CONFIG_NAND_LIMITS |
| 3128 | |
| 3129 | case QEMU_OPTION_netspeed: |
| 3130 | android_op_netspeed = (char*)optarg; |
| 3131 | break; |
| 3132 | |
| 3133 | case QEMU_OPTION_netdelay: |
| 3134 | android_op_netdelay = (char*)optarg; |
| 3135 | break; |
| 3136 | |
| 3137 | case QEMU_OPTION_netfast: |
| 3138 | android_op_netfast = 1; |
| 3139 | break; |
| 3140 | |
Vladimir Chtchetkine | 318f17a | 2010-08-27 09:09:45 -0700 | [diff] [blame] | 3141 | case QEMU_OPTION_tcpdump: |
| 3142 | android_op_tcpdump = (char*)optarg; |
| 3143 | break; |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3144 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3145 | case QEMU_OPTION_boot_property: |
| 3146 | boot_property_parse_option((char*)optarg); |
| 3147 | break; |
| 3148 | |
| 3149 | case QEMU_OPTION_lcd_density: |
| 3150 | android_op_lcd_density = (char*)optarg; |
| 3151 | break; |
| 3152 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3153 | case QEMU_OPTION_ui_port: |
| 3154 | android_op_ui_port = (char*)optarg; |
| 3155 | break; |
| 3156 | |
| 3157 | case QEMU_OPTION_ui_settings: |
| 3158 | android_op_ui_settings = (char*)optarg; |
| 3159 | break; |
| 3160 | |
David 'Digit' Turner | ca29fbb | 2011-01-02 13:17:22 +0100 | [diff] [blame] | 3161 | case QEMU_OPTION_audio_test_out: |
| 3162 | android_audio_test_start_out(); |
| 3163 | break; |
| 3164 | |
Vladimir Chtchetkine | 90c6235 | 2011-01-13 11:24:07 -0800 | [diff] [blame] | 3165 | case QEMU_OPTION_android_avdname: |
| 3166 | android_op_avd_name = (char*)optarg; |
| 3167 | break; |
| 3168 | |
| 3169 | case QEMU_OPTION_timezone: |
| 3170 | if (timezone_set((char*)optarg)) { |
| 3171 | fprintf(stderr, "emulator: it seems the timezone '%s' is not in zoneinfo format\n", |
| 3172 | (char*)optarg); |
| 3173 | } |
| 3174 | break; |
| 3175 | |
David 'Digit' Turner | 5bb450e | 2014-03-14 17:19:45 +0100 | [diff] [blame] | 3176 | #ifdef CONFIG_ANDROID_MEMCHECK |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 3177 | case QEMU_OPTION_android_memcheck: |
| 3178 | android_op_memcheck = (char*)optarg; |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3179 | /* This will set ro.kernel.memcheck system property |
| 3180 | * to memcheck's tracing flags. */ |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 3181 | stralloc_add_format(kernel_config, " memcheck=%s", android_op_memcheck); |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 3182 | break; |
David 'Digit' Turner | 5bb450e | 2014-03-14 17:19:45 +0100 | [diff] [blame] | 3183 | #endif // CONFIG_ANDROID_MEMCHECK |
David 'Digit' Turner | bdb6f2d | 2011-02-23 15:57:25 +0100 | [diff] [blame] | 3184 | |
| 3185 | case QEMU_OPTION_snapshot_no_time_update: |
| 3186 | android_snapshot_update_time = 0; |
| 3187 | break; |
Vladimir Chtchetkine | b8dcaff | 2011-09-17 11:15:47 -0700 | [diff] [blame] | 3188 | |
| 3189 | case QEMU_OPTION_list_webcam: |
| 3190 | android_list_web_cameras(); |
| 3191 | exit(0); |
| 3192 | |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 3193 | default: |
| 3194 | os_parse_cmd_args(popt->index, optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | } |
| 3198 | |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3199 | /* Initialize character map. */ |
| 3200 | if (android_charmap_setup(op_charmap_file)) { |
| 3201 | if (op_charmap_file) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3202 | PANIC( |
| 3203 | "Unable to initialize character map from file %s.", |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3204 | op_charmap_file); |
| 3205 | } else { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3206 | PANIC( |
| 3207 | "Unable to initialize default character map."); |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3208 | } |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3211 | /* If no data_dir is specified then try to find it relative to the |
| 3212 | executable path. */ |
| 3213 | if (!data_dir) { |
| 3214 | data_dir = find_datadir(argv[0]); |
| 3215 | } |
| 3216 | /* If all else fails use the install patch specified when building. */ |
| 3217 | if (!data_dir) { |
| 3218 | data_dir = CONFIG_QEMU_SHAREDIR; |
| 3219 | } |
| 3220 | |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 3221 | if (!android_op_hwini) { |
| 3222 | PANIC("Missing -android-hw <file> option!"); |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3223 | } |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 3224 | hw_ini = iniFile_newFromFile(android_op_hwini); |
| 3225 | if (hw_ini == NULL) { |
| 3226 | PANIC("Could not find %s file.", android_op_hwini); |
| 3227 | } |
David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 3228 | |
| 3229 | androidHwConfig_init(android_hw, 0); |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3230 | androidHwConfig_read(android_hw, hw_ini); |
David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 3231 | |
Vladimir Chtchetkine | db450d7 | 2012-01-12 13:37:40 -0800 | [diff] [blame] | 3232 | /* If we're loading VM from a snapshot, make sure that the current HW config |
| 3233 | * matches the one with which the VM has been saved. */ |
| 3234 | if (loadvm && *loadvm && !snaphost_match_configs(hw_ini, loadvm)) { |
| 3235 | exit(0); |
| 3236 | } |
| 3237 | |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3238 | iniFile_free(hw_ini); |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 3239 | |
David 'Digit' Turner | c6e0cae | 2014-03-07 23:08:30 +0100 | [diff] [blame] | 3240 | const char* kernelSerialDevicePrefix = |
| 3241 | androidHwConfig_getKernelSerialPrefix(android_hw); |
| 3242 | VERBOSE_PRINT(init, "Using kernel serial device prefix: %s", |
| 3243 | kernelSerialDevicePrefix); |
| 3244 | |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 3245 | { |
| 3246 | int width = android_hw->hw_lcd_width; |
| 3247 | int height = android_hw->hw_lcd_height; |
| 3248 | int depth = android_hw->hw_lcd_depth; |
| 3249 | |
| 3250 | /* A bit of sanity checking */ |
| 3251 | if (width <= 0 || height <= 0 || |
| 3252 | (depth != 16 && depth != 32) || |
| 3253 | (((width|height) & 3) != 0) ) |
| 3254 | { |
| 3255 | PANIC("Invalid display configuration (%d,%d,%d)", |
| 3256 | width, height, depth); |
| 3257 | } |
| 3258 | android_display_width = width; |
| 3259 | android_display_height = height; |
| 3260 | android_display_bpp = depth; |
| 3261 | } |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3262 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3263 | #ifdef CONFIG_NAND_LIMITS |
| 3264 | /* Init nand stuff. */ |
| 3265 | if (android_op_nand_limits) { |
| 3266 | parse_nand_limits(android_op_nand_limits); |
| 3267 | } |
| 3268 | #endif // CONFIG_NAND_LIMITS |
| 3269 | |
David 'Digit' Turner | 53eb66d | 2011-03-01 14:58:23 +0100 | [diff] [blame] | 3270 | /* Initialize AVD name from hardware configuration if needed */ |
| 3271 | if (!android_op_avd_name) { |
| 3272 | if (android_hw->avd_name && *android_hw->avd_name) { |
| 3273 | android_op_avd_name = android_hw->avd_name; |
| 3274 | VERBOSE_PRINT(init,"AVD Name: %s", android_op_avd_name); |
| 3275 | } |
| 3276 | } |
| 3277 | |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3278 | bool systemImageIsExt4 = false; |
| 3279 | bool dataImageIsExt4 = false; |
| 3280 | bool cacheImageIsExt4 = false; |
| 3281 | |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3282 | /* Initialize system partition image */ |
| 3283 | { |
| 3284 | char tmp[PATH_MAX+32]; |
| 3285 | const char* sysImage = android_hw->disk_systemPartition_path; |
| 3286 | const char* initImage = android_hw->disk_systemPartition_initPath; |
| 3287 | uint64_t sysBytes = android_hw->disk_systemPartition_size; |
| 3288 | |
| 3289 | if (sysBytes == 0) { |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3290 | PANIC("Invalid system partition size: %" PRIu64, sysBytes); |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3291 | } |
| 3292 | |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3293 | snprintf(tmp,sizeof(tmp),"system,size=0x%" PRIx64, sysBytes); |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3294 | |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3295 | const char* imageFile = NULL; |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3296 | if (sysImage && *sysImage) { |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3297 | imageFile = sysImage; |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3298 | if (filelock_create(sysImage) == NULL) { |
| 3299 | fprintf(stderr,"WARNING: System image already in use, changes will not persist!\n"); |
| 3300 | /* If there is no file= parameters, nand_add_dev will create |
| 3301 | * a temporary file to back the partition image. */ |
| 3302 | } else { |
| 3303 | pstrcat(tmp,sizeof(tmp),",file="); |
| 3304 | pstrcat(tmp,sizeof(tmp),sysImage); |
| 3305 | } |
| 3306 | } |
| 3307 | if (initImage && *initImage) { |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3308 | imageFile = initImage; |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3309 | if (!path_exists(initImage)) { |
| 3310 | PANIC("Invalid initial system image path: %s", initImage); |
| 3311 | } |
| 3312 | pstrcat(tmp,sizeof(tmp),",initfile="); |
| 3313 | pstrcat(tmp,sizeof(tmp),initImage); |
| 3314 | } else { |
| 3315 | PANIC("Missing initial system image path!"); |
| 3316 | } |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3317 | systemImageIsExt4 = imageFile && android_pathIsExt4PartitionImage(imageFile); |
| 3318 | if (systemImageIsExt4) { |
Deepanshu Gupta | 04b20f4 | 2013-09-11 12:04:27 -0700 | [diff] [blame] | 3319 | /* Using a nand device to approximate a block device until full |
| 3320 | * support is added */ |
| 3321 | pstrcat(tmp,sizeof(tmp),",pagesize=512,extrasize=0"); |
| 3322 | } |
David 'Digit' Turner | 28f52f2 | 2014-02-26 12:17:25 +0100 | [diff] [blame] | 3323 | VERBOSE_PRINT(init, "System partition format: %s", |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3324 | systemImageIsExt4 ? "ext4" : "yaffs2"); |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3325 | nand_add_dev(tmp); |
| 3326 | } |
| 3327 | |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3328 | /* Initialize data partition image */ |
| 3329 | { |
| 3330 | char tmp[PATH_MAX+32]; |
| 3331 | const char* dataImage = android_hw->disk_dataPartition_path; |
| 3332 | const char* initImage = android_hw->disk_dataPartition_initPath; |
| 3333 | uint64_t dataBytes = android_hw->disk_dataPartition_size; |
| 3334 | |
| 3335 | if (dataBytes == 0) { |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3336 | PANIC("Invalid data partition size: %" PRIu64, dataBytes); |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3337 | } |
| 3338 | |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3339 | snprintf(tmp,sizeof(tmp),"userdata,size=0x%" PRIx64, dataBytes); |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3340 | |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3341 | const char* imageFile = dataImage; |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3342 | if (dataImage && *dataImage) { |
| 3343 | if (filelock_create(dataImage) == NULL) { |
| 3344 | fprintf(stderr, "WARNING: Data partition already in use. Changes will not persist!\n"); |
| 3345 | /* Note: if there is no file= parameters, nand_add_dev() will |
| 3346 | * create a temporary file to back the partition image. */ |
| 3347 | } else { |
| 3348 | /* Create the file if needed */ |
| 3349 | if (!path_exists(dataImage)) { |
David 'Digit' Turner | e8ab08c | 2011-03-15 23:08:50 +0100 | [diff] [blame] | 3350 | if (path_empty_file(dataImage) < 0) { |
| 3351 | PANIC("Could not create data image file %s: %s", dataImage, strerror(errno)); |
| 3352 | } |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3353 | } |
| 3354 | pstrcat(tmp, sizeof(tmp), ",file="); |
| 3355 | pstrcat(tmp, sizeof(tmp), dataImage); |
| 3356 | } |
| 3357 | } |
| 3358 | if (initImage && *initImage) { |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3359 | imageFile = initImage; |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3360 | pstrcat(tmp, sizeof(tmp), ",initfile="); |
| 3361 | pstrcat(tmp, sizeof(tmp), initImage); |
| 3362 | } |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3363 | dataImageIsExt4 = imageFile && android_pathIsExt4PartitionImage(imageFile); |
| 3364 | if (dataImageIsExt4) { |
Deepanshu Gupta | 04b20f4 | 2013-09-11 12:04:27 -0700 | [diff] [blame] | 3365 | /* Using a nand device to approximate a block device until full |
| 3366 | * support is added */ |
| 3367 | pstrcat(tmp, sizeof(tmp), ",pagesize=512,extrasize=0"); |
| 3368 | } |
David 'Digit' Turner | 28f52f2 | 2014-02-26 12:17:25 +0100 | [diff] [blame] | 3369 | VERBOSE_PRINT(init, "Data partition format: %s", |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3370 | dataImageIsExt4 ? "ext4" : "yaffs2"); |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3371 | nand_add_dev(tmp); |
| 3372 | } |
| 3373 | |
David 'Digit' Turner | 48a3c66 | 2011-03-01 14:03:20 +0100 | [diff] [blame] | 3374 | /* Init SD-Card stuff. For Android, it is always hda */ |
| 3375 | /* If the -hda option was used, ignore the Android-provided one */ |
| 3376 | if (hda_opts == NULL) { |
| 3377 | const char* sdPath = android_hw->hw_sdCard_path; |
| 3378 | if (sdPath && *sdPath) { |
| 3379 | if (!path_exists(sdPath)) { |
| 3380 | fprintf(stderr, "WARNING: SD Card image is missing: %s\n", sdPath); |
| 3381 | } else if (filelock_create(sdPath) == NULL) { |
| 3382 | fprintf(stderr, "WARNING: SD Card image already in use: %s\n", sdPath); |
| 3383 | } else { |
| 3384 | /* Successful locking */ |
| 3385 | hda_opts = drive_add(sdPath, HD_ALIAS, 0); |
David 'Digit' Turner | 8fc3e6e | 2011-05-09 10:17:20 +0200 | [diff] [blame] | 3386 | /* Set this property of any operation involving the SD Card |
| 3387 | * will be x100 slower, due to the corresponding file being |
| 3388 | * mounted as O_DIRECT. Note that this is only 'unsafe' in |
| 3389 | * the context of an emulator crash. The data is already |
| 3390 | * synced properly when the emulator exits (either normally or through ^C). |
| 3391 | */ |
| 3392 | qemu_opt_set(hda_opts, "cache", "unsafe"); |
David 'Digit' Turner | 48a3c66 | 2011-03-01 14:03:20 +0100 | [diff] [blame] | 3393 | } |
| 3394 | } |
| 3395 | } |
| 3396 | |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 3397 | if (hdb_opts == NULL) { |
| 3398 | const char* spath = android_hw->disk_snapStorage_path; |
| 3399 | if (spath && *spath) { |
| 3400 | if (!path_exists(spath)) { |
| 3401 | PANIC("Snapshot storage file does not exist: %s", spath); |
| 3402 | } |
| 3403 | if (filelock_create(spath) == NULL) { |
David 'Digit' Turner | 4297b82 | 2011-05-04 19:18:15 +0200 | [diff] [blame] | 3404 | PANIC("Snapshot storage already in use: %s", spath); |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 3405 | } |
| 3406 | hdb_opts = drive_add(spath, HD_ALIAS, 1); |
David 'Digit' Turner | 8fc3e6e | 2011-05-09 10:17:20 +0200 | [diff] [blame] | 3407 | /* See comment above to understand why this is needed. */ |
David 'Digit' Turner | 9fb360e | 2011-05-04 22:01:28 +0200 | [diff] [blame] | 3408 | qemu_opt_set(hdb_opts, "cache", "unsafe"); |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 3409 | } |
| 3410 | } |
| 3411 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3412 | /* Set the VM's max heap size, passed as a boot property */ |
| 3413 | if (android_hw->vm_heapSize > 0) { |
| 3414 | char tmp[64]; |
| 3415 | snprintf(tmp, sizeof(tmp), "%dm", android_hw->vm_heapSize); |
| 3416 | boot_property_add("dalvik.vm.heapsize",tmp); |
| 3417 | } |
| 3418 | |
Siva Velusamy | 0faeb3a | 2013-10-29 14:23:35 -0700 | [diff] [blame] | 3419 | /* From API 19 and above, the platform provides an explicit property for low memory devices. */ |
| 3420 | if (android_hw->hw_ramSize <= 512) { |
| 3421 | boot_property_add("ro.config.low_ram", "true"); |
| 3422 | } |
| 3423 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3424 | /* Initialize net speed and delays stuff. */ |
| 3425 | if (android_parse_network_speed(android_op_netspeed) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3426 | PANIC("invalid -netspeed parameter '%s'", |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3427 | android_op_netspeed); |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | if ( android_parse_network_latency(android_op_netdelay) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3431 | PANIC("invalid -netdelay parameter '%s'", |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3432 | android_op_netdelay); |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | if (android_op_netfast) { |
| 3436 | qemu_net_download_speed = 0; |
| 3437 | qemu_net_upload_speed = 0; |
| 3438 | qemu_net_min_latency = 0; |
| 3439 | qemu_net_max_latency = 0; |
| 3440 | } |
| 3441 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3442 | /* Initialize LCD density */ |
David 'Digit' Turner | 5377c5b | 2011-02-10 16:52:19 +0100 | [diff] [blame] | 3443 | if (android_hw->hw_lcd_density) { |
| 3444 | long density = android_hw->hw_lcd_density; |
| 3445 | if (density <= 0) { |
| 3446 | PANIC("Invalid hw.lcd.density value: %ld", density); |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3447 | } |
| 3448 | hwLcd_setBootProperty(density); |
| 3449 | } |
| 3450 | |
Xavier Ducrohet | fa0c8e2 | 2011-10-04 10:41:26 -0700 | [diff] [blame] | 3451 | /* Initialize presence of hardware nav button */ |
| 3452 | boot_property_add("qemu.hw.mainkeys", android_hw->hw_mainKeys ? "1" : "0"); |
| 3453 | |
Vladimir Chtchetkine | 318f17a | 2010-08-27 09:09:45 -0700 | [diff] [blame] | 3454 | /* Initialize TCP dump */ |
| 3455 | if (android_op_tcpdump) { |
| 3456 | if (qemu_tcpdump_start(android_op_tcpdump) < 0) { |
| 3457 | fprintf(stdout, "could not start packet capture: %s\n", strerror(errno)); |
| 3458 | } |
| 3459 | } |
| 3460 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3461 | /* Initialize modem */ |
| 3462 | if (android_op_radio) { |
| 3463 | CharDriverState* cs = qemu_chr_open("radio", android_op_radio, NULL); |
| 3464 | if (cs == NULL) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3465 | PANIC("unsupported character device specification: %s\n" |
| 3466 | "used -help-char-devices for list of available formats", |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3467 | android_op_radio); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3468 | } |
| 3469 | android_qemud_set_channel( ANDROID_QEMUD_GSM, cs); |
| 3470 | } else if (android_hw->hw_gsmModem != 0 ) { |
| 3471 | if ( android_qemud_get_channel( ANDROID_QEMUD_GSM, &android_modem_cs ) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3472 | PANIC("could not initialize qemud 'gsm' channel"); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | /* Initialize GPS */ |
| 3477 | if (android_op_gps) { |
| 3478 | CharDriverState* cs = qemu_chr_open("gps", android_op_gps, NULL); |
| 3479 | if (cs == NULL) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3480 | PANIC("unsupported character device specification: %s\n" |
| 3481 | "used -help-char-devices for list of available formats", |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3482 | android_op_gps); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3483 | } |
| 3484 | android_qemud_set_channel( ANDROID_QEMUD_GPS, cs); |
| 3485 | } else if (android_hw->hw_gps != 0) { |
| 3486 | if ( android_qemud_get_channel( "gps", &android_gps_cs ) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3487 | PANIC("could not initialize qemud 'gps' channel"); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | /* Initialize audio. */ |
| 3492 | if (android_op_audio) { |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3493 | if ( !audio_check_backend_name( 0, android_op_audio ) ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3494 | PANIC("'%s' is not a valid audio output backend. see -help-audio-out", |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3495 | android_op_audio); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3496 | } |
David 'Digit' Turner | f816a75 | 2011-06-23 18:40:11 +0200 | [diff] [blame] | 3497 | setenv("QEMU_AUDIO_DRV", android_op_audio, 1); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
David 'Digit' Turner | 5b48149 | 2011-04-11 17:37:32 +0200 | [diff] [blame] | 3500 | /* Initialize OpenGLES emulation */ |
David 'Digit' Turner | d4d688e | 2011-04-26 18:09:17 +0200 | [diff] [blame] | 3501 | //android_hw_opengles_init(); |
David 'Digit' Turner | 5b48149 | 2011-04-11 17:37:32 +0200 | [diff] [blame] | 3502 | |
Vladimir Chtchetkine | ae0d813 | 2011-09-13 10:48:02 -0700 | [diff] [blame] | 3503 | /* Initialize fake camera */ |
Vladimir Chtchetkine | 7485c29 | 2012-03-19 11:35:29 -0700 | [diff] [blame] | 3504 | if (strcmp(android_hw->hw_camera_back, "emulated") && |
| 3505 | strcmp(android_hw->hw_camera_front, "emulated")) { |
| 3506 | /* Fake camera is not used for camera emulation. */ |
| 3507 | boot_property_add("qemu.sf.fake_camera", "none"); |
Vladimir Chtchetkine | ae0d813 | 2011-09-13 10:48:02 -0700 | [diff] [blame] | 3508 | } else { |
Vladimir Chtchetkine | 7485c29 | 2012-03-19 11:35:29 -0700 | [diff] [blame] | 3509 | /* Fake camera is used for at least one camera emulation. */ |
| 3510 | if (!strcmp(android_hw->hw_camera_back, "emulated") && |
| 3511 | !strcmp(android_hw->hw_camera_front, "emulated")) { |
| 3512 | /* Fake camera is used for both, front and back camera emulation. */ |
| 3513 | boot_property_add("qemu.sf.fake_camera", "both"); |
| 3514 | } else if (!strcmp(android_hw->hw_camera_back, "emulated")) { |
| 3515 | boot_property_add("qemu.sf.fake_camera", "back"); |
| 3516 | } else { |
| 3517 | boot_property_add("qemu.sf.fake_camera", "front"); |
| 3518 | } |
Vladimir Chtchetkine | ae0d813 | 2011-09-13 10:48:02 -0700 | [diff] [blame] | 3519 | } |
| 3520 | |
Vladimir Chtchetkine | 035f805 | 2012-05-18 12:19:32 -0700 | [diff] [blame] | 3521 | /* Set LCD density (if required by -qemu, and AVD is missing it. */ |
| 3522 | if (android_op_lcd_density && !android_hw->hw_lcd_density) { |
| 3523 | int density; |
| 3524 | if (parse_int(android_op_lcd_density, &density) || density <= 0) { |
| 3525 | PANIC("-lcd-density : %d", density); |
| 3526 | } |
| 3527 | hwLcd_setBootProperty(density); |
| 3528 | } |
| 3529 | |
Vladimir Chtchetkine | b8dcaff | 2011-09-17 11:15:47 -0700 | [diff] [blame] | 3530 | /* Initialize camera emulation. */ |
| 3531 | android_camera_service_init(); |
| 3532 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3533 | if (android_op_cpu_delay) { |
| 3534 | char* end; |
| 3535 | long delay = strtol(android_op_cpu_delay, &end, 0); |
| 3536 | if (end == NULL || *end || delay < 0 || delay > 1000 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3537 | PANIC("option -cpu-delay must be an integer between 0 and 1000" ); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3538 | } |
| 3539 | if (delay > 0) |
| 3540 | delay = (1000-delay); |
| 3541 | |
| 3542 | qemu_cpu_delay = (int) delay; |
| 3543 | } |
| 3544 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3545 | if (android_op_dns_server) { |
| 3546 | char* x = strchr(android_op_dns_server, ','); |
| 3547 | dns_count = 0; |
| 3548 | if (x == NULL) |
| 3549 | { |
| 3550 | if ( add_dns_server( android_op_dns_server ) == 0 ) |
| 3551 | dns_count = 1; |
| 3552 | } |
| 3553 | else |
| 3554 | { |
| 3555 | x = android_op_dns_server; |
| 3556 | while (*x) { |
| 3557 | char* y = strchr(x, ','); |
| 3558 | |
| 3559 | if (y != NULL) { |
| 3560 | *y = 0; |
| 3561 | y++; |
| 3562 | } else { |
| 3563 | y = x + strlen(x); |
| 3564 | } |
| 3565 | |
| 3566 | if (y > x && add_dns_server( x ) == 0) { |
| 3567 | dns_count += 1; |
| 3568 | } |
| 3569 | x = y; |
| 3570 | } |
| 3571 | } |
| 3572 | if (dns_count == 0) |
| 3573 | fprintf( stdout, "### WARNING: will use system default DNS server\n" ); |
| 3574 | } |
| 3575 | |
| 3576 | if (dns_count == 0) |
| 3577 | dns_count = slirp_get_system_dns_servers(); |
| 3578 | if (dns_count) { |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 3579 | stralloc_add_format(kernel_config, " ndns=%d", dns_count); |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
David 'Digit' Turner | 5bb450e | 2014-03-14 17:19:45 +0100 | [diff] [blame] | 3582 | #ifdef CONFIG_ANDROID_MEMCHECK |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 3583 | if (android_op_memcheck) { |
| 3584 | memcheck_init(android_op_memcheck); |
| 3585 | } |
David 'Digit' Turner | 5bb450e | 2014-03-14 17:19:45 +0100 | [diff] [blame] | 3586 | #endif // CONFIG_ANDROID_MEMCHECK |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 3587 | |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3588 | /* Initialize cache partition, if any */ |
| 3589 | if (android_hw->disk_cachePartition != 0) { |
| 3590 | char tmp[PATH_MAX+32]; |
| 3591 | const char* partPath = android_hw->disk_cachePartition_path; |
David 'Digit' Turner | e8ab08c | 2011-03-15 23:08:50 +0100 | [diff] [blame] | 3592 | uint64_t partSize = android_hw->disk_cachePartition_size; |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3593 | |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3594 | snprintf(tmp,sizeof(tmp),"cache,size=0x%" PRIx64, partSize); |
David 'Digit' Turner | e8ab08c | 2011-03-15 23:08:50 +0100 | [diff] [blame] | 3595 | |
| 3596 | if (partPath && *partPath && strcmp(partPath, "<temp>") != 0) { |
| 3597 | if (filelock_create(partPath) == NULL) { |
| 3598 | fprintf(stderr, "WARNING: Cache partition already in use. Changes will not persist!\n"); |
| 3599 | /* Note: if there is no file= parameters, nand_add_dev() will |
| 3600 | * create a temporary file to back the partition image. */ |
| 3601 | } else { |
| 3602 | /* Create the file if needed */ |
| 3603 | if (!path_exists(partPath)) { |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3604 | // TODO(digit): For EXT4, create a real empty ext4 partition image. |
David 'Digit' Turner | e8ab08c | 2011-03-15 23:08:50 +0100 | [diff] [blame] | 3605 | if (path_empty_file(partPath) < 0) { |
| 3606 | PANIC("Could not create cache image file %s: %s", partPath, strerror(errno)); |
| 3607 | } |
| 3608 | } |
| 3609 | pstrcat(tmp, sizeof(tmp), ",file="); |
| 3610 | pstrcat(tmp, sizeof(tmp), partPath); |
| 3611 | } |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3612 | } |
David 'Digit' Turner | a44d1dc | 2014-03-19 17:58:41 +0100 | [diff] [blame] | 3613 | // NOTE: The following line is commented to avoid problems with the |
| 3614 | // current state of the emulator and AOSP/master. In a nutshell, |
| 3615 | // take it out of the comment once proper support for generating |
| 3616 | // EXT4 partitions on demand is added to the emulator, and |
| 3617 | // /etc/fstab.goldfish is modified to mount an EXT4, not YAFFS2, |
| 3618 | // partition for /cache. |
| 3619 | // |
| 3620 | // cacheImageIsExt4 = partPath && android_pathIsExt4PartitionImage(partPath); |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3621 | if (cacheImageIsExt4) { |
Deepanshu Gupta | 04b20f4 | 2013-09-11 12:04:27 -0700 | [diff] [blame] | 3622 | /* Using a nand device to approximate a block device until full |
| 3623 | * support is added */ |
| 3624 | pstrcat(tmp, sizeof(tmp), ",pagesize=512,extrasize=0"); |
| 3625 | } |
David 'Digit' Turner | 28f52f2 | 2014-02-26 12:17:25 +0100 | [diff] [blame] | 3626 | VERBOSE_PRINT(init, "Cache partition format: %s", |
David 'Digit' Turner | 890f464 | 2014-02-24 11:53:03 +0100 | [diff] [blame] | 3627 | cacheImageIsExt4 ? "ext4" : "yaffs2"); |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3628 | nand_add_dev(tmp); |
| 3629 | } |
| 3630 | |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3631 | /* qemu.gles will be read by the OpenGL ES emulation libraries. |
| 3632 | * If set to 0, the software GL ES renderer will be used as a fallback. |
| 3633 | * If the parameter is undefined, this means the system image runs |
| 3634 | * inside an emulator that doesn't support GPU emulation at all. |
| 3635 | * |
| 3636 | * We always start the GL ES renderer so we can gather stats on the |
| 3637 | * underlying GL implementation. If GL ES acceleration is disabled, |
| 3638 | * we just shut it down again once we have the strings. */ |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3639 | { |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3640 | int qemu_gles = 0; |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3641 | if (android_initOpenglesEmulation() == 0 && |
Jesse Hall | ba5c1f6 | 2012-05-08 15:44:35 -0700 | [diff] [blame] | 3642 | android_startOpenglesRenderer(android_hw->hw_lcd_width, android_hw->hw_lcd_height) == 0) |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3643 | { |
| 3644 | android_getOpenglesHardwareStrings( |
| 3645 | android_gl_vendor, sizeof(android_gl_vendor), |
| 3646 | android_gl_renderer, sizeof(android_gl_renderer), |
| 3647 | android_gl_version, sizeof(android_gl_version)); |
| 3648 | if (android_hw->hw_gpu_enabled) { |
| 3649 | qemu_gles = 1; |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3650 | } else { |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3651 | android_stopOpenglesRenderer(); |
| 3652 | qemu_gles = 0; |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3653 | } |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3654 | } else { |
| 3655 | dwarning("Could not initialize OpenglES emulation, using software renderer."); |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3656 | } |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3657 | if (qemu_gles) { |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3658 | stralloc_add_str(kernel_params, " qemu.gles=1"); |
| 3659 | } else { |
| 3660 | stralloc_add_str(kernel_params, " qemu.gles=0"); |
| 3661 | } |
| 3662 | } |
| 3663 | |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 3664 | /* We always force qemu=1 when running inside QEMU */ |
| 3665 | stralloc_add_str(kernel_params, " qemu=1"); |
| 3666 | |
| 3667 | /* We always initialize the first serial port for the android-kmsg |
| 3668 | * character device (used to send kernel messages) */ |
| 3669 | serial_hds_add_at(0, "android-kmsg"); |
David 'Digit' Turner | c6e0cae | 2014-03-07 23:08:30 +0100 | [diff] [blame] | 3670 | stralloc_add_format(kernel_params, |
| 3671 | " console=%s0", |
| 3672 | kernelSerialDevicePrefix); |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 3673 | |
| 3674 | /* We always initialize the second serial port for the android-qemud |
| 3675 | * character device as well */ |
| 3676 | serial_hds_add_at(1, "android-qemud"); |
David 'Digit' Turner | c6e0cae | 2014-03-07 23:08:30 +0100 | [diff] [blame] | 3677 | stralloc_add_format(kernel_params, |
| 3678 | " android.qemud=%s1", |
| 3679 | kernelSerialDevicePrefix); |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 3680 | |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 3681 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
| 3682 | os_pidfile_error(); |
| 3683 | exit(1); |
| 3684 | } |
| 3685 | |
David 'Digit' Turner | 7e9f6c1 | 2014-01-22 18:42:40 +0100 | [diff] [blame] | 3686 | /* Open the logfile at this point, if necessary. We can't open the logfile |
| 3687 | * when encountering either of the logging options (-d or -D) because the |
| 3688 | * other one may be encountered later on the command line, changing the |
| 3689 | * location or level of logging. |
| 3690 | */ |
| 3691 | if (log_mask) { |
| 3692 | int mask; |
| 3693 | if (log_file) { |
| 3694 | qemu_set_log_filename(log_file); |
| 3695 | } |
| 3696 | |
| 3697 | mask = qemu_str_to_log_mask(log_mask); |
| 3698 | if (!mask) { |
| 3699 | qemu_print_log_usage(stdout); |
| 3700 | exit(1); |
| 3701 | } |
| 3702 | qemu_set_log(mask); |
| 3703 | } |
David 'Digit' Turner | c005246 | 2014-02-25 18:39:29 +0100 | [diff] [blame] | 3704 | |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 3705 | #if defined(CONFIG_KVM) |
| 3706 | if (kvm_allowed < 0) { |
| 3707 | kvm_allowed = kvm_check_allowed(); |
| 3708 | } |
| 3709 | #endif |
| 3710 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3711 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
| 3712 | if (smp_cpus > machine->max_cpus) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3713 | PANIC("Number of SMP cpus requested (%d), exceeds max cpus " |
| 3714 | "supported by machine `%s' (%d)", smp_cpus, machine->name, |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3715 | machine->max_cpus); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | if (display_type == DT_NOGRAPHIC) { |
| 3719 | if (serial_device_index == 0) |
| 3720 | serial_devices[0] = "stdio"; |
| 3721 | if (parallel_device_index == 0) |
| 3722 | parallel_devices[0] = "null"; |
| 3723 | if (strncmp(monitor_device, "vc", 2) == 0) |
| 3724 | monitor_device = "stdio"; |
| 3725 | } |
| 3726 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3727 | if (qemu_init_main_loop()) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3728 | PANIC("qemu_init_main_loop failed"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3729 | } |
David 'Digit' Turner | 0b01949 | 2011-03-01 14:02:42 +0100 | [diff] [blame] | 3730 | |
| 3731 | if (kernel_filename == NULL) { |
| 3732 | kernel_filename = android_hw->kernel_path; |
| 3733 | } |
| 3734 | if (initrd_filename == NULL) { |
| 3735 | initrd_filename = android_hw->disk_ramdisk_path; |
| 3736 | } |
| 3737 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3738 | linux_boot = (kernel_filename != NULL); |
| 3739 | net_boot = (boot_devices_bitmap >> ('n' - 'a')) & 0xF; |
| 3740 | |
| 3741 | if (!linux_boot && *kernel_cmdline != '\0') { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3742 | PANIC("-append only allowed with -kernel option"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | if (!linux_boot && initrd_filename != NULL) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3746 | PANIC("-initrd only allowed with -kernel option"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | /* boot to floppy or the default cd if no hard disk defined yet */ |
| 3750 | if (!boot_devices[0]) { |
| 3751 | boot_devices = "cad"; |
| 3752 | } |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 3753 | os_set_line_buffering(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3754 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3755 | if (init_timer_alarm() < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3756 | PANIC("could not initialize alarm timer"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3757 | } |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 3758 | configure_icount(icount_option); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3759 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3760 | /* init network clients */ |
| 3761 | if (nb_net_clients == 0) { |
| 3762 | /* if no clients, we use a default config */ |
| 3763 | net_clients[nb_net_clients++] = "nic"; |
| 3764 | #ifdef CONFIG_SLIRP |
| 3765 | net_clients[nb_net_clients++] = "user"; |
| 3766 | #endif |
| 3767 | } |
| 3768 | |
| 3769 | for(i = 0;i < nb_net_clients; i++) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3770 | if (net_client_parse(net_clients[i]) < 0) { |
| 3771 | PANIC("Unable to parse net clients"); |
| 3772 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3773 | } |
| 3774 | net_client_check(); |
| 3775 | |
| 3776 | #ifdef TARGET_I386 |
| 3777 | /* XXX: this should be moved in the PC machine instantiation code */ |
| 3778 | if (net_boot != 0) { |
| 3779 | int netroms = 0; |
| 3780 | for (i = 0; i < nb_nics && i < 4; i++) { |
| 3781 | const char *model = nd_table[i].model; |
| 3782 | char buf[1024]; |
| 3783 | char *filename; |
| 3784 | if (net_boot & (1 << i)) { |
| 3785 | if (model == NULL) |
| 3786 | model = "ne2k_pci"; |
| 3787 | snprintf(buf, sizeof(buf), "pxe-%s.bin", model); |
| 3788 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, buf); |
| 3789 | if (filename && get_image_size(filename) > 0) { |
| 3790 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3791 | PANIC("Too many option ROMs"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3792 | } |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 3793 | option_rom[nb_option_roms] = g_strdup(buf); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3794 | nb_option_roms++; |
| 3795 | netroms++; |
| 3796 | } |
| 3797 | if (filename) { |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 3798 | g_free(filename); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | } |
| 3802 | if (netroms == 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3803 | PANIC("No valid PXE rom found for network device"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | #endif |
| 3807 | |
| 3808 | /* init the bluetooth world */ |
| 3809 | for (i = 0; i < nb_bt_opts; i++) |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3810 | if (bt_parse(bt_opts[i])) { |
| 3811 | PANIC("Unable to parse bluetooth options"); |
| 3812 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3813 | |
| 3814 | /* init the memory */ |
David 'Digit' Turner | 5377c5b | 2011-02-10 16:52:19 +0100 | [diff] [blame] | 3815 | if (ram_size == 0) { |
| 3816 | ram_size = android_hw->hw_ramSize * 1024LL * 1024; |
| 3817 | if (ram_size == 0) { |
| 3818 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; |
| 3819 | } |
| 3820 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3821 | |
Vladimir Chtchetkine | cf289fb | 2012-05-14 08:04:29 -0700 | [diff] [blame] | 3822 | /* Quite often (especially on older XP machines) attempts to allocate large |
| 3823 | * VM RAM is going to fail, and crash the emulator. Since it's failing deep |
| 3824 | * inside QEMU, it's not really possible to provide the user with a |
| 3825 | * meaningful explanation for the crash. So, lets see if QEMU is going to be |
| 3826 | * able to allocate requested amount of RAM, and if not, lets try to come up |
| 3827 | * with a recomendation. */ |
| 3828 | { |
| 3829 | ram_addr_t r_ram = ram_size; |
| 3830 | void* alloc_check = malloc(r_ram); |
| 3831 | while (alloc_check == NULL && r_ram > 1024 * 1024) { |
| 3832 | /* Make it 25% less */ |
| 3833 | r_ram -= r_ram / 4; |
| 3834 | alloc_check = malloc(r_ram); |
| 3835 | } |
| 3836 | if (alloc_check != NULL) { |
| 3837 | free(alloc_check); |
| 3838 | } |
| 3839 | if (r_ram != ram_size) { |
| 3840 | /* Requested RAM is too large. Report this, as well as calculated |
| 3841 | * recomendation. */ |
| 3842 | dwarning("Requested RAM size of %dMB is too large for your environment, and is reduced to %dMB.", |
| 3843 | (int)(ram_size / 1024 / 1024), (int)(r_ram / 1024 / 1024)); |
| 3844 | ram_size = r_ram; |
| 3845 | } |
| 3846 | } |
| 3847 | |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 3848 | #ifndef _WIN32 |
David 'Digit' Turner | f9077a8 | 2014-02-10 23:10:47 +0100 | [diff] [blame] | 3849 | qemu_log_rotation_init(); |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 3850 | #endif |
| 3851 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3852 | /* init the dynamic translator */ |
| 3853 | cpu_exec_init_all(tb_size * 1024 * 1024); |
| 3854 | |
| 3855 | bdrv_init(); |
| 3856 | |
| 3857 | /* we always create the cdrom drive, even if no disk is there */ |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 3858 | #if 0 |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3859 | if (nb_drives_opt < MAX_DRIVES) |
| 3860 | drive_add(NULL, CDROM_ALIAS); |
| 3861 | |
| 3862 | /* we always create at least one floppy */ |
| 3863 | |
| 3864 | if (nb_drives_opt < MAX_DRIVES) |
| 3865 | drive_add(NULL, FD_ALIAS, 0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3866 | /* we always create one sd slot, even if no card is in it */ |
| 3867 | |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 3868 | if (1) { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3869 | drive_add(NULL, SD_ALIAS); |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 3870 | } |
| 3871 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3872 | |
| 3873 | /* open the virtual block devices */ |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 3874 | if (snapshot) |
| 3875 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
| 3876 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0) |
| 3877 | exit(1); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3878 | |
David 'Digit' Turner | 5cb5c0b | 2014-02-17 16:04:03 +0100 | [diff] [blame] | 3879 | //register_savevm(NULL, "timer", 0, 2, timer_save, timer_load, &timers_state); |
| 3880 | |
| 3881 | SaveVMHandlers* ops = g_malloc0(sizeof(*ops)); |
| 3882 | ops->save_live_state = ram_save_live; |
| 3883 | ops->load_state = ram_load; |
| 3884 | |
| 3885 | register_savevm_live(NULL, |
| 3886 | "ram", |
| 3887 | 0, |
| 3888 | 3, |
| 3889 | ops, |
| 3890 | NULL); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3891 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3892 | /* must be after terminal init, SDL library changes signal handlers */ |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 3893 | os_setup_signal_handling(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3894 | |
| 3895 | /* Maintain compatibility with multiple stdio monitors */ |
| 3896 | if (!strcmp(monitor_device,"stdio")) { |
| 3897 | for (i = 0; i < MAX_SERIAL_PORTS; i++) { |
| 3898 | const char *devname = serial_devices[i]; |
| 3899 | if (devname && !strcmp(devname,"mon:stdio")) { |
| 3900 | monitor_device = NULL; |
| 3901 | break; |
| 3902 | } else if (devname && !strcmp(devname,"stdio")) { |
| 3903 | monitor_device = NULL; |
| 3904 | serial_devices[i] = "mon:stdio"; |
| 3905 | break; |
| 3906 | } |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | if (nb_numa_nodes > 0) { |
| 3911 | int i; |
| 3912 | |
| 3913 | if (nb_numa_nodes > smp_cpus) { |
| 3914 | nb_numa_nodes = smp_cpus; |
| 3915 | } |
| 3916 | |
| 3917 | /* If no memory size if given for any node, assume the default case |
| 3918 | * and distribute the available memory equally across all nodes |
| 3919 | */ |
| 3920 | for (i = 0; i < nb_numa_nodes; i++) { |
| 3921 | if (node_mem[i] != 0) |
| 3922 | break; |
| 3923 | } |
| 3924 | if (i == nb_numa_nodes) { |
| 3925 | uint64_t usedmem = 0; |
| 3926 | |
| 3927 | /* On Linux, the each node's border has to be 8MB aligned, |
| 3928 | * the final node gets the rest. |
| 3929 | */ |
| 3930 | for (i = 0; i < nb_numa_nodes - 1; i++) { |
| 3931 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); |
| 3932 | usedmem += node_mem[i]; |
| 3933 | } |
| 3934 | node_mem[i] = ram_size - usedmem; |
| 3935 | } |
| 3936 | |
| 3937 | for (i = 0; i < nb_numa_nodes; i++) { |
| 3938 | if (node_cpumask[i] != 0) |
| 3939 | break; |
| 3940 | } |
| 3941 | /* assigning the VCPUs round-robin is easier to implement, guest OSes |
| 3942 | * must cope with this anyway, because there are BIOSes out there in |
| 3943 | * real machines which also use this scheme. |
| 3944 | */ |
| 3945 | if (i == nb_numa_nodes) { |
| 3946 | for (i = 0; i < smp_cpus; i++) { |
| 3947 | node_cpumask[i % nb_numa_nodes] |= 1 << i; |
| 3948 | } |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | if (kvm_enabled()) { |
| 3953 | int ret; |
| 3954 | |
| 3955 | ret = kvm_init(smp_cpus); |
| 3956 | if (ret < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3957 | PANIC("failed to initialize KVM"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3958 | } |
| 3959 | } |
| 3960 | |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 3961 | #ifdef CONFIG_HAX |
| 3962 | if (!hax_disabled) |
| 3963 | { |
| 3964 | int ret; |
| 3965 | |
Jiang, Yunhong | 4a5a0ef | 2012-02-23 06:31:12 +0800 | [diff] [blame] | 3966 | hax_set_ramsize(ram_size); |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 3967 | ret = hax_init(smp_cpus); |
| 3968 | fprintf(stderr, "HAX is %s and emulator runs in %s mode\n", |
| 3969 | !ret ? "working" :"not working", !ret ? "fast virt" : "emulation"); |
| 3970 | } |
| 3971 | #endif |
| 3972 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3973 | if (monitor_device) { |
| 3974 | monitor_hd = qemu_chr_open("monitor", monitor_device, NULL); |
| 3975 | if (!monitor_hd) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3976 | PANIC("qemu: could not open monitor device '%s'", |
| 3977 | monitor_device); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | for(i = 0; i < MAX_SERIAL_PORTS; i++) { |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 3982 | serial_hds_add(serial_devices[i]); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | for(i = 0; i < MAX_PARALLEL_PORTS; i++) { |
| 3986 | const char *devname = parallel_devices[i]; |
| 3987 | if (devname && strcmp(devname, "none")) { |
| 3988 | char label[32]; |
| 3989 | snprintf(label, sizeof(label), "parallel%d", i); |
| 3990 | parallel_hds[i] = qemu_chr_open(label, devname, NULL); |
| 3991 | if (!parallel_hds[i]) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3992 | PANIC("qemu: could not open parallel device '%s'", |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3993 | devname); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3994 | } |
| 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) { |
| 3999 | const char *devname = virtio_consoles[i]; |
| 4000 | if (devname && strcmp(devname, "none")) { |
| 4001 | char label[32]; |
| 4002 | snprintf(label, sizeof(label), "virtcon%d", i); |
| 4003 | virtcon_hds[i] = qemu_chr_open(label, devname, NULL); |
| 4004 | if (!virtcon_hds[i]) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4005 | PANIC("qemu: could not open virtio console '%s'", |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4006 | devname); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4007 | } |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | module_call_init(MODULE_INIT_DEVICE); |
| 4012 | |
| 4013 | |
David 'Digit' Turner | 2d238fd | 2011-03-25 10:34:47 +0100 | [diff] [blame] | 4014 | /* Check the CPU Architecture value */ |
| 4015 | #if defined(TARGET_ARM) |
| 4016 | if (strcmp(android_hw->hw_cpu_arch,"arm") != 0) { |
| 4017 | fprintf(stderr, "-- Invalid CPU architecture: %s, expected 'arm'\n", |
| 4018 | android_hw->hw_cpu_arch); |
| 4019 | exit(1); |
| 4020 | } |
Vladimir Chtchetkine | 33f89d0 | 2011-09-28 09:19:09 -0700 | [diff] [blame] | 4021 | #elif defined(TARGET_I386) |
David 'Digit' Turner | 2d238fd | 2011-03-25 10:34:47 +0100 | [diff] [blame] | 4022 | if (strcmp(android_hw->hw_cpu_arch,"x86") != 0) { |
| 4023 | fprintf(stderr, "-- Invalid CPU architecture: %s, expected 'x86'\n", |
| 4024 | android_hw->hw_cpu_arch); |
| 4025 | exit(1); |
| 4026 | } |
| 4027 | #endif |
| 4028 | |
| 4029 | /* Grab CPU model if provided in hardware.ini */ |
| 4030 | if ( !cpu_model |
| 4031 | && android_hw->hw_cpu_model |
| 4032 | && android_hw->hw_cpu_model[0] != '\0') |
| 4033 | { |
| 4034 | cpu_model = android_hw->hw_cpu_model; |
| 4035 | } |
| 4036 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 4037 | /* Combine kernel command line passed from the UI with parameters |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4038 | * collected during initialization. |
| 4039 | * |
| 4040 | * The order is the following: |
| 4041 | * - parameters from the hw configuration (kernel.parameters) |
| 4042 | * - additionnal parameters from options (e.g. -memcheck) |
| 4043 | * - the -append parameters. |
| 4044 | */ |
| 4045 | { |
| 4046 | const char* kernel_parameters; |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 4047 | |
David 'Digit' Turner | 0b01949 | 2011-03-01 14:02:42 +0100 | [diff] [blame] | 4048 | if (android_hw->kernel_parameters) { |
David 'Digit' Turner | 62c7ae5 | 2011-03-08 15:46:53 +0100 | [diff] [blame] | 4049 | stralloc_add_c(kernel_params, ' '); |
David 'Digit' Turner | 0b01949 | 2011-03-01 14:02:42 +0100 | [diff] [blame] | 4050 | stralloc_add_str(kernel_params, android_hw->kernel_parameters); |
| 4051 | } |
| 4052 | |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4053 | /* If not empty, kernel_config always contains a leading space */ |
| 4054 | stralloc_append(kernel_params, kernel_config); |
| 4055 | |
| 4056 | if (*kernel_cmdline) { |
| 4057 | stralloc_add_c(kernel_params, ' '); |
| 4058 | stralloc_add_str(kernel_params, kernel_cmdline); |
| 4059 | } |
| 4060 | |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 4061 | /* Remove any leading/trailing spaces */ |
| 4062 | stralloc_strip(kernel_params); |
| 4063 | |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4064 | kernel_parameters = stralloc_cstr(kernel_params); |
| 4065 | VERBOSE_PRINT(init, "Kernel parameters: %s", kernel_parameters); |
| 4066 | |
| 4067 | machine->init(ram_size, |
| 4068 | boot_devices, |
| 4069 | kernel_filename, |
| 4070 | kernel_parameters, |
| 4071 | initrd_filename, |
| 4072 | cpu_model); |
| 4073 | |
Vladimir Chtchetkine | 8dd31e8 | 2012-02-15 17:16:04 -0800 | [diff] [blame] | 4074 | /* Initialize multi-touch emulation. */ |
Vladimir Chtchetkine | 863d101 | 2012-03-16 12:25:23 -0700 | [diff] [blame] | 4075 | if (androidHwConfig_isScreenMultiTouch(android_hw)) { |
Vladimir Chtchetkine | 8dd31e8 | 2012-02-15 17:16:04 -0800 | [diff] [blame] | 4076 | mts_port_create(NULL); |
| 4077 | } |
| 4078 | |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4079 | stralloc_reset(kernel_params); |
| 4080 | stralloc_reset(kernel_config); |
| 4081 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4082 | |
David 'Digit' Turner | 6657678 | 2014-03-24 16:57:57 +0100 | [diff] [blame^] | 4083 | CPU_FOREACH(cpu) { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4084 | for (i = 0; i < nb_numa_nodes; i++) { |
David 'Digit' Turner | 6657678 | 2014-03-24 16:57:57 +0100 | [diff] [blame^] | 4085 | if (node_cpumask[i] & (1 << cpu->cpu_index)) { |
| 4086 | cpu->numa_node = i; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4087 | } |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | current_machine = machine; |
| 4092 | |
David 'Digit' Turner | e2678e1 | 2014-01-16 15:56:43 +0100 | [diff] [blame] | 4093 | /* Set KVM's vcpu state to qemu's initial CPUOldState. */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4094 | if (kvm_enabled()) { |
| 4095 | int ret; |
| 4096 | |
| 4097 | ret = kvm_sync_vcpus(); |
| 4098 | if (ret < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4099 | PANIC("failed to initialize vcpus"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4100 | } |
| 4101 | } |
| 4102 | |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 4103 | #ifdef CONFIG_HAX |
| 4104 | if (hax_enabled()) |
| 4105 | hax_sync_vcpus(); |
| 4106 | #endif |
| 4107 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4108 | /* init USB devices */ |
| 4109 | if (usb_enabled) { |
| 4110 | for(i = 0; i < usb_devices_index; i++) { |
| 4111 | if (usb_device_add(usb_devices[i], 0) < 0) { |
| 4112 | fprintf(stderr, "Warning: could not add USB device %s\n", |
| 4113 | usb_devices[i]); |
| 4114 | } |
| 4115 | } |
| 4116 | } |
| 4117 | |
Vladimir Chtchetkine | cf755ea | 2011-01-12 14:38:19 -0800 | [diff] [blame] | 4118 | /* just use the first displaystate for the moment */ |
David 'Digit' Turner | 94702b0 | 2011-01-20 02:46:33 +0100 | [diff] [blame] | 4119 | ds = get_displaystate(); |
Vladimir Chtchetkine | cf755ea | 2011-01-12 14:38:19 -0800 | [diff] [blame] | 4120 | |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 4121 | /* Initialize display from the command line parameters. */ |
| 4122 | android_display_reset(ds, |
| 4123 | android_display_width, |
| 4124 | android_display_height, |
| 4125 | android_display_bpp); |
Vladimir Chtchetkine | dd50f7d | 2010-07-30 09:16:41 -0700 | [diff] [blame] | 4126 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4127 | if (display_type == DT_DEFAULT) { |
| 4128 | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
| 4129 | display_type = DT_SDL; |
| 4130 | #else |
| 4131 | display_type = DT_VNC; |
| 4132 | vnc_display = "localhost:0,to=99"; |
| 4133 | show_vnc_port = 1; |
| 4134 | #endif |
| 4135 | } |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 4136 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4137 | |
| 4138 | switch (display_type) { |
| 4139 | case DT_NOGRAPHIC: |
| 4140 | break; |
| 4141 | #if defined(CONFIG_CURSES) |
| 4142 | case DT_CURSES: |
| 4143 | curses_display_init(ds, full_screen); |
| 4144 | break; |
| 4145 | #endif |
Vladimir Chtchetkine | eb83825 | 2010-07-15 12:27:56 -0700 | [diff] [blame] | 4146 | #if defined(CONFIG_SDL) && !defined(CONFIG_STANDALONE_CORE) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4147 | case DT_SDL: |
| 4148 | sdl_display_init(ds, full_screen, no_frame); |
| 4149 | break; |
| 4150 | #elif defined(CONFIG_COCOA) |
| 4151 | case DT_SDL: |
| 4152 | cocoa_display_init(ds, full_screen); |
| 4153 | break; |
Vladimir Chtchetkine | 72d83df | 2010-12-14 09:24:02 -0800 | [diff] [blame] | 4154 | #elif defined(CONFIG_STANDALONE_CORE) |
| 4155 | case DT_SDL: |
Vladimir Chtchetkine | e95660a | 2010-12-20 08:28:03 -0800 | [diff] [blame] | 4156 | coredisplay_init(ds); |
Vladimir Chtchetkine | 72d83df | 2010-12-14 09:24:02 -0800 | [diff] [blame] | 4157 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4158 | #endif |
| 4159 | case DT_VNC: |
| 4160 | vnc_display_init(ds); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4161 | if (vnc_display_open(ds, vnc_display) < 0) { |
| 4162 | PANIC("Unable to initialize VNC display"); |
| 4163 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4164 | |
| 4165 | if (show_vnc_port) { |
| 4166 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); |
| 4167 | } |
| 4168 | break; |
| 4169 | default: |
| 4170 | break; |
| 4171 | } |
| 4172 | dpy_resize(ds); |
| 4173 | |
| 4174 | dcl = ds->listeners; |
| 4175 | while (dcl != NULL) { |
| 4176 | if (dcl->dpy_refresh != NULL) { |
David 'Digit' Turner | dcda949 | 2014-02-16 15:13:55 +0100 | [diff] [blame] | 4177 | ds->gui_timer = timer_new(QEMU_CLOCK_REALTIME, SCALE_MS, gui_update, ds); |
| 4178 | timer_mod(ds->gui_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4179 | } |
| 4180 | dcl = dcl->next; |
| 4181 | } |
| 4182 | |
| 4183 | if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) { |
David 'Digit' Turner | dcda949 | 2014-02-16 15:13:55 +0100 | [diff] [blame] | 4184 | nographic_timer = timer_new(QEMU_CLOCK_REALTIME, SCALE_MS, nographic_update, NULL); |
| 4185 | timer_mod(nographic_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
David 'Digit' Turner | 94702b0 | 2011-01-20 02:46:33 +0100 | [diff] [blame] | 4188 | text_consoles_set_display(ds); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4189 | qemu_chr_initial_reset(); |
| 4190 | |
| 4191 | if (monitor_device && monitor_hd) |
| 4192 | monitor_init(monitor_hd, MONITOR_USE_READLINE | MONITOR_IS_DEFAULT); |
| 4193 | |
| 4194 | for(i = 0; i < MAX_SERIAL_PORTS; i++) { |
| 4195 | const char *devname = serial_devices[i]; |
| 4196 | if (devname && strcmp(devname, "none")) { |
| 4197 | if (strstart(devname, "vc", 0)) |
| 4198 | qemu_chr_printf(serial_hds[i], "serial%d console\r\n", i); |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | for(i = 0; i < MAX_PARALLEL_PORTS; i++) { |
| 4203 | const char *devname = parallel_devices[i]; |
| 4204 | if (devname && strcmp(devname, "none")) { |
| 4205 | if (strstart(devname, "vc", 0)) |
| 4206 | qemu_chr_printf(parallel_hds[i], "parallel%d console\r\n", i); |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) { |
| 4211 | const char *devname = virtio_consoles[i]; |
| 4212 | if (virtcon_hds[i] && devname) { |
| 4213 | if (strstart(devname, "vc", 0)) |
| 4214 | qemu_chr_printf(virtcon_hds[i], "virtio console%d\r\n", i); |
| 4215 | } |
| 4216 | } |
| 4217 | |
| 4218 | if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4219 | PANIC("qemu: could not open gdbserver on device '%s'", |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4220 | gdbstub_dev); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4223 | /* call android-specific setup function */ |
| 4224 | android_emulation_setup(); |
| 4225 | |
Vladimir Chtchetkine | 5758404 | 2011-01-20 16:15:30 -0800 | [diff] [blame] | 4226 | #if !defined(CONFIG_STANDALONE_CORE) |
| 4227 | // For the standalone emulator (UI+core in one executable) we need to |
| 4228 | // set the window title here. |
| 4229 | android_emulator_set_base_port(android_base_port); |
| 4230 | #endif |
| 4231 | |
Ot ten Thije | 871da2a | 2010-09-20 10:29:22 +0100 | [diff] [blame] | 4232 | if (loadvm) |
| 4233 | do_loadvm(cur_mon, loadvm); |
| 4234 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4235 | if (incoming) { |
| 4236 | autostart = 0; /* fixme how to deal with -daemonize */ |
| 4237 | qemu_start_incoming_migration(incoming); |
| 4238 | } |
| 4239 | |
| 4240 | if (autostart) |
| 4241 | vm_start(); |
| 4242 | |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 4243 | os_setup_post(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4244 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4245 | #ifdef CONFIG_ANDROID |
| 4246 | // This will notify the UI that the core is successfuly initialized |
| 4247 | android_core_init_completed(); |
| 4248 | #endif // CONFIG_ANDROID |
| 4249 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4250 | main_loop(); |
| 4251 | quit_timers(); |
| 4252 | net_cleanup(); |
| 4253 | android_emulation_teardown(); |
| 4254 | return 0; |
| 4255 | } |
Vladimir Chtchetkine | eb83825 | 2010-07-15 12:27:56 -0700 | [diff] [blame] | 4256 | |
| 4257 | void |
| 4258 | android_emulation_teardown(void) |
| 4259 | { |
| 4260 | android_charmap_done(); |
| 4261 | } |