root / vl.c @ b3755a91
History | View | Annotate | Download (157 kB)
1 | 0824d6fc | bellard | /*
|
---|---|---|---|
2 | 80cabfad | bellard | * QEMU System Emulator
|
3 | 5fafdf24 | ths | *
|
4 | 68d0f70e | bellard | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 1df912cf | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 1df912cf | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 1df912cf | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 1df912cf | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 1df912cf | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 1df912cf | bellard | * furnished to do so, subject to the following conditions:
|
12 | 1df912cf | bellard | *
|
13 | 1df912cf | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 1df912cf | bellard | * all copies or substantial portions of the Software.
|
15 | 1df912cf | bellard | *
|
16 | 1df912cf | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 1df912cf | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 1df912cf | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 1df912cf | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 1df912cf | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 1df912cf | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 1df912cf | bellard | * THE SOFTWARE.
|
23 | 0824d6fc | bellard | */
|
24 | 0824d6fc | bellard | #include <unistd.h> |
25 | 0824d6fc | bellard | #include <fcntl.h> |
26 | 0824d6fc | bellard | #include <signal.h> |
27 | 0824d6fc | bellard | #include <time.h> |
28 | 0824d6fc | bellard | #include <errno.h> |
29 | 67b915a5 | bellard | #include <sys/time.h> |
30 | c88676f8 | bellard | #include <zlib.h> |
31 | 67b915a5 | bellard | |
32 | 71e72a19 | Juan Quintela | /* Needed early for CONFIG_BSD etc. */
|
33 | d40cdb10 | blueswir1 | #include "config-host.h" |
34 | d40cdb10 | blueswir1 | |
35 | 67b915a5 | bellard | #ifndef _WIN32
|
36 | 5cea8590 | Paul Brook | #include <libgen.h> |
37 | 0858532e | aliguori | #include <pwd.h> |
38 | 67b915a5 | bellard | #include <sys/times.h> |
39 | f1510b2c | bellard | #include <sys/wait.h> |
40 | 67b915a5 | bellard | #include <termios.h> |
41 | 67b915a5 | bellard | #include <sys/mman.h> |
42 | f1510b2c | bellard | #include <sys/ioctl.h> |
43 | 24646c7e | blueswir1 | #include <sys/resource.h> |
44 | f1510b2c | bellard | #include <sys/socket.h> |
45 | c94c8d64 | bellard | #include <netinet/in.h> |
46 | 24646c7e | blueswir1 | #include <net/if.h> |
47 | 24646c7e | blueswir1 | #include <arpa/inet.h> |
48 | 9d728e8c | bellard | #include <dirent.h> |
49 | 7c9d8e07 | bellard | #include <netdb.h> |
50 | cb4b976b | ths | #include <sys/select.h> |
51 | 71e72a19 | Juan Quintela | #ifdef CONFIG_BSD
|
52 | 7d3505c5 | bellard | #include <sys/stat.h> |
53 | a167ba50 | Aurelien Jarno | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
54 | 7d3505c5 | bellard | #include <libutil.h> |
55 | 24646c7e | blueswir1 | #else
|
56 | 24646c7e | blueswir1 | #include <util.h> |
57 | 128ab2ff | blueswir1 | #endif
|
58 | bbe813a2 | Aurelien Jarno | #else
|
59 | 223f0d72 | blueswir1 | #ifdef __linux__
|
60 | 7d3505c5 | bellard | #include <pty.h> |
61 | 7d3505c5 | bellard | #include <malloc.h> |
62 | fd872598 | bellard | #include <linux/rtc.h> |
63 | 1889465a | Andi Kleen | #include <sys/prctl.h> |
64 | bd494f4c | ths | |
65 | bd494f4c | ths | /* For the benefit of older linux systems which don't supply it,
|
66 | bd494f4c | ths | we use a local copy of hpet.h. */
|
67 | bd494f4c | ths | /* #include <linux/hpet.h> */
|
68 | bd494f4c | ths | #include "hpet.h" |
69 | bd494f4c | ths | |
70 | e57a8c0e | bellard | #include <linux/ppdev.h> |
71 | 5867c88a | ths | #include <linux/parport.h> |
72 | 223f0d72 | blueswir1 | #endif
|
73 | 223f0d72 | blueswir1 | #ifdef __sun__
|
74 | d5d10bc3 | ths | #include <sys/stat.h> |
75 | d5d10bc3 | ths | #include <sys/ethernet.h> |
76 | d5d10bc3 | ths | #include <sys/sockio.h> |
77 | d5d10bc3 | ths | #include <netinet/arp.h> |
78 | d5d10bc3 | ths | #include <netinet/in.h> |
79 | d5d10bc3 | ths | #include <netinet/in_systm.h> |
80 | d5d10bc3 | ths | #include <netinet/ip.h> |
81 | d5d10bc3 | ths | #include <netinet/ip_icmp.h> // must come after ip.h |
82 | d5d10bc3 | ths | #include <netinet/udp.h> |
83 | d5d10bc3 | ths | #include <netinet/tcp.h> |
84 | d5d10bc3 | ths | #include <net/if.h> |
85 | d5d10bc3 | ths | #include <syslog.h> |
86 | d5d10bc3 | ths | #include <stropts.h> |
87 | 8d32cf0e | Blue Swirl | /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for
|
88 | 8d32cf0e | Blue Swirl | discussion about Solaris header problems */
|
89 | 8d32cf0e | Blue Swirl | extern int madvise(caddr_t, size_t, int); |
90 | 67b915a5 | bellard | #endif
|
91 | 7d3505c5 | bellard | #endif
|
92 | ec530c81 | bellard | #endif
|
93 | 67b915a5 | bellard | |
94 | 9892fbfb | blueswir1 | #if defined(__OpenBSD__)
|
95 | 9892fbfb | blueswir1 | #include <util.h> |
96 | 9892fbfb | blueswir1 | #endif
|
97 | 9892fbfb | blueswir1 | |
98 | 8a16d273 | ths | #if defined(CONFIG_VDE)
|
99 | 8a16d273 | ths | #include <libvdeplug.h> |
100 | 8a16d273 | ths | #endif
|
101 | 8a16d273 | ths | |
102 | 67b915a5 | bellard | #ifdef _WIN32
|
103 | 49dc768d | aliguori | #include <windows.h> |
104 | 4fddf62a | ths | #include <mmsystem.h> |
105 | 67b915a5 | bellard | #endif
|
106 | 67b915a5 | bellard | |
107 | 73332e5c | bellard | #ifdef CONFIG_SDL
|
108 | 59a36a2f | Stefan Weil | #if defined(__APPLE__) || defined(main)
|
109 | 6693665a | Stefan Weil | #include <SDL.h> |
110 | 880fec5d | malc | int qemu_main(int argc, char **argv, char **envp); |
111 | 880fec5d | malc | int main(int argc, char **argv) |
112 | 880fec5d | malc | { |
113 | 59a36a2f | Stefan Weil | return qemu_main(argc, argv, NULL); |
114 | 880fec5d | malc | } |
115 | 880fec5d | malc | #undef main
|
116 | 880fec5d | malc | #define main qemu_main
|
117 | 96bcd4f8 | bellard | #endif
|
118 | 73332e5c | bellard | #endif /* CONFIG_SDL */ |
119 | 0824d6fc | bellard | |
120 | 5b0753e0 | bellard | #ifdef CONFIG_COCOA
|
121 | 5b0753e0 | bellard | #undef main
|
122 | 5b0753e0 | bellard | #define main qemu_main
|
123 | 5b0753e0 | bellard | #endif /* CONFIG_COCOA */ |
124 | 5b0753e0 | bellard | |
125 | 511d2b14 | blueswir1 | #include "hw/hw.h" |
126 | 511d2b14 | blueswir1 | #include "hw/boards.h" |
127 | 511d2b14 | blueswir1 | #include "hw/usb.h" |
128 | 511d2b14 | blueswir1 | #include "hw/pcmcia.h" |
129 | 511d2b14 | blueswir1 | #include "hw/pc.h" |
130 | 511d2b14 | blueswir1 | #include "hw/audiodev.h" |
131 | 511d2b14 | blueswir1 | #include "hw/isa.h" |
132 | 511d2b14 | blueswir1 | #include "hw/baum.h" |
133 | 511d2b14 | blueswir1 | #include "hw/bt.h" |
134 | 9dd986cc | Richard W.M. Jones | #include "hw/watchdog.h" |
135 | b6f6e3d3 | aliguori | #include "hw/smbios.h" |
136 | e37630ca | aliguori | #include "hw/xen.h" |
137 | bd3c948d | Gerd Hoffmann | #include "hw/qdev.h" |
138 | 45a50b16 | Gerd Hoffmann | #include "hw/loader.h" |
139 | 5ef4efa4 | aurel32 | #include "bt-host.h" |
140 | 511d2b14 | blueswir1 | #include "net.h" |
141 | 68ac40d2 | Mark McLoughlin | #include "net/slirp.h" |
142 | 511d2b14 | blueswir1 | #include "monitor.h" |
143 | 511d2b14 | blueswir1 | #include "console.h" |
144 | 511d2b14 | blueswir1 | #include "sysemu.h" |
145 | 511d2b14 | blueswir1 | #include "gdbstub.h" |
146 | 511d2b14 | blueswir1 | #include "qemu-timer.h" |
147 | 511d2b14 | blueswir1 | #include "qemu-char.h" |
148 | 511d2b14 | blueswir1 | #include "cache-utils.h" |
149 | 511d2b14 | blueswir1 | #include "block.h" |
150 | c163b5ca | lirans@il.ibm.com | #include "block_int.h" |
151 | c163b5ca | lirans@il.ibm.com | #include "block-migration.h" |
152 | a718acec | blueswir1 | #include "dma.h" |
153 | 511d2b14 | blueswir1 | #include "audio/audio.h" |
154 | 511d2b14 | blueswir1 | #include "migration.h" |
155 | 511d2b14 | blueswir1 | #include "kvm.h" |
156 | 511d2b14 | blueswir1 | #include "balloon.h" |
157 | d3f24367 | Kevin Wolf | #include "qemu-option.h" |
158 | 7282a033 | Gerd Hoffmann | #include "qemu-config.h" |
159 | e78c48ec | Luiz Capitulino | #include "qemu-objects.h" |
160 | 511d2b14 | blueswir1 | |
161 | 0824d6fc | bellard | #include "disas.h" |
162 | fc01f7e7 | bellard | |
163 | 8a7ddc38 | bellard | #include "exec-all.h" |
164 | 0824d6fc | bellard | |
165 | 511d2b14 | blueswir1 | #include "qemu_socket.h" |
166 | 511d2b14 | blueswir1 | |
167 | d918f23e | Jan Kiszka | #include "slirp/libslirp.h" |
168 | 511d2b14 | blueswir1 | |
169 | 72cf2d4f | Blue Swirl | #include "qemu-queue.h" |
170 | 72cf2d4f | Blue Swirl | |
171 | 9dc63a1e | blueswir1 | //#define DEBUG_NET
|
172 | 9dc63a1e | blueswir1 | //#define DEBUG_SLIRP
|
173 | 330d0414 | bellard | |
174 | 1bfe856e | bellard | #define DEFAULT_RAM_SIZE 128 |
175 | 313aa567 | bellard | |
176 | 98b19252 | Amit Shah | #define MAX_VIRTIO_CONSOLES 1 |
177 | 98b19252 | Amit Shah | |
178 | 5cea8590 | Paul Brook | static const char *data_dir; |
179 | 1192dad8 | j_mayer | const char *bios_name = NULL; |
180 | e4bcb14c | ths | /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
|
181 | faea38e7 | bellard | to store the VM snapshots */
|
182 | 72cf2d4f | Blue Swirl | struct drivelist drives = QTAILQ_HEAD_INITIALIZER(drives);
|
183 | 72cf2d4f | Blue Swirl | struct driveoptlist driveopts = QTAILQ_HEAD_INITIALIZER(driveopts);
|
184 | cb5a7aa8 | malc | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
|
185 | 993fbfdb | Anthony Liguori | DisplayType display_type = DT_DEFAULT; |
186 | 3d11d0eb | bellard | const char* keyboard_layout = NULL; |
187 | c227f099 | Anthony Liguori | ram_addr_t ram_size; |
188 | c902760f | Marcelo Tosatti | const char *mem_path = NULL; |
189 | c902760f | Marcelo Tosatti | #ifdef MAP_POPULATE
|
190 | c902760f | Marcelo Tosatti | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
191 | c902760f | Marcelo Tosatti | #endif
|
192 | c4b1fcc0 | bellard | int nb_nics;
|
193 | 7c9d8e07 | bellard | NICInfo nd_table[MAX_NICS]; |
194 | 8a7ddc38 | bellard | int vm_running;
|
195 | d399f677 | Paolo Bonzini | int autostart;
|
196 | f6503059 | balrog | static int rtc_utc = 1; |
197 | f6503059 | balrog | static int rtc_date_offset = -1; /* -1 means no change */ |
198 | 6875204c | Jan Kiszka | QEMUClock *rtc_clock; |
199 | 64465297 | Gerd Hoffmann | int vga_interface_type = VGA_NONE;
|
200 | d827220b | bellard | #ifdef TARGET_SPARC
|
201 | d827220b | bellard | int graphic_width = 1024; |
202 | d827220b | bellard | int graphic_height = 768; |
203 | eee0b836 | blueswir1 | int graphic_depth = 8; |
204 | d827220b | bellard | #else
|
205 | 1bfe856e | bellard | int graphic_width = 800; |
206 | 1bfe856e | bellard | int graphic_height = 600; |
207 | e9b137c2 | bellard | int graphic_depth = 15; |
208 | eee0b836 | blueswir1 | #endif
|
209 | dbed7e40 | blueswir1 | static int full_screen = 0; |
210 | 634a21f6 | blueswir1 | #ifdef CONFIG_SDL
|
211 | dbed7e40 | blueswir1 | static int no_frame = 0; |
212 | 634a21f6 | blueswir1 | #endif
|
213 | 667accab | ths | int no_quit = 0; |
214 | 8d11df9e | bellard | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
215 | 6508fe59 | bellard | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
216 | 9ede2fde | aliguori | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
217 | a09db21f | bellard | #ifdef TARGET_I386
|
218 | a09db21f | bellard | int win2k_install_hack = 0; |
219 | 73822ec8 | aliguori | int rtc_td_hack = 0; |
220 | a09db21f | bellard | #endif
|
221 | bb36d470 | bellard | int usb_enabled = 0; |
222 | 1b530a6d | aurel32 | int singlestep = 0; |
223 | 6a00d601 | bellard | int smp_cpus = 1; |
224 | 6be68d7e | Jes Sorensen | int max_cpus = 0; |
225 | dc6b1c09 | Andre Przywara | int smp_cores = 1; |
226 | dc6b1c09 | Andre Przywara | int smp_threads = 1; |
227 | 73fc9742 | ths | const char *vnc_display; |
228 | 6515b203 | bellard | int acpi_enabled = 1; |
229 | 16b29ae1 | aliguori | int no_hpet = 0; |
230 | 52ca8d6a | bellard | int fd_bootchk = 1; |
231 | d1beab82 | bellard | int no_reboot = 0; |
232 | b2f76161 | aurel32 | int no_shutdown = 0; |
233 | 9467cd46 | balrog | int cursor_hide = 1; |
234 | a171fe39 | balrog | int graphic_rotate = 0; |
235 | 6b35e7bf | Jes Sorensen | uint8_t irq0override = 1;
|
236 | b9e82a59 | blueswir1 | #ifndef _WIN32
|
237 | 71e3ceb8 | ths | int daemonize = 0; |
238 | b9e82a59 | blueswir1 | #endif
|
239 | 09aaa160 | Markus Armbruster | const char *watchdog; |
240 | 9ae02555 | ths | const char *option_rom[MAX_OPTION_ROMS]; |
241 | 9ae02555 | ths | int nb_option_roms;
|
242 | 8e71621f | pbrook | int semihosting_enabled = 0; |
243 | 2b8f2d41 | balrog | #ifdef TARGET_ARM
|
244 | 2b8f2d41 | balrog | int old_param = 0; |
245 | 2b8f2d41 | balrog | #endif
|
246 | c35734b2 | ths | const char *qemu_name; |
247 | 3780e197 | ths | int alt_grab = 0; |
248 | 0ca9f8a4 | Dustin Kirkland | int ctrl_grab = 0; |
249 | 95efd11c | blueswir1 | #if defined(TARGET_SPARC) || defined(TARGET_PPC)
|
250 | 66508601 | blueswir1 | unsigned int nb_prom_envs = 0; |
251 | 66508601 | blueswir1 | const char *prom_envs[MAX_PROM_ENVS]; |
252 | 66508601 | blueswir1 | #endif
|
253 | 95387491 | Jan Kiszka | int boot_menu;
|
254 | 0824d6fc | bellard | |
255 | 268a362c | aliguori | int nb_numa_nodes;
|
256 | 268a362c | aliguori | uint64_t node_mem[MAX_NODES]; |
257 | 268a362c | aliguori | uint64_t node_cpumask[MAX_NODES]; |
258 | 268a362c | aliguori | |
259 | ee5605e5 | balrog | static CPUState *cur_cpu;
|
260 | ee5605e5 | balrog | static CPUState *next_cpu;
|
261 | 43b96858 | aliguori | static int timer_alarm_pending = 1; |
262 | bf20dc07 | ths | /* Conversion factor from emulated instructions to virtual clock ticks. */
|
263 | 2e70f6ef | pbrook | static int icount_time_shift; |
264 | bf20dc07 | ths | /* Arbitrarily pick 1MIPS as the minimum allowable speed. */
|
265 | 2e70f6ef | pbrook | #define MAX_ICOUNT_SHIFT 10 |
266 | 2e70f6ef | pbrook | /* Compensate for varying guest execution speed. */
|
267 | 2e70f6ef | pbrook | static int64_t qemu_icount_bias;
|
268 | dbed7e40 | blueswir1 | static QEMUTimer *icount_rt_timer;
|
269 | dbed7e40 | blueswir1 | static QEMUTimer *icount_vm_timer;
|
270 | 9043b62d | blueswir1 | static QEMUTimer *nographic_timer;
|
271 | ee5605e5 | balrog | |
272 | 8fcb1b90 | blueswir1 | uint8_t qemu_uuid[16];
|
273 | 8fcb1b90 | blueswir1 | |
274 | 76e30d0f | Jan Kiszka | static QEMUBootSetHandler *boot_set_handler;
|
275 | 76e30d0f | Jan Kiszka | static void *boot_set_opaque; |
276 | 76e30d0f | Jan Kiszka | |
277 | cc84de95 | Marcelo Tosatti | #ifdef SIGRTMIN
|
278 | cc84de95 | Marcelo Tosatti | #define SIG_IPI (SIGRTMIN+4) |
279 | cc84de95 | Marcelo Tosatti | #else
|
280 | cc84de95 | Marcelo Tosatti | #define SIG_IPI SIGUSR1
|
281 | cc84de95 | Marcelo Tosatti | #endif
|
282 | cc84de95 | Marcelo Tosatti | |
283 | 998bbd74 | Gerd Hoffmann | static int default_serial = 1; |
284 | 6a5e8b0e | Gerd Hoffmann | static int default_parallel = 1; |
285 | 986c5f78 | Gerd Hoffmann | static int default_virtcon = 1; |
286 | abdeed06 | Gerd Hoffmann | static int default_monitor = 1; |
287 | 64465297 | Gerd Hoffmann | static int default_vga = 1; |
288 | ac33f8fa | Gerd Hoffmann | static int default_floppy = 1; |
289 | ac33f8fa | Gerd Hoffmann | static int default_cdrom = 1; |
290 | ac33f8fa | Gerd Hoffmann | static int default_sdcard = 1; |
291 | 998bbd74 | Gerd Hoffmann | |
292 | 998bbd74 | Gerd Hoffmann | static struct { |
293 | 998bbd74 | Gerd Hoffmann | const char *driver; |
294 | 998bbd74 | Gerd Hoffmann | int *flag;
|
295 | 998bbd74 | Gerd Hoffmann | } default_list[] = { |
296 | 6a5e8b0e | Gerd Hoffmann | { .driver = "isa-serial", .flag = &default_serial },
|
297 | 6a5e8b0e | Gerd Hoffmann | { .driver = "isa-parallel", .flag = &default_parallel },
|
298 | d8bcbabf | Gerd Hoffmann | { .driver = "isa-fdc", .flag = &default_floppy },
|
299 | d8bcbabf | Gerd Hoffmann | { .driver = "ide-drive", .flag = &default_cdrom },
|
300 | 392ecf54 | Amit Shah | { .driver = "virtio-serial-pci", .flag = &default_virtcon },
|
301 | 392ecf54 | Amit Shah | { .driver = "virtio-serial-s390", .flag = &default_virtcon },
|
302 | 392ecf54 | Amit Shah | { .driver = "virtio-serial", .flag = &default_virtcon },
|
303 | 64465297 | Gerd Hoffmann | { .driver = "VGA", .flag = &default_vga },
|
304 | 69fd02ee | Gerd Hoffmann | { .driver = "cirrus-vga", .flag = &default_vga },
|
305 | 69fd02ee | Gerd Hoffmann | { .driver = "vmware-svga", .flag = &default_vga },
|
306 | 998bbd74 | Gerd Hoffmann | }; |
307 | 998bbd74 | Gerd Hoffmann | |
308 | 998bbd74 | Gerd Hoffmann | static int default_driver_check(QemuOpts *opts, void *opaque) |
309 | 998bbd74 | Gerd Hoffmann | { |
310 | 998bbd74 | Gerd Hoffmann | const char *driver = qemu_opt_get(opts, "driver"); |
311 | 998bbd74 | Gerd Hoffmann | int i;
|
312 | 998bbd74 | Gerd Hoffmann | |
313 | 998bbd74 | Gerd Hoffmann | if (!driver)
|
314 | 998bbd74 | Gerd Hoffmann | return 0; |
315 | 998bbd74 | Gerd Hoffmann | for (i = 0; i < ARRAY_SIZE(default_list); i++) { |
316 | 998bbd74 | Gerd Hoffmann | if (strcmp(default_list[i].driver, driver) != 0) |
317 | 998bbd74 | Gerd Hoffmann | continue;
|
318 | 998bbd74 | Gerd Hoffmann | *(default_list[i].flag) = 0;
|
319 | 998bbd74 | Gerd Hoffmann | } |
320 | 998bbd74 | Gerd Hoffmann | return 0; |
321 | 998bbd74 | Gerd Hoffmann | } |
322 | 998bbd74 | Gerd Hoffmann | |
323 | 0824d6fc | bellard | /***********************************************************/
|
324 | 26aa7d72 | bellard | /* x86 ISA bus support */
|
325 | 26aa7d72 | bellard | |
326 | c227f099 | Anthony Liguori | target_phys_addr_t isa_mem_base = 0;
|
327 | 3de388f6 | bellard | PicState2 *isa_pic; |
328 | 0824d6fc | bellard | |
329 | 0824d6fc | bellard | /***********************************************************/
|
330 | 0824d6fc | bellard | void hw_error(const char *fmt, ...) |
331 | 0824d6fc | bellard | { |
332 | 0824d6fc | bellard | va_list ap; |
333 | 6a00d601 | bellard | CPUState *env; |
334 | 0824d6fc | bellard | |
335 | 0824d6fc | bellard | va_start(ap, fmt); |
336 | 0824d6fc | bellard | fprintf(stderr, "qemu: hardware error: ");
|
337 | 0824d6fc | bellard | vfprintf(stderr, fmt, ap); |
338 | 0824d6fc | bellard | fprintf(stderr, "\n");
|
339 | 6a00d601 | bellard | for(env = first_cpu; env != NULL; env = env->next_cpu) { |
340 | 6a00d601 | bellard | fprintf(stderr, "CPU #%d:\n", env->cpu_index);
|
341 | 0824d6fc | bellard | #ifdef TARGET_I386
|
342 | 6a00d601 | bellard | cpu_dump_state(env, stderr, fprintf, X86_DUMP_FPU); |
343 | c45886db | bellard | #else
|
344 | 6a00d601 | bellard | cpu_dump_state(env, stderr, fprintf, 0);
|
345 | 0824d6fc | bellard | #endif
|
346 | 6a00d601 | bellard | } |
347 | 0824d6fc | bellard | va_end(ap); |
348 | 0824d6fc | bellard | abort(); |
349 | 0824d6fc | bellard | } |
350 | 1889465a | Andi Kleen | |
351 | 1889465a | Andi Kleen | static void set_proc_name(const char *s) |
352 | 1889465a | Andi Kleen | { |
353 | 6ca8d0fd | Nathan Froyd | #if defined(__linux__) && defined(PR_SET_NAME)
|
354 | 1889465a | Andi Kleen | char name[16]; |
355 | 1889465a | Andi Kleen | if (!s)
|
356 | 1889465a | Andi Kleen | return;
|
357 | 1889465a | Andi Kleen | name[sizeof(name) - 1] = 0; |
358 | 1889465a | Andi Kleen | strncpy(name, s, sizeof(name));
|
359 | 1889465a | Andi Kleen | /* Could rewrite argv[0] too, but that's a bit more complicated.
|
360 | 1889465a | Andi Kleen | This simple way is enough for `top'. */
|
361 | 1889465a | Andi Kleen | prctl(PR_SET_NAME, name); |
362 | 1889465a | Andi Kleen | #endif
|
363 | 1889465a | Andi Kleen | } |
364 | df751fa8 | aliguori | |
365 | df751fa8 | aliguori | /***************/
|
366 | df751fa8 | aliguori | /* ballooning */
|
367 | df751fa8 | aliguori | |
368 | df751fa8 | aliguori | static QEMUBalloonEvent *qemu_balloon_event;
|
369 | df751fa8 | aliguori | void *qemu_balloon_event_opaque;
|
370 | df751fa8 | aliguori | |
371 | df751fa8 | aliguori | void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) |
372 | df751fa8 | aliguori | { |
373 | df751fa8 | aliguori | qemu_balloon_event = func; |
374 | df751fa8 | aliguori | qemu_balloon_event_opaque = opaque; |
375 | df751fa8 | aliguori | } |
376 | df751fa8 | aliguori | |
377 | 625a5bef | Adam Litke | int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) |
378 | df751fa8 | aliguori | { |
379 | 625a5bef | Adam Litke | if (qemu_balloon_event) {
|
380 | 625a5bef | Adam Litke | qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque); |
381 | 625a5bef | Adam Litke | return 1; |
382 | 625a5bef | Adam Litke | } else {
|
383 | 625a5bef | Adam Litke | return 0; |
384 | 625a5bef | Adam Litke | } |
385 | df751fa8 | aliguori | } |
386 | df751fa8 | aliguori | |
387 | 625a5bef | Adam Litke | int qemu_balloon_status(MonitorCompletion cb, void *opaque) |
388 | df751fa8 | aliguori | { |
389 | 625a5bef | Adam Litke | if (qemu_balloon_event) {
|
390 | 625a5bef | Adam Litke | qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque);
|
391 | 625a5bef | Adam Litke | return 1; |
392 | 625a5bef | Adam Litke | } else {
|
393 | 625a5bef | Adam Litke | return 0; |
394 | 625a5bef | Adam Litke | } |
395 | df751fa8 | aliguori | } |
396 | 0824d6fc | bellard | |
397 | 455204eb | ths | |
398 | 8f0056b7 | Paolo Bonzini | /***********************************************************/
|
399 | 8f0056b7 | Paolo Bonzini | /* real time host monotonic timer */
|
400 | 09b26c5e | bellard | |
401 | 1dce7c3c | bellard | /* compute with 96 bit intermediate result: (a*b)/c */
|
402 | 1dce7c3c | bellard | uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) |
403 | 0824d6fc | bellard | { |
404 | 1dce7c3c | bellard | union {
|
405 | 1dce7c3c | bellard | uint64_t ll; |
406 | 1dce7c3c | bellard | struct {
|
407 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
408 | 1dce7c3c | bellard | uint32_t high, low; |
409 | 1dce7c3c | bellard | #else
|
410 | 1dce7c3c | bellard | uint32_t low, high; |
411 | 3b46e624 | ths | #endif
|
412 | 1dce7c3c | bellard | } l; |
413 | 1dce7c3c | bellard | } u, res; |
414 | 1dce7c3c | bellard | uint64_t rl, rh; |
415 | 0824d6fc | bellard | |
416 | 1dce7c3c | bellard | u.ll = a; |
417 | 1dce7c3c | bellard | rl = (uint64_t)u.l.low * (uint64_t)b; |
418 | 1dce7c3c | bellard | rh = (uint64_t)u.l.high * (uint64_t)b; |
419 | 1dce7c3c | bellard | rh += (rl >> 32);
|
420 | 1dce7c3c | bellard | res.l.high = rh / c; |
421 | 1dce7c3c | bellard | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; |
422 | 1dce7c3c | bellard | return res.ll;
|
423 | 34865134 | bellard | } |
424 | 34865134 | bellard | |
425 | 21d5d12b | Jan Kiszka | static int64_t get_clock_realtime(void) |
426 | 21d5d12b | Jan Kiszka | { |
427 | 21d5d12b | Jan Kiszka | struct timeval tv;
|
428 | 21d5d12b | Jan Kiszka | |
429 | 21d5d12b | Jan Kiszka | gettimeofday(&tv, NULL);
|
430 | 21d5d12b | Jan Kiszka | return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000); |
431 | 21d5d12b | Jan Kiszka | } |
432 | 21d5d12b | Jan Kiszka | |
433 | 1dce7c3c | bellard | #ifdef WIN32
|
434 | 0824d6fc | bellard | |
435 | 1dce7c3c | bellard | static int64_t clock_freq;
|
436 | 1115dde7 | bellard | |
437 | 1dce7c3c | bellard | static void init_get_clock(void) |
438 | 1115dde7 | bellard | { |
439 | a8e5ac33 | bellard | LARGE_INTEGER freq; |
440 | a8e5ac33 | bellard | int ret;
|
441 | 1dce7c3c | bellard | ret = QueryPerformanceFrequency(&freq); |
442 | 1dce7c3c | bellard | if (ret == 0) { |
443 | 1dce7c3c | bellard | fprintf(stderr, "Could not calibrate ticks\n");
|
444 | 1dce7c3c | bellard | exit(1);
|
445 | 1dce7c3c | bellard | } |
446 | 1dce7c3c | bellard | clock_freq = freq.QuadPart; |
447 | 1115dde7 | bellard | } |
448 | 1115dde7 | bellard | |
449 | 1dce7c3c | bellard | static int64_t get_clock(void) |
450 | b8076a74 | bellard | { |
451 | 1dce7c3c | bellard | LARGE_INTEGER ti; |
452 | 1dce7c3c | bellard | QueryPerformanceCounter(&ti); |
453 | 274dfed8 | Anthony Liguori | return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq);
|
454 | b8076a74 | bellard | } |
455 | b8076a74 | bellard | |
456 | 1dce7c3c | bellard | #else
|
457 | 90cb9493 | bellard | |
458 | 1dce7c3c | bellard | static int use_rt_clock; |
459 | 1dce7c3c | bellard | |
460 | 1dce7c3c | bellard | static void init_get_clock(void) |
461 | 90cb9493 | bellard | { |
462 | 1dce7c3c | bellard | use_rt_clock = 0;
|
463 | c5e97233 | blueswir1 | #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \ |
464 | a167ba50 | Aurelien Jarno | || defined(__DragonFly__) || defined(__FreeBSD_kernel__) |
465 | 1dce7c3c | bellard | { |
466 | 1dce7c3c | bellard | struct timespec ts;
|
467 | 1dce7c3c | bellard | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { |
468 | 1dce7c3c | bellard | use_rt_clock = 1;
|
469 | 1dce7c3c | bellard | } |
470 | 1dce7c3c | bellard | } |
471 | 1dce7c3c | bellard | #endif
|
472 | 90cb9493 | bellard | } |
473 | 90cb9493 | bellard | |
474 | 1dce7c3c | bellard | static int64_t get_clock(void) |
475 | fdbb4691 | bellard | { |
476 | c5e97233 | blueswir1 | #if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \ |
477 | a167ba50 | Aurelien Jarno | || defined(__DragonFly__) || defined(__FreeBSD_kernel__) |
478 | 1dce7c3c | bellard | if (use_rt_clock) {
|
479 | 1dce7c3c | bellard | struct timespec ts;
|
480 | 1dce7c3c | bellard | clock_gettime(CLOCK_MONOTONIC, &ts); |
481 | 1dce7c3c | bellard | return ts.tv_sec * 1000000000LL + ts.tv_nsec; |
482 | 5fafdf24 | ths | } else
|
483 | fdbb4691 | bellard | #endif
|
484 | 1dce7c3c | bellard | { |
485 | 1dce7c3c | bellard | /* XXX: using gettimeofday leads to problems if the date
|
486 | 1dce7c3c | bellard | changes, so it should be avoided. */
|
487 | 21d5d12b | Jan Kiszka | return get_clock_realtime();
|
488 | 1dce7c3c | bellard | } |
489 | fdbb4691 | bellard | } |
490 | 34865134 | bellard | #endif
|
491 | 34865134 | bellard | |
492 | 2e70f6ef | pbrook | /* Return the virtual CPU time, based on the instruction counter. */
|
493 | 2e70f6ef | pbrook | static int64_t cpu_get_icount(void) |
494 | 2e70f6ef | pbrook | { |
495 | 2e70f6ef | pbrook | int64_t icount; |
496 | 2e70f6ef | pbrook | CPUState *env = cpu_single_env;; |
497 | 2e70f6ef | pbrook | icount = qemu_icount; |
498 | 2e70f6ef | pbrook | if (env) {
|
499 | 2e70f6ef | pbrook | if (!can_do_io(env))
|
500 | 2e70f6ef | pbrook | fprintf(stderr, "Bad clock read\n");
|
501 | 2e70f6ef | pbrook | icount -= (env->icount_decr.u16.low + env->icount_extra); |
502 | 2e70f6ef | pbrook | } |
503 | 2e70f6ef | pbrook | return qemu_icount_bias + (icount << icount_time_shift);
|
504 | 2e70f6ef | pbrook | } |
505 | 2e70f6ef | pbrook | |
506 | 1dce7c3c | bellard | /***********************************************************/
|
507 | 1dce7c3c | bellard | /* guest cycle counter */
|
508 | 1dce7c3c | bellard | |
509 | 6f68e33e | Juan Quintela | typedef struct TimersState { |
510 | 6f68e33e | Juan Quintela | int64_t cpu_ticks_prev; |
511 | 6f68e33e | Juan Quintela | int64_t cpu_ticks_offset; |
512 | 6f68e33e | Juan Quintela | int64_t cpu_clock_offset; |
513 | 6f68e33e | Juan Quintela | int32_t cpu_ticks_enabled; |
514 | 274dfed8 | Anthony Liguori | int64_t dummy; |
515 | 6f68e33e | Juan Quintela | } TimersState; |
516 | 6f68e33e | Juan Quintela | |
517 | 6f68e33e | Juan Quintela | TimersState timers_state; |
518 | 34865134 | bellard | |
519 | 1dce7c3c | bellard | /* return the host CPU cycle counter and handle stop/restart */
|
520 | 1dce7c3c | bellard | int64_t cpu_get_ticks(void)
|
521 | 34865134 | bellard | { |
522 | 2e70f6ef | pbrook | if (use_icount) {
|
523 | 2e70f6ef | pbrook | return cpu_get_icount();
|
524 | 2e70f6ef | pbrook | } |
525 | 6f68e33e | Juan Quintela | if (!timers_state.cpu_ticks_enabled) {
|
526 | 6f68e33e | Juan Quintela | return timers_state.cpu_ticks_offset;
|
527 | 8a7ddc38 | bellard | } else {
|
528 | eade0f19 | bellard | int64_t ticks; |
529 | eade0f19 | bellard | ticks = cpu_get_real_ticks(); |
530 | 6f68e33e | Juan Quintela | if (timers_state.cpu_ticks_prev > ticks) {
|
531 | eade0f19 | bellard | /* Note: non increasing ticks may happen if the host uses
|
532 | eade0f19 | bellard | software suspend */
|
533 | 6f68e33e | Juan Quintela | timers_state.cpu_ticks_offset += timers_state.cpu_ticks_prev - ticks; |
534 | eade0f19 | bellard | } |
535 | 6f68e33e | Juan Quintela | timers_state.cpu_ticks_prev = ticks; |
536 | 6f68e33e | Juan Quintela | return ticks + timers_state.cpu_ticks_offset;
|
537 | 8a7ddc38 | bellard | } |
538 | 34865134 | bellard | } |
539 | 34865134 | bellard | |
540 | 1dce7c3c | bellard | /* return the host CPU monotonic timer and handle stop/restart */
|
541 | 1dce7c3c | bellard | static int64_t cpu_get_clock(void) |
542 | 1dce7c3c | bellard | { |
543 | 1dce7c3c | bellard | int64_t ti; |
544 | 6f68e33e | Juan Quintela | if (!timers_state.cpu_ticks_enabled) {
|
545 | 6f68e33e | Juan Quintela | return timers_state.cpu_clock_offset;
|
546 | 1dce7c3c | bellard | } else {
|
547 | 1dce7c3c | bellard | ti = get_clock(); |
548 | 6f68e33e | Juan Quintela | return ti + timers_state.cpu_clock_offset;
|
549 | 1dce7c3c | bellard | } |
550 | 1dce7c3c | bellard | } |
551 | 1dce7c3c | bellard | |
552 | 34865134 | bellard | /* enable cpu_get_ticks() */
|
553 | 34865134 | bellard | void cpu_enable_ticks(void) |
554 | 34865134 | bellard | { |
555 | 6f68e33e | Juan Quintela | if (!timers_state.cpu_ticks_enabled) {
|
556 | 6f68e33e | Juan Quintela | timers_state.cpu_ticks_offset -= cpu_get_real_ticks(); |
557 | 6f68e33e | Juan Quintela | timers_state.cpu_clock_offset -= get_clock(); |
558 | 6f68e33e | Juan Quintela | timers_state.cpu_ticks_enabled = 1;
|
559 | 8a7ddc38 | bellard | } |
560 | 34865134 | bellard | } |
561 | 34865134 | bellard | |
562 | 34865134 | bellard | /* disable cpu_get_ticks() : the clock is stopped. You must not call
|
563 | 34865134 | bellard | cpu_get_ticks() after that. */
|
564 | 34865134 | bellard | void cpu_disable_ticks(void) |
565 | 34865134 | bellard | { |
566 | 6f68e33e | Juan Quintela | if (timers_state.cpu_ticks_enabled) {
|
567 | 6f68e33e | Juan Quintela | timers_state.cpu_ticks_offset = cpu_get_ticks(); |
568 | 6f68e33e | Juan Quintela | timers_state.cpu_clock_offset = cpu_get_clock(); |
569 | 6f68e33e | Juan Quintela | timers_state.cpu_ticks_enabled = 0;
|
570 | 8a7ddc38 | bellard | } |
571 | 34865134 | bellard | } |
572 | 34865134 | bellard | |
573 | 1dce7c3c | bellard | /***********************************************************/
|
574 | 1dce7c3c | bellard | /* timers */
|
575 | 5fafdf24 | ths | |
576 | 0fdddf80 | Jan Kiszka | #define QEMU_CLOCK_REALTIME 0 |
577 | 0fdddf80 | Jan Kiszka | #define QEMU_CLOCK_VIRTUAL 1 |
578 | 21d5d12b | Jan Kiszka | #define QEMU_CLOCK_HOST 2 |
579 | 8a7ddc38 | bellard | |
580 | 8a7ddc38 | bellard | struct QEMUClock {
|
581 | 8a7ddc38 | bellard | int type;
|
582 | 8a7ddc38 | bellard | /* XXX: add frequency */
|
583 | 8a7ddc38 | bellard | }; |
584 | 8a7ddc38 | bellard | |
585 | 8a7ddc38 | bellard | struct QEMUTimer {
|
586 | 8a7ddc38 | bellard | QEMUClock *clock; |
587 | 8a7ddc38 | bellard | int64_t expire_time; |
588 | 8a7ddc38 | bellard | QEMUTimerCB *cb; |
589 | 8a7ddc38 | bellard | void *opaque;
|
590 | 8a7ddc38 | bellard | struct QEMUTimer *next;
|
591 | 8a7ddc38 | bellard | }; |
592 | 8a7ddc38 | bellard | |
593 | c8994013 | ths | struct qemu_alarm_timer {
|
594 | c8994013 | ths | char const *name; |
595 | efe75411 | ths | unsigned int flags; |
596 | c8994013 | ths | |
597 | c8994013 | ths | int (*start)(struct qemu_alarm_timer *t); |
598 | c8994013 | ths | void (*stop)(struct qemu_alarm_timer *t); |
599 | efe75411 | ths | void (*rearm)(struct qemu_alarm_timer *t); |
600 | c8994013 | ths | void *priv;
|
601 | c8994013 | ths | }; |
602 | c8994013 | ths | |
603 | efe75411 | ths | #define ALARM_FLAG_DYNTICKS 0x1 |
604 | d5d08334 | balrog | #define ALARM_FLAG_EXPIRED 0x2 |
605 | efe75411 | ths | |
606 | efe75411 | ths | static inline int alarm_has_dynticks(struct qemu_alarm_timer *t) |
607 | efe75411 | ths | { |
608 | e332340a | Jean-Christophe Dubois | return t && (t->flags & ALARM_FLAG_DYNTICKS);
|
609 | efe75411 | ths | } |
610 | efe75411 | ths | |
611 | efe75411 | ths | static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t) |
612 | efe75411 | ths | { |
613 | efe75411 | ths | if (!alarm_has_dynticks(t))
|
614 | efe75411 | ths | return;
|
615 | efe75411 | ths | |
616 | efe75411 | ths | t->rearm(t); |
617 | efe75411 | ths | } |
618 | efe75411 | ths | |
619 | efe75411 | ths | /* TODO: MIN_TIMER_REARM_US should be optimized */
|
620 | efe75411 | ths | #define MIN_TIMER_REARM_US 250 |
621 | efe75411 | ths | |
622 | c8994013 | ths | static struct qemu_alarm_timer *alarm_timer; |
623 | 8a7ddc38 | bellard | |
624 | 40c3bac3 | bellard | #ifdef _WIN32
|
625 | c8994013 | ths | |
626 | c8994013 | ths | struct qemu_alarm_win32 {
|
627 | c8994013 | ths | MMRESULT timerId; |
628 | c8994013 | ths | unsigned int period; |
629 | ef28c4b0 | Blue Swirl | } alarm_win32_data = {0, -1}; |
630 | c8994013 | ths | |
631 | c8994013 | ths | static int win32_start_timer(struct qemu_alarm_timer *t); |
632 | c8994013 | ths | static void win32_stop_timer(struct qemu_alarm_timer *t); |
633 | efe75411 | ths | static void win32_rearm_timer(struct qemu_alarm_timer *t); |
634 | c8994013 | ths | |
635 | 40c3bac3 | bellard | #else
|
636 | c8994013 | ths | |
637 | c8994013 | ths | static int unix_start_timer(struct qemu_alarm_timer *t); |
638 | c8994013 | ths | static void unix_stop_timer(struct qemu_alarm_timer *t); |
639 | c8994013 | ths | |
640 | 231c6586 | ths | #ifdef __linux__
|
641 | 231c6586 | ths | |
642 | efe75411 | ths | static int dynticks_start_timer(struct qemu_alarm_timer *t); |
643 | efe75411 | ths | static void dynticks_stop_timer(struct qemu_alarm_timer *t); |
644 | efe75411 | ths | static void dynticks_rearm_timer(struct qemu_alarm_timer *t); |
645 | efe75411 | ths | |
646 | c40ec5a9 | ths | static int hpet_start_timer(struct qemu_alarm_timer *t); |
647 | c40ec5a9 | ths | static void hpet_stop_timer(struct qemu_alarm_timer *t); |
648 | c40ec5a9 | ths | |
649 | c8994013 | ths | static int rtc_start_timer(struct qemu_alarm_timer *t); |
650 | c8994013 | ths | static void rtc_stop_timer(struct qemu_alarm_timer *t); |
651 | c8994013 | ths | |
652 | efe75411 | ths | #endif /* __linux__ */ |
653 | 8a7ddc38 | bellard | |
654 | c8994013 | ths | #endif /* _WIN32 */ |
655 | c8994013 | ths | |
656 | 2e70f6ef | pbrook | /* Correlation between real and virtual time is always going to be
|
657 | bf20dc07 | ths | fairly approximate, so ignore small variation.
|
658 | 2e70f6ef | pbrook | When the guest is idle real and virtual time will be aligned in
|
659 | 2e70f6ef | pbrook | the IO wait loop. */
|
660 | 274dfed8 | Anthony Liguori | #define ICOUNT_WOBBLE (get_ticks_per_sec() / 10) |
661 | 2e70f6ef | pbrook | |
662 | 2e70f6ef | pbrook | static void icount_adjust(void) |
663 | 2e70f6ef | pbrook | { |
664 | 2e70f6ef | pbrook | int64_t cur_time; |
665 | 2e70f6ef | pbrook | int64_t cur_icount; |
666 | 2e70f6ef | pbrook | int64_t delta; |
667 | 2e70f6ef | pbrook | static int64_t last_delta;
|
668 | 2e70f6ef | pbrook | /* If the VM is not running, then do nothing. */
|
669 | 2e70f6ef | pbrook | if (!vm_running)
|
670 | 2e70f6ef | pbrook | return;
|
671 | 2e70f6ef | pbrook | |
672 | 2e70f6ef | pbrook | cur_time = cpu_get_clock(); |
673 | 2e70f6ef | pbrook | cur_icount = qemu_get_clock(vm_clock); |
674 | 2e70f6ef | pbrook | delta = cur_icount - cur_time; |
675 | 2e70f6ef | pbrook | /* FIXME: This is a very crude algorithm, somewhat prone to oscillation. */
|
676 | 2e70f6ef | pbrook | if (delta > 0 |
677 | 2e70f6ef | pbrook | && last_delta + ICOUNT_WOBBLE < delta * 2
|
678 | 2e70f6ef | pbrook | && icount_time_shift > 0) {
|
679 | 2e70f6ef | pbrook | /* The guest is getting too far ahead. Slow time down. */
|
680 | 2e70f6ef | pbrook | icount_time_shift--; |
681 | 2e70f6ef | pbrook | } |
682 | 2e70f6ef | pbrook | if (delta < 0 |
683 | 2e70f6ef | pbrook | && last_delta - ICOUNT_WOBBLE > delta * 2
|
684 | 2e70f6ef | pbrook | && icount_time_shift < MAX_ICOUNT_SHIFT) { |
685 | 2e70f6ef | pbrook | /* The guest is getting too far behind. Speed time up. */
|
686 | 2e70f6ef | pbrook | icount_time_shift++; |
687 | 2e70f6ef | pbrook | } |
688 | 2e70f6ef | pbrook | last_delta = delta; |
689 | 2e70f6ef | pbrook | qemu_icount_bias = cur_icount - (qemu_icount << icount_time_shift); |
690 | 2e70f6ef | pbrook | } |
691 | 2e70f6ef | pbrook | |
692 | 2e70f6ef | pbrook | static void icount_adjust_rt(void * opaque) |
693 | 2e70f6ef | pbrook | { |
694 | 2e70f6ef | pbrook | qemu_mod_timer(icount_rt_timer, |
695 | 2e70f6ef | pbrook | qemu_get_clock(rt_clock) + 1000);
|
696 | 2e70f6ef | pbrook | icount_adjust(); |
697 | 2e70f6ef | pbrook | } |
698 | 2e70f6ef | pbrook | |
699 | 2e70f6ef | pbrook | static void icount_adjust_vm(void * opaque) |
700 | 2e70f6ef | pbrook | { |
701 | 2e70f6ef | pbrook | qemu_mod_timer(icount_vm_timer, |
702 | 274dfed8 | Anthony Liguori | qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
|
703 | 2e70f6ef | pbrook | icount_adjust(); |
704 | 2e70f6ef | pbrook | } |
705 | 2e70f6ef | pbrook | |
706 | 2e70f6ef | pbrook | static void init_icount_adjust(void) |
707 | 2e70f6ef | pbrook | { |
708 | 2e70f6ef | pbrook | /* Have both realtime and virtual time triggers for speed adjustment.
|
709 | 2e70f6ef | pbrook | The realtime trigger catches emulated time passing too slowly,
|
710 | 2e70f6ef | pbrook | the virtual time trigger catches emulated time passing too fast.
|
711 | 2e70f6ef | pbrook | Realtime triggers occur even when idle, so use them less frequently
|
712 | 2e70f6ef | pbrook | than VM triggers. */
|
713 | 2e70f6ef | pbrook | icount_rt_timer = qemu_new_timer(rt_clock, icount_adjust_rt, NULL);
|
714 | 2e70f6ef | pbrook | qemu_mod_timer(icount_rt_timer, |
715 | 2e70f6ef | pbrook | qemu_get_clock(rt_clock) + 1000);
|
716 | 2e70f6ef | pbrook | icount_vm_timer = qemu_new_timer(vm_clock, icount_adjust_vm, NULL);
|
717 | 2e70f6ef | pbrook | qemu_mod_timer(icount_vm_timer, |
718 | 274dfed8 | Anthony Liguori | qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
|
719 | 2e70f6ef | pbrook | } |
720 | 2e70f6ef | pbrook | |
721 | c8994013 | ths | static struct qemu_alarm_timer alarm_timers[] = { |
722 | efe75411 | ths | #ifndef _WIN32
|
723 | 231c6586 | ths | #ifdef __linux__
|
724 | efe75411 | ths | {"dynticks", ALARM_FLAG_DYNTICKS, dynticks_start_timer,
|
725 | efe75411 | ths | dynticks_stop_timer, dynticks_rearm_timer, NULL},
|
726 | c40ec5a9 | ths | /* HPET - if available - is preferred */
|
727 | efe75411 | ths | {"hpet", 0, hpet_start_timer, hpet_stop_timer, NULL, NULL}, |
728 | c40ec5a9 | ths | /* ...otherwise try RTC */
|
729 | efe75411 | ths | {"rtc", 0, rtc_start_timer, rtc_stop_timer, NULL, NULL}, |
730 | c8994013 | ths | #endif
|
731 | efe75411 | ths | {"unix", 0, unix_start_timer, unix_stop_timer, NULL, NULL}, |
732 | c8994013 | ths | #else
|
733 | efe75411 | ths | {"dynticks", ALARM_FLAG_DYNTICKS, win32_start_timer,
|
734 | efe75411 | ths | win32_stop_timer, win32_rearm_timer, &alarm_win32_data}, |
735 | efe75411 | ths | {"win32", 0, win32_start_timer, |
736 | efe75411 | ths | win32_stop_timer, NULL, &alarm_win32_data},
|
737 | c8994013 | ths | #endif
|
738 | c8994013 | ths | {NULL, }
|
739 | c8994013 | ths | }; |
740 | c8994013 | ths | |
741 | 3f47aa8c | blueswir1 | static void show_available_alarms(void) |
742 | f3dcfada | ths | { |
743 | f3dcfada | ths | int i;
|
744 | f3dcfada | ths | |
745 | f3dcfada | ths | printf("Available alarm timers, in order of precedence:\n");
|
746 | f3dcfada | ths | for (i = 0; alarm_timers[i].name; i++) |
747 | f3dcfada | ths | printf("%s\n", alarm_timers[i].name);
|
748 | f3dcfada | ths | } |
749 | f3dcfada | ths | |
750 | f3dcfada | ths | static void configure_alarms(char const *opt) |
751 | f3dcfada | ths | { |
752 | f3dcfada | ths | int i;
|
753 | f3dcfada | ths | int cur = 0; |
754 | b1503cda | malc | int count = ARRAY_SIZE(alarm_timers) - 1; |
755 | f3dcfada | ths | char *arg;
|
756 | f3dcfada | ths | char *name;
|
757 | 2e70f6ef | pbrook | struct qemu_alarm_timer tmp;
|
758 | f3dcfada | ths | |
759 | 3adda04c | aurel32 | if (!strcmp(opt, "?")) { |
760 | f3dcfada | ths | show_available_alarms(); |
761 | f3dcfada | ths | exit(0);
|
762 | f3dcfada | ths | } |
763 | f3dcfada | ths | |
764 | 73ffc805 | Jean-Christophe DUBOIS | arg = qemu_strdup(opt); |
765 | f3dcfada | ths | |
766 | f3dcfada | ths | /* Reorder the array */
|
767 | f3dcfada | ths | name = strtok(arg, ",");
|
768 | f3dcfada | ths | while (name) {
|
769 | e2b577e5 | balrog | for (i = 0; i < count && alarm_timers[i].name; i++) { |
770 | f3dcfada | ths | if (!strcmp(alarm_timers[i].name, name))
|
771 | f3dcfada | ths | break;
|
772 | f3dcfada | ths | } |
773 | f3dcfada | ths | |
774 | f3dcfada | ths | if (i == count) {
|
775 | f3dcfada | ths | fprintf(stderr, "Unknown clock %s\n", name);
|
776 | f3dcfada | ths | goto next;
|
777 | f3dcfada | ths | } |
778 | f3dcfada | ths | |
779 | f3dcfada | ths | if (i < cur)
|
780 | f3dcfada | ths | /* Ignore */
|
781 | f3dcfada | ths | goto next;
|
782 | f3dcfada | ths | |
783 | f3dcfada | ths | /* Swap */
|
784 | f3dcfada | ths | tmp = alarm_timers[i]; |
785 | f3dcfada | ths | alarm_timers[i] = alarm_timers[cur]; |
786 | f3dcfada | ths | alarm_timers[cur] = tmp; |
787 | f3dcfada | ths | |
788 | f3dcfada | ths | cur++; |
789 | f3dcfada | ths | next:
|
790 | f3dcfada | ths | name = strtok(NULL, ","); |
791 | f3dcfada | ths | } |
792 | f3dcfada | ths | |
793 | 73ffc805 | Jean-Christophe DUBOIS | qemu_free(arg); |
794 | f3dcfada | ths | |
795 | f3dcfada | ths | if (cur) {
|
796 | 2e70f6ef | pbrook | /* Disable remaining timers */
|
797 | f3dcfada | ths | for (i = cur; i < count; i++)
|
798 | f3dcfada | ths | alarm_timers[i].name = NULL;
|
799 | 3adda04c | aurel32 | } else {
|
800 | 3adda04c | aurel32 | show_available_alarms(); |
801 | 3adda04c | aurel32 | exit(1);
|
802 | f3dcfada | ths | } |
803 | f3dcfada | ths | } |
804 | f3dcfada | ths | |
805 | 21d5d12b | Jan Kiszka | #define QEMU_NUM_CLOCKS 3 |
806 | 21d5d12b | Jan Kiszka | |
807 | c8994013 | ths | QEMUClock *rt_clock; |
808 | c8994013 | ths | QEMUClock *vm_clock; |
809 | 21d5d12b | Jan Kiszka | QEMUClock *host_clock; |
810 | c8994013 | ths | |
811 | 21d5d12b | Jan Kiszka | static QEMUTimer *active_timers[QEMU_NUM_CLOCKS];
|
812 | c8994013 | ths | |
813 | 9596ebb7 | pbrook | static QEMUClock *qemu_new_clock(int type) |
814 | 8a7ddc38 | bellard | { |
815 | 8a7ddc38 | bellard | QEMUClock *clock; |
816 | 8a7ddc38 | bellard | clock = qemu_mallocz(sizeof(QEMUClock));
|
817 | 8a7ddc38 | bellard | clock->type = type; |
818 | 8a7ddc38 | bellard | return clock;
|
819 | 8a7ddc38 | bellard | } |
820 | 8a7ddc38 | bellard | |
821 | 8a7ddc38 | bellard | QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque)
|
822 | 8a7ddc38 | bellard | { |
823 | 8a7ddc38 | bellard | QEMUTimer *ts; |
824 | 8a7ddc38 | bellard | |
825 | 8a7ddc38 | bellard | ts = qemu_mallocz(sizeof(QEMUTimer));
|
826 | 8a7ddc38 | bellard | ts->clock = clock; |
827 | 8a7ddc38 | bellard | ts->cb = cb; |
828 | 8a7ddc38 | bellard | ts->opaque = opaque; |
829 | 8a7ddc38 | bellard | return ts;
|
830 | 8a7ddc38 | bellard | } |
831 | 8a7ddc38 | bellard | |
832 | 8a7ddc38 | bellard | void qemu_free_timer(QEMUTimer *ts)
|
833 | 8a7ddc38 | bellard | { |
834 | 8a7ddc38 | bellard | qemu_free(ts); |
835 | 8a7ddc38 | bellard | } |
836 | 8a7ddc38 | bellard | |
837 | 8a7ddc38 | bellard | /* stop a timer, but do not dealloc it */
|
838 | 8a7ddc38 | bellard | void qemu_del_timer(QEMUTimer *ts)
|
839 | 8a7ddc38 | bellard | { |
840 | 8a7ddc38 | bellard | QEMUTimer **pt, *t; |
841 | 8a7ddc38 | bellard | |
842 | 8a7ddc38 | bellard | /* NOTE: this code must be signal safe because
|
843 | 8a7ddc38 | bellard | qemu_timer_expired() can be called from a signal. */
|
844 | 8a7ddc38 | bellard | pt = &active_timers[ts->clock->type]; |
845 | 8a7ddc38 | bellard | for(;;) {
|
846 | 8a7ddc38 | bellard | t = *pt; |
847 | 8a7ddc38 | bellard | if (!t)
|
848 | 8a7ddc38 | bellard | break;
|
849 | 8a7ddc38 | bellard | if (t == ts) {
|
850 | 8a7ddc38 | bellard | *pt = t->next; |
851 | 8a7ddc38 | bellard | break;
|
852 | 8a7ddc38 | bellard | } |
853 | 8a7ddc38 | bellard | pt = &t->next; |
854 | 8a7ddc38 | bellard | } |
855 | 8a7ddc38 | bellard | } |
856 | 8a7ddc38 | bellard | |
857 | 8a7ddc38 | bellard | /* modify the current timer so that it will be fired when current_time
|
858 | 8a7ddc38 | bellard | >= expire_time. The corresponding callback will be called. */
|
859 | 8a7ddc38 | bellard | void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
|
860 | 8a7ddc38 | bellard | { |
861 | 8a7ddc38 | bellard | QEMUTimer **pt, *t; |
862 | 8a7ddc38 | bellard | |
863 | 8a7ddc38 | bellard | qemu_del_timer(ts); |
864 | 8a7ddc38 | bellard | |
865 | 8a7ddc38 | bellard | /* add the timer in the sorted list */
|
866 | 8a7ddc38 | bellard | /* NOTE: this code must be signal safe because
|
867 | 8a7ddc38 | bellard | qemu_timer_expired() can be called from a signal. */
|
868 | 8a7ddc38 | bellard | pt = &active_timers[ts->clock->type]; |
869 | 8a7ddc38 | bellard | for(;;) {
|
870 | 8a7ddc38 | bellard | t = *pt; |
871 | 8a7ddc38 | bellard | if (!t)
|
872 | 8a7ddc38 | bellard | break;
|
873 | 5fafdf24 | ths | if (t->expire_time > expire_time)
|
874 | 8a7ddc38 | bellard | break;
|
875 | 8a7ddc38 | bellard | pt = &t->next; |
876 | 8a7ddc38 | bellard | } |
877 | 8a7ddc38 | bellard | ts->expire_time = expire_time; |
878 | 8a7ddc38 | bellard | ts->next = *pt; |
879 | 8a7ddc38 | bellard | *pt = ts; |
880 | d5d08334 | balrog | |
881 | d5d08334 | balrog | /* Rearm if necessary */
|
882 | 2e70f6ef | pbrook | if (pt == &active_timers[ts->clock->type]) {
|
883 | 2e70f6ef | pbrook | if ((alarm_timer->flags & ALARM_FLAG_EXPIRED) == 0) { |
884 | 2e70f6ef | pbrook | qemu_rearm_alarm_timer(alarm_timer); |
885 | 2e70f6ef | pbrook | } |
886 | 2e70f6ef | pbrook | /* Interrupt execution to force deadline recalculation. */
|
887 | d9f75a4e | aliguori | if (use_icount)
|
888 | d9f75a4e | aliguori | qemu_notify_event(); |
889 | 2e70f6ef | pbrook | } |
890 | 8a7ddc38 | bellard | } |
891 | 8a7ddc38 | bellard | |
892 | 8a7ddc38 | bellard | int qemu_timer_pending(QEMUTimer *ts)
|
893 | 8a7ddc38 | bellard | { |
894 | 8a7ddc38 | bellard | QEMUTimer *t; |
895 | 8a7ddc38 | bellard | for(t = active_timers[ts->clock->type]; t != NULL; t = t->next) { |
896 | 8a7ddc38 | bellard | if (t == ts)
|
897 | 8a7ddc38 | bellard | return 1; |
898 | 8a7ddc38 | bellard | } |
899 | 8a7ddc38 | bellard | return 0; |
900 | 8a7ddc38 | bellard | } |
901 | 8a7ddc38 | bellard | |
902 | 2430ffe4 | Stefano Stabellini | int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)
|
903 | 8a7ddc38 | bellard | { |
904 | 8a7ddc38 | bellard | if (!timer_head)
|
905 | 8a7ddc38 | bellard | return 0; |
906 | 8a7ddc38 | bellard | return (timer_head->expire_time <= current_time);
|
907 | 8a7ddc38 | bellard | } |
908 | 8a7ddc38 | bellard | |
909 | 8a7ddc38 | bellard | static void qemu_run_timers(QEMUTimer **ptimer_head, int64_t current_time) |
910 | 8a7ddc38 | bellard | { |
911 | 8a7ddc38 | bellard | QEMUTimer *ts; |
912 | 3b46e624 | ths | |
913 | 8a7ddc38 | bellard | for(;;) {
|
914 | 8a7ddc38 | bellard | ts = *ptimer_head; |
915 | e95c8d51 | bellard | if (!ts || ts->expire_time > current_time)
|
916 | 8a7ddc38 | bellard | break;
|
917 | 8a7ddc38 | bellard | /* remove timer from the list before calling the callback */
|
918 | 8a7ddc38 | bellard | *ptimer_head = ts->next; |
919 | 8a7ddc38 | bellard | ts->next = NULL;
|
920 | 3b46e624 | ths | |
921 | 8a7ddc38 | bellard | /* run the callback (the timer list can be modified) */
|
922 | 8a7ddc38 | bellard | ts->cb(ts->opaque); |
923 | 8a7ddc38 | bellard | } |
924 | 8a7ddc38 | bellard | } |
925 | 8a7ddc38 | bellard | |
926 | 8a7ddc38 | bellard | int64_t qemu_get_clock(QEMUClock *clock) |
927 | 8a7ddc38 | bellard | { |
928 | 8a7ddc38 | bellard | switch(clock->type) {
|
929 | 0fdddf80 | Jan Kiszka | case QEMU_CLOCK_REALTIME:
|
930 | 1dce7c3c | bellard | return get_clock() / 1000000; |
931 | 8a7ddc38 | bellard | default:
|
932 | 0fdddf80 | Jan Kiszka | case QEMU_CLOCK_VIRTUAL:
|
933 | 2e70f6ef | pbrook | if (use_icount) {
|
934 | 2e70f6ef | pbrook | return cpu_get_icount();
|
935 | 2e70f6ef | pbrook | } else {
|
936 | 2e70f6ef | pbrook | return cpu_get_clock();
|
937 | 2e70f6ef | pbrook | } |
938 | 21d5d12b | Jan Kiszka | case QEMU_CLOCK_HOST:
|
939 | 21d5d12b | Jan Kiszka | return get_clock_realtime();
|
940 | 8a7ddc38 | bellard | } |
941 | 8a7ddc38 | bellard | } |
942 | 8a7ddc38 | bellard | |
943 | 41c872b6 | Paolo Bonzini | int64_t qemu_get_clock_ns(QEMUClock *clock) |
944 | 41c872b6 | Paolo Bonzini | { |
945 | 41c872b6 | Paolo Bonzini | switch(clock->type) {
|
946 | 41c872b6 | Paolo Bonzini | case QEMU_CLOCK_REALTIME:
|
947 | 41c872b6 | Paolo Bonzini | return get_clock();
|
948 | 41c872b6 | Paolo Bonzini | default:
|
949 | 41c872b6 | Paolo Bonzini | case QEMU_CLOCK_VIRTUAL:
|
950 | 41c872b6 | Paolo Bonzini | if (use_icount) {
|
951 | 41c872b6 | Paolo Bonzini | return cpu_get_icount();
|
952 | 41c872b6 | Paolo Bonzini | } else {
|
953 | 41c872b6 | Paolo Bonzini | return cpu_get_clock();
|
954 | 41c872b6 | Paolo Bonzini | } |
955 | 41c872b6 | Paolo Bonzini | case QEMU_CLOCK_HOST:
|
956 | 41c872b6 | Paolo Bonzini | return get_clock_realtime();
|
957 | 41c872b6 | Paolo Bonzini | } |
958 | 41c872b6 | Paolo Bonzini | } |
959 | 41c872b6 | Paolo Bonzini | |
960 | 0fdddf80 | Jan Kiszka | static void init_clocks(void) |
961 | 1dce7c3c | bellard | { |
962 | 1dce7c3c | bellard | init_get_clock(); |
963 | 0fdddf80 | Jan Kiszka | rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME); |
964 | 0fdddf80 | Jan Kiszka | vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL); |
965 | 21d5d12b | Jan Kiszka | host_clock = qemu_new_clock(QEMU_CLOCK_HOST); |
966 | 6875204c | Jan Kiszka | |
967 | 6875204c | Jan Kiszka | rtc_clock = host_clock; |
968 | 1dce7c3c | bellard | } |
969 | 1dce7c3c | bellard | |
970 | 8a7ddc38 | bellard | /* save a timer */
|
971 | 8a7ddc38 | bellard | void qemu_put_timer(QEMUFile *f, QEMUTimer *ts)
|
972 | 8a7ddc38 | bellard | { |
973 | 8a7ddc38 | bellard | uint64_t expire_time; |
974 | 8a7ddc38 | bellard | |
975 | 8a7ddc38 | bellard | if (qemu_timer_pending(ts)) {
|
976 | 8a7ddc38 | bellard | expire_time = ts->expire_time; |
977 | 8a7ddc38 | bellard | } else {
|
978 | 8a7ddc38 | bellard | expire_time = -1;
|
979 | 8a7ddc38 | bellard | } |
980 | 8a7ddc38 | bellard | qemu_put_be64(f, expire_time); |
981 | 8a7ddc38 | bellard | } |
982 | 8a7ddc38 | bellard | |
983 | 8a7ddc38 | bellard | void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
|
984 | 8a7ddc38 | bellard | { |
985 | 8a7ddc38 | bellard | uint64_t expire_time; |
986 | 8a7ddc38 | bellard | |
987 | 8a7ddc38 | bellard | expire_time = qemu_get_be64(f); |
988 | 8a7ddc38 | bellard | if (expire_time != -1) { |
989 | 8a7ddc38 | bellard | qemu_mod_timer(ts, expire_time); |
990 | 8a7ddc38 | bellard | } else {
|
991 | 8a7ddc38 | bellard | qemu_del_timer(ts); |
992 | 8a7ddc38 | bellard | } |
993 | 8a7ddc38 | bellard | } |
994 | 8a7ddc38 | bellard | |
995 | 2faf58cd | Juan Quintela | static const VMStateDescription vmstate_timers = { |
996 | 2faf58cd | Juan Quintela | .name = "timer",
|
997 | 2faf58cd | Juan Quintela | .version_id = 2,
|
998 | 2faf58cd | Juan Quintela | .minimum_version_id = 1,
|
999 | 2faf58cd | Juan Quintela | .minimum_version_id_old = 1,
|
1000 | 2faf58cd | Juan Quintela | .fields = (VMStateField []) { |
1001 | 2faf58cd | Juan Quintela | VMSTATE_INT64(cpu_ticks_offset, TimersState), |
1002 | 274dfed8 | Anthony Liguori | VMSTATE_INT64(dummy, TimersState), |
1003 | 2faf58cd | Juan Quintela | VMSTATE_INT64_V(cpu_clock_offset, TimersState, 2),
|
1004 | 2faf58cd | Juan Quintela | VMSTATE_END_OF_LIST() |
1005 | c88676f8 | bellard | } |
1006 | 2faf58cd | Juan Quintela | }; |
1007 | 8a7ddc38 | bellard | |
1008 | 50317c7f | aliguori | static void qemu_event_increment(void); |
1009 | 50317c7f | aliguori | |
1010 | 67b915a5 | bellard | #ifdef _WIN32
|
1011 | b9e82a59 | blueswir1 | static void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg, |
1012 | b9e82a59 | blueswir1 | DWORD_PTR dwUser, DWORD_PTR dw1, |
1013 | b9e82a59 | blueswir1 | DWORD_PTR dw2) |
1014 | 67b915a5 | bellard | #else
|
1015 | 8a7ddc38 | bellard | static void host_alarm_handler(int host_signum) |
1016 | 67b915a5 | bellard | #endif
|
1017 | 8a7ddc38 | bellard | { |
1018 | 02ba45c5 | bellard | #if 0
|
1019 | 02ba45c5 | bellard | #define DISP_FREQ 1000
|
1020 | 02ba45c5 | bellard | {
|
1021 | 02ba45c5 | bellard | static int64_t delta_min = INT64_MAX;
|
1022 | 02ba45c5 | bellard | static int64_t delta_max, delta_cum, last_clock, delta, ti;
|
1023 | 02ba45c5 | bellard | static int count;
|
1024 | 02ba45c5 | bellard | ti = qemu_get_clock(vm_clock);
|
1025 | 02ba45c5 | bellard | if (last_clock != 0) {
|
1026 | 02ba45c5 | bellard | delta = ti - last_clock;
|
1027 | 02ba45c5 | bellard | if (delta < delta_min)
|
1028 | 02ba45c5 | bellard | delta_min = delta;
|
1029 | 02ba45c5 | bellard | if (delta > delta_max)
|
1030 | 02ba45c5 | bellard | delta_max = delta;
|
1031 | 02ba45c5 | bellard | delta_cum += delta;
|
1032 | 02ba45c5 | bellard | if (++count == DISP_FREQ) {
|
1033 | 26a76461 | bellard | printf("timer: min=%" PRId64 " us max=%" PRId64 " us avg=%" PRId64 " us avg_freq=%0.3f Hz\n",
|
1034 | 6ee093c9 | Juan Quintela | muldiv64(delta_min, 1000000, get_ticks_per_sec()),
|
1035 | 6ee093c9 | Juan Quintela | muldiv64(delta_max, 1000000, get_ticks_per_sec()),
|
1036 | 6ee093c9 | Juan Quintela | muldiv64(delta_cum, 1000000 / DISP_FREQ, get_ticks_per_sec()),
|
1037 | 6ee093c9 | Juan Quintela | (double)get_ticks_per_sec() / ((double)delta_cum / DISP_FREQ));
|
1038 | 02ba45c5 | bellard | count = 0;
|
1039 | 02ba45c5 | bellard | delta_min = INT64_MAX;
|
1040 | 02ba45c5 | bellard | delta_max = 0;
|
1041 | 02ba45c5 | bellard | delta_cum = 0;
|
1042 | 02ba45c5 | bellard | }
|
1043 | 02ba45c5 | bellard | }
|
1044 | 02ba45c5 | bellard | last_clock = ti;
|
1045 | 02ba45c5 | bellard | }
|
1046 | 02ba45c5 | bellard | #endif
|
1047 | efe75411 | ths | if (alarm_has_dynticks(alarm_timer) ||
|
1048 | 2e70f6ef | pbrook | (!use_icount && |
1049 | 0fdddf80 | Jan Kiszka | qemu_timer_expired(active_timers[QEMU_CLOCK_VIRTUAL], |
1050 | 2e70f6ef | pbrook | qemu_get_clock(vm_clock))) || |
1051 | 0fdddf80 | Jan Kiszka | qemu_timer_expired(active_timers[QEMU_CLOCK_REALTIME], |
1052 | 21d5d12b | Jan Kiszka | qemu_get_clock(rt_clock)) || |
1053 | 21d5d12b | Jan Kiszka | qemu_timer_expired(active_timers[QEMU_CLOCK_HOST], |
1054 | 21d5d12b | Jan Kiszka | qemu_get_clock(host_clock))) { |
1055 | 50317c7f | aliguori | qemu_event_increment(); |
1056 | e332340a | Jean-Christophe Dubois | if (alarm_timer) alarm_timer->flags |= ALARM_FLAG_EXPIRED;
|
1057 | d5d08334 | balrog | |
1058 | d6dc3d42 | aliguori | #ifndef CONFIG_IOTHREAD
|
1059 | d6dc3d42 | aliguori | if (next_cpu) {
|
1060 | 4f8eb8da | balrog | /* stop the currently executing cpu because a timer occured */
|
1061 | d6dc3d42 | aliguori | cpu_exit(next_cpu); |
1062 | 4f8eb8da | balrog | } |
1063 | d6dc3d42 | aliguori | #endif
|
1064 | 43b96858 | aliguori | timer_alarm_pending = 1;
|
1065 | d9f75a4e | aliguori | qemu_notify_event(); |
1066 | 8a7ddc38 | bellard | } |
1067 | 8a7ddc38 | bellard | } |
1068 | 8a7ddc38 | bellard | |
1069 | 2e70f6ef | pbrook | static int64_t qemu_next_deadline(void) |
1070 | efe75411 | ths | { |
1071 | 21d5d12b | Jan Kiszka | /* To avoid problems with overflow limit this to 2^32. */
|
1072 | 21d5d12b | Jan Kiszka | int64_t delta = INT32_MAX; |
1073 | efe75411 | ths | |
1074 | 0fdddf80 | Jan Kiszka | if (active_timers[QEMU_CLOCK_VIRTUAL]) {
|
1075 | 0fdddf80 | Jan Kiszka | delta = active_timers[QEMU_CLOCK_VIRTUAL]->expire_time - |
1076 | 2e70f6ef | pbrook | qemu_get_clock(vm_clock); |
1077 | 21d5d12b | Jan Kiszka | } |
1078 | 21d5d12b | Jan Kiszka | if (active_timers[QEMU_CLOCK_HOST]) {
|
1079 | 21d5d12b | Jan Kiszka | int64_t hdelta = active_timers[QEMU_CLOCK_HOST]->expire_time - |
1080 | 21d5d12b | Jan Kiszka | qemu_get_clock(host_clock); |
1081 | 21d5d12b | Jan Kiszka | if (hdelta < delta)
|
1082 | 21d5d12b | Jan Kiszka | delta = hdelta; |
1083 | efe75411 | ths | } |
1084 | efe75411 | ths | |
1085 | 2e70f6ef | pbrook | if (delta < 0) |
1086 | 2e70f6ef | pbrook | delta = 0;
|
1087 | efe75411 | ths | |
1088 | 2e70f6ef | pbrook | return delta;
|
1089 | 2e70f6ef | pbrook | } |
1090 | 2e70f6ef | pbrook | |
1091 | f64382ba | Jan Kiszka | #if defined(__linux__)
|
1092 | 2e70f6ef | pbrook | static uint64_t qemu_next_deadline_dyntick(void) |
1093 | 2e70f6ef | pbrook | { |
1094 | 2e70f6ef | pbrook | int64_t delta; |
1095 | 2e70f6ef | pbrook | int64_t rtdelta; |
1096 | 2e70f6ef | pbrook | |
1097 | 2e70f6ef | pbrook | if (use_icount)
|
1098 | 2e70f6ef | pbrook | delta = INT32_MAX; |
1099 | 2e70f6ef | pbrook | else
|
1100 | 2e70f6ef | pbrook | delta = (qemu_next_deadline() + 999) / 1000; |
1101 | 2e70f6ef | pbrook | |
1102 | 0fdddf80 | Jan Kiszka | if (active_timers[QEMU_CLOCK_REALTIME]) {
|
1103 | 0fdddf80 | Jan Kiszka | rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time - |
1104 | 2e70f6ef | pbrook | qemu_get_clock(rt_clock))*1000;
|
1105 | 2e70f6ef | pbrook | if (rtdelta < delta)
|
1106 | 2e70f6ef | pbrook | delta = rtdelta; |
1107 | 2e70f6ef | pbrook | } |
1108 | 2e70f6ef | pbrook | |
1109 | 2e70f6ef | pbrook | if (delta < MIN_TIMER_REARM_US)
|
1110 | 2e70f6ef | pbrook | delta = MIN_TIMER_REARM_US; |
1111 | 2e70f6ef | pbrook | |
1112 | 2e70f6ef | pbrook | return delta;
|
1113 | efe75411 | ths | } |
1114 | 8632fb9a | blueswir1 | #endif
|
1115 | efe75411 | ths | |
1116 | fd872598 | bellard | #ifndef _WIN32
|
1117 | fd872598 | bellard | |
1118 | 7183b4b4 | aliguori | /* Sets a specific flag */
|
1119 | 7183b4b4 | aliguori | static int fcntl_setfl(int fd, int flag) |
1120 | 7183b4b4 | aliguori | { |
1121 | 7183b4b4 | aliguori | int flags;
|
1122 | 7183b4b4 | aliguori | |
1123 | 7183b4b4 | aliguori | flags = fcntl(fd, F_GETFL); |
1124 | 7183b4b4 | aliguori | if (flags == -1) |
1125 | 7183b4b4 | aliguori | return -errno;
|
1126 | 7183b4b4 | aliguori | |
1127 | 7183b4b4 | aliguori | if (fcntl(fd, F_SETFL, flags | flag) == -1) |
1128 | 7183b4b4 | aliguori | return -errno;
|
1129 | 7183b4b4 | aliguori | |
1130 | 7183b4b4 | aliguori | return 0; |
1131 | 7183b4b4 | aliguori | } |
1132 | 7183b4b4 | aliguori | |
1133 | 829309c7 | bellard | #if defined(__linux__)
|
1134 | 829309c7 | bellard | |
1135 | fd872598 | bellard | #define RTC_FREQ 1024 |
1136 | fd872598 | bellard | |
1137 | de9a95f0 | aurel32 | static void enable_sigio_timer(int fd) |
1138 | c8994013 | ths | { |
1139 | c8994013 | ths | struct sigaction act;
|
1140 | c8994013 | ths | |
1141 | c8994013 | ths | /* timer signal */
|
1142 | c8994013 | ths | sigfillset(&act.sa_mask); |
1143 | c8994013 | ths | act.sa_flags = 0;
|
1144 | c8994013 | ths | act.sa_handler = host_alarm_handler; |
1145 | c8994013 | ths | |
1146 | c8994013 | ths | sigaction(SIGIO, &act, NULL);
|
1147 | 7183b4b4 | aliguori | fcntl_setfl(fd, O_ASYNC); |
1148 | c8994013 | ths | fcntl(fd, F_SETOWN, getpid()); |
1149 | c8994013 | ths | } |
1150 | 829309c7 | bellard | |
1151 | c40ec5a9 | ths | static int hpet_start_timer(struct qemu_alarm_timer *t) |
1152 | c40ec5a9 | ths | { |
1153 | c40ec5a9 | ths | struct hpet_info info;
|
1154 | c40ec5a9 | ths | int r, fd;
|
1155 | c40ec5a9 | ths | |
1156 | 40ff6d7e | Kevin Wolf | fd = qemu_open("/dev/hpet", O_RDONLY);
|
1157 | c40ec5a9 | ths | if (fd < 0) |
1158 | c40ec5a9 | ths | return -1; |
1159 | c40ec5a9 | ths | |
1160 | c40ec5a9 | ths | /* Set frequency */
|
1161 | c40ec5a9 | ths | r = ioctl(fd, HPET_IRQFREQ, RTC_FREQ); |
1162 | c40ec5a9 | ths | if (r < 0) { |
1163 | c40ec5a9 | ths | fprintf(stderr, "Could not configure '/dev/hpet' to have a 1024Hz timer. This is not a fatal\n"
|
1164 | c40ec5a9 | ths | "error, but for better emulation accuracy type:\n"
|
1165 | c40ec5a9 | ths | "'echo 1024 > /proc/sys/dev/hpet/max-user-freq' as root.\n");
|
1166 | c40ec5a9 | ths | goto fail;
|
1167 | c40ec5a9 | ths | } |
1168 | c40ec5a9 | ths | |
1169 | c40ec5a9 | ths | /* Check capabilities */
|
1170 | c40ec5a9 | ths | r = ioctl(fd, HPET_INFO, &info); |
1171 | c40ec5a9 | ths | if (r < 0) |
1172 | c40ec5a9 | ths | goto fail;
|
1173 | c40ec5a9 | ths | |
1174 | c40ec5a9 | ths | /* Enable periodic mode */
|
1175 | c40ec5a9 | ths | r = ioctl(fd, HPET_EPI, 0);
|
1176 | c40ec5a9 | ths | if (info.hi_flags && (r < 0)) |
1177 | c40ec5a9 | ths | goto fail;
|
1178 | c40ec5a9 | ths | |
1179 | c40ec5a9 | ths | /* Enable interrupt */
|
1180 | c40ec5a9 | ths | r = ioctl(fd, HPET_IE_ON, 0);
|
1181 | c40ec5a9 | ths | if (r < 0) |
1182 | c40ec5a9 | ths | goto fail;
|
1183 | c40ec5a9 | ths | |
1184 | c40ec5a9 | ths | enable_sigio_timer(fd); |
1185 | fcdc2129 | pbrook | t->priv = (void *)(long)fd; |
1186 | c40ec5a9 | ths | |
1187 | c40ec5a9 | ths | return 0; |
1188 | c40ec5a9 | ths | fail:
|
1189 | c40ec5a9 | ths | close(fd); |
1190 | c40ec5a9 | ths | return -1; |
1191 | c40ec5a9 | ths | } |
1192 | c40ec5a9 | ths | |
1193 | c40ec5a9 | ths | static void hpet_stop_timer(struct qemu_alarm_timer *t) |
1194 | c40ec5a9 | ths | { |
1195 | fcdc2129 | pbrook | int fd = (long)t->priv; |
1196 | c40ec5a9 | ths | |
1197 | c40ec5a9 | ths | close(fd); |
1198 | c40ec5a9 | ths | } |
1199 | c40ec5a9 | ths | |
1200 | c8994013 | ths | static int rtc_start_timer(struct qemu_alarm_timer *t) |
1201 | fd872598 | bellard | { |
1202 | c8994013 | ths | int rtc_fd;
|
1203 | b5a23ad4 | balrog | unsigned long current_rtc_freq = 0; |
1204 | c8994013 | ths | |
1205 | 40ff6d7e | Kevin Wolf | TFR(rtc_fd = qemu_open("/dev/rtc", O_RDONLY));
|
1206 | fd872598 | bellard | if (rtc_fd < 0) |
1207 | fd872598 | bellard | return -1; |
1208 | b5a23ad4 | balrog | ioctl(rtc_fd, RTC_IRQP_READ, ¤t_rtc_freq); |
1209 | b5a23ad4 | balrog | if (current_rtc_freq != RTC_FREQ &&
|
1210 | b5a23ad4 | balrog | ioctl(rtc_fd, RTC_IRQP_SET, RTC_FREQ) < 0) {
|
1211 | fd872598 | bellard | fprintf(stderr, "Could not configure '/dev/rtc' to have a 1024 Hz timer. This is not a fatal\n"
|
1212 | fd872598 | bellard | "error, but for better emulation accuracy either use a 2.6 host Linux kernel or\n"
|
1213 | fd872598 | bellard | "type 'echo 1024 > /proc/sys/dev/rtc/max-user-freq' as root.\n");
|
1214 | fd872598 | bellard | goto fail;
|
1215 | fd872598 | bellard | } |
1216 | fd872598 | bellard | if (ioctl(rtc_fd, RTC_PIE_ON, 0) < 0) { |
1217 | fd872598 | bellard | fail:
|
1218 | fd872598 | bellard | close(rtc_fd); |
1219 | fd872598 | bellard | return -1; |
1220 | fd872598 | bellard | } |
1221 | c8994013 | ths | |
1222 | c8994013 | ths | enable_sigio_timer(rtc_fd); |
1223 | c8994013 | ths | |
1224 | fcdc2129 | pbrook | t->priv = (void *)(long)rtc_fd; |
1225 | c8994013 | ths | |
1226 | fd872598 | bellard | return 0; |
1227 | fd872598 | bellard | } |
1228 | fd872598 | bellard | |
1229 | c8994013 | ths | static void rtc_stop_timer(struct qemu_alarm_timer *t) |
1230 | 829309c7 | bellard | { |
1231 | fcdc2129 | pbrook | int rtc_fd = (long)t->priv; |
1232 | c8994013 | ths | |
1233 | c8994013 | ths | close(rtc_fd); |
1234 | 829309c7 | bellard | } |
1235 | 829309c7 | bellard | |
1236 | efe75411 | ths | static int dynticks_start_timer(struct qemu_alarm_timer *t) |
1237 | efe75411 | ths | { |
1238 | efe75411 | ths | struct sigevent ev;
|
1239 | efe75411 | ths | timer_t host_timer; |
1240 | efe75411 | ths | struct sigaction act;
|
1241 | efe75411 | ths | |
1242 | efe75411 | ths | sigfillset(&act.sa_mask); |
1243 | efe75411 | ths | act.sa_flags = 0;
|
1244 | efe75411 | ths | act.sa_handler = host_alarm_handler; |
1245 | efe75411 | ths | |
1246 | efe75411 | ths | sigaction(SIGALRM, &act, NULL);
|
1247 | efe75411 | ths | |
1248 | 9ed415b2 | Jean-Christophe Dubois | /*
|
1249 | 9ed415b2 | Jean-Christophe Dubois | * Initialize ev struct to 0 to avoid valgrind complaining
|
1250 | 9ed415b2 | Jean-Christophe Dubois | * about uninitialized data in timer_create call
|
1251 | 9ed415b2 | Jean-Christophe Dubois | */
|
1252 | 9ed415b2 | Jean-Christophe Dubois | memset(&ev, 0, sizeof(ev)); |
1253 | efe75411 | ths | ev.sigev_value.sival_int = 0;
|
1254 | efe75411 | ths | ev.sigev_notify = SIGEV_SIGNAL; |
1255 | efe75411 | ths | ev.sigev_signo = SIGALRM; |
1256 | efe75411 | ths | |
1257 | efe75411 | ths | if (timer_create(CLOCK_REALTIME, &ev, &host_timer)) {
|
1258 | efe75411 | ths | perror("timer_create");
|
1259 | efe75411 | ths | |
1260 | efe75411 | ths | /* disable dynticks */
|
1261 | efe75411 | ths | fprintf(stderr, "Dynamic Ticks disabled\n");
|
1262 | efe75411 | ths | |
1263 | efe75411 | ths | return -1; |
1264 | efe75411 | ths | } |
1265 | efe75411 | ths | |
1266 | 0399bfe0 | blueswir1 | t->priv = (void *)(long)host_timer; |
1267 | efe75411 | ths | |
1268 | efe75411 | ths | return 0; |
1269 | efe75411 | ths | } |
1270 | efe75411 | ths | |
1271 | efe75411 | ths | static void dynticks_stop_timer(struct qemu_alarm_timer *t) |
1272 | efe75411 | ths | { |
1273 | 0399bfe0 | blueswir1 | timer_t host_timer = (timer_t)(long)t->priv;
|
1274 | efe75411 | ths | |
1275 | efe75411 | ths | timer_delete(host_timer); |
1276 | efe75411 | ths | } |
1277 | efe75411 | ths | |
1278 | efe75411 | ths | static void dynticks_rearm_timer(struct qemu_alarm_timer *t) |
1279 | efe75411 | ths | { |
1280 | 0399bfe0 | blueswir1 | timer_t host_timer = (timer_t)(long)t->priv;
|
1281 | efe75411 | ths | struct itimerspec timeout;
|
1282 | efe75411 | ths | int64_t nearest_delta_us = INT64_MAX; |
1283 | efe75411 | ths | int64_t current_us; |
1284 | efe75411 | ths | |
1285 | 0fdddf80 | Jan Kiszka | if (!active_timers[QEMU_CLOCK_REALTIME] &&
|
1286 | 21d5d12b | Jan Kiszka | !active_timers[QEMU_CLOCK_VIRTUAL] && |
1287 | 21d5d12b | Jan Kiszka | !active_timers[QEMU_CLOCK_HOST]) |
1288 | d5d08334 | balrog | return;
|
1289 | efe75411 | ths | |
1290 | 2e70f6ef | pbrook | nearest_delta_us = qemu_next_deadline_dyntick(); |
1291 | efe75411 | ths | |
1292 | efe75411 | ths | /* check whether a timer is already running */
|
1293 | efe75411 | ths | if (timer_gettime(host_timer, &timeout)) {
|
1294 | efe75411 | ths | perror("gettime");
|
1295 | efe75411 | ths | fprintf(stderr, "Internal timer error: aborting\n");
|
1296 | efe75411 | ths | exit(1);
|
1297 | efe75411 | ths | } |
1298 | efe75411 | ths | current_us = timeout.it_value.tv_sec * 1000000 + timeout.it_value.tv_nsec/1000; |
1299 | efe75411 | ths | if (current_us && current_us <= nearest_delta_us)
|
1300 | efe75411 | ths | return;
|
1301 | efe75411 | ths | |
1302 | efe75411 | ths | timeout.it_interval.tv_sec = 0;
|
1303 | efe75411 | ths | timeout.it_interval.tv_nsec = 0; /* 0 for one-shot timer */ |
1304 | efe75411 | ths | timeout.it_value.tv_sec = nearest_delta_us / 1000000;
|
1305 | efe75411 | ths | timeout.it_value.tv_nsec = (nearest_delta_us % 1000000) * 1000; |
1306 | efe75411 | ths | if (timer_settime(host_timer, 0 /* RELATIVE */, &timeout, NULL)) { |
1307 | efe75411 | ths | perror("settime");
|
1308 | efe75411 | ths | fprintf(stderr, "Internal timer error: aborting\n");
|
1309 | efe75411 | ths | exit(1);
|
1310 | efe75411 | ths | } |
1311 | efe75411 | ths | } |
1312 | efe75411 | ths | |
1313 | 70744b3a | ths | #endif /* defined(__linux__) */ |
1314 | 231c6586 | ths | |
1315 | c8994013 | ths | static int unix_start_timer(struct qemu_alarm_timer *t) |
1316 | c8994013 | ths | { |
1317 | c8994013 | ths | struct sigaction act;
|
1318 | c8994013 | ths | struct itimerval itv;
|
1319 | c8994013 | ths | int err;
|
1320 | c8994013 | ths | |
1321 | c8994013 | ths | /* timer signal */
|
1322 | c8994013 | ths | sigfillset(&act.sa_mask); |
1323 | c8994013 | ths | act.sa_flags = 0;
|
1324 | c8994013 | ths | act.sa_handler = host_alarm_handler; |
1325 | c8994013 | ths | |
1326 | c8994013 | ths | sigaction(SIGALRM, &act, NULL);
|
1327 | c8994013 | ths | |
1328 | c8994013 | ths | itv.it_interval.tv_sec = 0;
|
1329 | c8994013 | ths | /* for i386 kernel 2.6 to get 1 ms */
|
1330 | c8994013 | ths | itv.it_interval.tv_usec = 999;
|
1331 | c8994013 | ths | itv.it_value.tv_sec = 0;
|
1332 | c8994013 | ths | itv.it_value.tv_usec = 10 * 1000; |
1333 | c8994013 | ths | |
1334 | c8994013 | ths | err = setitimer(ITIMER_REAL, &itv, NULL);
|
1335 | c8994013 | ths | if (err)
|
1336 | c8994013 | ths | return -1; |
1337 | c8994013 | ths | |
1338 | c8994013 | ths | return 0; |
1339 | c8994013 | ths | } |
1340 | c8994013 | ths | |
1341 | c8994013 | ths | static void unix_stop_timer(struct qemu_alarm_timer *t) |
1342 | c8994013 | ths | { |
1343 | c8994013 | ths | struct itimerval itv;
|
1344 | c8994013 | ths | |
1345 | c8994013 | ths | memset(&itv, 0, sizeof(itv)); |
1346 | c8994013 | ths | setitimer(ITIMER_REAL, &itv, NULL);
|
1347 | c8994013 | ths | } |
1348 | c8994013 | ths | |
1349 | 829309c7 | bellard | #endif /* !defined(_WIN32) */ |
1350 | fd872598 | bellard | |
1351 | f49e58dc | aliguori | |
1352 | c8994013 | ths | #ifdef _WIN32
|
1353 | c8994013 | ths | |
1354 | c8994013 | ths | static int win32_start_timer(struct qemu_alarm_timer *t) |
1355 | c8994013 | ths | { |
1356 | c8994013 | ths | TIMECAPS tc; |
1357 | c8994013 | ths | struct qemu_alarm_win32 *data = t->priv;
|
1358 | efe75411 | ths | UINT flags; |
1359 | c8994013 | ths | |
1360 | c8994013 | ths | memset(&tc, 0, sizeof(tc)); |
1361 | c8994013 | ths | timeGetDevCaps(&tc, sizeof(tc));
|
1362 | c8994013 | ths | |
1363 | c8994013 | ths | if (data->period < tc.wPeriodMin)
|
1364 | c8994013 | ths | data->period = tc.wPeriodMin; |
1365 | c8994013 | ths | |
1366 | c8994013 | ths | timeBeginPeriod(data->period); |
1367 | c8994013 | ths | |
1368 | efe75411 | ths | flags = TIME_CALLBACK_FUNCTION; |
1369 | efe75411 | ths | if (alarm_has_dynticks(t))
|
1370 | efe75411 | ths | flags |= TIME_ONESHOT; |
1371 | efe75411 | ths | else
|
1372 | efe75411 | ths | flags |= TIME_PERIODIC; |
1373 | efe75411 | ths | |
1374 | c8994013 | ths | data->timerId = timeSetEvent(1, // interval (ms) |
1375 | c8994013 | ths | data->period, // resolution
|
1376 | c8994013 | ths | host_alarm_handler, // function
|
1377 | c8994013 | ths | (DWORD)t, // parameter
|
1378 | efe75411 | ths | flags); |
1379 | c8994013 | ths | |
1380 | c8994013 | ths | if (!data->timerId) {
|
1381 | 20889d4e | Blue Swirl | fprintf(stderr, "Failed to initialize win32 alarm timer: %ld\n",
|
1382 | 705e83f6 | malc | GetLastError()); |
1383 | c8994013 | ths | timeEndPeriod(data->period); |
1384 | c8994013 | ths | return -1; |
1385 | c8994013 | ths | } |
1386 | c8994013 | ths | |
1387 | c8994013 | ths | return 0; |
1388 | c8994013 | ths | } |
1389 | c8994013 | ths | |
1390 | c8994013 | ths | static void win32_stop_timer(struct qemu_alarm_timer *t) |
1391 | c8994013 | ths | { |
1392 | c8994013 | ths | struct qemu_alarm_win32 *data = t->priv;
|
1393 | c8994013 | ths | |
1394 | c8994013 | ths | timeKillEvent(data->timerId); |
1395 | c8994013 | ths | timeEndPeriod(data->period); |
1396 | c8994013 | ths | } |
1397 | c8994013 | ths | |
1398 | efe75411 | ths | static void win32_rearm_timer(struct qemu_alarm_timer *t) |
1399 | efe75411 | ths | { |
1400 | efe75411 | ths | struct qemu_alarm_win32 *data = t->priv;
|
1401 | efe75411 | ths | |
1402 | 0fdddf80 | Jan Kiszka | if (!active_timers[QEMU_CLOCK_REALTIME] &&
|
1403 | 21d5d12b | Jan Kiszka | !active_timers[QEMU_CLOCK_VIRTUAL] && |
1404 | 21d5d12b | Jan Kiszka | !active_timers[QEMU_CLOCK_HOST]) |
1405 | d5d08334 | balrog | return;
|
1406 | efe75411 | ths | |
1407 | efe75411 | ths | timeKillEvent(data->timerId); |
1408 | efe75411 | ths | |
1409 | efe75411 | ths | data->timerId = timeSetEvent(1,
|
1410 | efe75411 | ths | data->period, |
1411 | efe75411 | ths | host_alarm_handler, |
1412 | efe75411 | ths | (DWORD)t, |
1413 | efe75411 | ths | TIME_ONESHOT | TIME_PERIODIC); |
1414 | efe75411 | ths | |
1415 | efe75411 | ths | if (!data->timerId) {
|
1416 | 20889d4e | Blue Swirl | fprintf(stderr, "Failed to re-arm win32 alarm timer %ld\n",
|
1417 | 705e83f6 | malc | GetLastError()); |
1418 | efe75411 | ths | |
1419 | efe75411 | ths | timeEndPeriod(data->period); |
1420 | efe75411 | ths | exit(1);
|
1421 | efe75411 | ths | } |
1422 | efe75411 | ths | } |
1423 | efe75411 | ths | |
1424 | c8994013 | ths | #endif /* _WIN32 */ |
1425 | c8994013 | ths | |
1426 | 7183b4b4 | aliguori | static int init_timer_alarm(void) |
1427 | 8a7ddc38 | bellard | { |
1428 | 223f0d72 | blueswir1 | struct qemu_alarm_timer *t = NULL; |
1429 | c8994013 | ths | int i, err = -1; |
1430 | f49e58dc | aliguori | |
1431 | c8994013 | ths | for (i = 0; alarm_timers[i].name; i++) { |
1432 | c8994013 | ths | t = &alarm_timers[i]; |
1433 | c8994013 | ths | |
1434 | c8994013 | ths | err = t->start(t); |
1435 | c8994013 | ths | if (!err)
|
1436 | c8994013 | ths | break;
|
1437 | 67b915a5 | bellard | } |
1438 | fd872598 | bellard | |
1439 | c8994013 | ths | if (err) {
|
1440 | 7183b4b4 | aliguori | err = -ENOENT; |
1441 | 7183b4b4 | aliguori | goto fail;
|
1442 | 67b915a5 | bellard | } |
1443 | c8994013 | ths | |
1444 | c8994013 | ths | alarm_timer = t; |
1445 | 7183b4b4 | aliguori | |
1446 | 6abfbd79 | aliguori | return 0; |
1447 | 7183b4b4 | aliguori | |
1448 | 7183b4b4 | aliguori | fail:
|
1449 | 7183b4b4 | aliguori | return err;
|
1450 | 8a7ddc38 | bellard | } |
1451 | 8a7ddc38 | bellard | |
1452 | 9596ebb7 | pbrook | static void quit_timers(void) |
1453 | 40c3bac3 | bellard | { |
1454 | c8994013 | ths | alarm_timer->stop(alarm_timer); |
1455 | c8994013 | ths | alarm_timer = NULL;
|
1456 | 40c3bac3 | bellard | } |
1457 | 40c3bac3 | bellard | |
1458 | c4b1fcc0 | bellard | /***********************************************************/
|
1459 | f6503059 | balrog | /* host time/date access */
|
1460 | f6503059 | balrog | void qemu_get_timedate(struct tm *tm, int offset) |
1461 | f6503059 | balrog | { |
1462 | f6503059 | balrog | time_t ti; |
1463 | f6503059 | balrog | struct tm *ret;
|
1464 | f6503059 | balrog | |
1465 | f6503059 | balrog | time(&ti); |
1466 | f6503059 | balrog | ti += offset; |
1467 | f6503059 | balrog | if (rtc_date_offset == -1) { |
1468 | f6503059 | balrog | if (rtc_utc)
|
1469 | f6503059 | balrog | ret = gmtime(&ti); |
1470 | f6503059 | balrog | else
|
1471 | f6503059 | balrog | ret = localtime(&ti); |
1472 | f6503059 | balrog | } else {
|
1473 | f6503059 | balrog | ti -= rtc_date_offset; |
1474 | f6503059 | balrog | ret = gmtime(&ti); |
1475 | f6503059 | balrog | } |
1476 | f6503059 | balrog | |
1477 | f6503059 | balrog | memcpy(tm, ret, sizeof(struct tm)); |
1478 | f6503059 | balrog | } |
1479 | f6503059 | balrog | |
1480 | f6503059 | balrog | int qemu_timedate_diff(struct tm *tm) |
1481 | f6503059 | balrog | { |
1482 | f6503059 | balrog | time_t seconds; |
1483 | f6503059 | balrog | |
1484 | f6503059 | balrog | if (rtc_date_offset == -1) |
1485 | f6503059 | balrog | if (rtc_utc)
|
1486 | f6503059 | balrog | seconds = mktimegm(tm); |
1487 | f6503059 | balrog | else
|
1488 | f6503059 | balrog | seconds = mktime(tm); |
1489 | f6503059 | balrog | else
|
1490 | f6503059 | balrog | seconds = mktimegm(tm) + rtc_date_offset; |
1491 | f6503059 | balrog | |
1492 | f6503059 | balrog | return seconds - time(NULL); |
1493 | f6503059 | balrog | } |
1494 | f6503059 | balrog | |
1495 | 80cd3478 | Luiz Capitulino | void rtc_change_mon_event(struct tm *tm) |
1496 | 80cd3478 | Luiz Capitulino | { |
1497 | 80cd3478 | Luiz Capitulino | QObject *data; |
1498 | 80cd3478 | Luiz Capitulino | |
1499 | 80cd3478 | Luiz Capitulino | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm));
|
1500 | 80cd3478 | Luiz Capitulino | monitor_protocol_event(QEVENT_RTC_CHANGE, data); |
1501 | 80cd3478 | Luiz Capitulino | qobject_decref(data); |
1502 | 80cd3478 | Luiz Capitulino | } |
1503 | 80cd3478 | Luiz Capitulino | |
1504 | 1ed2fc1f | Jan Kiszka | static void configure_rtc_date_offset(const char *startdate, int legacy) |
1505 | 1ed2fc1f | Jan Kiszka | { |
1506 | 1ed2fc1f | Jan Kiszka | time_t rtc_start_date; |
1507 | 1ed2fc1f | Jan Kiszka | struct tm tm;
|
1508 | 1ed2fc1f | Jan Kiszka | |
1509 | 1ed2fc1f | Jan Kiszka | if (!strcmp(startdate, "now") && legacy) { |
1510 | 1ed2fc1f | Jan Kiszka | rtc_date_offset = -1;
|
1511 | 1ed2fc1f | Jan Kiszka | } else {
|
1512 | 1ed2fc1f | Jan Kiszka | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", |
1513 | 1ed2fc1f | Jan Kiszka | &tm.tm_year, |
1514 | 1ed2fc1f | Jan Kiszka | &tm.tm_mon, |
1515 | 1ed2fc1f | Jan Kiszka | &tm.tm_mday, |
1516 | 1ed2fc1f | Jan Kiszka | &tm.tm_hour, |
1517 | 1ed2fc1f | Jan Kiszka | &tm.tm_min, |
1518 | 1ed2fc1f | Jan Kiszka | &tm.tm_sec) == 6) {
|
1519 | 1ed2fc1f | Jan Kiszka | /* OK */
|
1520 | 1ed2fc1f | Jan Kiszka | } else if (sscanf(startdate, "%d-%d-%d", |
1521 | 1ed2fc1f | Jan Kiszka | &tm.tm_year, |
1522 | 1ed2fc1f | Jan Kiszka | &tm.tm_mon, |
1523 | 1ed2fc1f | Jan Kiszka | &tm.tm_mday) == 3) {
|
1524 | 1ed2fc1f | Jan Kiszka | tm.tm_hour = 0;
|
1525 | 1ed2fc1f | Jan Kiszka | tm.tm_min = 0;
|
1526 | 1ed2fc1f | Jan Kiszka | tm.tm_sec = 0;
|
1527 | 1ed2fc1f | Jan Kiszka | } else {
|
1528 | 1ed2fc1f | Jan Kiszka | goto date_fail;
|
1529 | 1ed2fc1f | Jan Kiszka | } |
1530 | 1ed2fc1f | Jan Kiszka | tm.tm_year -= 1900;
|
1531 | 1ed2fc1f | Jan Kiszka | tm.tm_mon--; |
1532 | 1ed2fc1f | Jan Kiszka | rtc_start_date = mktimegm(&tm); |
1533 | 1ed2fc1f | Jan Kiszka | if (rtc_start_date == -1) { |
1534 | 1ed2fc1f | Jan Kiszka | date_fail:
|
1535 | 1ed2fc1f | Jan Kiszka | fprintf(stderr, "Invalid date format. Valid formats are:\n"
|
1536 | 1ed2fc1f | Jan Kiszka | "'2006-06-17T16:01:21' or '2006-06-17'\n");
|
1537 | 1ed2fc1f | Jan Kiszka | exit(1);
|
1538 | 1ed2fc1f | Jan Kiszka | } |
1539 | 1ed2fc1f | Jan Kiszka | rtc_date_offset = time(NULL) - rtc_start_date;
|
1540 | 1ed2fc1f | Jan Kiszka | } |
1541 | 1ed2fc1f | Jan Kiszka | } |
1542 | 1ed2fc1f | Jan Kiszka | |
1543 | 1ed2fc1f | Jan Kiszka | static void configure_rtc(QemuOpts *opts) |
1544 | 1ed2fc1f | Jan Kiszka | { |
1545 | 1ed2fc1f | Jan Kiszka | const char *value; |
1546 | 1ed2fc1f | Jan Kiszka | |
1547 | 1ed2fc1f | Jan Kiszka | value = qemu_opt_get(opts, "base");
|
1548 | 1ed2fc1f | Jan Kiszka | if (value) {
|
1549 | 1ed2fc1f | Jan Kiszka | if (!strcmp(value, "utc")) { |
1550 | 1ed2fc1f | Jan Kiszka | rtc_utc = 1;
|
1551 | 1ed2fc1f | Jan Kiszka | } else if (!strcmp(value, "localtime")) { |
1552 | 1ed2fc1f | Jan Kiszka | rtc_utc = 0;
|
1553 | 1ed2fc1f | Jan Kiszka | } else {
|
1554 | 1ed2fc1f | Jan Kiszka | configure_rtc_date_offset(value, 0);
|
1555 | 1ed2fc1f | Jan Kiszka | } |
1556 | 1ed2fc1f | Jan Kiszka | } |
1557 | 6875204c | Jan Kiszka | value = qemu_opt_get(opts, "clock");
|
1558 | 6875204c | Jan Kiszka | if (value) {
|
1559 | 6875204c | Jan Kiszka | if (!strcmp(value, "host")) { |
1560 | 6875204c | Jan Kiszka | rtc_clock = host_clock; |
1561 | 6875204c | Jan Kiszka | } else if (!strcmp(value, "vm")) { |
1562 | 6875204c | Jan Kiszka | rtc_clock = vm_clock; |
1563 | 6875204c | Jan Kiszka | } else {
|
1564 | 6875204c | Jan Kiszka | fprintf(stderr, "qemu: invalid option value '%s'\n", value);
|
1565 | 6875204c | Jan Kiszka | exit(1);
|
1566 | 6875204c | Jan Kiszka | } |
1567 | 6875204c | Jan Kiszka | } |
1568 | 1ed2fc1f | Jan Kiszka | #ifdef CONFIG_TARGET_I386
|
1569 | 1ed2fc1f | Jan Kiszka | value = qemu_opt_get(opts, "driftfix");
|
1570 | 1ed2fc1f | Jan Kiszka | if (value) {
|
1571 | 1ed2fc1f | Jan Kiszka | if (!strcmp(buf, "slew")) { |
1572 | 1ed2fc1f | Jan Kiszka | rtc_td_hack = 1;
|
1573 | 1ed2fc1f | Jan Kiszka | } else if (!strcmp(buf, "none")) { |
1574 | 1ed2fc1f | Jan Kiszka | rtc_td_hack = 0;
|
1575 | 1ed2fc1f | Jan Kiszka | } else {
|
1576 | 1ed2fc1f | Jan Kiszka | fprintf(stderr, "qemu: invalid option value '%s'\n", value);
|
1577 | 1ed2fc1f | Jan Kiszka | exit(1);
|
1578 | 1ed2fc1f | Jan Kiszka | } |
1579 | 1ed2fc1f | Jan Kiszka | } |
1580 | 1ed2fc1f | Jan Kiszka | #endif
|
1581 | 1ed2fc1f | Jan Kiszka | } |
1582 | 1ed2fc1f | Jan Kiszka | |
1583 | fd1dff4b | bellard | #ifdef _WIN32
|
1584 | fd1dff4b | bellard | static void socket_cleanup(void) |
1585 | fd1dff4b | bellard | { |
1586 | fd1dff4b | bellard | WSACleanup(); |
1587 | fd1dff4b | bellard | } |
1588 | 82c643ff | bellard | |
1589 | fd1dff4b | bellard | static int socket_init(void) |
1590 | fd1dff4b | bellard | { |
1591 | fd1dff4b | bellard | WSADATA Data; |
1592 | fd1dff4b | bellard | int ret, err;
|
1593 | fd1dff4b | bellard | |
1594 | fd1dff4b | bellard | ret = WSAStartup(MAKEWORD(2,2), &Data); |
1595 | fd1dff4b | bellard | if (ret != 0) { |
1596 | fd1dff4b | bellard | err = WSAGetLastError(); |
1597 | fd1dff4b | bellard | fprintf(stderr, "WSAStartup: %d\n", err);
|
1598 | fd1dff4b | bellard | return -1; |
1599 | fd1dff4b | bellard | } |
1600 | fd1dff4b | bellard | atexit(socket_cleanup); |
1601 | fd1dff4b | bellard | return 0; |
1602 | fd1dff4b | bellard | } |
1603 | 64b7b733 | aurel32 | #endif
|
1604 | 64b7b733 | aurel32 | |
1605 | 1ae26a18 | balrog | /***********************************************************/
|
1606 | 1ae26a18 | balrog | /* Bluetooth support */
|
1607 | 1ae26a18 | balrog | static int nb_hcis; |
1608 | 1ae26a18 | balrog | static int cur_hci; |
1609 | 1ae26a18 | balrog | static struct HCIInfo *hci_table[MAX_NICS]; |
1610 | dc72ac14 | balrog | |
1611 | 1ae26a18 | balrog | static struct bt_vlan_s { |
1612 | 1ae26a18 | balrog | struct bt_scatternet_s net;
|
1613 | 1ae26a18 | balrog | int id;
|
1614 | 1ae26a18 | balrog | struct bt_vlan_s *next;
|
1615 | 1ae26a18 | balrog | } *first_bt_vlan; |
1616 | 1ae26a18 | balrog | |
1617 | 1ae26a18 | balrog | /* find or alloc a new bluetooth "VLAN" */
|
1618 | 674bb261 | blueswir1 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
1619 | 1ae26a18 | balrog | { |
1620 | 1ae26a18 | balrog | struct bt_vlan_s **pvlan, *vlan;
|
1621 | 1ae26a18 | balrog | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { |
1622 | 1ae26a18 | balrog | if (vlan->id == id)
|
1623 | 1ae26a18 | balrog | return &vlan->net;
|
1624 | 1ae26a18 | balrog | } |
1625 | 1ae26a18 | balrog | vlan = qemu_mallocz(sizeof(struct bt_vlan_s)); |
1626 | 1ae26a18 | balrog | vlan->id = id; |
1627 | 1ae26a18 | balrog | pvlan = &first_bt_vlan; |
1628 | 1ae26a18 | balrog | while (*pvlan != NULL) |
1629 | 1ae26a18 | balrog | pvlan = &(*pvlan)->next; |
1630 | 1ae26a18 | balrog | *pvlan = vlan; |
1631 | 1ae26a18 | balrog | return &vlan->net;
|
1632 | 1ae26a18 | balrog | } |
1633 | 1ae26a18 | balrog | |
1634 | 1ae26a18 | balrog | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) |
1635 | 1ae26a18 | balrog | { |
1636 | 1ae26a18 | balrog | } |
1637 | 1ae26a18 | balrog | |
1638 | 1ae26a18 | balrog | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) |
1639 | 1ae26a18 | balrog | { |
1640 | 1ae26a18 | balrog | return -ENOTSUP;
|
1641 | 1ae26a18 | balrog | } |
1642 | 1ae26a18 | balrog | |
1643 | 1ae26a18 | balrog | static struct HCIInfo null_hci = { |
1644 | 1ae26a18 | balrog | .cmd_send = null_hci_send, |
1645 | 1ae26a18 | balrog | .sco_send = null_hci_send, |
1646 | 1ae26a18 | balrog | .acl_send = null_hci_send, |
1647 | 1ae26a18 | balrog | .bdaddr_set = null_hci_addr_set, |
1648 | 1ae26a18 | balrog | }; |
1649 | 1ae26a18 | balrog | |
1650 | 1ae26a18 | balrog | struct HCIInfo *qemu_next_hci(void) |
1651 | 1ae26a18 | balrog | { |
1652 | 1ae26a18 | balrog | if (cur_hci == nb_hcis)
|
1653 | 1ae26a18 | balrog | return &null_hci;
|
1654 | 1ae26a18 | balrog | |
1655 | 1ae26a18 | balrog | return hci_table[cur_hci++];
|
1656 | 1ae26a18 | balrog | } |
1657 | 1ae26a18 | balrog | |
1658 | dc72ac14 | balrog | static struct HCIInfo *hci_init(const char *str) |
1659 | dc72ac14 | balrog | { |
1660 | dc72ac14 | balrog | char *endp;
|
1661 | dc72ac14 | balrog | struct bt_scatternet_s *vlan = 0; |
1662 | dc72ac14 | balrog | |
1663 | dc72ac14 | balrog | if (!strcmp(str, "null")) |
1664 | dc72ac14 | balrog | /* null */
|
1665 | dc72ac14 | balrog | return &null_hci;
|
1666 | dc72ac14 | balrog | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) |
1667 | dc72ac14 | balrog | /* host[:hciN] */
|
1668 | dc72ac14 | balrog | return bt_host_hci(str[4] ? str + 5 : "hci0"); |
1669 | dc72ac14 | balrog | else if (!strncmp(str, "hci", 3)) { |
1670 | dc72ac14 | balrog | /* hci[,vlan=n] */
|
1671 | dc72ac14 | balrog | if (str[3]) { |
1672 | dc72ac14 | balrog | if (!strncmp(str + 3, ",vlan=", 6)) { |
1673 | dc72ac14 | balrog | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); |
1674 | dc72ac14 | balrog | if (*endp)
|
1675 | dc72ac14 | balrog | vlan = 0;
|
1676 | dc72ac14 | balrog | } |
1677 | dc72ac14 | balrog | } else
|
1678 | dc72ac14 | balrog | vlan = qemu_find_bt_vlan(0);
|
1679 | dc72ac14 | balrog | if (vlan)
|
1680 | dc72ac14 | balrog | return bt_new_hci(vlan);
|
1681 | dc72ac14 | balrog | } |
1682 | dc72ac14 | balrog | |
1683 | dc72ac14 | balrog | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
|
1684 | dc72ac14 | balrog | |
1685 | dc72ac14 | balrog | return 0; |
1686 | dc72ac14 | balrog | } |
1687 | dc72ac14 | balrog | |
1688 | dc72ac14 | balrog | static int bt_hci_parse(const char *str) |
1689 | dc72ac14 | balrog | { |
1690 | dc72ac14 | balrog | struct HCIInfo *hci;
|
1691 | c227f099 | Anthony Liguori | bdaddr_t bdaddr; |
1692 | dc72ac14 | balrog | |
1693 | dc72ac14 | balrog | if (nb_hcis >= MAX_NICS) {
|
1694 | dc72ac14 | balrog | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
|
1695 | dc72ac14 | balrog | return -1; |
1696 | dc72ac14 | balrog | } |
1697 | dc72ac14 | balrog | |
1698 | dc72ac14 | balrog | hci = hci_init(str); |
1699 | dc72ac14 | balrog | if (!hci)
|
1700 | dc72ac14 | balrog | return -1; |
1701 | dc72ac14 | balrog | |
1702 | dc72ac14 | balrog | bdaddr.b[0] = 0x52; |
1703 | dc72ac14 | balrog | bdaddr.b[1] = 0x54; |
1704 | dc72ac14 | balrog | bdaddr.b[2] = 0x00; |
1705 | dc72ac14 | balrog | bdaddr.b[3] = 0x12; |
1706 | dc72ac14 | balrog | bdaddr.b[4] = 0x34; |
1707 | dc72ac14 | balrog | bdaddr.b[5] = 0x56 + nb_hcis; |
1708 | dc72ac14 | balrog | hci->bdaddr_set(hci, bdaddr.b); |
1709 | dc72ac14 | balrog | |
1710 | dc72ac14 | balrog | hci_table[nb_hcis++] = hci; |
1711 | dc72ac14 | balrog | |
1712 | dc72ac14 | balrog | return 0; |
1713 | dc72ac14 | balrog | } |
1714 | dc72ac14 | balrog | |
1715 | dc72ac14 | balrog | static void bt_vhci_add(int vlan_id) |
1716 | dc72ac14 | balrog | { |
1717 | dc72ac14 | balrog | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
|
1718 | dc72ac14 | balrog | |
1719 | dc72ac14 | balrog | if (!vlan->slave)
|
1720 | dc72ac14 | balrog | fprintf(stderr, "qemu: warning: adding a VHCI to "
|
1721 | dc72ac14 | balrog | "an empty scatternet %i\n", vlan_id);
|
1722 | dc72ac14 | balrog | |
1723 | dc72ac14 | balrog | bt_vhci_init(bt_new_hci(vlan)); |
1724 | dc72ac14 | balrog | } |
1725 | dc72ac14 | balrog | |
1726 | dc72ac14 | balrog | static struct bt_device_s *bt_device_add(const char *opt) |
1727 | dc72ac14 | balrog | { |
1728 | dc72ac14 | balrog | struct bt_scatternet_s *vlan;
|
1729 | dc72ac14 | balrog | int vlan_id = 0; |
1730 | dc72ac14 | balrog | char *endp = strstr(opt, ",vlan="); |
1731 | dc72ac14 | balrog | int len = (endp ? endp - opt : strlen(opt)) + 1; |
1732 | dc72ac14 | balrog | char devname[10]; |
1733 | dc72ac14 | balrog | |
1734 | dc72ac14 | balrog | pstrcpy(devname, MIN(sizeof(devname), len), opt);
|
1735 | dc72ac14 | balrog | |
1736 | dc72ac14 | balrog | if (endp) {
|
1737 | dc72ac14 | balrog | vlan_id = strtol(endp + 6, &endp, 0); |
1738 | dc72ac14 | balrog | if (*endp) {
|
1739 | dc72ac14 | balrog | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
|
1740 | dc72ac14 | balrog | return 0; |
1741 | dc72ac14 | balrog | } |
1742 | dc72ac14 | balrog | } |
1743 | dc72ac14 | balrog | |
1744 | dc72ac14 | balrog | vlan = qemu_find_bt_vlan(vlan_id); |
1745 | dc72ac14 | balrog | |
1746 | dc72ac14 | balrog | if (!vlan->slave)
|
1747 | dc72ac14 | balrog | fprintf(stderr, "qemu: warning: adding a slave device to "
|
1748 | dc72ac14 | balrog | "an empty scatternet %i\n", vlan_id);
|
1749 | dc72ac14 | balrog | |
1750 | dc72ac14 | balrog | if (!strcmp(devname, "keyboard")) |
1751 | dc72ac14 | balrog | return bt_keyboard_init(vlan);
|
1752 | dc72ac14 | balrog | |
1753 | dc72ac14 | balrog | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
|
1754 | dc72ac14 | balrog | return 0; |
1755 | dc72ac14 | balrog | } |
1756 | dc72ac14 | balrog | |
1757 | dc72ac14 | balrog | static int bt_parse(const char *opt) |
1758 | dc72ac14 | balrog | { |
1759 | dc72ac14 | balrog | const char *endp, *p; |
1760 | dc72ac14 | balrog | int vlan;
|
1761 | dc72ac14 | balrog | |
1762 | dc72ac14 | balrog | if (strstart(opt, "hci", &endp)) { |
1763 | dc72ac14 | balrog | if (!*endp || *endp == ',') { |
1764 | dc72ac14 | balrog | if (*endp)
|
1765 | dc72ac14 | balrog | if (!strstart(endp, ",vlan=", 0)) |
1766 | dc72ac14 | balrog | opt = endp + 1;
|
1767 | dc72ac14 | balrog | |
1768 | dc72ac14 | balrog | return bt_hci_parse(opt);
|
1769 | dc72ac14 | balrog | } |
1770 | dc72ac14 | balrog | } else if (strstart(opt, "vhci", &endp)) { |
1771 | dc72ac14 | balrog | if (!*endp || *endp == ',') { |
1772 | dc72ac14 | balrog | if (*endp) {
|
1773 | dc72ac14 | balrog | if (strstart(endp, ",vlan=", &p)) { |
1774 | dc72ac14 | balrog | vlan = strtol(p, (char **) &endp, 0); |
1775 | dc72ac14 | balrog | if (*endp) {
|
1776 | dc72ac14 | balrog | fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
|
1777 | dc72ac14 | balrog | return 1; |
1778 | dc72ac14 | balrog | } |
1779 | dc72ac14 | balrog | } else {
|
1780 | dc72ac14 | balrog | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); |
1781 | dc72ac14 | balrog | return 1; |
1782 | dc72ac14 | balrog | } |
1783 | dc72ac14 | balrog | } else
|
1784 | dc72ac14 | balrog | vlan = 0;
|
1785 | dc72ac14 | balrog | |
1786 | dc72ac14 | balrog | bt_vhci_add(vlan); |
1787 | dc72ac14 | balrog | return 0; |
1788 | dc72ac14 | balrog | } |
1789 | dc72ac14 | balrog | } else if (strstart(opt, "device:", &endp)) |
1790 | dc72ac14 | balrog | return !bt_device_add(endp);
|
1791 | dc72ac14 | balrog | |
1792 | dc72ac14 | balrog | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
|
1793 | dc72ac14 | balrog | return 1; |
1794 | dc72ac14 | balrog | } |
1795 | dc72ac14 | balrog | |
1796 | 1ae26a18 | balrog | /***********************************************************/
|
1797 | 1ae26a18 | balrog | /* QEMU Block devices */
|
1798 | 1ae26a18 | balrog | |
1799 | 609497ab | balrog | #define HD_ALIAS "index=%d,media=disk" |
1800 | e4bcb14c | ths | #define CDROM_ALIAS "index=2,media=cdrom" |
1801 | e4bcb14c | ths | #define FD_ALIAS "index=%d,if=floppy" |
1802 | 609497ab | balrog | #define PFLASH_ALIAS "if=pflash" |
1803 | 609497ab | balrog | #define MTD_ALIAS "if=mtd" |
1804 | 9d413d1d | balrog | #define SD_ALIAS "index=0,if=sd" |
1805 | e4bcb14c | ths | |
1806 | 9dfd7c7a | Gerd Hoffmann | QemuOpts *drive_add(const char *file, const char *fmt, ...) |
1807 | e4bcb14c | ths | { |
1808 | e4bcb14c | ths | va_list ap; |
1809 | 9dfd7c7a | Gerd Hoffmann | char optstr[1024]; |
1810 | 9dfd7c7a | Gerd Hoffmann | QemuOpts *opts; |
1811 | e4bcb14c | ths | |
1812 | e4bcb14c | ths | va_start(ap, fmt); |
1813 | 9dfd7c7a | Gerd Hoffmann | vsnprintf(optstr, sizeof(optstr), fmt, ap);
|
1814 | e4bcb14c | ths | va_end(ap); |
1815 | e4bcb14c | ths | |
1816 | 7282a033 | Gerd Hoffmann | opts = qemu_opts_parse(&qemu_drive_opts, optstr, NULL);
|
1817 | 9dfd7c7a | Gerd Hoffmann | if (!opts) {
|
1818 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "%s: huh? duplicate? (%s)\n",
|
1819 | 9dfd7c7a | Gerd Hoffmann | __FUNCTION__, optstr); |
1820 | 9dfd7c7a | Gerd Hoffmann | return NULL; |
1821 | 9dfd7c7a | Gerd Hoffmann | } |
1822 | 9dfd7c7a | Gerd Hoffmann | if (file)
|
1823 | 9dfd7c7a | Gerd Hoffmann | qemu_opt_set(opts, "file", file);
|
1824 | 9dfd7c7a | Gerd Hoffmann | return opts;
|
1825 | b01b1111 | aliguori | } |
1826 | b01b1111 | aliguori | |
1827 | 751c6a17 | Gerd Hoffmann | DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) |
1828 | e4bcb14c | ths | { |
1829 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
1830 | e4bcb14c | ths | |
1831 | e4bcb14c | ths | /* seek interface, bus and unit */
|
1832 | e4bcb14c | ths | |
1833 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(dinfo, &drives, next) { |
1834 | 751c6a17 | Gerd Hoffmann | if (dinfo->type == type &&
|
1835 | 751c6a17 | Gerd Hoffmann | dinfo->bus == bus && |
1836 | 751c6a17 | Gerd Hoffmann | dinfo->unit == unit) |
1837 | 751c6a17 | Gerd Hoffmann | return dinfo;
|
1838 | 751c6a17 | Gerd Hoffmann | } |
1839 | e4bcb14c | ths | |
1840 | 751c6a17 | Gerd Hoffmann | return NULL; |
1841 | e4bcb14c | ths | } |
1842 | e4bcb14c | ths | |
1843 | 2e810b36 | Gerd Hoffmann | DriveInfo *drive_get_by_id(const char *id) |
1844 | 1dae12e6 | Gerd Hoffmann | { |
1845 | 1dae12e6 | Gerd Hoffmann | DriveInfo *dinfo; |
1846 | 1dae12e6 | Gerd Hoffmann | |
1847 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(dinfo, &drives, next) { |
1848 | 1dae12e6 | Gerd Hoffmann | if (strcmp(id, dinfo->id))
|
1849 | 1dae12e6 | Gerd Hoffmann | continue;
|
1850 | 1dae12e6 | Gerd Hoffmann | return dinfo;
|
1851 | 1dae12e6 | Gerd Hoffmann | } |
1852 | 1dae12e6 | Gerd Hoffmann | return NULL; |
1853 | 1dae12e6 | Gerd Hoffmann | } |
1854 | 1dae12e6 | Gerd Hoffmann | |
1855 | f60d39bc | ths | int drive_get_max_bus(BlockInterfaceType type)
|
1856 | e4bcb14c | ths | { |
1857 | e4bcb14c | ths | int max_bus;
|
1858 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
1859 | e4bcb14c | ths | |
1860 | e4bcb14c | ths | max_bus = -1;
|
1861 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(dinfo, &drives, next) { |
1862 | 751c6a17 | Gerd Hoffmann | if(dinfo->type == type &&
|
1863 | 751c6a17 | Gerd Hoffmann | dinfo->bus > max_bus) |
1864 | 751c6a17 | Gerd Hoffmann | max_bus = dinfo->bus; |
1865 | e4bcb14c | ths | } |
1866 | e4bcb14c | ths | return max_bus;
|
1867 | e4bcb14c | ths | } |
1868 | e4bcb14c | ths | |
1869 | fa879c64 | aliguori | const char *drive_get_serial(BlockDriverState *bdrv) |
1870 | fa879c64 | aliguori | { |
1871 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
1872 | fa879c64 | aliguori | |
1873 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(dinfo, &drives, next) { |
1874 | 751c6a17 | Gerd Hoffmann | if (dinfo->bdrv == bdrv)
|
1875 | 751c6a17 | Gerd Hoffmann | return dinfo->serial;
|
1876 | 751c6a17 | Gerd Hoffmann | } |
1877 | fa879c64 | aliguori | |
1878 | fa879c64 | aliguori | return "\0"; |
1879 | fa879c64 | aliguori | } |
1880 | fa879c64 | aliguori | |
1881 | f7850099 | Kevin Wolf | BlockInterfaceErrorAction drive_get_on_error( |
1882 | f7850099 | Kevin Wolf | BlockDriverState *bdrv, int is_read)
|
1883 | 428c5705 | aliguori | { |
1884 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
1885 | 428c5705 | aliguori | |
1886 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(dinfo, &drives, next) { |
1887 | 751c6a17 | Gerd Hoffmann | if (dinfo->bdrv == bdrv)
|
1888 | e9b2e818 | Kevin Wolf | return is_read ? dinfo->on_read_error : dinfo->on_write_error;
|
1889 | 751c6a17 | Gerd Hoffmann | } |
1890 | 428c5705 | aliguori | |
1891 | e9b2e818 | Kevin Wolf | return is_read ? BLOCK_ERR_REPORT : BLOCK_ERR_STOP_ENOSPC;
|
1892 | 428c5705 | aliguori | } |
1893 | 428c5705 | aliguori | |
1894 | a1620fac | aurel32 | static void bdrv_format_print(void *opaque, const char *name) |
1895 | a1620fac | aurel32 | { |
1896 | a1620fac | aurel32 | fprintf(stderr, " %s", name);
|
1897 | a1620fac | aurel32 | } |
1898 | a1620fac | aurel32 | |
1899 | 56a14938 | Gerd Hoffmann | void drive_uninit(DriveInfo *dinfo)
|
1900 | b01b1111 | aliguori | { |
1901 | 56a14938 | Gerd Hoffmann | qemu_opts_del(dinfo->opts); |
1902 | 56a14938 | Gerd Hoffmann | bdrv_delete(dinfo->bdrv); |
1903 | 56a14938 | Gerd Hoffmann | QTAILQ_REMOVE(&drives, dinfo, next); |
1904 | 56a14938 | Gerd Hoffmann | qemu_free(dinfo); |
1905 | b01b1111 | aliguori | } |
1906 | b01b1111 | aliguori | |
1907 | e9b2e818 | Kevin Wolf | static int parse_block_error_action(const char *buf, int is_read) |
1908 | e9b2e818 | Kevin Wolf | { |
1909 | e9b2e818 | Kevin Wolf | if (!strcmp(buf, "ignore")) { |
1910 | e9b2e818 | Kevin Wolf | return BLOCK_ERR_IGNORE;
|
1911 | e9b2e818 | Kevin Wolf | } else if (!is_read && !strcmp(buf, "enospc")) { |
1912 | e9b2e818 | Kevin Wolf | return BLOCK_ERR_STOP_ENOSPC;
|
1913 | e9b2e818 | Kevin Wolf | } else if (!strcmp(buf, "stop")) { |
1914 | e9b2e818 | Kevin Wolf | return BLOCK_ERR_STOP_ANY;
|
1915 | e9b2e818 | Kevin Wolf | } else if (!strcmp(buf, "report")) { |
1916 | e9b2e818 | Kevin Wolf | return BLOCK_ERR_REPORT;
|
1917 | e9b2e818 | Kevin Wolf | } else {
|
1918 | e9b2e818 | Kevin Wolf | fprintf(stderr, "qemu: '%s' invalid %s error action\n",
|
1919 | e9b2e818 | Kevin Wolf | buf, is_read ? "read" : "write"); |
1920 | e9b2e818 | Kevin Wolf | return -1; |
1921 | e9b2e818 | Kevin Wolf | } |
1922 | e9b2e818 | Kevin Wolf | } |
1923 | e9b2e818 | Kevin Wolf | |
1924 | 9dfd7c7a | Gerd Hoffmann | DriveInfo *drive_init(QemuOpts *opts, void *opaque,
|
1925 | 751c6a17 | Gerd Hoffmann | int *fatal_error)
|
1926 | e4bcb14c | ths | { |
1927 | 9dfd7c7a | Gerd Hoffmann | const char *buf; |
1928 | 9dfd7c7a | Gerd Hoffmann | const char *file = NULL; |
1929 | c8522bdf | balrog | char devname[128]; |
1930 | 9dfd7c7a | Gerd Hoffmann | const char *serial; |
1931 | c8522bdf | balrog | const char *mediastr = ""; |
1932 | f60d39bc | ths | BlockInterfaceType type; |
1933 | e4bcb14c | ths | enum { MEDIA_DISK, MEDIA_CDROM } media;
|
1934 | e4bcb14c | ths | int bus_id, unit_id;
|
1935 | e4bcb14c | ths | int cyls, heads, secs, translation;
|
1936 | 1e72d3b7 | aurel32 | BlockDriver *drv = NULL;
|
1937 | 4d73cd3b | aliguori | QEMUMachine *machine = opaque; |
1938 | e4bcb14c | ths | int max_devs;
|
1939 | e4bcb14c | ths | int index;
|
1940 | 33f00271 | balrog | int cache;
|
1941 | 5c6c3a6c | Christoph Hellwig | int aio = 0; |
1942 | 59f2689d | Naphtali Sprei | int ro = 0; |
1943 | e9b2e818 | Kevin Wolf | int bdrv_flags;
|
1944 | e9b2e818 | Kevin Wolf | int on_read_error, on_write_error;
|
1945 | c2cc47a4 | Markus Armbruster | const char *devaddr; |
1946 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo; |
1947 | 9dfd7c7a | Gerd Hoffmann | int snapshot = 0; |
1948 | e4bcb14c | ths | |
1949 | 9dfd7c7a | Gerd Hoffmann | *fatal_error = 1;
|
1950 | e4bcb14c | ths | |
1951 | e4bcb14c | ths | translation = BIOS_ATA_TRANSLATION_AUTO; |
1952 | 0aa217e4 | Kevin Wolf | cache = 1;
|
1953 | e4bcb14c | ths | |
1954 | 4d007814 | Gerd Hoffmann | if (machine && machine->use_scsi) {
|
1955 | f60d39bc | ths | type = IF_SCSI; |
1956 | e4bcb14c | ths | max_devs = MAX_SCSI_DEVS; |
1957 | 363a37d5 | blueswir1 | pstrcpy(devname, sizeof(devname), "scsi"); |
1958 | e4bcb14c | ths | } else {
|
1959 | f60d39bc | ths | type = IF_IDE; |
1960 | e4bcb14c | ths | max_devs = MAX_IDE_DEVS; |
1961 | 363a37d5 | blueswir1 | pstrcpy(devname, sizeof(devname), "ide"); |
1962 | e4bcb14c | ths | } |
1963 | e4bcb14c | ths | media = MEDIA_DISK; |
1964 | e4bcb14c | ths | |
1965 | e4bcb14c | ths | /* extract parameters */
|
1966 | 9dfd7c7a | Gerd Hoffmann | bus_id = qemu_opt_get_number(opts, "bus", 0); |
1967 | 9dfd7c7a | Gerd Hoffmann | unit_id = qemu_opt_get_number(opts, "unit", -1); |
1968 | 9dfd7c7a | Gerd Hoffmann | index = qemu_opt_get_number(opts, "index", -1); |
1969 | e4bcb14c | ths | |
1970 | 9dfd7c7a | Gerd Hoffmann | cyls = qemu_opt_get_number(opts, "cyls", 0); |
1971 | 9dfd7c7a | Gerd Hoffmann | heads = qemu_opt_get_number(opts, "heads", 0); |
1972 | 9dfd7c7a | Gerd Hoffmann | secs = qemu_opt_get_number(opts, "secs", 0); |
1973 | e4bcb14c | ths | |
1974 | 9dfd7c7a | Gerd Hoffmann | snapshot = qemu_opt_get_bool(opts, "snapshot", 0); |
1975 | 59f2689d | Naphtali Sprei | ro = qemu_opt_get_bool(opts, "readonly", 0); |
1976 | e4bcb14c | ths | |
1977 | 9dfd7c7a | Gerd Hoffmann | file = qemu_opt_get(opts, "file");
|
1978 | 9dfd7c7a | Gerd Hoffmann | serial = qemu_opt_get(opts, "serial");
|
1979 | 9dfd7c7a | Gerd Hoffmann | |
1980 | 9dfd7c7a | Gerd Hoffmann | if ((buf = qemu_opt_get(opts, "if")) != NULL) { |
1981 | ae45d369 | bellard | pstrcpy(devname, sizeof(devname), buf);
|
1982 | e4bcb14c | ths | if (!strcmp(buf, "ide")) { |
1983 | f60d39bc | ths | type = IF_IDE; |
1984 | e4bcb14c | ths | max_devs = MAX_IDE_DEVS; |
1985 | e4bcb14c | ths | } else if (!strcmp(buf, "scsi")) { |
1986 | f60d39bc | ths | type = IF_SCSI; |
1987 | e4bcb14c | ths | max_devs = MAX_SCSI_DEVS; |
1988 | e4bcb14c | ths | } else if (!strcmp(buf, "floppy")) { |
1989 | f60d39bc | ths | type = IF_FLOPPY; |
1990 | e4bcb14c | ths | max_devs = 0;
|
1991 | e4bcb14c | ths | } else if (!strcmp(buf, "pflash")) { |
1992 | f60d39bc | ths | type = IF_PFLASH; |
1993 | e4bcb14c | ths | max_devs = 0;
|
1994 | e4bcb14c | ths | } else if (!strcmp(buf, "mtd")) { |
1995 | f60d39bc | ths | type = IF_MTD; |
1996 | e4bcb14c | ths | max_devs = 0;
|
1997 | e4bcb14c | ths | } else if (!strcmp(buf, "sd")) { |
1998 | f60d39bc | ths | type = IF_SD; |
1999 | e4bcb14c | ths | max_devs = 0;
|
2000 | 6e02c38d | aliguori | } else if (!strcmp(buf, "virtio")) { |
2001 | 6e02c38d | aliguori | type = IF_VIRTIO; |
2002 | 6e02c38d | aliguori | max_devs = 0;
|
2003 | 62d23efa | aliguori | } else if (!strcmp(buf, "xen")) { |
2004 | 62d23efa | aliguori | type = IF_XEN; |
2005 | 62d23efa | aliguori | max_devs = 0;
|
2006 | a8659e90 | Gerd Hoffmann | } else if (!strcmp(buf, "none")) { |
2007 | a8659e90 | Gerd Hoffmann | type = IF_NONE; |
2008 | a8659e90 | Gerd Hoffmann | max_devs = 0;
|
2009 | 62d23efa | aliguori | } else {
|
2010 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "qemu: unsupported bus type '%s'\n", buf);
|
2011 | 751c6a17 | Gerd Hoffmann | return NULL; |
2012 | e4bcb14c | ths | } |
2013 | e4bcb14c | ths | } |
2014 | e4bcb14c | ths | |
2015 | e4bcb14c | ths | if (cyls || heads || secs) {
|
2016 | 5afe3f04 | Blue Swirl | if (cyls < 1 || (type == IF_IDE && cyls > 16383)) { |
2017 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", buf);
|
2018 | 751c6a17 | Gerd Hoffmann | return NULL; |
2019 | e4bcb14c | ths | } |
2020 | 5afe3f04 | Blue Swirl | if (heads < 1 || (type == IF_IDE && heads > 16)) { |
2021 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "qemu: '%s' invalid physical heads number\n", buf);
|
2022 | 751c6a17 | Gerd Hoffmann | return NULL; |
2023 | e4bcb14c | ths | } |
2024 | 5afe3f04 | Blue Swirl | if (secs < 1 || (type == IF_IDE && secs > 63)) { |
2025 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "qemu: '%s' invalid physical secs number\n", buf);
|
2026 | 751c6a17 | Gerd Hoffmann | return NULL; |
2027 | e4bcb14c | ths | } |
2028 | e4bcb14c | ths | } |
2029 | e4bcb14c | ths | |
2030 | 9dfd7c7a | Gerd Hoffmann | if ((buf = qemu_opt_get(opts, "trans")) != NULL) { |
2031 | e4bcb14c | ths | if (!cyls) {
|
2032 | e4bcb14c | ths | fprintf(stderr, |
2033 | e4bcb14c | ths | "qemu: '%s' trans must be used with cyls,heads and secs\n",
|
2034 | 9dfd7c7a | Gerd Hoffmann | buf); |
2035 | 751c6a17 | Gerd Hoffmann | return NULL; |
2036 | e4bcb14c | ths | } |
2037 | e4bcb14c | ths | if (!strcmp(buf, "none")) |
2038 | e4bcb14c | ths | translation = BIOS_ATA_TRANSLATION_NONE; |
2039 | e4bcb14c | ths | else if (!strcmp(buf, "lba")) |
2040 | e4bcb14c | ths | translation = BIOS_ATA_TRANSLATION_LBA; |
2041 | e4bcb14c | ths | else if (!strcmp(buf, "auto")) |
2042 | e4bcb14c | ths | translation = BIOS_ATA_TRANSLATION_AUTO; |
2043 | e4bcb14c | ths | else {
|
2044 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "qemu: '%s' invalid translation type\n", buf);
|
2045 | 751c6a17 | Gerd Hoffmann | return NULL; |
2046 | e4bcb14c | ths | } |
2047 | e4bcb14c | ths | } |
2048 | e4bcb14c | ths | |
2049 | 9dfd7c7a | Gerd Hoffmann | if ((buf = qemu_opt_get(opts, "media")) != NULL) { |
2050 | e4bcb14c | ths | if (!strcmp(buf, "disk")) { |
2051 | e4bcb14c | ths | media = MEDIA_DISK; |
2052 | e4bcb14c | ths | } else if (!strcmp(buf, "cdrom")) { |
2053 | e4bcb14c | ths | if (cyls || secs || heads) {
|
2054 | e4bcb14c | ths | fprintf(stderr, |
2055 | 9dfd7c7a | Gerd Hoffmann | "qemu: '%s' invalid physical CHS format\n", buf);
|
2056 | 751c6a17 | Gerd Hoffmann | return NULL; |
2057 | e4bcb14c | ths | } |
2058 | e4bcb14c | ths | media = MEDIA_CDROM; |
2059 | e4bcb14c | ths | } else {
|
2060 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "qemu: '%s' invalid media\n", buf);
|
2061 | 751c6a17 | Gerd Hoffmann | return NULL; |
2062 | e4bcb14c | ths | } |
2063 | e4bcb14c | ths | } |
2064 | e4bcb14c | ths | |
2065 | 9dfd7c7a | Gerd Hoffmann | if ((buf = qemu_opt_get(opts, "cache")) != NULL) { |
2066 | 9f7965c7 | aliguori | if (!strcmp(buf, "off") || !strcmp(buf, "none")) |
2067 | 33f00271 | balrog | cache = 0;
|
2068 | 9f7965c7 | aliguori | else if (!strcmp(buf, "writethrough")) |
2069 | 33f00271 | balrog | cache = 1;
|
2070 | 9f7965c7 | aliguori | else if (!strcmp(buf, "writeback")) |
2071 | 9f7965c7 | aliguori | cache = 2;
|
2072 | 33f00271 | balrog | else {
|
2073 | 33f00271 | balrog | fprintf(stderr, "qemu: invalid cache option\n");
|
2074 | 751c6a17 | Gerd Hoffmann | return NULL; |
2075 | 33f00271 | balrog | } |
2076 | 33f00271 | balrog | } |
2077 | 33f00271 | balrog | |
2078 | 5c6c3a6c | Christoph Hellwig | #ifdef CONFIG_LINUX_AIO
|
2079 | 5c6c3a6c | Christoph Hellwig | if ((buf = qemu_opt_get(opts, "aio")) != NULL) { |
2080 | 5c6c3a6c | Christoph Hellwig | if (!strcmp(buf, "threads")) |
2081 | 5c6c3a6c | Christoph Hellwig | aio = 0;
|
2082 | 5c6c3a6c | Christoph Hellwig | else if (!strcmp(buf, "native")) |
2083 | 5c6c3a6c | Christoph Hellwig | aio = 1;
|
2084 | 5c6c3a6c | Christoph Hellwig | else {
|
2085 | 5c6c3a6c | Christoph Hellwig | fprintf(stderr, "qemu: invalid aio option\n");
|
2086 | 5c6c3a6c | Christoph Hellwig | return NULL; |
2087 | 5c6c3a6c | Christoph Hellwig | } |
2088 | 5c6c3a6c | Christoph Hellwig | } |
2089 | 5c6c3a6c | Christoph Hellwig | #endif
|
2090 | 5c6c3a6c | Christoph Hellwig | |
2091 | 9dfd7c7a | Gerd Hoffmann | if ((buf = qemu_opt_get(opts, "format")) != NULL) { |
2092 | a1620fac | aurel32 | if (strcmp(buf, "?") == 0) { |
2093 | a1620fac | aurel32 | fprintf(stderr, "qemu: Supported formats:");
|
2094 | a1620fac | aurel32 | bdrv_iterate_format(bdrv_format_print, NULL);
|
2095 | a1620fac | aurel32 | fprintf(stderr, "\n");
|
2096 | 751c6a17 | Gerd Hoffmann | return NULL; |
2097 | a1620fac | aurel32 | } |
2098 | eb852011 | Markus Armbruster | drv = bdrv_find_whitelisted_format(buf); |
2099 | 1e72d3b7 | aurel32 | if (!drv) {
|
2100 | 1e72d3b7 | aurel32 | fprintf(stderr, "qemu: '%s' invalid format\n", buf);
|
2101 | 751c6a17 | Gerd Hoffmann | return NULL; |
2102 | 1e72d3b7 | aurel32 | } |
2103 | 1e72d3b7 | aurel32 | } |
2104 | 1e72d3b7 | aurel32 | |
2105 | e9b2e818 | Kevin Wolf | on_write_error = BLOCK_ERR_STOP_ENOSPC; |
2106 | 9dfd7c7a | Gerd Hoffmann | if ((buf = qemu_opt_get(opts, "werror")) != NULL) { |
2107 | 869a5c6d | aliguori | if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) {
|
2108 | ea8a5d7f | aliguori | fprintf(stderr, "werror is no supported by this format\n");
|
2109 | 751c6a17 | Gerd Hoffmann | return NULL; |
2110 | 428c5705 | aliguori | } |
2111 | e9b2e818 | Kevin Wolf | |
2112 | e9b2e818 | Kevin Wolf | on_write_error = parse_block_error_action(buf, 0);
|
2113 | e9b2e818 | Kevin Wolf | if (on_write_error < 0) { |
2114 | e9b2e818 | Kevin Wolf | return NULL; |
2115 | e9b2e818 | Kevin Wolf | } |
2116 | e9b2e818 | Kevin Wolf | } |
2117 | e9b2e818 | Kevin Wolf | |
2118 | e9b2e818 | Kevin Wolf | on_read_error = BLOCK_ERR_REPORT; |
2119 | e9b2e818 | Kevin Wolf | if ((buf = qemu_opt_get(opts, "rerror")) != NULL) { |
2120 | f35d68f0 | Kevin Wolf | if (type != IF_IDE && type != IF_VIRTIO) {
|
2121 | e9b2e818 | Kevin Wolf | fprintf(stderr, "rerror is no supported by this format\n");
|
2122 | e9b2e818 | Kevin Wolf | return NULL; |
2123 | e9b2e818 | Kevin Wolf | } |
2124 | e9b2e818 | Kevin Wolf | |
2125 | e9b2e818 | Kevin Wolf | on_read_error = parse_block_error_action(buf, 1);
|
2126 | e9b2e818 | Kevin Wolf | if (on_read_error < 0) { |
2127 | 751c6a17 | Gerd Hoffmann | return NULL; |
2128 | 428c5705 | aliguori | } |
2129 | 428c5705 | aliguori | } |
2130 | 428c5705 | aliguori | |
2131 | 9dfd7c7a | Gerd Hoffmann | if ((devaddr = qemu_opt_get(opts, "addr")) != NULL) { |
2132 | c2cc47a4 | Markus Armbruster | if (type != IF_VIRTIO) {
|
2133 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "addr is not supported\n");
|
2134 | 751c6a17 | Gerd Hoffmann | return NULL; |
2135 | c2cc47a4 | Markus Armbruster | } |
2136 | c2cc47a4 | Markus Armbruster | } |
2137 | c2cc47a4 | Markus Armbruster | |
2138 | e4bcb14c | ths | /* compute bus and unit according index */
|
2139 | e4bcb14c | ths | |
2140 | e4bcb14c | ths | if (index != -1) { |
2141 | e4bcb14c | ths | if (bus_id != 0 || unit_id != -1) { |
2142 | e4bcb14c | ths | fprintf(stderr, |
2143 | 9dfd7c7a | Gerd Hoffmann | "qemu: index cannot be used with bus and unit\n");
|
2144 | 751c6a17 | Gerd Hoffmann | return NULL; |
2145 | e4bcb14c | ths | } |
2146 | e4bcb14c | ths | if (max_devs == 0) |
2147 | e4bcb14c | ths | { |
2148 | e4bcb14c | ths | unit_id = index; |
2149 | e4bcb14c | ths | bus_id = 0;
|
2150 | e4bcb14c | ths | } else {
|
2151 | e4bcb14c | ths | unit_id = index % max_devs; |
2152 | e4bcb14c | ths | bus_id = index / max_devs; |
2153 | e4bcb14c | ths | } |
2154 | e4bcb14c | ths | } |
2155 | e4bcb14c | ths | |
2156 | e4bcb14c | ths | /* if user doesn't specify a unit_id,
|
2157 | e4bcb14c | ths | * try to find the first free
|
2158 | e4bcb14c | ths | */
|
2159 | e4bcb14c | ths | |
2160 | e4bcb14c | ths | if (unit_id == -1) { |
2161 | e4bcb14c | ths | unit_id = 0;
|
2162 | 751c6a17 | Gerd Hoffmann | while (drive_get(type, bus_id, unit_id) != NULL) { |
2163 | e4bcb14c | ths | unit_id++; |
2164 | e4bcb14c | ths | if (max_devs && unit_id >= max_devs) {
|
2165 | e4bcb14c | ths | unit_id -= max_devs; |
2166 | e4bcb14c | ths | bus_id++; |
2167 | e4bcb14c | ths | } |
2168 | e4bcb14c | ths | } |
2169 | e4bcb14c | ths | } |
2170 | e4bcb14c | ths | |
2171 | e4bcb14c | ths | /* check unit id */
|
2172 | e4bcb14c | ths | |
2173 | e4bcb14c | ths | if (max_devs && unit_id >= max_devs) {
|
2174 | 9dfd7c7a | Gerd Hoffmann | fprintf(stderr, "qemu: unit %d too big (max is %d)\n",
|
2175 | 9dfd7c7a | Gerd Hoffmann | unit_id, max_devs - 1);
|
2176 | 751c6a17 | Gerd Hoffmann | return NULL; |
2177 | e4bcb14c | ths | } |
2178 | e4bcb14c | ths | |
2179 | e4bcb14c | ths | /*
|
2180 | e4bcb14c | ths | * ignore multiple definitions
|
2181 | e4bcb14c | ths | */
|
2182 | e4bcb14c | ths | |
2183 | 751c6a17 | Gerd Hoffmann | if (drive_get(type, bus_id, unit_id) != NULL) { |
2184 | 751c6a17 | Gerd Hoffmann | *fatal_error = 0;
|
2185 | 751c6a17 | Gerd Hoffmann | return NULL; |
2186 | 751c6a17 | Gerd Hoffmann | } |
2187 | e4bcb14c | ths | |
2188 | e4bcb14c | ths | /* init */
|
2189 | e4bcb14c | ths | |
2190 | 751c6a17 | Gerd Hoffmann | dinfo = qemu_mallocz(sizeof(*dinfo));
|
2191 | e23d9c4d | Gerd Hoffmann | if ((buf = qemu_opts_id(opts)) != NULL) { |
2192 | 9dfd7c7a | Gerd Hoffmann | dinfo->id = qemu_strdup(buf); |
2193 | 9dfd7c7a | Gerd Hoffmann | } else {
|
2194 | 1dae12e6 | Gerd Hoffmann | /* no id supplied -> create one */
|
2195 | 9dfd7c7a | Gerd Hoffmann | dinfo->id = qemu_mallocz(32);
|
2196 | 1dae12e6 | Gerd Hoffmann | if (type == IF_IDE || type == IF_SCSI)
|
2197 | 1dae12e6 | Gerd Hoffmann | mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; |
2198 | 1dae12e6 | Gerd Hoffmann | if (max_devs)
|
2199 | 9dfd7c7a | Gerd Hoffmann | snprintf(dinfo->id, 32, "%s%i%s%i", |
2200 | 1dae12e6 | Gerd Hoffmann | devname, bus_id, mediastr, unit_id); |
2201 | 1dae12e6 | Gerd Hoffmann | else
|
2202 | 9dfd7c7a | Gerd Hoffmann | snprintf(dinfo->id, 32, "%s%s%i", |
2203 | 1dae12e6 | Gerd Hoffmann | devname, mediastr, unit_id); |
2204 | 1dae12e6 | Gerd Hoffmann | } |
2205 | 1dae12e6 | Gerd Hoffmann | dinfo->bdrv = bdrv_new(dinfo->id); |
2206 | 751c6a17 | Gerd Hoffmann | dinfo->devaddr = devaddr; |
2207 | 751c6a17 | Gerd Hoffmann | dinfo->type = type; |
2208 | 751c6a17 | Gerd Hoffmann | dinfo->bus = bus_id; |
2209 | 751c6a17 | Gerd Hoffmann | dinfo->unit = unit_id; |
2210 | e9b2e818 | Kevin Wolf | dinfo->on_read_error = on_read_error; |
2211 | e9b2e818 | Kevin Wolf | dinfo->on_write_error = on_write_error; |
2212 | 9dfd7c7a | Gerd Hoffmann | dinfo->opts = opts; |
2213 | 9dfd7c7a | Gerd Hoffmann | if (serial)
|
2214 | 9dfd7c7a | Gerd Hoffmann | strncpy(dinfo->serial, serial, sizeof(serial));
|
2215 | 72cf2d4f | Blue Swirl | QTAILQ_INSERT_TAIL(&drives, dinfo, next); |
2216 | e4bcb14c | ths | |
2217 | f60d39bc | ths | switch(type) {
|
2218 | e4bcb14c | ths | case IF_IDE:
|
2219 | e4bcb14c | ths | case IF_SCSI:
|
2220 | 62d23efa | aliguori | case IF_XEN:
|
2221 | c219331e | Gerd Hoffmann | case IF_NONE:
|
2222 | e4bcb14c | ths | switch(media) {
|
2223 | e4bcb14c | ths | case MEDIA_DISK:
|
2224 | e4bcb14c | ths | if (cyls != 0) { |
2225 | 1dae12e6 | Gerd Hoffmann | bdrv_set_geometry_hint(dinfo->bdrv, cyls, heads, secs); |
2226 | 1dae12e6 | Gerd Hoffmann | bdrv_set_translation_hint(dinfo->bdrv, translation); |
2227 | e4bcb14c | ths | } |
2228 | e4bcb14c | ths | break;
|
2229 | e4bcb14c | ths | case MEDIA_CDROM:
|
2230 | 1dae12e6 | Gerd Hoffmann | bdrv_set_type_hint(dinfo->bdrv, BDRV_TYPE_CDROM); |
2231 | e4bcb14c | ths | break;
|
2232 | e4bcb14c | ths | } |
2233 | e4bcb14c | ths | break;
|
2234 | e4bcb14c | ths | case IF_SD:
|
2235 | e4bcb14c | ths | /* FIXME: This isn't really a floppy, but it's a reasonable
|
2236 | e4bcb14c | ths | approximation. */
|
2237 | e4bcb14c | ths | case IF_FLOPPY:
|
2238 | 1dae12e6 | Gerd Hoffmann | bdrv_set_type_hint(dinfo->bdrv, BDRV_TYPE_FLOPPY); |
2239 | e4bcb14c | ths | break;
|
2240 | e4bcb14c | ths | case IF_PFLASH:
|
2241 | e4bcb14c | ths | case IF_MTD:
|
2242 | e4bcb14c | ths | break;
|
2243 | d176c495 | Gerd Hoffmann | case IF_VIRTIO:
|
2244 | d176c495 | Gerd Hoffmann | /* add virtio block device */
|
2245 | d176c495 | Gerd Hoffmann | opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
2246 | d176c495 | Gerd Hoffmann | qemu_opt_set(opts, "driver", "virtio-blk-pci"); |
2247 | d176c495 | Gerd Hoffmann | qemu_opt_set(opts, "drive", dinfo->id);
|
2248 | d176c495 | Gerd Hoffmann | if (devaddr)
|
2249 | d176c495 | Gerd Hoffmann | qemu_opt_set(opts, "addr", devaddr);
|
2250 | d176c495 | Gerd Hoffmann | break;
|
2251 | aae9460e | Paul Brook | case IF_COUNT:
|
2252 | aae9460e | Paul Brook | abort(); |
2253 | e4bcb14c | ths | } |
2254 | 9dfd7c7a | Gerd Hoffmann | if (!file) {
|
2255 | 751c6a17 | Gerd Hoffmann | *fatal_error = 0;
|
2256 | 751c6a17 | Gerd Hoffmann | return NULL; |
2257 | 751c6a17 | Gerd Hoffmann | } |
2258 | 33f00271 | balrog | bdrv_flags = 0;
|
2259 | 9f7965c7 | aliguori | if (snapshot) {
|
2260 | 33f00271 | balrog | bdrv_flags |= BDRV_O_SNAPSHOT; |
2261 | 9f7965c7 | aliguori | cache = 2; /* always use write-back with snapshot */ |
2262 | 9f7965c7 | aliguori | } |
2263 | 9f7965c7 | aliguori | if (cache == 0) /* no caching */ |
2264 | 9f7965c7 | aliguori | bdrv_flags |= BDRV_O_NOCACHE; |
2265 | 9f7965c7 | aliguori | else if (cache == 2) /* write-back */ |
2266 | 9f7965c7 | aliguori | bdrv_flags |= BDRV_O_CACHE_WB; |
2267 | 5c6c3a6c | Christoph Hellwig | |
2268 | 5c6c3a6c | Christoph Hellwig | if (aio == 1) { |
2269 | 5c6c3a6c | Christoph Hellwig | bdrv_flags |= BDRV_O_NATIVE_AIO; |
2270 | 5c6c3a6c | Christoph Hellwig | } else {
|
2271 | 5c6c3a6c | Christoph Hellwig | bdrv_flags &= ~BDRV_O_NATIVE_AIO; |
2272 | 5c6c3a6c | Christoph Hellwig | } |
2273 | 5c6c3a6c | Christoph Hellwig | |
2274 | 59f2689d | Naphtali Sprei | if (ro == 1) { |
2275 | f5edb014 | Naphtali Sprei | if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY) {
|
2276 | f5edb014 | Naphtali Sprei | fprintf(stderr, "qemu: readonly flag not supported for drive with this interface\n");
|
2277 | 59f2689d | Naphtali Sprei | return NULL; |
2278 | 59f2689d | Naphtali Sprei | } |
2279 | b196b153 | Naphtali Sprei | } |
2280 | b196b153 | Naphtali Sprei | /*
|
2281 | b196b153 | Naphtali Sprei | * cdrom is read-only. Set it now, after above interface checking
|
2282 | b196b153 | Naphtali Sprei | * since readonly attribute not explicitly required, so no error.
|
2283 | b196b153 | Naphtali Sprei | */
|
2284 | b196b153 | Naphtali Sprei | if (media == MEDIA_CDROM) {
|
2285 | f5edb014 | Naphtali Sprei | ro = 1;
|
2286 | 59f2689d | Naphtali Sprei | } |
2287 | f5edb014 | Naphtali Sprei | bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
|
2288 | 59f2689d | Naphtali Sprei | |
2289 | 1dae12e6 | Gerd Hoffmann | if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) { |
2290 | 850810d0 | Justin M. Forbes | fprintf(stderr, "qemu: could not open disk image %s: %s\n",
|
2291 | 850810d0 | Justin M. Forbes | file, strerror(errno)); |
2292 | 751c6a17 | Gerd Hoffmann | return NULL; |
2293 | e4bcb14c | ths | } |
2294 | 5c6c3a6c | Christoph Hellwig | |
2295 | 1dae12e6 | Gerd Hoffmann | if (bdrv_key_required(dinfo->bdrv))
|
2296 | c0f4ce77 | aliguori | autostart = 0;
|
2297 | 751c6a17 | Gerd Hoffmann | *fatal_error = 0;
|
2298 | 751c6a17 | Gerd Hoffmann | return dinfo;
|
2299 | e4bcb14c | ths | } |
2300 | e4bcb14c | ths | |
2301 | 9dfd7c7a | Gerd Hoffmann | static int drive_init_func(QemuOpts *opts, void *opaque) |
2302 | 9dfd7c7a | Gerd Hoffmann | { |
2303 | 9dfd7c7a | Gerd Hoffmann | QEMUMachine *machine = opaque; |
2304 | 9dfd7c7a | Gerd Hoffmann | int fatal_error = 0; |
2305 | 9dfd7c7a | Gerd Hoffmann | |
2306 | 9dfd7c7a | Gerd Hoffmann | if (drive_init(opts, machine, &fatal_error) == NULL) { |
2307 | 9dfd7c7a | Gerd Hoffmann | if (fatal_error)
|
2308 | 9dfd7c7a | Gerd Hoffmann | return 1; |
2309 | 9dfd7c7a | Gerd Hoffmann | } |
2310 | 9dfd7c7a | Gerd Hoffmann | return 0; |
2311 | 9dfd7c7a | Gerd Hoffmann | } |
2312 | 9dfd7c7a | Gerd Hoffmann | |
2313 | 9dfd7c7a | Gerd Hoffmann | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) |
2314 | 9dfd7c7a | Gerd Hoffmann | { |
2315 | 9dfd7c7a | Gerd Hoffmann | if (NULL == qemu_opt_get(opts, "snapshot")) { |
2316 | 9dfd7c7a | Gerd Hoffmann | qemu_opt_set(opts, "snapshot", "on"); |
2317 | 9dfd7c7a | Gerd Hoffmann | } |
2318 | 9dfd7c7a | Gerd Hoffmann | return 0; |
2319 | 9dfd7c7a | Gerd Hoffmann | } |
2320 | 9dfd7c7a | Gerd Hoffmann | |
2321 | 76e30d0f | Jan Kiszka | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
2322 | 76e30d0f | Jan Kiszka | { |
2323 | 76e30d0f | Jan Kiszka | boot_set_handler = func; |
2324 | 76e30d0f | Jan Kiszka | boot_set_opaque = opaque; |
2325 | 76e30d0f | Jan Kiszka | } |
2326 | 76e30d0f | Jan Kiszka | |
2327 | 76e30d0f | Jan Kiszka | int qemu_boot_set(const char *boot_devices) |
2328 | 76e30d0f | Jan Kiszka | { |
2329 | 76e30d0f | Jan Kiszka | if (!boot_set_handler) {
|
2330 | 76e30d0f | Jan Kiszka | return -EINVAL;
|
2331 | 76e30d0f | Jan Kiszka | } |
2332 | 76e30d0f | Jan Kiszka | return boot_set_handler(boot_set_opaque, boot_devices);
|
2333 | 76e30d0f | Jan Kiszka | } |
2334 | 76e30d0f | Jan Kiszka | |
2335 | ef3adf68 | Jan Kiszka | static int parse_bootdevices(char *devices) |
2336 | ef3adf68 | Jan Kiszka | { |
2337 | ef3adf68 | Jan Kiszka | /* We just do some generic consistency checks */
|
2338 | ef3adf68 | Jan Kiszka | const char *p; |
2339 | ef3adf68 | Jan Kiszka | int bitmap = 0; |
2340 | ef3adf68 | Jan Kiszka | |
2341 | ef3adf68 | Jan Kiszka | for (p = devices; *p != '\0'; p++) { |
2342 | ef3adf68 | Jan Kiszka | /* Allowed boot devices are:
|
2343 | ef3adf68 | Jan Kiszka | * a-b: floppy disk drives
|
2344 | ef3adf68 | Jan Kiszka | * c-f: IDE disk drives
|
2345 | ef3adf68 | Jan Kiszka | * g-m: machine implementation dependant drives
|
2346 | ef3adf68 | Jan Kiszka | * n-p: network devices
|
2347 | ef3adf68 | Jan Kiszka | * It's up to each machine implementation to check if the given boot
|
2348 | ef3adf68 | Jan Kiszka | * devices match the actual hardware implementation and firmware
|
2349 | ef3adf68 | Jan Kiszka | * features.
|
2350 | ef3adf68 | Jan Kiszka | */
|
2351 | ef3adf68 | Jan Kiszka | if (*p < 'a' || *p > 'p') { |
2352 | ef3adf68 | Jan Kiszka | fprintf(stderr, "Invalid boot device '%c'\n", *p);
|
2353 | ef3adf68 | Jan Kiszka | exit(1);
|
2354 | ef3adf68 | Jan Kiszka | } |
2355 | ef3adf68 | Jan Kiszka | if (bitmap & (1 << (*p - 'a'))) { |
2356 | ef3adf68 | Jan Kiszka | fprintf(stderr, "Boot device '%c' was given twice\n", *p);
|
2357 | ef3adf68 | Jan Kiszka | exit(1);
|
2358 | ef3adf68 | Jan Kiszka | } |
2359 | ef3adf68 | Jan Kiszka | bitmap |= 1 << (*p - 'a'); |
2360 | ef3adf68 | Jan Kiszka | } |
2361 | ef3adf68 | Jan Kiszka | return bitmap;
|
2362 | ef3adf68 | Jan Kiszka | } |
2363 | ef3adf68 | Jan Kiszka | |
2364 | e0f084bf | Jan Kiszka | static void restore_boot_devices(void *opaque) |
2365 | e0f084bf | Jan Kiszka | { |
2366 | e0f084bf | Jan Kiszka | char *standard_boot_devices = opaque;
|
2367 | e0f084bf | Jan Kiszka | |
2368 | e0f084bf | Jan Kiszka | qemu_boot_set(standard_boot_devices); |
2369 | e0f084bf | Jan Kiszka | |
2370 | e0f084bf | Jan Kiszka | qemu_unregister_reset(restore_boot_devices, standard_boot_devices); |
2371 | e0f084bf | Jan Kiszka | qemu_free(standard_boot_devices); |
2372 | e0f084bf | Jan Kiszka | } |
2373 | e0f084bf | Jan Kiszka | |
2374 | 268a362c | aliguori | static void numa_add(const char *optarg) |
2375 | 268a362c | aliguori | { |
2376 | 268a362c | aliguori | char option[128]; |
2377 | 268a362c | aliguori | char *endptr;
|
2378 | 268a362c | aliguori | unsigned long long value, endvalue; |
2379 | 268a362c | aliguori | int nodenr;
|
2380 | 268a362c | aliguori | |
2381 | 268a362c | aliguori | optarg = get_opt_name(option, 128, optarg, ',') + 1; |
2382 | 268a362c | aliguori | if (!strcmp(option, "node")) { |
2383 | 268a362c | aliguori | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
2384 | 268a362c | aliguori | nodenr = nb_numa_nodes; |
2385 | 268a362c | aliguori | } else {
|
2386 | 268a362c | aliguori | nodenr = strtoull(option, NULL, 10); |
2387 | 268a362c | aliguori | } |
2388 | 268a362c | aliguori | |
2389 | 268a362c | aliguori | if (get_param_value(option, 128, "mem", optarg) == 0) { |
2390 | 268a362c | aliguori | node_mem[nodenr] = 0;
|
2391 | 268a362c | aliguori | } else {
|
2392 | 268a362c | aliguori | value = strtoull(option, &endptr, 0);
|
2393 | 268a362c | aliguori | switch (*endptr) {
|
2394 | 268a362c | aliguori | case 0: case 'M': case 'm': |
2395 | 268a362c | aliguori | value <<= 20;
|
2396 | 268a362c | aliguori | break;
|
2397 | 268a362c | aliguori | case 'G': case 'g': |
2398 | 268a362c | aliguori | value <<= 30;
|
2399 | 268a362c | aliguori | break;
|
2400 | 268a362c | aliguori | } |
2401 | 268a362c | aliguori | node_mem[nodenr] = value; |
2402 | 268a362c | aliguori | } |
2403 | 268a362c | aliguori | if (get_param_value(option, 128, "cpus", optarg) == 0) { |
2404 | 268a362c | aliguori | node_cpumask[nodenr] = 0;
|
2405 | 268a362c | aliguori | } else {
|
2406 | 268a362c | aliguori | value = strtoull(option, &endptr, 10);
|
2407 | 268a362c | aliguori | if (value >= 64) { |
2408 | 268a362c | aliguori | value = 63;
|
2409 | 268a362c | aliguori | fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
|
2410 | 268a362c | aliguori | } else {
|
2411 | 268a362c | aliguori | if (*endptr == '-') { |
2412 | 268a362c | aliguori | endvalue = strtoull(endptr+1, &endptr, 10); |
2413 | 268a362c | aliguori | if (endvalue >= 63) { |
2414 | 268a362c | aliguori | endvalue = 62;
|
2415 | 268a362c | aliguori | fprintf(stderr, |
2416 | 268a362c | aliguori | "only 63 CPUs in NUMA mode supported.\n");
|
2417 | 268a362c | aliguori | } |
2418 | 0dfbd514 | Paolo Bonzini | value = (2ULL << endvalue) - (1ULL << value); |
2419 | 268a362c | aliguori | } else {
|
2420 | 0dfbd514 | Paolo Bonzini | value = 1ULL << value;
|
2421 | 268a362c | aliguori | } |
2422 | 268a362c | aliguori | } |
2423 | 268a362c | aliguori | node_cpumask[nodenr] = value; |
2424 | 268a362c | aliguori | } |
2425 | 268a362c | aliguori | nb_numa_nodes++; |
2426 | 268a362c | aliguori | } |
2427 | 268a362c | aliguori | return;
|
2428 | 268a362c | aliguori | } |
2429 | 268a362c | aliguori | |
2430 | dc6b1c09 | Andre Przywara | static void smp_parse(const char *optarg) |
2431 | dc6b1c09 | Andre Przywara | { |
2432 | dc6b1c09 | Andre Przywara | int smp, sockets = 0, threads = 0, cores = 0; |
2433 | dc6b1c09 | Andre Przywara | char *endptr;
|
2434 | dc6b1c09 | Andre Przywara | char option[128]; |
2435 | dc6b1c09 | Andre Przywara | |
2436 | dc6b1c09 | Andre Przywara | smp = strtoul(optarg, &endptr, 10);
|
2437 | dc6b1c09 | Andre Przywara | if (endptr != optarg) {
|
2438 | dc6b1c09 | Andre Przywara | if (*endptr == ',') { |
2439 | dc6b1c09 | Andre Przywara | endptr++; |
2440 | dc6b1c09 | Andre Przywara | } |
2441 | dc6b1c09 | Andre Przywara | } |
2442 | dc6b1c09 | Andre Przywara | if (get_param_value(option, 128, "sockets", endptr) != 0) |
2443 | dc6b1c09 | Andre Przywara | sockets = strtoull(option, NULL, 10); |
2444 | dc6b1c09 | Andre Przywara | if (get_param_value(option, 128, "cores", endptr) != 0) |
2445 | dc6b1c09 | Andre Przywara | cores = strtoull(option, NULL, 10); |
2446 | dc6b1c09 | Andre Przywara | if (get_param_value(option, 128, "threads", endptr) != 0) |
2447 | dc6b1c09 | Andre Przywara | threads = strtoull(option, NULL, 10); |
2448 | dc6b1c09 | Andre Przywara | if (get_param_value(option, 128, "maxcpus", endptr) != 0) |
2449 | dc6b1c09 | Andre Przywara | max_cpus = strtoull(option, NULL, 10); |
2450 | dc6b1c09 | Andre Przywara | |
2451 | dc6b1c09 | Andre Przywara | /* compute missing values, prefer sockets over cores over threads */
|
2452 | dc6b1c09 | Andre Przywara | if (smp == 0 || sockets == 0) { |
2453 | dc6b1c09 | Andre Przywara | sockets = sockets > 0 ? sockets : 1; |
2454 | dc6b1c09 | Andre Przywara | cores = cores > 0 ? cores : 1; |
2455 | dc6b1c09 | Andre Przywara | threads = threads > 0 ? threads : 1; |
2456 | dc6b1c09 | Andre Przywara | if (smp == 0) { |
2457 | dc6b1c09 | Andre Przywara | smp = cores * threads * sockets; |
2458 | dc6b1c09 | Andre Przywara | } |
2459 | dc6b1c09 | Andre Przywara | } else {
|
2460 | dc6b1c09 | Andre Przywara | if (cores == 0) { |
2461 | dc6b1c09 | Andre Przywara | threads = threads > 0 ? threads : 1; |
2462 | dc6b1c09 | Andre Przywara | cores = smp / (sockets * threads); |
2463 | dc6b1c09 | Andre Przywara | } else {
|
2464 | 5cdc9b76 | Amit Shah | if (sockets) {
|
2465 | dc6b1c09 | Andre Przywara | threads = smp / (cores * sockets); |
2466 | dc6b1c09 | Andre Przywara | } |
2467 | dc6b1c09 | Andre Przywara | } |
2468 | dc6b1c09 | Andre Przywara | } |
2469 | dc6b1c09 | Andre Przywara | smp_cpus = smp; |
2470 | dc6b1c09 | Andre Przywara | smp_cores = cores > 0 ? cores : 1; |
2471 | dc6b1c09 | Andre Przywara | smp_threads = threads > 0 ? threads : 1; |
2472 | dc6b1c09 | Andre Przywara | if (max_cpus == 0) |
2473 | dc6b1c09 | Andre Przywara | max_cpus = smp_cpus; |
2474 | dc6b1c09 | Andre Przywara | } |
2475 | dc6b1c09 | Andre Przywara | |
2476 | 330d0414 | bellard | /***********************************************************/
|
2477 | a594cfbf | bellard | /* USB devices */
|
2478 | a594cfbf | bellard | |
2479 | c0f4ce77 | aliguori | static int usb_device_add(const char *devname, int is_hotplug) |
2480 | a594cfbf | bellard | { |
2481 | a594cfbf | bellard | const char *p; |
2482 | a5d2f727 | Gerd Hoffmann | USBDevice *dev = NULL;
|
2483 | a594cfbf | bellard | |
2484 | a5d2f727 | Gerd Hoffmann | if (!usb_enabled)
|
2485 | a594cfbf | bellard | return -1; |
2486 | a594cfbf | bellard | |
2487 | 0958b4cc | Gerd Hoffmann | /* drivers with .usbdevice_name entry in USBDeviceInfo */
|
2488 | 0958b4cc | Gerd Hoffmann | dev = usbdevice_create(devname); |
2489 | 0958b4cc | Gerd Hoffmann | if (dev)
|
2490 | 0958b4cc | Gerd Hoffmann | goto done;
|
2491 | 0958b4cc | Gerd Hoffmann | |
2492 | a5d2f727 | Gerd Hoffmann | /* the other ones */
|
2493 | a594cfbf | bellard | if (strstart(devname, "host:", &p)) { |
2494 | a594cfbf | bellard | dev = usb_host_device_open(p); |
2495 | dc72ac14 | balrog | } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { |
2496 | dc72ac14 | balrog | dev = usb_bt_init(devname[2] ? hci_init(p) :
|
2497 | dc72ac14 | balrog | bt_new_hci(qemu_find_bt_vlan(0)));
|
2498 | a594cfbf | bellard | } else {
|
2499 | a594cfbf | bellard | return -1; |
2500 | a594cfbf | bellard | } |
2501 | 0d92ed30 | pbrook | if (!dev)
|
2502 | 0d92ed30 | pbrook | return -1; |
2503 | 0d92ed30 | pbrook | |
2504 | a5d2f727 | Gerd Hoffmann | done:
|
2505 | a594cfbf | bellard | return 0; |
2506 | a594cfbf | bellard | } |
2507 | a594cfbf | bellard | |
2508 | 1f3870ab | aliguori | static int usb_device_del(const char *devname) |
2509 | 1f3870ab | aliguori | { |
2510 | 1f3870ab | aliguori | int bus_num, addr;
|
2511 | 1f3870ab | aliguori | const char *p; |
2512 | 1f3870ab | aliguori | |
2513 | 5d0c5750 | aliguori | if (strstart(devname, "host:", &p)) |
2514 | 5d0c5750 | aliguori | return usb_host_device_close(p);
|
2515 | 5d0c5750 | aliguori | |
2516 | a5d2f727 | Gerd Hoffmann | if (!usb_enabled)
|
2517 | 1f3870ab | aliguori | return -1; |
2518 | 1f3870ab | aliguori | |
2519 | 1f3870ab | aliguori | p = strchr(devname, '.');
|
2520 | 1f3870ab | aliguori | if (!p)
|
2521 | 1f3870ab | aliguori | return -1; |
2522 | 1f3870ab | aliguori | bus_num = strtoul(devname, NULL, 0); |
2523 | 1f3870ab | aliguori | addr = strtoul(p + 1, NULL, 0); |
2524 | 1f3870ab | aliguori | |
2525 | a5d2f727 | Gerd Hoffmann | return usb_device_delete_addr(bus_num, addr);
|
2526 | 1f3870ab | aliguori | } |
2527 | 1f3870ab | aliguori | |
2528 | bd3c948d | Gerd Hoffmann | static int usb_parse(const char *cmdline) |
2529 | bd3c948d | Gerd Hoffmann | { |
2530 | 59d1c1c2 | Scott Tsai | int r;
|
2531 | 59d1c1c2 | Scott Tsai | r = usb_device_add(cmdline, 0);
|
2532 | 59d1c1c2 | Scott Tsai | if (r < 0) { |
2533 | 59d1c1c2 | Scott Tsai | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
|
2534 | 59d1c1c2 | Scott Tsai | } |
2535 | 59d1c1c2 | Scott Tsai | return r;
|
2536 | bd3c948d | Gerd Hoffmann | } |
2537 | bd3c948d | Gerd Hoffmann | |
2538 | d54908a5 | Luiz Capitulino | void do_usb_add(Monitor *mon, const QDict *qdict) |
2539 | a594cfbf | bellard | { |
2540 | 59d1c1c2 | Scott Tsai | const char *devname = qdict_get_str(qdict, "devname"); |
2541 | 59d1c1c2 | Scott Tsai | if (usb_device_add(devname, 1) < 0) { |
2542 | 59d1c1c2 | Scott Tsai | qemu_error("could not add USB device '%s'\n", devname);
|
2543 | 59d1c1c2 | Scott Tsai | } |
2544 | a594cfbf | bellard | } |
2545 | a594cfbf | bellard | |
2546 | d54908a5 | Luiz Capitulino | void do_usb_del(Monitor *mon, const QDict *qdict) |
2547 | a594cfbf | bellard | { |
2548 | 59d1c1c2 | Scott Tsai | const char *devname = qdict_get_str(qdict, "devname"); |
2549 | 59d1c1c2 | Scott Tsai | if (usb_device_del(devname) < 0) { |
2550 | 59d1c1c2 | Scott Tsai | qemu_error("could not delete USB device '%s'\n", devname);
|
2551 | 59d1c1c2 | Scott Tsai | } |
2552 | a594cfbf | bellard | } |
2553 | a594cfbf | bellard | |
2554 | f7cce898 | bellard | /***********************************************************/
|
2555 | 201a51fc | balrog | /* PCMCIA/Cardbus */
|
2556 | 201a51fc | balrog | |
2557 | 201a51fc | balrog | static struct pcmcia_socket_entry_s { |
2558 | bc24a225 | Paul Brook | PCMCIASocket *socket; |
2559 | 201a51fc | balrog | struct pcmcia_socket_entry_s *next;
|
2560 | 201a51fc | balrog | } *pcmcia_sockets = 0;
|
2561 | 201a51fc | balrog | |
2562 | bc24a225 | Paul Brook | void pcmcia_socket_register(PCMCIASocket *socket)
|
2563 | 201a51fc | balrog | { |
2564 | 201a51fc | balrog | struct pcmcia_socket_entry_s *entry;
|
2565 | 201a51fc | balrog | |
2566 | 201a51fc | balrog | entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s)); |
2567 | 201a51fc | balrog | entry->socket = socket; |
2568 | 201a51fc | balrog | entry->next = pcmcia_sockets; |
2569 | 201a51fc | balrog | pcmcia_sockets = entry; |
2570 | 201a51fc | balrog | } |
2571 | 201a51fc | balrog | |
2572 | bc24a225 | Paul Brook | void pcmcia_socket_unregister(PCMCIASocket *socket)
|
2573 | 201a51fc | balrog | { |
2574 | 201a51fc | balrog | struct pcmcia_socket_entry_s *entry, **ptr;
|
2575 | 201a51fc | balrog | |
2576 | 201a51fc | balrog | ptr = &pcmcia_sockets; |
2577 | 201a51fc | balrog | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
|
2578 | 201a51fc | balrog | if (entry->socket == socket) {
|
2579 | 201a51fc | balrog | *ptr = entry->next; |
2580 | 201a51fc | balrog | qemu_free(entry); |
2581 | 201a51fc | balrog | } |
2582 | 201a51fc | balrog | } |
2583 | 201a51fc | balrog | |
2584 | 376253ec | aliguori | void pcmcia_info(Monitor *mon)
|
2585 | 201a51fc | balrog | { |
2586 | 201a51fc | balrog | struct pcmcia_socket_entry_s *iter;
|
2587 | 376253ec | aliguori | |
2588 | 201a51fc | balrog | if (!pcmcia_sockets)
|
2589 | 376253ec | aliguori | monitor_printf(mon, "No PCMCIA sockets\n");
|
2590 | 201a51fc | balrog | |
2591 | 201a51fc | balrog | for (iter = pcmcia_sockets; iter; iter = iter->next)
|
2592 | 376253ec | aliguori | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
|
2593 | 376253ec | aliguori | iter->socket->attached ? iter->socket->card_string : |
2594 | 376253ec | aliguori | "Empty");
|
2595 | 201a51fc | balrog | } |
2596 | 201a51fc | balrog | |
2597 | 201a51fc | balrog | /***********************************************************/
|
2598 | 8a7ddc38 | bellard | /* I/O handling */
|
2599 | 0824d6fc | bellard | |
2600 | c4b1fcc0 | bellard | typedef struct IOHandlerRecord { |
2601 | c4b1fcc0 | bellard | int fd;
|
2602 | 7c9d8e07 | bellard | IOCanRWHandler *fd_read_poll; |
2603 | 7c9d8e07 | bellard | IOHandler *fd_read; |
2604 | 7c9d8e07 | bellard | IOHandler *fd_write; |
2605 | cafffd40 | ths | int deleted;
|
2606 | c4b1fcc0 | bellard | void *opaque;
|
2607 | c4b1fcc0 | bellard | /* temporary data */
|
2608 | c4b1fcc0 | bellard | struct pollfd *ufd;
|
2609 | 8a7ddc38 | bellard | struct IOHandlerRecord *next;
|
2610 | c4b1fcc0 | bellard | } IOHandlerRecord; |
2611 | c4b1fcc0 | bellard | |
2612 | 8a7ddc38 | bellard | static IOHandlerRecord *first_io_handler;
|
2613 | c4b1fcc0 | bellard | |
2614 | 7c9d8e07 | bellard | /* XXX: fd_read_poll should be suppressed, but an API change is
|
2615 | 7c9d8e07 | bellard | necessary in the character devices to suppress fd_can_read(). */
|
2616 | 5fafdf24 | ths | int qemu_set_fd_handler2(int fd, |
2617 | 5fafdf24 | ths | IOCanRWHandler *fd_read_poll, |
2618 | 5fafdf24 | ths | IOHandler *fd_read, |
2619 | 5fafdf24 | ths | IOHandler *fd_write, |
2620 | 7c9d8e07 | bellard | void *opaque)
|
2621 | c4b1fcc0 | bellard | { |
2622 | 7c9d8e07 | bellard | IOHandlerRecord **pioh, *ioh; |
2623 | c4b1fcc0 | bellard | |
2624 | 7c9d8e07 | bellard | if (!fd_read && !fd_write) {
|
2625 | 7c9d8e07 | bellard | pioh = &first_io_handler; |
2626 | 7c9d8e07 | bellard | for(;;) {
|
2627 | 7c9d8e07 | bellard | ioh = *pioh; |
2628 | 7c9d8e07 | bellard | if (ioh == NULL) |
2629 | 7c9d8e07 | bellard | break;
|
2630 | 7c9d8e07 | bellard | if (ioh->fd == fd) {
|
2631 | cafffd40 | ths | ioh->deleted = 1;
|
2632 | 7c9d8e07 | bellard | break;
|
2633 | 7c9d8e07 | bellard | } |
2634 | 7c9d8e07 | bellard | pioh = &ioh->next; |
2635 | 7c9d8e07 | bellard | } |
2636 | 7c9d8e07 | bellard | } else {
|
2637 | 7c9d8e07 | bellard | for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { |
2638 | 7c9d8e07 | bellard | if (ioh->fd == fd)
|
2639 | 7c9d8e07 | bellard | goto found;
|
2640 | 7c9d8e07 | bellard | } |
2641 | 7c9d8e07 | bellard | ioh = qemu_mallocz(sizeof(IOHandlerRecord));
|
2642 | 7c9d8e07 | bellard | ioh->next = first_io_handler; |
2643 | 7c9d8e07 | bellard | first_io_handler = ioh; |
2644 | 7c9d8e07 | bellard | found:
|
2645 | 7c9d8e07 | bellard | ioh->fd = fd; |
2646 | 7c9d8e07 | bellard | ioh->fd_read_poll = fd_read_poll; |
2647 | 7c9d8e07 | bellard | ioh->fd_read = fd_read; |
2648 | 7c9d8e07 | bellard | ioh->fd_write = fd_write; |
2649 | 7c9d8e07 | bellard | ioh->opaque = opaque; |
2650 | cafffd40 | ths | ioh->deleted = 0;
|
2651 | 7c9d8e07 | bellard | } |
2652 | c4b1fcc0 | bellard | return 0; |
2653 | c4b1fcc0 | bellard | } |
2654 | c4b1fcc0 | bellard | |
2655 | 5fafdf24 | ths | int qemu_set_fd_handler(int fd, |
2656 | 5fafdf24 | ths | IOHandler *fd_read, |
2657 | 5fafdf24 | ths | IOHandler *fd_write, |
2658 | 7c9d8e07 | bellard | void *opaque)
|
2659 | 8a7ddc38 | bellard | { |
2660 | 7c9d8e07 | bellard | return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque); |
2661 | 8a7ddc38 | bellard | } |
2662 | 8a7ddc38 | bellard | |
2663 | 56f3a5d0 | aliguori | #ifdef _WIN32
|
2664 | 8a7ddc38 | bellard | /***********************************************************/
|
2665 | f331110f | bellard | /* Polling handling */
|
2666 | f331110f | bellard | |
2667 | f331110f | bellard | typedef struct PollingEntry { |
2668 | f331110f | bellard | PollingFunc *func; |
2669 | f331110f | bellard | void *opaque;
|
2670 | f331110f | bellard | struct PollingEntry *next;
|
2671 | f331110f | bellard | } PollingEntry; |
2672 | f331110f | bellard | |
2673 | f331110f | bellard | static PollingEntry *first_polling_entry;
|
2674 | f331110f | bellard | |
2675 | f331110f | bellard | int qemu_add_polling_cb(PollingFunc *func, void *opaque) |
2676 | f331110f | bellard | { |
2677 | f331110f | bellard | PollingEntry **ppe, *pe; |
2678 | f331110f | bellard | pe = qemu_mallocz(sizeof(PollingEntry));
|
2679 | f331110f | bellard | pe->func = func; |
2680 | f331110f | bellard | pe->opaque = opaque; |
2681 | f331110f | bellard | for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next); |
2682 | f331110f | bellard | *ppe = pe; |
2683 | f331110f | bellard | return 0; |
2684 | f331110f | bellard | } |
2685 | f331110f | bellard | |
2686 | f331110f | bellard | void qemu_del_polling_cb(PollingFunc *func, void *opaque) |
2687 | f331110f | bellard | { |
2688 | f331110f | bellard | PollingEntry **ppe, *pe; |
2689 | f331110f | bellard | for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next) { |
2690 | f331110f | bellard | pe = *ppe; |
2691 | f331110f | bellard | if (pe->func == func && pe->opaque == opaque) {
|
2692 | f331110f | bellard | *ppe = pe->next; |
2693 | f331110f | bellard | qemu_free(pe); |
2694 | f331110f | bellard | break;
|
2695 | f331110f | bellard | } |
2696 | f331110f | bellard | } |
2697 | f331110f | bellard | } |
2698 | f331110f | bellard | |
2699 | a18e524a | bellard | /***********************************************************/
|
2700 | a18e524a | bellard | /* Wait objects support */
|
2701 | a18e524a | bellard | typedef struct WaitObjects { |
2702 | a18e524a | bellard | int num;
|
2703 | a18e524a | bellard | HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
|
2704 | a18e524a | bellard | WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
|
2705 | a18e524a | bellard | void *opaque[MAXIMUM_WAIT_OBJECTS + 1]; |
2706 | a18e524a | bellard | } WaitObjects; |
2707 | a18e524a | bellard | |
2708 | a18e524a | bellard | static WaitObjects wait_objects = {0}; |
2709 | 3b46e624 | ths | |
2710 | a18e524a | bellard | int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) |
2711 | a18e524a | bellard | { |
2712 | a18e524a | bellard | WaitObjects *w = &wait_objects; |
2713 | a18e524a | bellard | |
2714 | a18e524a | bellard | if (w->num >= MAXIMUM_WAIT_OBJECTS)
|
2715 | a18e524a | bellard | return -1; |
2716 | a18e524a | bellard | w->events[w->num] = handle; |
2717 | a18e524a | bellard | w->func[w->num] = func; |
2718 | a18e524a | bellard | w->opaque[w->num] = opaque; |
2719 | a18e524a | bellard | w->num++; |
2720 | a18e524a | bellard | return 0; |
2721 | a18e524a | bellard | } |
2722 | a18e524a | bellard | |
2723 | a18e524a | bellard | void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) |
2724 | a18e524a | bellard | { |
2725 | a18e524a | bellard | int i, found;
|
2726 | a18e524a | bellard | WaitObjects *w = &wait_objects; |
2727 | a18e524a | bellard | |
2728 | a18e524a | bellard | found = 0;
|
2729 | a18e524a | bellard | for (i = 0; i < w->num; i++) { |
2730 | a18e524a | bellard | if (w->events[i] == handle)
|
2731 | a18e524a | bellard | found = 1;
|
2732 | a18e524a | bellard | if (found) {
|
2733 | a18e524a | bellard | w->events[i] = w->events[i + 1];
|
2734 | a18e524a | bellard | w->func[i] = w->func[i + 1];
|
2735 | a18e524a | bellard | w->opaque[i] = w->opaque[i + 1];
|
2736 | 3b46e624 | ths | } |
2737 | a18e524a | bellard | } |
2738 | a18e524a | bellard | if (found)
|
2739 | a18e524a | bellard | w->num--; |
2740 | a18e524a | bellard | } |
2741 | a18e524a | bellard | #endif
|
2742 | a18e524a | bellard | |
2743 | 8a7ddc38 | bellard | /***********************************************************/
|
2744 | 8a7ddc38 | bellard | /* ram save/restore */
|
2745 | 8a7ddc38 | bellard | |
2746 | 94fb0909 | Juan Quintela | #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ |
2747 | 475e4277 | aliguori | #define RAM_SAVE_FLAG_COMPRESS 0x02 |
2748 | 475e4277 | aliguori | #define RAM_SAVE_FLAG_MEM_SIZE 0x04 |
2749 | 475e4277 | aliguori | #define RAM_SAVE_FLAG_PAGE 0x08 |
2750 | 475e4277 | aliguori | #define RAM_SAVE_FLAG_EOS 0x10 |
2751 | 475e4277 | aliguori | |
2752 | 475e4277 | aliguori | static int is_dup_page(uint8_t *page, uint8_t ch) |
2753 | 8a7ddc38 | bellard | { |
2754 | 475e4277 | aliguori | uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch; |
2755 | 475e4277 | aliguori | uint32_t *array = (uint32_t *)page; |
2756 | 475e4277 | aliguori | int i;
|
2757 | 3b46e624 | ths | |
2758 | 475e4277 | aliguori | for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) { |
2759 | 475e4277 | aliguori | if (array[i] != val)
|
2760 | 475e4277 | aliguori | return 0; |
2761 | 475e4277 | aliguori | } |
2762 | 475e4277 | aliguori | |
2763 | 475e4277 | aliguori | return 1; |
2764 | 475e4277 | aliguori | } |
2765 | 475e4277 | aliguori | |
2766 | 475e4277 | aliguori | static int ram_save_block(QEMUFile *f) |
2767 | 475e4277 | aliguori | { |
2768 | c227f099 | Anthony Liguori | static ram_addr_t current_addr = 0; |
2769 | c227f099 | Anthony Liguori | ram_addr_t saved_addr = current_addr; |
2770 | c227f099 | Anthony Liguori | ram_addr_t addr = 0;
|
2771 | 475e4277 | aliguori | int found = 0; |
2772 | 475e4277 | aliguori | |
2773 | 94a6b54f | pbrook | while (addr < last_ram_offset) {
|
2774 | 475e4277 | aliguori | if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) {
|
2775 | 5579c7f3 | pbrook | uint8_t *p; |
2776 | 475e4277 | aliguori | |
2777 | 475e4277 | aliguori | cpu_physical_memory_reset_dirty(current_addr, |
2778 | 475e4277 | aliguori | current_addr + TARGET_PAGE_SIZE, |
2779 | 475e4277 | aliguori | MIGRATION_DIRTY_FLAG); |
2780 | 475e4277 | aliguori | |
2781 | 5579c7f3 | pbrook | p = qemu_get_ram_ptr(current_addr); |
2782 | 475e4277 | aliguori | |
2783 | 5579c7f3 | pbrook | if (is_dup_page(p, *p)) {
|
2784 | 475e4277 | aliguori | qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_COMPRESS); |
2785 | 5579c7f3 | pbrook | qemu_put_byte(f, *p); |
2786 | 475e4277 | aliguori | } else {
|
2787 | 475e4277 | aliguori | qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_PAGE); |
2788 | 5579c7f3 | pbrook | qemu_put_buffer(f, p, TARGET_PAGE_SIZE); |
2789 | c88676f8 | bellard | } |
2790 | 475e4277 | aliguori | |
2791 | 475e4277 | aliguori | found = 1;
|
2792 | 475e4277 | aliguori | break;
|
2793 | c88676f8 | bellard | } |
2794 | 475e4277 | aliguori | addr += TARGET_PAGE_SIZE; |
2795 | 94a6b54f | pbrook | current_addr = (saved_addr + addr) % last_ram_offset; |
2796 | 8a7ddc38 | bellard | } |
2797 | 475e4277 | aliguori | |
2798 | 475e4277 | aliguori | return found;
|
2799 | 8a7ddc38 | bellard | } |
2800 | 8a7ddc38 | bellard | |
2801 | 84307938 | Jan Kiszka | static uint64_t bytes_transferred;
|
2802 | 475e4277 | aliguori | |
2803 | c227f099 | Anthony Liguori | static ram_addr_t ram_save_remaining(void) |
2804 | 475e4277 | aliguori | { |
2805 | c227f099 | Anthony Liguori | ram_addr_t addr; |
2806 | c227f099 | Anthony Liguori | ram_addr_t count = 0;
|
2807 | 475e4277 | aliguori | |
2808 | 94a6b54f | pbrook | for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) { |
2809 | 475e4277 | aliguori | if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG))
|
2810 | 475e4277 | aliguori | count++; |
2811 | 475e4277 | aliguori | } |
2812 | 475e4277 | aliguori | |
2813 | 475e4277 | aliguori | return count;
|
2814 | 475e4277 | aliguori | } |
2815 | 475e4277 | aliguori | |
2816 | 9f9e28cd | Glauber Costa | uint64_t ram_bytes_remaining(void)
|
2817 | 9f9e28cd | Glauber Costa | { |
2818 | 9f9e28cd | Glauber Costa | return ram_save_remaining() * TARGET_PAGE_SIZE;
|
2819 | 9f9e28cd | Glauber Costa | } |
2820 | 9f9e28cd | Glauber Costa | |
2821 | 9f9e28cd | Glauber Costa | uint64_t ram_bytes_transferred(void)
|
2822 | 9f9e28cd | Glauber Costa | { |
2823 | 9f9e28cd | Glauber Costa | return bytes_transferred;
|
2824 | 9f9e28cd | Glauber Costa | } |
2825 | 9f9e28cd | Glauber Costa | |
2826 | 9f9e28cd | Glauber Costa | uint64_t ram_bytes_total(void)
|
2827 | 9f9e28cd | Glauber Costa | { |
2828 | 9f9e28cd | Glauber Costa | return last_ram_offset;
|
2829 | 9f9e28cd | Glauber Costa | } |
2830 | 9f9e28cd | Glauber Costa | |
2831 | f327aa0c | Jan Kiszka | static int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) |
2832 | 475e4277 | aliguori | { |
2833 | c227f099 | Anthony Liguori | ram_addr_t addr; |
2834 | a0a3fd60 | Glauber Costa | uint64_t bytes_transferred_last; |
2835 | a0a3fd60 | Glauber Costa | double bwidth = 0; |
2836 | a0a3fd60 | Glauber Costa | uint64_t expected_time = 0;
|
2837 | 475e4277 | aliguori | |
2838 | 4ec7fcc7 | Jan Kiszka | if (stage < 0) { |
2839 | 4ec7fcc7 | Jan Kiszka | cpu_physical_memory_set_dirty_tracking(0);
|
2840 | 4ec7fcc7 | Jan Kiszka | return 0; |
2841 | 4ec7fcc7 | Jan Kiszka | } |
2842 | 4ec7fcc7 | Jan Kiszka | |
2843 | 9fa06385 | Jan Kiszka | if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) { |
2844 | b0a46a33 | Jan Kiszka | qemu_file_set_error(f); |
2845 | b0a46a33 | Jan Kiszka | return 0; |
2846 | b0a46a33 | Jan Kiszka | } |
2847 | b0a46a33 | Jan Kiszka | |
2848 | 475e4277 | aliguori | if (stage == 1) { |
2849 | 84307938 | Jan Kiszka | bytes_transferred = 0;
|
2850 | 84307938 | Jan Kiszka | |
2851 | 475e4277 | aliguori | /* Make sure all dirty bits are set */
|
2852 | 94a6b54f | pbrook | for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) { |
2853 | 475e4277 | aliguori | if (!cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG))
|
2854 | 475e4277 | aliguori | cpu_physical_memory_set_dirty(addr); |
2855 | 475e4277 | aliguori | } |
2856 | b0a46a33 | Jan Kiszka | |
2857 | 475e4277 | aliguori | /* Enable dirty memory tracking */
|
2858 | 475e4277 | aliguori | cpu_physical_memory_set_dirty_tracking(1);
|
2859 | 475e4277 | aliguori | |
2860 | 94a6b54f | pbrook | qemu_put_be64(f, last_ram_offset | RAM_SAVE_FLAG_MEM_SIZE); |
2861 | 475e4277 | aliguori | } |
2862 | 475e4277 | aliguori | |
2863 | a0a3fd60 | Glauber Costa | bytes_transferred_last = bytes_transferred; |
2864 | 41c872b6 | Paolo Bonzini | bwidth = qemu_get_clock_ns(rt_clock); |
2865 | a0a3fd60 | Glauber Costa | |
2866 | 475e4277 | aliguori | while (!qemu_file_rate_limit(f)) {
|
2867 | 475e4277 | aliguori | int ret;
|
2868 | 475e4277 | aliguori | |
2869 | 475e4277 | aliguori | ret = ram_save_block(f); |
2870 | 9f9e28cd | Glauber Costa | bytes_transferred += ret * TARGET_PAGE_SIZE; |
2871 | 475e4277 | aliguori | if (ret == 0) /* no more blocks */ |
2872 | 475e4277 | aliguori | break;
|
2873 | 475e4277 | aliguori | } |
2874 | 475e4277 | aliguori | |
2875 | 41c872b6 | Paolo Bonzini | bwidth = qemu_get_clock_ns(rt_clock) - bwidth; |
2876 | a0a3fd60 | Glauber Costa | bwidth = (bytes_transferred - bytes_transferred_last) / bwidth; |
2877 | a0a3fd60 | Glauber Costa | |
2878 | a0a3fd60 | Glauber Costa | /* if we haven't transferred anything this round, force expected_time to a
|
2879 | a0a3fd60 | Glauber Costa | * a very high value, but without crashing */
|
2880 | a0a3fd60 | Glauber Costa | if (bwidth == 0) |
2881 | a0a3fd60 | Glauber Costa | bwidth = 0.000001; |
2882 | a0a3fd60 | Glauber Costa | |
2883 | 475e4277 | aliguori | /* try transferring iterative blocks of memory */
|
2884 | 475e4277 | aliguori | if (stage == 3) { |
2885 | 475e4277 | aliguori | /* flush all remaining blocks regardless of rate limiting */
|
2886 | 9f9e28cd | Glauber Costa | while (ram_save_block(f) != 0) { |
2887 | 9f9e28cd | Glauber Costa | bytes_transferred += TARGET_PAGE_SIZE; |
2888 | 9f9e28cd | Glauber Costa | } |
2889 | 8215e914 | aliguori | cpu_physical_memory_set_dirty_tracking(0);
|
2890 | 475e4277 | aliguori | } |
2891 | 475e4277 | aliguori | |
2892 | 475e4277 | aliguori | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
2893 | 475e4277 | aliguori | |
2894 | a0a3fd60 | Glauber Costa | expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth; |
2895 | a0a3fd60 | Glauber Costa | |
2896 | a0a3fd60 | Glauber Costa | return (stage == 2) && (expected_time <= migrate_max_downtime()); |
2897 | 475e4277 | aliguori | } |
2898 | 475e4277 | aliguori | |
2899 | 475e4277 | aliguori | static int ram_load(QEMUFile *f, void *opaque, int version_id) |
2900 | 475e4277 | aliguori | { |
2901 | c227f099 | Anthony Liguori | ram_addr_t addr; |
2902 | 475e4277 | aliguori | int flags;
|
2903 | 475e4277 | aliguori | |
2904 | 475e4277 | aliguori | if (version_id != 3) |
2905 | 475e4277 | aliguori | return -EINVAL;
|
2906 | 475e4277 | aliguori | |
2907 | 475e4277 | aliguori | do {
|
2908 | 475e4277 | aliguori | addr = qemu_get_be64(f); |
2909 | 475e4277 | aliguori | |
2910 | 475e4277 | aliguori | flags = addr & ~TARGET_PAGE_MASK; |
2911 | 475e4277 | aliguori | addr &= TARGET_PAGE_MASK; |
2912 | 475e4277 | aliguori | |
2913 | 475e4277 | aliguori | if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
|
2914 | 94a6b54f | pbrook | if (addr != last_ram_offset)
|
2915 | 475e4277 | aliguori | return -EINVAL;
|
2916 | 475e4277 | aliguori | } |
2917 | 475e4277 | aliguori | |
2918 | 475e4277 | aliguori | if (flags & RAM_SAVE_FLAG_COMPRESS) {
|
2919 | 475e4277 | aliguori | uint8_t ch = qemu_get_byte(f); |
2920 | 779c6bef | Anthony Liguori | memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE); |
2921 | 779c6bef | Anthony Liguori | #ifndef _WIN32
|
2922 | 30868442 | Anthony Liguori | if (ch == 0 && |
2923 | 30868442 | Anthony Liguori | (!kvm_enabled() || kvm_has_sync_mmu())) { |
2924 | 30868442 | Anthony Liguori | madvise(qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE, MADV_DONTNEED); |
2925 | 779c6bef | Anthony Liguori | } |
2926 | 30868442 | Anthony Liguori | #endif
|
2927 | 9a743e5b | Jan Kiszka | } else if (flags & RAM_SAVE_FLAG_PAGE) { |
2928 | 5579c7f3 | pbrook | qemu_get_buffer(f, qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE); |
2929 | 9a743e5b | Jan Kiszka | } |
2930 | 9a743e5b | Jan Kiszka | if (qemu_file_has_error(f)) {
|
2931 | 9a743e5b | Jan Kiszka | return -EIO;
|
2932 | 9a743e5b | Jan Kiszka | } |
2933 | 475e4277 | aliguori | } while (!(flags & RAM_SAVE_FLAG_EOS));
|
2934 | 475e4277 | aliguori | |
2935 | 8a7ddc38 | bellard | return 0; |
2936 | 8a7ddc38 | bellard | } |
2937 | 8a7ddc38 | bellard | |
2938 | 9e472e10 | aliguori | void qemu_service_io(void) |
2939 | 9e472e10 | aliguori | { |
2940 | d9f75a4e | aliguori | qemu_notify_event(); |
2941 | 9e472e10 | aliguori | } |
2942 | 9e472e10 | aliguori | |
2943 | 8a7ddc38 | bellard | /***********************************************************/
|
2944 | cc1daa40 | bellard | /* machine registration */
|
2945 | cc1daa40 | bellard | |
2946 | bdaf78e0 | blueswir1 | static QEMUMachine *first_machine = NULL; |
2947 | 6f338c34 | aliguori | QEMUMachine *current_machine = NULL;
|
2948 | cc1daa40 | bellard | |
2949 | cc1daa40 | bellard | int qemu_register_machine(QEMUMachine *m)
|
2950 | cc1daa40 | bellard | { |
2951 | cc1daa40 | bellard | QEMUMachine **pm; |
2952 | cc1daa40 | bellard | pm = &first_machine; |
2953 | cc1daa40 | bellard | while (*pm != NULL) |
2954 | cc1daa40 | bellard | pm = &(*pm)->next; |
2955 | cc1daa40 | bellard | m->next = NULL;
|
2956 | cc1daa40 | bellard | *pm = m; |
2957 | cc1daa40 | bellard | return 0; |
2958 | cc1daa40 | bellard | } |
2959 | cc1daa40 | bellard | |
2960 | 9596ebb7 | pbrook | static QEMUMachine *find_machine(const char *name) |
2961 | cc1daa40 | bellard | { |
2962 | cc1daa40 | bellard | QEMUMachine *m; |
2963 | cc1daa40 | bellard | |
2964 | cc1daa40 | bellard | for(m = first_machine; m != NULL; m = m->next) { |
2965 | cc1daa40 | bellard | if (!strcmp(m->name, name))
|
2966 | cc1daa40 | bellard | return m;
|
2967 | 3f6599e6 | Mark McLoughlin | if (m->alias && !strcmp(m->alias, name))
|
2968 | 3f6599e6 | Mark McLoughlin | return m;
|
2969 | cc1daa40 | bellard | } |
2970 | cc1daa40 | bellard | return NULL; |
2971 | cc1daa40 | bellard | } |
2972 | cc1daa40 | bellard | |
2973 | 0c257437 | Anthony Liguori | static QEMUMachine *find_default_machine(void) |
2974 | 0c257437 | Anthony Liguori | { |
2975 | 0c257437 | Anthony Liguori | QEMUMachine *m; |
2976 | 0c257437 | Anthony Liguori | |
2977 | 0c257437 | Anthony Liguori | for(m = first_machine; m != NULL; m = m->next) { |
2978 | 0c257437 | Anthony Liguori | if (m->is_default) {
|
2979 | 0c257437 | Anthony Liguori | return m;
|
2980 | 0c257437 | Anthony Liguori | } |
2981 | 0c257437 | Anthony Liguori | } |
2982 | 0c257437 | Anthony Liguori | return NULL; |
2983 | 0c257437 | Anthony Liguori | } |
2984 | 0c257437 | Anthony Liguori | |
2985 | cc1daa40 | bellard | /***********************************************************/
|
2986 | 8a7ddc38 | bellard | /* main execution loop */
|
2987 | 8a7ddc38 | bellard | |
2988 | 9596ebb7 | pbrook | static void gui_update(void *opaque) |
2989 | 8a7ddc38 | bellard | { |
2990 | 7d957bd8 | aliguori | uint64_t interval = GUI_REFRESH_INTERVAL; |
2991 | 740733bb | ths | DisplayState *ds = opaque; |
2992 | 7d957bd8 | aliguori | DisplayChangeListener *dcl = ds->listeners; |
2993 | 7d957bd8 | aliguori | |
2994 | 62a2744c | Sheng Yang | qemu_flush_coalesced_mmio_buffer(); |
2995 | 7d957bd8 | aliguori | dpy_refresh(ds); |
2996 | 7d957bd8 | aliguori | |
2997 | 7d957bd8 | aliguori | while (dcl != NULL) { |
2998 | 7d957bd8 | aliguori | if (dcl->gui_timer_interval &&
|
2999 | 7d957bd8 | aliguori | dcl->gui_timer_interval < interval) |
3000 | 7d957bd8 | aliguori | interval = dcl->gui_timer_interval; |
3001 | 7d957bd8 | aliguori | dcl = dcl->next; |
3002 | 7d957bd8 | aliguori | } |
3003 | 7d957bd8 | aliguori | qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock)); |
3004 | 8a7ddc38 | bellard | } |
3005 | 8a7ddc38 | bellard | |
3006 | 9043b62d | blueswir1 | static void nographic_update(void *opaque) |
3007 | 9043b62d | blueswir1 | { |
3008 | 9043b62d | blueswir1 | uint64_t interval = GUI_REFRESH_INTERVAL; |
3009 | 9043b62d | blueswir1 | |
3010 | 62a2744c | Sheng Yang | qemu_flush_coalesced_mmio_buffer(); |
3011 | 9043b62d | blueswir1 | qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock)); |
3012 | 9043b62d | blueswir1 | } |
3013 | 9043b62d | blueswir1 | |
3014 | ea375f9a | Jan Kiszka | void cpu_synchronize_all_states(void) |
3015 | ea375f9a | Jan Kiszka | { |
3016 | ea375f9a | Jan Kiszka | CPUState *cpu; |
3017 | ea375f9a | Jan Kiszka | |
3018 | ea375f9a | Jan Kiszka | for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
|
3019 | ea375f9a | Jan Kiszka | cpu_synchronize_state(cpu); |
3020 | ea375f9a | Jan Kiszka | } |
3021 | ea375f9a | Jan Kiszka | } |
3022 | ea375f9a | Jan Kiszka | |
3023 | ea375f9a | Jan Kiszka | void cpu_synchronize_all_post_reset(void) |
3024 | ea375f9a | Jan Kiszka | { |
3025 | ea375f9a | Jan Kiszka | CPUState *cpu; |
3026 | ea375f9a | Jan Kiszka | |
3027 | ea375f9a | Jan Kiszka | for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
|
3028 | ea375f9a | Jan Kiszka | cpu_synchronize_post_reset(cpu); |
3029 | ea375f9a | Jan Kiszka | } |
3030 | ea375f9a | Jan Kiszka | } |
3031 | ea375f9a | Jan Kiszka | |
3032 | ea375f9a | Jan Kiszka | void cpu_synchronize_all_post_init(void) |
3033 | ea375f9a | Jan Kiszka | { |
3034 | ea375f9a | Jan Kiszka | CPUState *cpu; |
3035 | ea375f9a | Jan Kiszka | |
3036 | ea375f9a | Jan Kiszka | for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
|
3037 | ea375f9a | Jan Kiszka | cpu_synchronize_post_init(cpu); |
3038 | ea375f9a | Jan Kiszka | } |
3039 | ea375f9a | Jan Kiszka | } |
3040 | ea375f9a | Jan Kiszka | |
3041 | 0bd48850 | bellard | struct vm_change_state_entry {
|
3042 | 0bd48850 | bellard | VMChangeStateHandler *cb; |
3043 | 0bd48850 | bellard | void *opaque;
|
3044 | 72cf2d4f | Blue Swirl | QLIST_ENTRY (vm_change_state_entry) entries; |
3045 | 0bd48850 | bellard | }; |
3046 | 0bd48850 | bellard | |
3047 | 72cf2d4f | Blue Swirl | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
|
3048 | 0bd48850 | bellard | |
3049 | 0bd48850 | bellard | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
3050 | 0bd48850 | bellard | void *opaque)
|
3051 | 0bd48850 | bellard | { |
3052 | 0bd48850 | bellard | VMChangeStateEntry *e; |
3053 | 0bd48850 | bellard | |
3054 | 0bd48850 | bellard | e = qemu_mallocz(sizeof (*e));
|
3055 | 0bd48850 | bellard | |
3056 | 0bd48850 | bellard | e->cb = cb; |
3057 | 0bd48850 | bellard | e->opaque = opaque; |
3058 | 72cf2d4f | Blue Swirl | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
3059 | 0bd48850 | bellard | return e;
|
3060 | 0bd48850 | bellard | } |
3061 | 0bd48850 | bellard | |
3062 | 0bd48850 | bellard | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
|
3063 | 0bd48850 | bellard | { |
3064 | 72cf2d4f | Blue Swirl | QLIST_REMOVE (e, entries); |
3065 | 0bd48850 | bellard | qemu_free (e); |
3066 | 0bd48850 | bellard | } |
3067 | 0bd48850 | bellard | |
3068 | 9781e040 | aliguori | static void vm_state_notify(int running, int reason) |
3069 | 0bd48850 | bellard | { |
3070 | 0bd48850 | bellard | VMChangeStateEntry *e; |
3071 | 0bd48850 | bellard | |
3072 | 0bd48850 | bellard | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
|
3073 | 9781e040 | aliguori | e->cb(e->opaque, running, reason); |
3074 | 0bd48850 | bellard | } |
3075 | 0bd48850 | bellard | } |
3076 | 0bd48850 | bellard | |
3077 | d6dc3d42 | aliguori | static void resume_all_vcpus(void); |
3078 | d6dc3d42 | aliguori | static void pause_all_vcpus(void); |
3079 | d6dc3d42 | aliguori | |
3080 | 8a7ddc38 | bellard | void vm_start(void) |
3081 | 8a7ddc38 | bellard | { |
3082 | 8a7ddc38 | bellard | if (!vm_running) {
|
3083 | 8a7ddc38 | bellard | cpu_enable_ticks(); |
3084 | 8a7ddc38 | bellard | vm_running = 1;
|
3085 | 9781e040 | aliguori | vm_state_notify(1, 0); |
3086 | efe75411 | ths | qemu_rearm_alarm_timer(alarm_timer); |
3087 | d6dc3d42 | aliguori | resume_all_vcpus(); |
3088 | 8a7ddc38 | bellard | } |
3089 | 8a7ddc38 | bellard | } |
3090 | 8a7ddc38 | bellard | |
3091 | bb0c6722 | bellard | /* reset/shutdown handler */
|
3092 | bb0c6722 | bellard | |
3093 | bb0c6722 | bellard | typedef struct QEMUResetEntry { |
3094 | 72cf2d4f | Blue Swirl | QTAILQ_ENTRY(QEMUResetEntry) entry; |
3095 | bb0c6722 | bellard | QEMUResetHandler *func; |
3096 | bb0c6722 | bellard | void *opaque;
|
3097 | bb0c6722 | bellard | } QEMUResetEntry; |
3098 | bb0c6722 | bellard | |
3099 | 72cf2d4f | Blue Swirl | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
|
3100 | 72cf2d4f | Blue Swirl | QTAILQ_HEAD_INITIALIZER(reset_handlers); |
3101 | bb0c6722 | bellard | static int reset_requested; |
3102 | bb0c6722 | bellard | static int shutdown_requested; |
3103 | 3475187d | bellard | static int powerdown_requested; |
3104 | e568902a | aliguori | static int debug_requested; |
3105 | 6e29f5da | aliguori | static int vmstop_requested; |
3106 | bb0c6722 | bellard | |
3107 | cf7a2fe2 | aurel32 | int qemu_shutdown_requested(void) |
3108 | cf7a2fe2 | aurel32 | { |
3109 | cf7a2fe2 | aurel32 | int r = shutdown_requested;
|
3110 | cf7a2fe2 | aurel32 | shutdown_requested = 0;
|
3111 | cf7a2fe2 | aurel32 | return r;
|
3112 | cf7a2fe2 | aurel32 | } |
3113 | cf7a2fe2 | aurel32 | |
3114 | cf7a2fe2 | aurel32 | int qemu_reset_requested(void) |
3115 | cf7a2fe2 | aurel32 | { |
3116 | cf7a2fe2 | aurel32 | int r = reset_requested;
|
3117 | cf7a2fe2 | aurel32 | reset_requested = 0;
|
3118 | cf7a2fe2 | aurel32 | return r;
|
3119 | cf7a2fe2 | aurel32 | } |
3120 | cf7a2fe2 | aurel32 | |
3121 | cf7a2fe2 | aurel32 | int qemu_powerdown_requested(void) |
3122 | cf7a2fe2 | aurel32 | { |
3123 | cf7a2fe2 | aurel32 | int r = powerdown_requested;
|
3124 | cf7a2fe2 | aurel32 | powerdown_requested = 0;
|
3125 | cf7a2fe2 | aurel32 | return r;
|
3126 | cf7a2fe2 | aurel32 | } |
3127 | cf7a2fe2 | aurel32 | |
3128 | e568902a | aliguori | static int qemu_debug_requested(void) |
3129 | e568902a | aliguori | { |
3130 | e568902a | aliguori | int r = debug_requested;
|
3131 | e568902a | aliguori | debug_requested = 0;
|
3132 | e568902a | aliguori | return r;
|
3133 | e568902a | aliguori | } |
3134 | e568902a | aliguori | |
3135 | 6e29f5da | aliguori | static int qemu_vmstop_requested(void) |
3136 | 6e29f5da | aliguori | { |
3137 | 6e29f5da | aliguori | int r = vmstop_requested;
|
3138 | 6e29f5da | aliguori | vmstop_requested = 0;
|
3139 | 6e29f5da | aliguori | return r;
|
3140 | 6e29f5da | aliguori | } |
3141 | 6e29f5da | aliguori | |
3142 | 6e29f5da | aliguori | static void do_vm_stop(int reason) |
3143 | 6e29f5da | aliguori | { |
3144 | 6e29f5da | aliguori | if (vm_running) {
|
3145 | 6e29f5da | aliguori | cpu_disable_ticks(); |
3146 | 6e29f5da | aliguori | vm_running = 0;
|
3147 | d6dc3d42 | aliguori | pause_all_vcpus(); |
3148 | 6e29f5da | aliguori | vm_state_notify(0, reason);
|
3149 | 6b8f8fff | Luiz Capitulino | monitor_protocol_event(QEVENT_STOP, NULL);
|
3150 | 6e29f5da | aliguori | } |
3151 | 6e29f5da | aliguori | } |
3152 | 6e29f5da | aliguori | |
3153 | a08d4367 | Jan Kiszka | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
3154 | bb0c6722 | bellard | { |
3155 | 55ddfe8e | Jan Kiszka | QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
|
3156 | bb0c6722 | bellard | |
3157 | bb0c6722 | bellard | re->func = func; |
3158 | bb0c6722 | bellard | re->opaque = opaque; |
3159 | 72cf2d4f | Blue Swirl | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
3160 | bb0c6722 | bellard | } |
3161 | bb0c6722 | bellard | |
3162 | dda9b29f | Jan Kiszka | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
3163 | bb0c6722 | bellard | { |
3164 | bb0c6722 | bellard | QEMUResetEntry *re; |
3165 | bb0c6722 | bellard | |
3166 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
3167 | dda9b29f | Jan Kiszka | if (re->func == func && re->opaque == opaque) {
|
3168 | 72cf2d4f | Blue Swirl | QTAILQ_REMOVE(&reset_handlers, re, entry); |
3169 | dda9b29f | Jan Kiszka | qemu_free(re); |
3170 | dda9b29f | Jan Kiszka | return;
|
3171 | dda9b29f | Jan Kiszka | } |
3172 | dda9b29f | Jan Kiszka | } |
3173 | dda9b29f | Jan Kiszka | } |
3174 | dda9b29f | Jan Kiszka | |
3175 | dda9b29f | Jan Kiszka | void qemu_system_reset(void) |
3176 | dda9b29f | Jan Kiszka | { |
3177 | dda9b29f | Jan Kiszka | QEMUResetEntry *re, *nre; |
3178 | dda9b29f | Jan Kiszka | |
3179 | dda9b29f | Jan Kiszka | /* reset all devices */
|
3180 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
3181 | bb0c6722 | bellard | re->func(re->opaque); |
3182 | bb0c6722 | bellard | } |
3183 | 81d9b784 | Luiz Capitulino | monitor_protocol_event(QEVENT_RESET, NULL);
|
3184 | ea375f9a | Jan Kiszka | cpu_synchronize_all_post_reset(); |
3185 | bb0c6722 | bellard | } |
3186 | bb0c6722 | bellard | |
3187 | bb0c6722 | bellard | void qemu_system_reset_request(void) |
3188 | bb0c6722 | bellard | { |
3189 | d1beab82 | bellard | if (no_reboot) {
|
3190 | d1beab82 | bellard | shutdown_requested = 1;
|
3191 | d1beab82 | bellard | } else {
|
3192 | d1beab82 | bellard | reset_requested = 1;
|
3193 | d1beab82 | bellard | } |
3194 | d9f75a4e | aliguori | qemu_notify_event(); |
3195 | bb0c6722 | bellard | } |
3196 | bb0c6722 | bellard | |
3197 | bb0c6722 | bellard | void qemu_system_shutdown_request(void) |
3198 | bb0c6722 | bellard | { |
3199 | bb0c6722 | bellard | shutdown_requested = 1;
|
3200 | d9f75a4e | aliguori | qemu_notify_event(); |
3201 | bb0c6722 | bellard | } |
3202 | bb0c6722 | bellard | |
3203 | 3475187d | bellard | void qemu_system_powerdown_request(void) |
3204 | 3475187d | bellard | { |
3205 | 3475187d | bellard | powerdown_requested = 1;
|
3206 | d9f75a4e | aliguori | qemu_notify_event(); |
3207 | d9f75a4e | aliguori | } |
3208 | d9f75a4e | aliguori | |
3209 | d6dc3d42 | aliguori | #ifdef CONFIG_IOTHREAD
|
3210 | d6dc3d42 | aliguori | static void qemu_system_vmstop_request(int reason) |
3211 | d9f75a4e | aliguori | { |
3212 | d6dc3d42 | aliguori | vmstop_requested = reason; |
3213 | d6dc3d42 | aliguori | qemu_notify_event(); |
3214 | bb0c6722 | bellard | } |
3215 | d6dc3d42 | aliguori | #endif
|
3216 | bb0c6722 | bellard | |
3217 | 50317c7f | aliguori | #ifndef _WIN32
|
3218 | 50317c7f | aliguori | static int io_thread_fd = -1; |
3219 | 50317c7f | aliguori | |
3220 | 50317c7f | aliguori | static void qemu_event_increment(void) |
3221 | 3fcf7b6b | aliguori | { |
3222 | f3dfda61 | Paolo Bonzini | /* Write 8 bytes to be compatible with eventfd. */
|
3223 | f3dfda61 | Paolo Bonzini | static uint64_t val = 1; |
3224 | dc330e28 | Kirill A. Shutemov | ssize_t ret; |
3225 | 50317c7f | aliguori | |
3226 | 50317c7f | aliguori | if (io_thread_fd == -1) |
3227 | 50317c7f | aliguori | return;
|
3228 | 50317c7f | aliguori | |
3229 | 652ce2d4 | Paolo Bonzini | do {
|
3230 | f3dfda61 | Paolo Bonzini | ret = write(io_thread_fd, &val, sizeof(val));
|
3231 | 652ce2d4 | Paolo Bonzini | } while (ret < 0 && errno == EINTR); |
3232 | 652ce2d4 | Paolo Bonzini | |
3233 | 652ce2d4 | Paolo Bonzini | /* EAGAIN is fine, a read must be pending. */
|
3234 | 652ce2d4 | Paolo Bonzini | if (ret < 0 && errno != EAGAIN) { |
3235 | dc330e28 | Kirill A. Shutemov | fprintf(stderr, "qemu_event_increment: write() filed: %s\n",
|
3236 | dc330e28 | Kirill A. Shutemov | strerror(errno)); |
3237 | dc330e28 | Kirill A. Shutemov | exit (1);
|
3238 | dc330e28 | Kirill A. Shutemov | } |
3239 | 50317c7f | aliguori | } |
3240 | 50317c7f | aliguori | |
3241 | 50317c7f | aliguori | static void qemu_event_read(void *opaque) |
3242 | 50317c7f | aliguori | { |
3243 | 50317c7f | aliguori | int fd = (unsigned long)opaque; |
3244 | 50317c7f | aliguori | ssize_t len; |
3245 | 1d0f0d91 | Paolo Bonzini | char buffer[512]; |
3246 | 50317c7f | aliguori | |
3247 | f3dfda61 | Paolo Bonzini | /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
|
3248 | 50317c7f | aliguori | do {
|
3249 | 50317c7f | aliguori | len = read(fd, buffer, sizeof(buffer));
|
3250 | 1d0f0d91 | Paolo Bonzini | } while ((len == -1 && errno == EINTR) || len == sizeof(buffer)); |
3251 | 50317c7f | aliguori | } |
3252 | 50317c7f | aliguori | |
3253 | 50317c7f | aliguori | static int qemu_event_init(void) |
3254 | 50317c7f | aliguori | { |
3255 | 50317c7f | aliguori | int err;
|
3256 | 50317c7f | aliguori | int fds[2]; |
3257 | 50317c7f | aliguori | |
3258 | f3dfda61 | Paolo Bonzini | err = qemu_eventfd(fds); |
3259 | 50317c7f | aliguori | if (err == -1) |
3260 | 50317c7f | aliguori | return -errno;
|
3261 | 50317c7f | aliguori | |
3262 | 50317c7f | aliguori | err = fcntl_setfl(fds[0], O_NONBLOCK);
|
3263 | 50317c7f | aliguori | if (err < 0) |
3264 | 50317c7f | aliguori | goto fail;
|
3265 | 50317c7f | aliguori | |
3266 | 50317c7f | aliguori | err = fcntl_setfl(fds[1], O_NONBLOCK);
|
3267 | 50317c7f | aliguori | if (err < 0) |
3268 | 50317c7f | aliguori | goto fail;
|
3269 | 50317c7f | aliguori | |
3270 | 50317c7f | aliguori | qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL, |
3271 | 50317c7f | aliguori | (void *)(unsigned long)fds[0]); |
3272 | 50317c7f | aliguori | |
3273 | 50317c7f | aliguori | io_thread_fd = fds[1];
|
3274 | a7e21219 | Jan Kiszka | return 0; |
3275 | a7e21219 | Jan Kiszka | |
3276 | 50317c7f | aliguori | fail:
|
3277 | 50317c7f | aliguori | close(fds[0]);
|
3278 | 50317c7f | aliguori | close(fds[1]);
|
3279 | 50317c7f | aliguori | return err;
|
3280 | 50317c7f | aliguori | } |
3281 | 50317c7f | aliguori | #else
|
3282 | 50317c7f | aliguori | HANDLE qemu_event_handle; |
3283 | 50317c7f | aliguori | |
3284 | 50317c7f | aliguori | static void dummy_event_handler(void *opaque) |
3285 | 50317c7f | aliguori | { |
3286 | 50317c7f | aliguori | } |
3287 | 50317c7f | aliguori | |
3288 | 50317c7f | aliguori | static int qemu_event_init(void) |
3289 | 50317c7f | aliguori | { |
3290 | 50317c7f | aliguori | qemu_event_handle = CreateEvent(NULL, FALSE, FALSE, NULL); |
3291 | 50317c7f | aliguori | if (!qemu_event_handle) {
|
3292 | 20889d4e | Blue Swirl | fprintf(stderr, "Failed CreateEvent: %ld\n", GetLastError());
|
3293 | 50317c7f | aliguori | return -1; |
3294 | 50317c7f | aliguori | } |
3295 | 50317c7f | aliguori | qemu_add_wait_object(qemu_event_handle, dummy_event_handler, NULL);
|
3296 | 3fcf7b6b | aliguori | return 0; |
3297 | 3fcf7b6b | aliguori | } |
3298 | 3fcf7b6b | aliguori | |
3299 | 50317c7f | aliguori | static void qemu_event_increment(void) |
3300 | 50317c7f | aliguori | { |
3301 | de1c90cf | malc | if (!SetEvent(qemu_event_handle)) {
|
3302 | 20889d4e | Blue Swirl | fprintf(stderr, "qemu_event_increment: SetEvent failed: %ld\n",
|
3303 | de1c90cf | malc | GetLastError()); |
3304 | de1c90cf | malc | exit (1);
|
3305 | de1c90cf | malc | } |
3306 | 50317c7f | aliguori | } |
3307 | 50317c7f | aliguori | #endif
|
3308 | 50317c7f | aliguori | |
3309 | d6dc3d42 | aliguori | static int cpu_can_run(CPUState *env) |
3310 | d6dc3d42 | aliguori | { |
3311 | d6dc3d42 | aliguori | if (env->stop)
|
3312 | d6dc3d42 | aliguori | return 0; |
3313 | d6dc3d42 | aliguori | if (env->stopped)
|
3314 | d6dc3d42 | aliguori | return 0; |
3315 | c5f32c99 | Marcelo Tosatti | if (!vm_running)
|
3316 | c5f32c99 | Marcelo Tosatti | return 0; |
3317 | d6dc3d42 | aliguori | return 1; |
3318 | d6dc3d42 | aliguori | } |
3319 | d6dc3d42 | aliguori | |
3320 | d6dc3d42 | aliguori | #ifndef CONFIG_IOTHREAD
|
3321 | 50317c7f | aliguori | static int qemu_init_main_loop(void) |
3322 | 50317c7f | aliguori | { |
3323 | 50317c7f | aliguori | return qemu_event_init();
|
3324 | 50317c7f | aliguori | } |
3325 | 50317c7f | aliguori | |
3326 | 0bf46a40 | aliguori | void qemu_init_vcpu(void *_env) |
3327 | 0bf46a40 | aliguori | { |
3328 | 0bf46a40 | aliguori | CPUState *env = _env; |
3329 | 0bf46a40 | aliguori | |
3330 | dc6b1c09 | Andre Przywara | env->nr_cores = smp_cores; |
3331 | dc6b1c09 | Andre Przywara | env->nr_threads = smp_threads; |
3332 | 3f7638ec | Jiri Denemark | if (kvm_enabled())
|
3333 | 3f7638ec | Jiri Denemark | kvm_init_vcpu(env); |
3334 | 0bf46a40 | aliguori | return;
|
3335 | 0bf46a40 | aliguori | } |
3336 | 0bf46a40 | aliguori | |
3337 | 8edac960 | aliguori | int qemu_cpu_self(void *env) |
3338 | 8edac960 | aliguori | { |
3339 | 8edac960 | aliguori | return 1; |
3340 | 8edac960 | aliguori | } |
3341 | 8edac960 | aliguori | |
3342 | d6dc3d42 | aliguori | static void resume_all_vcpus(void) |
3343 | d6dc3d42 | aliguori | { |
3344 | d6dc3d42 | aliguori | } |
3345 | d6dc3d42 | aliguori | |
3346 | d6dc3d42 | aliguori | static void pause_all_vcpus(void) |
3347 | d6dc3d42 | aliguori | { |
3348 | d6dc3d42 | aliguori | } |
3349 | d6dc3d42 | aliguori | |
3350 | 8edac960 | aliguori | void qemu_cpu_kick(void *env) |
3351 | 8edac960 | aliguori | { |
3352 | 8edac960 | aliguori | return;
|
3353 | 8edac960 | aliguori | } |
3354 | 8edac960 | aliguori | |
3355 | d6dc3d42 | aliguori | void qemu_notify_event(void) |
3356 | d6dc3d42 | aliguori | { |
3357 | d6dc3d42 | aliguori | CPUState *env = cpu_single_env; |
3358 | d6dc3d42 | aliguori | |
3359 | d6dc3d42 | aliguori | if (env) {
|
3360 | d6dc3d42 | aliguori | cpu_exit(env); |
3361 | 4a1418e0 | Anthony Liguori | } |
3362 | d6dc3d42 | aliguori | } |
3363 | d6dc3d42 | aliguori | |
3364 | d549db5a | Glauber Costa | void qemu_mutex_lock_iothread(void) {} |
3365 | d549db5a | Glauber Costa | void qemu_mutex_unlock_iothread(void) {} |
3366 | 4870852c | aliguori | |
3367 | 6e29f5da | aliguori | void vm_stop(int reason) |
3368 | 6e29f5da | aliguori | { |
3369 | 6e29f5da | aliguori | do_vm_stop(reason); |
3370 | 6e29f5da | aliguori | } |
3371 | 6e29f5da | aliguori | |
3372 | d6dc3d42 | aliguori | #else /* CONFIG_IOTHREAD */ |
3373 | d6dc3d42 | aliguori | |
3374 | d6dc3d42 | aliguori | #include "qemu-thread.h" |
3375 | d6dc3d42 | aliguori | |
3376 | d6dc3d42 | aliguori | QemuMutex qemu_global_mutex; |
3377 | d6dc3d42 | aliguori | static QemuMutex qemu_fair_mutex;
|
3378 | d6dc3d42 | aliguori | |
3379 | d6dc3d42 | aliguori | static QemuThread io_thread;
|
3380 | d6dc3d42 | aliguori | |
3381 | d6dc3d42 | aliguori | static QemuThread *tcg_cpu_thread;
|
3382 | d6dc3d42 | aliguori | static QemuCond *tcg_halt_cond;
|
3383 | d6dc3d42 | aliguori | |
3384 | d6dc3d42 | aliguori | static int qemu_system_ready; |
3385 | d6dc3d42 | aliguori | /* cpu creation */
|
3386 | d6dc3d42 | aliguori | static QemuCond qemu_cpu_cond;
|
3387 | d6dc3d42 | aliguori | /* system init */
|
3388 | d6dc3d42 | aliguori | static QemuCond qemu_system_cond;
|
3389 | d6dc3d42 | aliguori | static QemuCond qemu_pause_cond;
|
3390 | d6dc3d42 | aliguori | |
3391 | cc84de95 | Marcelo Tosatti | static void tcg_block_io_signals(void); |
3392 | cc84de95 | Marcelo Tosatti | static void kvm_block_io_signals(CPUState *env); |
3393 | d6dc3d42 | aliguori | static void unblock_io_signals(void); |
3394 | d6dc3d42 | aliguori | static int tcg_has_work(void); |
3395 | fed6c344 | Marcelo Tosatti | static int cpu_has_work(CPUState *env); |
3396 | d6dc3d42 | aliguori | |
3397 | d6dc3d42 | aliguori | static int qemu_init_main_loop(void) |
3398 | d6dc3d42 | aliguori | { |
3399 | d6dc3d42 | aliguori | int ret;
|
3400 | d6dc3d42 | aliguori | |
3401 | d6dc3d42 | aliguori | ret = qemu_event_init(); |
3402 | d6dc3d42 | aliguori | if (ret)
|
3403 | d6dc3d42 | aliguori | return ret;
|
3404 | d6dc3d42 | aliguori | |
3405 | d6dc3d42 | aliguori | qemu_cond_init(&qemu_pause_cond); |
3406 | d6dc3d42 | aliguori | qemu_mutex_init(&qemu_fair_mutex); |
3407 | d6dc3d42 | aliguori | qemu_mutex_init(&qemu_global_mutex); |
3408 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_global_mutex); |
3409 | d6dc3d42 | aliguori | |
3410 | d6dc3d42 | aliguori | unblock_io_signals(); |
3411 | d6dc3d42 | aliguori | qemu_thread_self(&io_thread); |
3412 | d6dc3d42 | aliguori | |
3413 | d6dc3d42 | aliguori | return 0; |
3414 | d6dc3d42 | aliguori | } |
3415 | d6dc3d42 | aliguori | |
3416 | fed6c344 | Marcelo Tosatti | static void qemu_wait_io_event_common(CPUState *env) |
3417 | fed6c344 | Marcelo Tosatti | { |
3418 | fed6c344 | Marcelo Tosatti | if (env->stop) {
|
3419 | fed6c344 | Marcelo Tosatti | env->stop = 0;
|
3420 | fed6c344 | Marcelo Tosatti | env->stopped = 1;
|
3421 | fed6c344 | Marcelo Tosatti | qemu_cond_signal(&qemu_pause_cond); |
3422 | fed6c344 | Marcelo Tosatti | } |
3423 | fed6c344 | Marcelo Tosatti | } |
3424 | fed6c344 | Marcelo Tosatti | |
3425 | d6dc3d42 | aliguori | static void qemu_wait_io_event(CPUState *env) |
3426 | d6dc3d42 | aliguori | { |
3427 | d6dc3d42 | aliguori | while (!tcg_has_work())
|
3428 | d6dc3d42 | aliguori | qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000);
|
3429 | d6dc3d42 | aliguori | |
3430 | d6dc3d42 | aliguori | qemu_mutex_unlock(&qemu_global_mutex); |
3431 | d6dc3d42 | aliguori | |
3432 | d6dc3d42 | aliguori | /*
|
3433 | d6dc3d42 | aliguori | * Users of qemu_global_mutex can be starved, having no chance
|
3434 | d6dc3d42 | aliguori | * to acquire it since this path will get to it first.
|
3435 | d6dc3d42 | aliguori | * So use another lock to provide fairness.
|
3436 | d6dc3d42 | aliguori | */
|
3437 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_fair_mutex); |
3438 | d6dc3d42 | aliguori | qemu_mutex_unlock(&qemu_fair_mutex); |
3439 | d6dc3d42 | aliguori | |
3440 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_global_mutex); |
3441 | fed6c344 | Marcelo Tosatti | qemu_wait_io_event_common(env); |
3442 | fed6c344 | Marcelo Tosatti | } |
3443 | fed6c344 | Marcelo Tosatti | |
3444 | cc84de95 | Marcelo Tosatti | static void qemu_kvm_eat_signal(CPUState *env, int timeout) |
3445 | cc84de95 | Marcelo Tosatti | { |
3446 | cc84de95 | Marcelo Tosatti | struct timespec ts;
|
3447 | cc84de95 | Marcelo Tosatti | int r, e;
|
3448 | cc84de95 | Marcelo Tosatti | siginfo_t siginfo; |
3449 | cc84de95 | Marcelo Tosatti | sigset_t waitset; |
3450 | cc84de95 | Marcelo Tosatti | |
3451 | cc84de95 | Marcelo Tosatti | ts.tv_sec = timeout / 1000;
|
3452 | cc84de95 | Marcelo Tosatti | ts.tv_nsec = (timeout % 1000) * 1000000; |
3453 | cc84de95 | Marcelo Tosatti | |
3454 | cc84de95 | Marcelo Tosatti | sigemptyset(&waitset); |
3455 | cc84de95 | Marcelo Tosatti | sigaddset(&waitset, SIG_IPI); |
3456 | cc84de95 | Marcelo Tosatti | |
3457 | cc84de95 | Marcelo Tosatti | qemu_mutex_unlock(&qemu_global_mutex); |
3458 | cc84de95 | Marcelo Tosatti | r = sigtimedwait(&waitset, &siginfo, &ts); |
3459 | cc84de95 | Marcelo Tosatti | e = errno; |
3460 | cc84de95 | Marcelo Tosatti | qemu_mutex_lock(&qemu_global_mutex); |
3461 | cc84de95 | Marcelo Tosatti | |
3462 | cc84de95 | Marcelo Tosatti | if (r == -1 && !(e == EAGAIN || e == EINTR)) { |
3463 | cc84de95 | Marcelo Tosatti | fprintf(stderr, "sigtimedwait: %s\n", strerror(e));
|
3464 | cc84de95 | Marcelo Tosatti | exit(1);
|
3465 | d6dc3d42 | aliguori | } |
3466 | d6dc3d42 | aliguori | } |
3467 | d6dc3d42 | aliguori | |
3468 | fed6c344 | Marcelo Tosatti | static void qemu_kvm_wait_io_event(CPUState *env) |
3469 | fed6c344 | Marcelo Tosatti | { |
3470 | fed6c344 | Marcelo Tosatti | while (!cpu_has_work(env))
|
3471 | fed6c344 | Marcelo Tosatti | qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000);
|
3472 | fed6c344 | Marcelo Tosatti | |
3473 | cc84de95 | Marcelo Tosatti | qemu_kvm_eat_signal(env, 0);
|
3474 | fed6c344 | Marcelo Tosatti | qemu_wait_io_event_common(env); |
3475 | d6dc3d42 | aliguori | } |
3476 | d6dc3d42 | aliguori | |
3477 | d6dc3d42 | aliguori | static int qemu_cpu_exec(CPUState *env); |
3478 | d6dc3d42 | aliguori | |
3479 | d6dc3d42 | aliguori | static void *kvm_cpu_thread_fn(void *arg) |
3480 | d6dc3d42 | aliguori | { |
3481 | d6dc3d42 | aliguori | CPUState *env = arg; |
3482 | d6dc3d42 | aliguori | |
3483 | d6dc3d42 | aliguori | qemu_thread_self(env->thread); |
3484 | 321c1cb1 | Jean-Christophe DUBOIS | if (kvm_enabled())
|
3485 | 321c1cb1 | Jean-Christophe DUBOIS | kvm_init_vcpu(env); |
3486 | d6dc3d42 | aliguori | |
3487 | cc84de95 | Marcelo Tosatti | kvm_block_io_signals(env); |
3488 | cc84de95 | Marcelo Tosatti | |
3489 | d6dc3d42 | aliguori | /* signal CPU creation */
|
3490 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_global_mutex); |
3491 | d6dc3d42 | aliguori | env->created = 1;
|
3492 | d6dc3d42 | aliguori | qemu_cond_signal(&qemu_cpu_cond); |
3493 | d6dc3d42 | aliguori | |
3494 | d6dc3d42 | aliguori | /* and wait for machine initialization */
|
3495 | d6dc3d42 | aliguori | while (!qemu_system_ready)
|
3496 | d6dc3d42 | aliguori | qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100);
|
3497 | d6dc3d42 | aliguori | |
3498 | d6dc3d42 | aliguori | while (1) { |
3499 | d6dc3d42 | aliguori | if (cpu_can_run(env))
|
3500 | d6dc3d42 | aliguori | qemu_cpu_exec(env); |
3501 | fed6c344 | Marcelo Tosatti | qemu_kvm_wait_io_event(env); |
3502 | d6dc3d42 | aliguori | } |
3503 | d6dc3d42 | aliguori | |
3504 | d6dc3d42 | aliguori | return NULL; |
3505 | d6dc3d42 | aliguori | } |
3506 | d6dc3d42 | aliguori | |
3507 | d6dc3d42 | aliguori | static void tcg_cpu_exec(void); |
3508 | d6dc3d42 | aliguori | |
3509 | d6dc3d42 | aliguori | static void *tcg_cpu_thread_fn(void *arg) |
3510 | d6dc3d42 | aliguori | { |
3511 | d6dc3d42 | aliguori | CPUState *env = arg; |
3512 | d6dc3d42 | aliguori | |
3513 | cc84de95 | Marcelo Tosatti | tcg_block_io_signals(); |
3514 | d6dc3d42 | aliguori | qemu_thread_self(env->thread); |
3515 | d6dc3d42 | aliguori | |
3516 | d6dc3d42 | aliguori | /* signal CPU creation */
|
3517 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_global_mutex); |
3518 | d6dc3d42 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) |
3519 | d6dc3d42 | aliguori | env->created = 1;
|
3520 | d6dc3d42 | aliguori | qemu_cond_signal(&qemu_cpu_cond); |
3521 | d6dc3d42 | aliguori | |
3522 | d6dc3d42 | aliguori | /* and wait for machine initialization */
|
3523 | d6dc3d42 | aliguori | while (!qemu_system_ready)
|
3524 | d6dc3d42 | aliguori | qemu_cond_timedwait(&qemu_system_cond, &qemu_global_mutex, 100);
|
3525 | d6dc3d42 | aliguori | |
3526 | d6dc3d42 | aliguori | while (1) { |
3527 | d6dc3d42 | aliguori | tcg_cpu_exec(); |
3528 | d6dc3d42 | aliguori | qemu_wait_io_event(cur_cpu); |
3529 | d6dc3d42 | aliguori | } |
3530 | d6dc3d42 | aliguori | |
3531 | d6dc3d42 | aliguori | return NULL; |
3532 | d6dc3d42 | aliguori | } |
3533 | d6dc3d42 | aliguori | |
3534 | d6dc3d42 | aliguori | void qemu_cpu_kick(void *_env) |
3535 | d6dc3d42 | aliguori | { |
3536 | d6dc3d42 | aliguori | CPUState *env = _env; |
3537 | d6dc3d42 | aliguori | qemu_cond_broadcast(env->halt_cond); |
3538 | d6dc3d42 | aliguori | if (kvm_enabled())
|
3539 | cc84de95 | Marcelo Tosatti | qemu_thread_signal(env->thread, SIG_IPI); |
3540 | d6dc3d42 | aliguori | } |
3541 | d6dc3d42 | aliguori | |
3542 | e5bc201d | Glauber Costa | int qemu_cpu_self(void *_env) |
3543 | d6dc3d42 | aliguori | { |
3544 | e5bc201d | Glauber Costa | CPUState *env = _env; |
3545 | e5bc201d | Glauber Costa | QemuThread this; |
3546 | e5bc201d | Glauber Costa | |
3547 | e5bc201d | Glauber Costa | qemu_thread_self(&this); |
3548 | e5bc201d | Glauber Costa | |
3549 | e5bc201d | Glauber Costa | return qemu_thread_equal(&this, env->thread);
|
3550 | d6dc3d42 | aliguori | } |
3551 | d6dc3d42 | aliguori | |
3552 | d6dc3d42 | aliguori | static void cpu_signal(int sig) |
3553 | d6dc3d42 | aliguori | { |
3554 | d6dc3d42 | aliguori | if (cpu_single_env)
|
3555 | d6dc3d42 | aliguori | cpu_exit(cpu_single_env); |
3556 | d6dc3d42 | aliguori | } |
3557 | d6dc3d42 | aliguori | |
3558 | cc84de95 | Marcelo Tosatti | static void tcg_block_io_signals(void) |
3559 | d6dc3d42 | aliguori | { |
3560 | d6dc3d42 | aliguori | sigset_t set; |
3561 | d6dc3d42 | aliguori | struct sigaction sigact;
|
3562 | d6dc3d42 | aliguori | |
3563 | d6dc3d42 | aliguori | sigemptyset(&set); |
3564 | d6dc3d42 | aliguori | sigaddset(&set, SIGUSR2); |
3565 | d6dc3d42 | aliguori | sigaddset(&set, SIGIO); |
3566 | d6dc3d42 | aliguori | sigaddset(&set, SIGALRM); |
3567 | adc8c965 | Marcelo Tosatti | sigaddset(&set, SIGCHLD); |
3568 | d6dc3d42 | aliguori | pthread_sigmask(SIG_BLOCK, &set, NULL);
|
3569 | d6dc3d42 | aliguori | |
3570 | d6dc3d42 | aliguori | sigemptyset(&set); |
3571 | cc84de95 | Marcelo Tosatti | sigaddset(&set, SIG_IPI); |
3572 | d6dc3d42 | aliguori | pthread_sigmask(SIG_UNBLOCK, &set, NULL);
|
3573 | d6dc3d42 | aliguori | |
3574 | d6dc3d42 | aliguori | memset(&sigact, 0, sizeof(sigact)); |
3575 | d6dc3d42 | aliguori | sigact.sa_handler = cpu_signal; |
3576 | cc84de95 | Marcelo Tosatti | sigaction(SIG_IPI, &sigact, NULL);
|
3577 | cc84de95 | Marcelo Tosatti | } |
3578 | cc84de95 | Marcelo Tosatti | |
3579 | cc84de95 | Marcelo Tosatti | static void dummy_signal(int sig) |
3580 | cc84de95 | Marcelo Tosatti | { |
3581 | cc84de95 | Marcelo Tosatti | } |
3582 | cc84de95 | Marcelo Tosatti | |
3583 | cc84de95 | Marcelo Tosatti | static void kvm_block_io_signals(CPUState *env) |
3584 | cc84de95 | Marcelo Tosatti | { |
3585 | cc84de95 | Marcelo Tosatti | int r;
|
3586 | cc84de95 | Marcelo Tosatti | sigset_t set; |
3587 | cc84de95 | Marcelo Tosatti | struct sigaction sigact;
|
3588 | cc84de95 | Marcelo Tosatti | |
3589 | cc84de95 | Marcelo Tosatti | sigemptyset(&set); |
3590 | cc84de95 | Marcelo Tosatti | sigaddset(&set, SIGUSR2); |
3591 | cc84de95 | Marcelo Tosatti | sigaddset(&set, SIGIO); |
3592 | cc84de95 | Marcelo Tosatti | sigaddset(&set, SIGALRM); |
3593 | cc84de95 | Marcelo Tosatti | sigaddset(&set, SIGCHLD); |
3594 | cc84de95 | Marcelo Tosatti | sigaddset(&set, SIG_IPI); |
3595 | cc84de95 | Marcelo Tosatti | pthread_sigmask(SIG_BLOCK, &set, NULL);
|
3596 | cc84de95 | Marcelo Tosatti | |
3597 | cc84de95 | Marcelo Tosatti | pthread_sigmask(SIG_BLOCK, NULL, &set);
|
3598 | cc84de95 | Marcelo Tosatti | sigdelset(&set, SIG_IPI); |
3599 | cc84de95 | Marcelo Tosatti | |
3600 | cc84de95 | Marcelo Tosatti | memset(&sigact, 0, sizeof(sigact)); |
3601 | cc84de95 | Marcelo Tosatti | sigact.sa_handler = dummy_signal; |
3602 | cc84de95 | Marcelo Tosatti | sigaction(SIG_IPI, &sigact, NULL);
|
3603 | cc84de95 | Marcelo Tosatti | |
3604 | cc84de95 | Marcelo Tosatti | r = kvm_set_signal_mask(env, &set); |
3605 | cc84de95 | Marcelo Tosatti | if (r) {
|
3606 | cc84de95 | Marcelo Tosatti | fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(r));
|
3607 | cc84de95 | Marcelo Tosatti | exit(1);
|
3608 | cc84de95 | Marcelo Tosatti | } |
3609 | d6dc3d42 | aliguori | } |
3610 | d6dc3d42 | aliguori | |
3611 | d6dc3d42 | aliguori | static void unblock_io_signals(void) |
3612 | d6dc3d42 | aliguori | { |
3613 | d6dc3d42 | aliguori | sigset_t set; |
3614 | d6dc3d42 | aliguori | |
3615 | d6dc3d42 | aliguori | sigemptyset(&set); |
3616 | d6dc3d42 | aliguori | sigaddset(&set, SIGUSR2); |
3617 | d6dc3d42 | aliguori | sigaddset(&set, SIGIO); |
3618 | d6dc3d42 | aliguori | sigaddset(&set, SIGALRM); |
3619 | d6dc3d42 | aliguori | pthread_sigmask(SIG_UNBLOCK, &set, NULL);
|
3620 | d6dc3d42 | aliguori | |
3621 | d6dc3d42 | aliguori | sigemptyset(&set); |
3622 | cc84de95 | Marcelo Tosatti | sigaddset(&set, SIG_IPI); |
3623 | d6dc3d42 | aliguori | pthread_sigmask(SIG_BLOCK, &set, NULL);
|
3624 | d6dc3d42 | aliguori | } |
3625 | d6dc3d42 | aliguori | |
3626 | d6dc3d42 | aliguori | static void qemu_signal_lock(unsigned int msecs) |
3627 | d6dc3d42 | aliguori | { |
3628 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_fair_mutex); |
3629 | d6dc3d42 | aliguori | |
3630 | d6dc3d42 | aliguori | while (qemu_mutex_trylock(&qemu_global_mutex)) {
|
3631 | cc84de95 | Marcelo Tosatti | qemu_thread_signal(tcg_cpu_thread, SIG_IPI); |
3632 | d6dc3d42 | aliguori | if (!qemu_mutex_timedlock(&qemu_global_mutex, msecs))
|
3633 | d6dc3d42 | aliguori | break;
|
3634 | d6dc3d42 | aliguori | } |
3635 | d6dc3d42 | aliguori | qemu_mutex_unlock(&qemu_fair_mutex); |
3636 | d6dc3d42 | aliguori | } |
3637 | d6dc3d42 | aliguori | |
3638 | d549db5a | Glauber Costa | void qemu_mutex_lock_iothread(void) |
3639 | d6dc3d42 | aliguori | { |
3640 | d6dc3d42 | aliguori | if (kvm_enabled()) {
|
3641 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_fair_mutex); |
3642 | d6dc3d42 | aliguori | qemu_mutex_lock(&qemu_global_mutex); |
3643 | d6dc3d42 | aliguori | qemu_mutex_unlock(&qemu_fair_mutex); |
3644 | d6dc3d42 | aliguori | } else
|
3645 | d6dc3d42 | aliguori | qemu_signal_lock(100);
|
3646 | d6dc3d42 | aliguori | } |
3647 | d6dc3d42 | aliguori | |
3648 | d549db5a | Glauber Costa | void qemu_mutex_unlock_iothread(void) |
3649 | d6dc3d42 | aliguori | { |
3650 | d6dc3d42 | aliguori | qemu_mutex_unlock(&qemu_global_mutex); |
3651 | d6dc3d42 | aliguori | } |
3652 | d6dc3d42 | aliguori | |
3653 | d6dc3d42 | aliguori | static int all_vcpus_paused(void) |
3654 | d6dc3d42 | aliguori | { |
3655 | d6dc3d42 | aliguori | CPUState *penv = first_cpu; |
3656 | d6dc3d42 | aliguori | |
3657 | d6dc3d42 | aliguori | while (penv) {
|
3658 | d6dc3d42 | aliguori | if (!penv->stopped)
|
3659 | d6dc3d42 | aliguori | return 0; |
3660 | d6dc3d42 | aliguori | penv = (CPUState *)penv->next_cpu; |
3661 | d6dc3d42 | aliguori | } |
3662 | d6dc3d42 | aliguori | |
3663 | d6dc3d42 | aliguori | return 1; |
3664 | d6dc3d42 | aliguori | } |
3665 | d6dc3d42 | aliguori | |
3666 | d6dc3d42 | aliguori | static void pause_all_vcpus(void) |
3667 | d6dc3d42 | aliguori | { |
3668 | d6dc3d42 | aliguori | CPUState *penv = first_cpu; |
3669 | d6dc3d42 | aliguori | |
3670 | d6dc3d42 | aliguori | while (penv) {
|
3671 | d6dc3d42 | aliguori | penv->stop = 1;
|
3672 | cc84de95 | Marcelo Tosatti | qemu_thread_signal(penv->thread, SIG_IPI); |
3673 | d6dc3d42 | aliguori | qemu_cpu_kick(penv); |
3674 | d6dc3d42 | aliguori | penv = (CPUState *)penv->next_cpu; |
3675 | d6dc3d42 | aliguori | } |
3676 | d6dc3d42 | aliguori | |
3677 | d6dc3d42 | aliguori | while (!all_vcpus_paused()) {
|
3678 | d6dc3d42 | aliguori | qemu_cond_timedwait(&qemu_pause_cond, &qemu_global_mutex, 100);
|
3679 | d6dc3d42 | aliguori | penv = first_cpu; |
3680 | d6dc3d42 | aliguori | while (penv) {
|
3681 | cc84de95 | Marcelo Tosatti | qemu_thread_signal(penv->thread, SIG_IPI); |
3682 | d6dc3d42 | aliguori | penv = (CPUState *)penv->next_cpu; |
3683 | d6dc3d42 | aliguori | } |
3684 | d6dc3d42 | aliguori | } |
3685 | d6dc3d42 | aliguori | } |
3686 | d6dc3d42 | aliguori | |
3687 | d6dc3d42 | aliguori | static void resume_all_vcpus(void) |
3688 | d6dc3d42 | aliguori | { |
3689 | d6dc3d42 | aliguori | CPUState *penv = first_cpu; |
3690 | d6dc3d42 | aliguori | |
3691 | d6dc3d42 | aliguori | while (penv) {
|
3692 | d6dc3d42 | aliguori | penv->stop = 0;
|
3693 | d6dc3d42 | aliguori | penv->stopped = 0;
|
3694 | cc84de95 | Marcelo Tosatti | qemu_thread_signal(penv->thread, SIG_IPI); |
3695 | d6dc3d42 | aliguori | qemu_cpu_kick(penv); |
3696 | d6dc3d42 | aliguori | penv = (CPUState *)penv->next_cpu; |
3697 | d6dc3d42 | aliguori | } |
3698 | d6dc3d42 | aliguori | } |
3699 | d6dc3d42 | aliguori | |
3700 | d6dc3d42 | aliguori | static void tcg_init_vcpu(void *_env) |
3701 | d6dc3d42 | aliguori | { |
3702 | d6dc3d42 | aliguori | CPUState *env = _env; |
3703 | d6dc3d42 | aliguori | /* share a single thread for all cpus with TCG */
|
3704 | d6dc3d42 | aliguori | if (!tcg_cpu_thread) {
|
3705 | d6dc3d42 | aliguori | env->thread = qemu_mallocz(sizeof(QemuThread));
|
3706 | d6dc3d42 | aliguori | env->halt_cond = qemu_mallocz(sizeof(QemuCond));
|
3707 | d6dc3d42 | aliguori | qemu_cond_init(env->halt_cond); |
3708 | d6dc3d42 | aliguori | qemu_thread_create(env->thread, tcg_cpu_thread_fn, env); |
3709 | d6dc3d42 | aliguori | while (env->created == 0) |
3710 | d6dc3d42 | aliguori | qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100);
|
3711 | d6dc3d42 | aliguori | tcg_cpu_thread = env->thread; |
3712 | d6dc3d42 | aliguori | tcg_halt_cond = env->halt_cond; |
3713 | d6dc3d42 | aliguori | } else {
|
3714 | d6dc3d42 | aliguori | env->thread = tcg_cpu_thread; |
3715 | d6dc3d42 | aliguori | env->halt_cond = tcg_halt_cond; |
3716 | d6dc3d42 | aliguori | } |
3717 | d6dc3d42 | aliguori | } |
3718 | d6dc3d42 | aliguori | |
3719 | d6dc3d42 | aliguori | static void kvm_start_vcpu(CPUState *env) |
3720 | d6dc3d42 | aliguori | { |
3721 | d6dc3d42 | aliguori | env->thread = qemu_mallocz(sizeof(QemuThread));
|
3722 | d6dc3d42 | aliguori | env->halt_cond = qemu_mallocz(sizeof(QemuCond));
|
3723 | d6dc3d42 | aliguori | qemu_cond_init(env->halt_cond); |
3724 | d6dc3d42 | aliguori | qemu_thread_create(env->thread, kvm_cpu_thread_fn, env); |
3725 | d6dc3d42 | aliguori | while (env->created == 0) |
3726 | d6dc3d42 | aliguori | qemu_cond_timedwait(&qemu_cpu_cond, &qemu_global_mutex, 100);
|
3727 | d6dc3d42 | aliguori | } |
3728 | d6dc3d42 | aliguori | |
3729 | d6dc3d42 | aliguori | void qemu_init_vcpu(void *_env) |
3730 | d6dc3d42 | aliguori | { |
3731 | d6dc3d42 | aliguori | CPUState *env = _env; |
3732 | d6dc3d42 | aliguori | |
3733 | 3f7638ec | Jiri Denemark | env->nr_cores = smp_cores; |
3734 | 3f7638ec | Jiri Denemark | env->nr_threads = smp_threads; |
3735 | d6dc3d42 | aliguori | if (kvm_enabled())
|
3736 | d6dc3d42 | aliguori | kvm_start_vcpu(env); |
3737 | d6dc3d42 | aliguori | else
|
3738 | d6dc3d42 | aliguori | tcg_init_vcpu(env); |
3739 | d6dc3d42 | aliguori | } |
3740 | d6dc3d42 | aliguori | |
3741 | d6dc3d42 | aliguori | void qemu_notify_event(void) |
3742 | d6dc3d42 | aliguori | { |
3743 | d6dc3d42 | aliguori | qemu_event_increment(); |
3744 | d6dc3d42 | aliguori | } |
3745 | d6dc3d42 | aliguori | |
3746 | d6dc3d42 | aliguori | void vm_stop(int reason) |
3747 | d6dc3d42 | aliguori | { |
3748 | d6dc3d42 | aliguori | QemuThread me; |
3749 | d6dc3d42 | aliguori | qemu_thread_self(&me); |
3750 | d6dc3d42 | aliguori | |
3751 | d6dc3d42 | aliguori | if (!qemu_thread_equal(&me, &io_thread)) {
|
3752 | d6dc3d42 | aliguori | qemu_system_vmstop_request(reason); |
3753 | d6dc3d42 | aliguori | /*
|
3754 | d6dc3d42 | aliguori | * FIXME: should not return to device code in case
|
3755 | d6dc3d42 | aliguori | * vm_stop() has been requested.
|
3756 | d6dc3d42 | aliguori | */
|
3757 | d6dc3d42 | aliguori | if (cpu_single_env) {
|
3758 | d6dc3d42 | aliguori | cpu_exit(cpu_single_env); |
3759 | d6dc3d42 | aliguori | cpu_single_env->stop = 1;
|
3760 | d6dc3d42 | aliguori | } |
3761 | d6dc3d42 | aliguori | return;
|
3762 | d6dc3d42 | aliguori | } |
3763 | d6dc3d42 | aliguori | do_vm_stop(reason); |
3764 | d6dc3d42 | aliguori | } |
3765 | d6dc3d42 | aliguori | |
3766 | d6dc3d42 | aliguori | #endif
|
3767 | d6dc3d42 | aliguori | |
3768 | d6dc3d42 | aliguori | |
3769 | 877cf882 | ths | #ifdef _WIN32
|
3770 | 69d6451c | blueswir1 | static void host_main_loop_wait(int *timeout) |
3771 | 56f3a5d0 | aliguori | { |
3772 | 56f3a5d0 | aliguori | int ret, ret2, i;
|
3773 | f331110f | bellard | PollingEntry *pe; |
3774 | f331110f | bellard | |
3775 | c4b1fcc0 | bellard | |
3776 | f331110f | bellard | /* XXX: need to suppress polling by better using win32 events */
|
3777 | f331110f | bellard | ret = 0;
|
3778 | f331110f | bellard | for(pe = first_polling_entry; pe != NULL; pe = pe->next) { |
3779 | f331110f | bellard | ret |= pe->func(pe->opaque); |
3780 | f331110f | bellard | } |
3781 | e6b1e558 | ths | if (ret == 0) { |
3782 | a18e524a | bellard | int err;
|
3783 | a18e524a | bellard | WaitObjects *w = &wait_objects; |
3784 | 3b46e624 | ths | |
3785 | 56f3a5d0 | aliguori | ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout); |
3786 | a18e524a | bellard | if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) { |
3787 | a18e524a | bellard | if (w->func[ret - WAIT_OBJECT_0])
|
3788 | a18e524a | bellard | w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]); |
3789 | 3b46e624 | ths | |
3790 | 5fafdf24 | ths | /* Check for additional signaled events */
|
3791 | e6b1e558 | ths | for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) { |
3792 | 3b46e624 | ths | |
3793 | e6b1e558 | ths | /* Check if event is signaled */
|
3794 | e6b1e558 | ths | ret2 = WaitForSingleObject(w->events[i], 0);
|
3795 | e6b1e558 | ths | if(ret2 == WAIT_OBJECT_0) {
|
3796 | e6b1e558 | ths | if (w->func[i])
|
3797 | e6b1e558 | ths | w->func[i](w->opaque[i]); |
3798 | e6b1e558 | ths | } else if (ret2 == WAIT_TIMEOUT) { |
3799 | e6b1e558 | ths | } else {
|
3800 | e6b1e558 | ths | err = GetLastError(); |
3801 | e6b1e558 | ths | fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err);
|
3802 | 3b46e624 | ths | } |
3803 | 3b46e624 | ths | } |
3804 | a18e524a | bellard | } else if (ret == WAIT_TIMEOUT) { |
3805 | a18e524a | bellard | } else {
|
3806 | a18e524a | bellard | err = GetLastError(); |
3807 | e6b1e558 | ths | fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);
|
3808 | a18e524a | bellard | } |
3809 | f331110f | bellard | } |
3810 | 56f3a5d0 | aliguori | |
3811 | 56f3a5d0 | aliguori | *timeout = 0;
|
3812 | 56f3a5d0 | aliguori | } |
3813 | 56f3a5d0 | aliguori | #else
|
3814 | 69d6451c | blueswir1 | static void host_main_loop_wait(int *timeout) |
3815 | 56f3a5d0 | aliguori | { |
3816 | 56f3a5d0 | aliguori | } |
3817 | fd1dff4b | bellard | #endif
|
3818 | 56f3a5d0 | aliguori | |
3819 | 56f3a5d0 | aliguori | void main_loop_wait(int timeout) |
3820 | 56f3a5d0 | aliguori | { |
3821 | 56f3a5d0 | aliguori | IOHandlerRecord *ioh; |
3822 | 56f3a5d0 | aliguori | fd_set rfds, wfds, xfds; |
3823 | 56f3a5d0 | aliguori | int ret, nfds;
|
3824 | 56f3a5d0 | aliguori | struct timeval tv;
|
3825 | 56f3a5d0 | aliguori | |
3826 | 56f3a5d0 | aliguori | qemu_bh_update_timeout(&timeout); |
3827 | 56f3a5d0 | aliguori | |
3828 | 56f3a5d0 | aliguori | host_main_loop_wait(&timeout); |
3829 | 56f3a5d0 | aliguori | |
3830 | fd1dff4b | bellard | /* poll any events */
|
3831 | fd1dff4b | bellard | /* XXX: separate device handlers from system ones */
|
3832 | 6abfbd79 | aliguori | nfds = -1;
|
3833 | fd1dff4b | bellard | FD_ZERO(&rfds); |
3834 | fd1dff4b | bellard | FD_ZERO(&wfds); |
3835 | e035649e | bellard | FD_ZERO(&xfds); |
3836 | fd1dff4b | bellard | for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { |
3837 | cafffd40 | ths | if (ioh->deleted)
|
3838 | cafffd40 | ths | continue;
|
3839 | fd1dff4b | bellard | if (ioh->fd_read &&
|
3840 | fd1dff4b | bellard | (!ioh->fd_read_poll || |
3841 | fd1dff4b | bellard | ioh->fd_read_poll(ioh->opaque) != 0)) {
|
3842 | fd1dff4b | bellard | FD_SET(ioh->fd, &rfds); |
3843 | fd1dff4b | bellard | if (ioh->fd > nfds)
|
3844 | fd1dff4b | bellard | nfds = ioh->fd; |
3845 | fd1dff4b | bellard | } |
3846 | fd1dff4b | bellard | if (ioh->fd_write) {
|
3847 | fd1dff4b | bellard | FD_SET(ioh->fd, &wfds); |
3848 | fd1dff4b | bellard | if (ioh->fd > nfds)
|
3849 | fd1dff4b | bellard | nfds = ioh->fd; |
3850 | fd1dff4b | bellard | } |
3851 | fd1dff4b | bellard | } |
3852 | 3b46e624 | ths | |
3853 | 56f3a5d0 | aliguori | tv.tv_sec = timeout / 1000;
|
3854 | 56f3a5d0 | aliguori | tv.tv_usec = (timeout % 1000) * 1000; |
3855 | 56f3a5d0 | aliguori | |
3856 | d918f23e | Jan Kiszka | slirp_select_fill(&nfds, &rfds, &wfds, &xfds); |
3857 | d918f23e | Jan Kiszka | |
3858 | 4870852c | aliguori | qemu_mutex_unlock_iothread(); |
3859 | e035649e | bellard | ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
|
3860 | 4870852c | aliguori | qemu_mutex_lock_iothread(); |
3861 | fd1dff4b | bellard | if (ret > 0) { |
3862 | cafffd40 | ths | IOHandlerRecord **pioh; |
3863 | cafffd40 | ths | |
3864 | cafffd40 | ths | for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { |
3865 | 6ab43fdc | ths | if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
|
3866 | fd1dff4b | bellard | ioh->fd_read(ioh->opaque); |
3867 | 7c9d8e07 | bellard | } |
3868 | 6ab43fdc | ths | if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
|
3869 | fd1dff4b | bellard | ioh->fd_write(ioh->opaque); |
3870 | c4b1fcc0 | bellard | } |
3871 | b4608c04 | bellard | } |
3872 | cafffd40 | ths | |
3873 | cafffd40 | ths | /* remove deleted IO handlers */
|
3874 | cafffd40 | ths | pioh = &first_io_handler; |
3875 | cafffd40 | ths | while (*pioh) {
|
3876 | cafffd40 | ths | ioh = *pioh; |
3877 | cafffd40 | ths | if (ioh->deleted) {
|
3878 | cafffd40 | ths | *pioh = ioh->next; |
3879 | cafffd40 | ths | qemu_free(ioh); |
3880 | 5fafdf24 | ths | } else
|
3881 | cafffd40 | ths | pioh = &ioh->next; |
3882 | cafffd40 | ths | } |
3883 | fd1dff4b | bellard | } |
3884 | d918f23e | Jan Kiszka | |
3885 | d918f23e | Jan Kiszka | slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
|
3886 | c20709aa | bellard | |
3887 | 50317c7f | aliguori | /* rearm timer, if not periodic */
|
3888 | 50317c7f | aliguori | if (alarm_timer->flags & ALARM_FLAG_EXPIRED) {
|
3889 | 50317c7f | aliguori | alarm_timer->flags &= ~ALARM_FLAG_EXPIRED; |
3890 | 50317c7f | aliguori | qemu_rearm_alarm_timer(alarm_timer); |
3891 | 50317c7f | aliguori | } |
3892 | 50317c7f | aliguori | |
3893 | 357c692c | aliguori | /* vm time timers */
|
3894 | d6dc3d42 | aliguori | if (vm_running) {
|
3895 | d6dc3d42 | aliguori | if (!cur_cpu || likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
|
3896 | 0fdddf80 | Jan Kiszka | qemu_run_timers(&active_timers[QEMU_CLOCK_VIRTUAL], |
3897 | 0fdddf80 | Jan Kiszka | qemu_get_clock(vm_clock)); |
3898 | d6dc3d42 | aliguori | } |
3899 | 357c692c | aliguori | |
3900 | 357c692c | aliguori | /* real time timers */
|
3901 | 0fdddf80 | Jan Kiszka | qemu_run_timers(&active_timers[QEMU_CLOCK_REALTIME], |
3902 | 357c692c | aliguori | qemu_get_clock(rt_clock)); |
3903 | 357c692c | aliguori | |
3904 | 21d5d12b | Jan Kiszka | qemu_run_timers(&active_timers[QEMU_CLOCK_HOST], |
3905 | 21d5d12b | Jan Kiszka | qemu_get_clock(host_clock)); |
3906 | 21d5d12b | Jan Kiszka | |
3907 | 423f0742 | pbrook | /* Check bottom-halves last in case any of the earlier events triggered
|
3908 | 423f0742 | pbrook | them. */
|
3909 | 423f0742 | pbrook | qemu_bh_poll(); |
3910 | 3b46e624 | ths | |
3911 | 5905b2e5 | bellard | } |
3912 | 5905b2e5 | bellard | |
3913 | 43b96858 | aliguori | static int qemu_cpu_exec(CPUState *env) |
3914 | 5905b2e5 | bellard | { |
3915 | 43b96858 | aliguori | int ret;
|
3916 | 89bfc105 | bellard | #ifdef CONFIG_PROFILER
|
3917 | 89bfc105 | bellard | int64_t ti; |
3918 | 89bfc105 | bellard | #endif
|
3919 | 5905b2e5 | bellard | |
3920 | 89bfc105 | bellard | #ifdef CONFIG_PROFILER
|
3921 | 43b96858 | aliguori | ti = profile_getclock(); |
3922 | 89bfc105 | bellard | #endif
|
3923 | 43b96858 | aliguori | if (use_icount) {
|
3924 | 43b96858 | aliguori | int64_t count; |
3925 | 43b96858 | aliguori | int decr;
|
3926 | 43b96858 | aliguori | qemu_icount -= (env->icount_decr.u16.low + env->icount_extra); |
3927 | 43b96858 | aliguori | env->icount_decr.u16.low = 0;
|
3928 | 43b96858 | aliguori | env->icount_extra = 0;
|
3929 | 43b96858 | aliguori | count = qemu_next_deadline(); |
3930 | 43b96858 | aliguori | count = (count + (1 << icount_time_shift) - 1) |
3931 | 43b96858 | aliguori | >> icount_time_shift; |
3932 | 43b96858 | aliguori | qemu_icount += count; |
3933 | 43b96858 | aliguori | decr = (count > 0xffff) ? 0xffff : count; |
3934 | 43b96858 | aliguori | count -= decr; |
3935 | 43b96858 | aliguori | env->icount_decr.u16.low = decr; |
3936 | 43b96858 | aliguori | env->icount_extra = count; |
3937 | 43b96858 | aliguori | } |
3938 | 43b96858 | aliguori | ret = cpu_exec(env); |
3939 | 89bfc105 | bellard | #ifdef CONFIG_PROFILER
|
3940 | 43b96858 | aliguori | qemu_time += profile_getclock() - ti; |
3941 | 89bfc105 | bellard | #endif
|
3942 | 43b96858 | aliguori | if (use_icount) {
|
3943 | 43b96858 | aliguori | /* Fold pending instructions back into the
|
3944 | 43b96858 | aliguori | instruction counter, and clear the interrupt flag. */
|
3945 | 43b96858 | aliguori | qemu_icount -= (env->icount_decr.u16.low |
3946 | 43b96858 | aliguori | + env->icount_extra); |
3947 | 43b96858 | aliguori | env->icount_decr.u32 = 0;
|
3948 | 43b96858 | aliguori | env->icount_extra = 0;
|
3949 | 43b96858 | aliguori | } |
3950 | 43b96858 | aliguori | return ret;
|
3951 | 43b96858 | aliguori | } |
3952 | 43b96858 | aliguori | |
3953 | e6e35b1e | aliguori | static void tcg_cpu_exec(void) |
3954 | e6e35b1e | aliguori | { |
3955 | d6dc3d42 | aliguori | int ret = 0; |
3956 | e6e35b1e | aliguori | |
3957 | e6e35b1e | aliguori | if (next_cpu == NULL) |
3958 | e6e35b1e | aliguori | next_cpu = first_cpu; |
3959 | e6e35b1e | aliguori | for (; next_cpu != NULL; next_cpu = next_cpu->next_cpu) { |
3960 | e6e35b1e | aliguori | CPUState *env = cur_cpu = next_cpu; |
3961 | e6e35b1e | aliguori | |
3962 | e6e35b1e | aliguori | if (timer_alarm_pending) {
|
3963 | e6e35b1e | aliguori | timer_alarm_pending = 0;
|
3964 | e6e35b1e | aliguori | break;
|
3965 | e6e35b1e | aliguori | } |
3966 | d6dc3d42 | aliguori | if (cpu_can_run(env))
|
3967 | d6dc3d42 | aliguori | ret = qemu_cpu_exec(env); |
3968 | c37cc7b0 | Marcelo Tosatti | else if (env->stop) |
3969 | c37cc7b0 | Marcelo Tosatti | break;
|
3970 | c37cc7b0 | Marcelo Tosatti | |
3971 | e6e35b1e | aliguori | if (ret == EXCP_DEBUG) {
|
3972 | e6e35b1e | aliguori | gdb_set_stop_cpu(env); |
3973 | e6e35b1e | aliguori | debug_requested = 1;
|
3974 | e6e35b1e | aliguori | break;
|
3975 | e6e35b1e | aliguori | } |
3976 | e6e35b1e | aliguori | } |
3977 | e6e35b1e | aliguori | } |
3978 | e6e35b1e | aliguori | |
3979 | 43b96858 | aliguori | static int cpu_has_work(CPUState *env) |
3980 | 43b96858 | aliguori | { |
3981 | d6dc3d42 | aliguori | if (env->stop)
|
3982 | d6dc3d42 | aliguori | return 1; |
3983 | d6dc3d42 | aliguori | if (env->stopped)
|
3984 | d6dc3d42 | aliguori | return 0; |
3985 | 43b96858 | aliguori | if (!env->halted)
|
3986 | 43b96858 | aliguori | return 1; |
3987 | 43b96858 | aliguori | if (qemu_cpu_has_work(env))
|
3988 | 43b96858 | aliguori | return 1; |
3989 | 43b96858 | aliguori | return 0; |
3990 | 43b96858 | aliguori | } |
3991 | 43b96858 | aliguori | |
3992 | 43b96858 | aliguori | static int tcg_has_work(void) |
3993 | 43b96858 | aliguori | { |
3994 | 43b96858 | aliguori | CPUState *env; |
3995 | 43b96858 | aliguori | |
3996 | 43b96858 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) |
3997 | 43b96858 | aliguori | if (cpu_has_work(env))
|
3998 | 43b96858 | aliguori | return 1; |
3999 | 43b96858 | aliguori | return 0; |
4000 | 43b96858 | aliguori | } |
4001 | 43b96858 | aliguori | |
4002 | 43b96858 | aliguori | static int qemu_calculate_timeout(void) |
4003 | 43b96858 | aliguori | { |
4004 | b319820d | Luiz Capitulino | #ifndef CONFIG_IOTHREAD
|
4005 | 43b96858 | aliguori | int timeout;
|
4006 | 43b96858 | aliguori | |
4007 | 43b96858 | aliguori | if (!vm_running)
|
4008 | 43b96858 | aliguori | timeout = 5000;
|
4009 | 43b96858 | aliguori | else if (tcg_has_work()) |
4010 | 43b96858 | aliguori | timeout = 0;
|
4011 | 43b96858 | aliguori | else if (!use_icount) |
4012 | 43b96858 | aliguori | timeout = 5000;
|
4013 | 43b96858 | aliguori | else {
|
4014 | 43b96858 | aliguori | /* XXX: use timeout computed from timers */
|
4015 | 43b96858 | aliguori | int64_t add; |
4016 | 43b96858 | aliguori | int64_t delta; |
4017 | 43b96858 | aliguori | /* Advance virtual time to the next event. */
|
4018 | 43b96858 | aliguori | if (use_icount == 1) { |
4019 | 43b96858 | aliguori | /* When not using an adaptive execution frequency
|
4020 | 43b96858 | aliguori | we tend to get badly out of sync with real time,
|
4021 | 43b96858 | aliguori | so just delay for a reasonable amount of time. */
|
4022 | 43b96858 | aliguori | delta = 0;
|
4023 | 43b96858 | aliguori | } else {
|
4024 | 43b96858 | aliguori | delta = cpu_get_icount() - cpu_get_clock(); |
4025 | 43b96858 | aliguori | } |
4026 | 43b96858 | aliguori | if (delta > 0) { |
4027 | 43b96858 | aliguori | /* If virtual time is ahead of real time then just
|
4028 | 43b96858 | aliguori | wait for IO. */
|
4029 | 43b96858 | aliguori | timeout = (delta / 1000000) + 1; |
4030 | 43b96858 | aliguori | } else {
|
4031 | 43b96858 | aliguori | /* Wait for either IO to occur or the next
|
4032 | 43b96858 | aliguori | timer event. */
|
4033 | 43b96858 | aliguori | add = qemu_next_deadline(); |
4034 | 43b96858 | aliguori | /* We advance the timer before checking for IO.
|
4035 | 43b96858 | aliguori | Limit the amount we advance so that early IO
|
4036 | 43b96858 | aliguori | activity won't get the guest too far ahead. */
|
4037 | 43b96858 | aliguori | if (add > 10000000) |
4038 | 43b96858 | aliguori | add = 10000000;
|
4039 | 43b96858 | aliguori | delta += add; |
4040 | 43b96858 | aliguori | add = (add + (1 << icount_time_shift) - 1) |
4041 | 43b96858 | aliguori | >> icount_time_shift; |
4042 | 43b96858 | aliguori | qemu_icount += add; |
4043 | 43b96858 | aliguori | timeout = delta / 1000000;
|
4044 | 43b96858 | aliguori | if (timeout < 0) |
4045 | 43b96858 | aliguori | timeout = 0;
|
4046 | 43b96858 | aliguori | } |
4047 | 43b96858 | aliguori | } |
4048 | 43b96858 | aliguori | |
4049 | 43b96858 | aliguori | return timeout;
|
4050 | b319820d | Luiz Capitulino | #else /* CONFIG_IOTHREAD */ |
4051 | b319820d | Luiz Capitulino | return 1000; |
4052 | b319820d | Luiz Capitulino | #endif
|
4053 | 43b96858 | aliguori | } |
4054 | 43b96858 | aliguori | |
4055 | 43b96858 | aliguori | static int vm_can_run(void) |
4056 | 43b96858 | aliguori | { |
4057 | 43b96858 | aliguori | if (powerdown_requested)
|
4058 | 43b96858 | aliguori | return 0; |
4059 | 43b96858 | aliguori | if (reset_requested)
|
4060 | 43b96858 | aliguori | return 0; |
4061 | 43b96858 | aliguori | if (shutdown_requested)
|
4062 | 43b96858 | aliguori | return 0; |
4063 | e568902a | aliguori | if (debug_requested)
|
4064 | e568902a | aliguori | return 0; |
4065 | 43b96858 | aliguori | return 1; |
4066 | 43b96858 | aliguori | } |
4067 | 43b96858 | aliguori | |
4068 | d9c32310 | Blue Swirl | qemu_irq qemu_system_powerdown; |
4069 | d9c32310 | Blue Swirl | |
4070 | 43b96858 | aliguori | static void main_loop(void) |
4071 | 43b96858 | aliguori | { |
4072 | 6e29f5da | aliguori | int r;
|
4073 | e6e35b1e | aliguori | |
4074 | d6dc3d42 | aliguori | #ifdef CONFIG_IOTHREAD
|
4075 | d6dc3d42 | aliguori | qemu_system_ready = 1;
|
4076 | d6dc3d42 | aliguori | qemu_cond_broadcast(&qemu_system_cond); |
4077 | d6dc3d42 | aliguori | #endif
|
4078 | d6dc3d42 | aliguori | |
4079 | 6e29f5da | aliguori | for (;;) {
|
4080 | 43b96858 | aliguori | do {
|
4081 | e6e35b1e | aliguori | #ifdef CONFIG_PROFILER
|
4082 | e6e35b1e | aliguori | int64_t ti; |
4083 | e6e35b1e | aliguori | #endif
|
4084 | d6dc3d42 | aliguori | #ifndef CONFIG_IOTHREAD
|
4085 | e6e35b1e | aliguori | tcg_cpu_exec(); |
4086 | d6dc3d42 | aliguori | #endif
|
4087 | 89bfc105 | bellard | #ifdef CONFIG_PROFILER
|
4088 | 43b96858 | aliguori | ti = profile_getclock(); |
4089 | 89bfc105 | bellard | #endif
|
4090 | 43b96858 | aliguori | main_loop_wait(qemu_calculate_timeout()); |
4091 | 89bfc105 | bellard | #ifdef CONFIG_PROFILER
|
4092 | 43b96858 | aliguori | dev_time += profile_getclock() - ti; |
4093 | 89bfc105 | bellard | #endif
|
4094 | e568902a | aliguori | } while (vm_can_run());
|
4095 | 43b96858 | aliguori | |
4096 | b1a15e7e | Luiz Capitulino | if (qemu_debug_requested()) {
|
4097 | e568902a | aliguori | vm_stop(EXCP_DEBUG); |
4098 | b1a15e7e | Luiz Capitulino | } |
4099 | 43b96858 | aliguori | if (qemu_shutdown_requested()) {
|
4100 | 242cd003 | Blue Swirl | monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
|
4101 | 43b96858 | aliguori | if (no_shutdown) {
|
4102 | 43b96858 | aliguori | vm_stop(0);
|
4103 | 43b96858 | aliguori | no_shutdown = 0;
|
4104 | 43b96858 | aliguori | } else
|
4105 | 43b96858 | aliguori | break;
|
4106 | 43b96858 | aliguori | } |
4107 | d6dc3d42 | aliguori | if (qemu_reset_requested()) {
|
4108 | d6dc3d42 | aliguori | pause_all_vcpus(); |
4109 | 43b96858 | aliguori | qemu_system_reset(); |
4110 | d6dc3d42 | aliguori | resume_all_vcpus(); |
4111 | d6dc3d42 | aliguori | } |
4112 | d9c32310 | Blue Swirl | if (qemu_powerdown_requested()) {
|
4113 | 242cd003 | Blue Swirl | monitor_protocol_event(QEVENT_POWERDOWN, NULL);
|
4114 | d9c32310 | Blue Swirl | qemu_irq_raise(qemu_system_powerdown); |
4115 | d9c32310 | Blue Swirl | } |
4116 | b1a15e7e | Luiz Capitulino | if ((r = qemu_vmstop_requested())) {
|
4117 | 6e29f5da | aliguori | vm_stop(r); |
4118 | b1a15e7e | Luiz Capitulino | } |
4119 | b4608c04 | bellard | } |
4120 | d6dc3d42 | aliguori | pause_all_vcpus(); |
4121 | b4608c04 | bellard | } |
4122 | b4608c04 | bellard | |
4123 | 9bd7e6d9 | pbrook | static void version(void) |
4124 | 9bd7e6d9 | pbrook | { |
4125 | 4a19f1ec | pbrook | printf("QEMU PC emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
4126 | 9bd7e6d9 | pbrook | } |
4127 | 9bd7e6d9 | pbrook | |
4128 | 15f82208 | ths | static void help(int exitcode) |
4129 | 0824d6fc | bellard | { |
4130 | e8105ebb | Paolo Bonzini | const char *options_help = |
4131 | 5824d651 | blueswir1 | #define DEF(option, opt_arg, opt_enum, opt_help) \
|
4132 | 5824d651 | blueswir1 | opt_help |
4133 | 5824d651 | blueswir1 | #define DEFHEADING(text) stringify(text) "\n" |
4134 | 5824d651 | blueswir1 | #include "qemu-options.h" |
4135 | 5824d651 | blueswir1 | #undef DEF
|
4136 | 5824d651 | blueswir1 | #undef DEFHEADING
|
4137 | 5824d651 | blueswir1 | #undef GEN_DOCS
|
4138 | e8105ebb | Paolo Bonzini | ; |
4139 | e8105ebb | Paolo Bonzini | version(); |
4140 | e8105ebb | Paolo Bonzini | printf("usage: %s [options] [disk_image]\n"
|
4141 | e8105ebb | Paolo Bonzini | "\n"
|
4142 | e8105ebb | Paolo Bonzini | "'disk_image' is a raw hard image image for IDE hard disk 0\n"
|
4143 | 3f020d70 | malc | "\n"
|
4144 | e8105ebb | Paolo Bonzini | "%s\n"
|
4145 | 3f020d70 | malc | "During emulation, the following keys are useful:\n"
|
4146 | 3f020d70 | malc | "ctrl-alt-f toggle full screen\n"
|
4147 | 3f020d70 | malc | "ctrl-alt-n switch to virtual console 'n'\n"
|
4148 | 3f020d70 | malc | "ctrl-alt toggle mouse and keyboard grab\n"
|
4149 | 3f020d70 | malc | "\n"
|
4150 | e8105ebb | Paolo Bonzini | "When using -nographic, press 'ctrl-a h' to get some help.\n",
|
4151 | e8105ebb | Paolo Bonzini | "qemu",
|
4152 | e8105ebb | Paolo Bonzini | options_help); |
4153 | 15f82208 | ths | exit(exitcode); |
4154 | 0824d6fc | bellard | } |
4155 | 0824d6fc | bellard | |
4156 | cd6f1169 | bellard | #define HAS_ARG 0x0001 |
4157 | cd6f1169 | bellard | |
4158 | cd6f1169 | bellard | enum {
|
4159 | 5824d651 | blueswir1 | #define DEF(option, opt_arg, opt_enum, opt_help) \
|
4160 | 5824d651 | blueswir1 | opt_enum, |
4161 | 5824d651 | blueswir1 | #define DEFHEADING(text)
|
4162 | 5824d651 | blueswir1 | #include "qemu-options.h" |
4163 | 5824d651 | blueswir1 | #undef DEF
|
4164 | 5824d651 | blueswir1 | #undef DEFHEADING
|
4165 | 5824d651 | blueswir1 | #undef GEN_DOCS
|
4166 | cd6f1169 | bellard | }; |
4167 | cd6f1169 | bellard | |
4168 | cd6f1169 | bellard | typedef struct QEMUOption { |
4169 | cd6f1169 | bellard | const char *name; |
4170 | cd6f1169 | bellard | int flags;
|
4171 | cd6f1169 | bellard | int index;
|
4172 | cd6f1169 | bellard | } QEMUOption; |
4173 | cd6f1169 | bellard | |
4174 | dbed7e40 | blueswir1 | static const QEMUOption qemu_options[] = { |
4175 | cd6f1169 | bellard | { "h", 0, QEMU_OPTION_h }, |
4176 | 5824d651 | blueswir1 | #define DEF(option, opt_arg, opt_enum, opt_help) \
|
4177 | 5824d651 | blueswir1 | { option, opt_arg, opt_enum }, |
4178 | 5824d651 | blueswir1 | #define DEFHEADING(text)
|
4179 | 5824d651 | blueswir1 | #include "qemu-options.h" |
4180 | 5824d651 | blueswir1 | #undef DEF
|
4181 | 5824d651 | blueswir1 | #undef DEFHEADING
|
4182 | 5824d651 | blueswir1 | #undef GEN_DOCS
|
4183 | cd6f1169 | bellard | { NULL },
|
4184 | fc01f7e7 | bellard | }; |
4185 | fc01f7e7 | bellard | |
4186 | 1d14ffa9 | bellard | #ifdef HAS_AUDIO
|
4187 | 6a36d84e | bellard | struct soundhw soundhw[] = {
|
4188 | b00052e4 | balrog | #ifdef HAS_AUDIO_CHOICE
|
4189 | 4ce7ff6e | aurel32 | #if defined(TARGET_I386) || defined(TARGET_MIPS)
|
4190 | fd06c375 | bellard | { |
4191 | fd06c375 | bellard | "pcspk",
|
4192 | fd06c375 | bellard | "PC speaker",
|
4193 | fd06c375 | bellard | 0,
|
4194 | fd06c375 | bellard | 1,
|
4195 | fd06c375 | bellard | { .init_isa = pcspk_audio_init } |
4196 | fd06c375 | bellard | }, |
4197 | fd06c375 | bellard | #endif
|
4198 | 4c9b53e3 | malc | |
4199 | 4c9b53e3 | malc | #ifdef CONFIG_SB16
|
4200 | 6a36d84e | bellard | { |
4201 | 6a36d84e | bellard | "sb16",
|
4202 | 6a36d84e | bellard | "Creative Sound Blaster 16",
|
4203 | 6a36d84e | bellard | 0,
|
4204 | 6a36d84e | bellard | 1,
|
4205 | 6a36d84e | bellard | { .init_isa = SB16_init } |
4206 | 6a36d84e | bellard | }, |
4207 | 4c9b53e3 | malc | #endif
|
4208 | 6a36d84e | bellard | |
4209 | cc53d26d | malc | #ifdef CONFIG_CS4231A
|
4210 | cc53d26d | malc | { |
4211 | cc53d26d | malc | "cs4231a",
|
4212 | cc53d26d | malc | "CS4231A",
|
4213 | cc53d26d | malc | 0,
|
4214 | cc53d26d | malc | 1,
|
4215 | cc53d26d | malc | { .init_isa = cs4231a_init } |
4216 | cc53d26d | malc | }, |
4217 | cc53d26d | malc | #endif
|
4218 | cc53d26d | malc | |
4219 | 1d14ffa9 | bellard | #ifdef CONFIG_ADLIB
|
4220 | 6a36d84e | bellard | { |
4221 | 6a36d84e | bellard | "adlib",
|
4222 | 1d14ffa9 | bellard | #ifdef HAS_YMF262
|
4223 | 6a36d84e | bellard | "Yamaha YMF262 (OPL3)",
|
4224 | 1d14ffa9 | bellard | #else
|
4225 | 6a36d84e | bellard | "Yamaha YM3812 (OPL2)",
|
4226 | 1d14ffa9 | bellard | #endif
|
4227 | 6a36d84e | bellard | 0,
|
4228 | 6a36d84e | bellard | 1,
|
4229 | 6a36d84e | bellard | { .init_isa = Adlib_init } |
4230 | 6a36d84e | bellard | }, |
4231 | 1d14ffa9 | bellard | #endif
|
4232 | 6a36d84e | bellard | |
4233 | 1d14ffa9 | bellard | #ifdef CONFIG_GUS
|
4234 | 6a36d84e | bellard | { |
4235 | 6a36d84e | bellard | "gus",
|
4236 | 6a36d84e | bellard | "Gravis Ultrasound GF1",
|
4237 | 6a36d84e | bellard | 0,
|
4238 | 6a36d84e | bellard | 1,
|
4239 | 6a36d84e | bellard | { .init_isa = GUS_init } |
4240 | 6a36d84e | bellard | }, |
4241 | 1d14ffa9 | bellard | #endif
|
4242 | 6a36d84e | bellard | |
4243 | 4c9b53e3 | malc | #ifdef CONFIG_AC97
|
4244 | e5c9a13e | balrog | { |
4245 | e5c9a13e | balrog | "ac97",
|
4246 | e5c9a13e | balrog | "Intel 82801AA AC97 Audio",
|
4247 | e5c9a13e | balrog | 0,
|
4248 | e5c9a13e | balrog | 0,
|
4249 | e5c9a13e | balrog | { .init_pci = ac97_init } |
4250 | e5c9a13e | balrog | }, |
4251 | 4c9b53e3 | malc | #endif
|
4252 | e5c9a13e | balrog | |
4253 | 4c9b53e3 | malc | #ifdef CONFIG_ES1370
|
4254 | 6a36d84e | bellard | { |
4255 | 6a36d84e | bellard | "es1370",
|
4256 | 6a36d84e | bellard | "ENSONIQ AudioPCI ES1370",
|
4257 | 6a36d84e | bellard | 0,
|
4258 | 6a36d84e | bellard | 0,
|
4259 | 6a36d84e | bellard | { .init_pci = es1370_init } |
4260 | 6a36d84e | bellard | }, |
4261 | b00052e4 | balrog | #endif
|
4262 | 6a36d84e | bellard | |
4263 | 4c9b53e3 | malc | #endif /* HAS_AUDIO_CHOICE */ |
4264 | 4c9b53e3 | malc | |
4265 | 6a36d84e | bellard | { NULL, NULL, 0, 0, { NULL } } |
4266 | 6a36d84e | bellard | }; |
4267 | 6a36d84e | bellard | |
4268 | 6a36d84e | bellard | static void select_soundhw (const char *optarg) |
4269 | 6a36d84e | bellard | { |
4270 | 6a36d84e | bellard | struct soundhw *c;
|
4271 | 6a36d84e | bellard | |
4272 | 6a36d84e | bellard | if (*optarg == '?') { |
4273 | 6a36d84e | bellard | show_valid_cards:
|
4274 | 6a36d84e | bellard | |
4275 | 6a36d84e | bellard | printf ("Valid sound card names (comma separated):\n");
|
4276 | 6a36d84e | bellard | for (c = soundhw; c->name; ++c) {
|
4277 | 6a36d84e | bellard | printf ("%-11s %s\n", c->name, c->descr);
|
4278 | 6a36d84e | bellard | } |
4279 | 6a36d84e | bellard | printf ("\n-soundhw all will enable all of the above\n");
|
4280 | 1d14ffa9 | bellard | exit (*optarg != '?');
|
4281 | 1d14ffa9 | bellard | } |
4282 | 1d14ffa9 | bellard | else {
|
4283 | 6a36d84e | bellard | size_t l; |
4284 | 1d14ffa9 | bellard | const char *p; |
4285 | 1d14ffa9 | bellard | char *e;
|
4286 | 1d14ffa9 | bellard | int bad_card = 0; |
4287 | 1d14ffa9 | bellard | |
4288 | 6a36d84e | bellard | if (!strcmp (optarg, "all")) { |
4289 | 6a36d84e | bellard | for (c = soundhw; c->name; ++c) {
|
4290 | 6a36d84e | bellard | c->enabled = 1;
|
4291 | 6a36d84e | bellard | } |
4292 | 6a36d84e | bellard | return;
|
4293 | 6a36d84e | bellard | } |
4294 | 1d14ffa9 | bellard | |
4295 | 6a36d84e | bellard | p = optarg; |
4296 | 1d14ffa9 | bellard | while (*p) {
|
4297 | 1d14ffa9 | bellard | e = strchr (p, ',');
|
4298 | 1d14ffa9 | bellard | l = !e ? strlen (p) : (size_t) (e - p); |
4299 | 6a36d84e | bellard | |
4300 | 6a36d84e | bellard | for (c = soundhw; c->name; ++c) {
|
4301 | b3d6fb4a | malc | if (!strncmp (c->name, p, l) && !c->name[l]) {
|
4302 | 6a36d84e | bellard | c->enabled = 1;
|
4303 | 1d14ffa9 | bellard | break;
|
4304 | 1d14ffa9 | bellard | } |
4305 | 1d14ffa9 | bellard | } |
4306 | 6a36d84e | bellard | |
4307 | 6a36d84e | bellard | if (!c->name) {
|
4308 | 1d14ffa9 | bellard | if (l > 80) { |
4309 | 1d14ffa9 | bellard | fprintf (stderr, |
4310 | 1d14ffa9 | bellard | "Unknown sound card name (too big to show)\n");
|
4311 | 1d14ffa9 | bellard | } |
4312 | 1d14ffa9 | bellard | else {
|
4313 | 1d14ffa9 | bellard | fprintf (stderr, "Unknown sound card name `%.*s'\n",
|
4314 | 1d14ffa9 | bellard | (int) l, p);
|
4315 | 1d14ffa9 | bellard | } |
4316 | 1d14ffa9 | bellard | bad_card = 1;
|
4317 | 1d14ffa9 | bellard | } |
4318 | 1d14ffa9 | bellard | p += l + (e != NULL);
|
4319 | 1d14ffa9 | bellard | } |
4320 | 1d14ffa9 | bellard | |
4321 | 1d14ffa9 | bellard | if (bad_card)
|
4322 | 1d14ffa9 | bellard | goto show_valid_cards;
|
4323 | 1d14ffa9 | bellard | } |
4324 | 1d14ffa9 | bellard | } |
4325 | 1d14ffa9 | bellard | #endif
|
4326 | 1d14ffa9 | bellard | |
4327 | 3893c124 | malc | static void select_vgahw (const char *p) |
4328 | 3893c124 | malc | { |
4329 | 3893c124 | malc | const char *opts; |
4330 | 3893c124 | malc | |
4331 | 64465297 | Gerd Hoffmann | default_vga = 0;
|
4332 | 86176759 | Zachary Amsden | vga_interface_type = VGA_NONE; |
4333 | 3893c124 | malc | if (strstart(p, "std", &opts)) { |
4334 | 86176759 | Zachary Amsden | vga_interface_type = VGA_STD; |
4335 | 3893c124 | malc | } else if (strstart(p, "cirrus", &opts)) { |
4336 | 86176759 | Zachary Amsden | vga_interface_type = VGA_CIRRUS; |
4337 | 3893c124 | malc | } else if (strstart(p, "vmware", &opts)) { |
4338 | 86176759 | Zachary Amsden | vga_interface_type = VGA_VMWARE; |
4339 | 94909d9f | aliguori | } else if (strstart(p, "xenfb", &opts)) { |
4340 | 86176759 | Zachary Amsden | vga_interface_type = VGA_XENFB; |
4341 | 28b85ed8 | aliguori | } else if (!strstart(p, "none", &opts)) { |
4342 | 3893c124 | malc | invalid_vga:
|
4343 | 3893c124 | malc | fprintf(stderr, "Unknown vga type: %s\n", p);
|
4344 | 3893c124 | malc | exit(1);
|
4345 | 3893c124 | malc | } |
4346 | cb5a7aa8 | malc | while (*opts) {
|
4347 | cb5a7aa8 | malc | const char *nextopt; |
4348 | cb5a7aa8 | malc | |
4349 | cb5a7aa8 | malc | if (strstart(opts, ",retrace=", &nextopt)) { |
4350 | cb5a7aa8 | malc | opts = nextopt; |
4351 | cb5a7aa8 | malc | if (strstart(opts, "dumb", &nextopt)) |
4352 | cb5a7aa8 | malc | vga_retrace_method = VGA_RETRACE_DUMB; |
4353 | cb5a7aa8 | malc | else if (strstart(opts, "precise", &nextopt)) |
4354 | cb5a7aa8 | malc | vga_retrace_method = VGA_RETRACE_PRECISE; |
4355 | cb5a7aa8 | malc | else goto invalid_vga; |
4356 | cb5a7aa8 | malc | } else goto invalid_vga; |
4357 | cb5a7aa8 | malc | opts = nextopt; |
4358 | cb5a7aa8 | malc | } |
4359 | 3893c124 | malc | } |
4360 | 3893c124 | malc | |
4361 | 7d4c3d53 | Markus Armbruster | #ifdef TARGET_I386
|
4362 | 7d4c3d53 | Markus Armbruster | static int balloon_parse(const char *arg) |
4363 | 7d4c3d53 | Markus Armbruster | { |
4364 | 382f0743 | Gerd Hoffmann | QemuOpts *opts; |
4365 | 7d4c3d53 | Markus Armbruster | |
4366 | 382f0743 | Gerd Hoffmann | if (strcmp(arg, "none") == 0) { |
4367 | 382f0743 | Gerd Hoffmann | return 0; |
4368 | 382f0743 | Gerd Hoffmann | } |
4369 | 382f0743 | Gerd Hoffmann | |
4370 | 382f0743 | Gerd Hoffmann | if (!strncmp(arg, "virtio", 6)) { |
4371 | 382f0743 | Gerd Hoffmann | if (arg[6] == ',') { |
4372 | 382f0743 | Gerd Hoffmann | /* have params -> parse them */
|
4373 | 382f0743 | Gerd Hoffmann | opts = qemu_opts_parse(&qemu_device_opts, arg+7, NULL); |
4374 | 382f0743 | Gerd Hoffmann | if (!opts)
|
4375 | 382f0743 | Gerd Hoffmann | return -1; |
4376 | 382f0743 | Gerd Hoffmann | } else {
|
4377 | 382f0743 | Gerd Hoffmann | /* create empty opts */
|
4378 | 382f0743 | Gerd Hoffmann | opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
4379 | 7d4c3d53 | Markus Armbruster | } |
4380 | 382f0743 | Gerd Hoffmann | qemu_opt_set(opts, "driver", "virtio-balloon-pci"); |
4381 | 382f0743 | Gerd Hoffmann | return 0; |
4382 | 7d4c3d53 | Markus Armbruster | } |
4383 | 382f0743 | Gerd Hoffmann | |
4384 | 382f0743 | Gerd Hoffmann | return -1; |
4385 | 7d4c3d53 | Markus Armbruster | } |
4386 | 7d4c3d53 | Markus Armbruster | #endif
|
4387 | 7d4c3d53 | Markus Armbruster | |
4388 | 3587d7e6 | bellard | #ifdef _WIN32
|
4389 | 3587d7e6 | bellard | static BOOL WINAPI qemu_ctrl_handler(DWORD type)
|
4390 | 3587d7e6 | bellard | { |
4391 | 3587d7e6 | bellard | exit(STATUS_CONTROL_C_EXIT); |
4392 | 3587d7e6 | bellard | return TRUE;
|
4393 | 3587d7e6 | bellard | } |
4394 | 3587d7e6 | bellard | #endif
|
4395 | 3587d7e6 | bellard | |
4396 | c4be29ff | aliguori | int qemu_uuid_parse(const char *str, uint8_t *uuid) |
4397 | 8fcb1b90 | blueswir1 | { |
4398 | 8fcb1b90 | blueswir1 | int ret;
|
4399 | 8fcb1b90 | blueswir1 | |
4400 | 8fcb1b90 | blueswir1 | if(strlen(str) != 36) |
4401 | 8fcb1b90 | blueswir1 | return -1; |
4402 | 8fcb1b90 | blueswir1 | |
4403 | 8fcb1b90 | blueswir1 | ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3], |
4404 | 8fcb1b90 | blueswir1 | &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9], |
4405 | 8fcb1b90 | blueswir1 | &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], &uuid[15]); |
4406 | 8fcb1b90 | blueswir1 | |
4407 | 8fcb1b90 | blueswir1 | if(ret != 16) |
4408 | 8fcb1b90 | blueswir1 | return -1; |
4409 | 8fcb1b90 | blueswir1 | |
4410 | b6f6e3d3 | aliguori | #ifdef TARGET_I386
|
4411 | b6f6e3d3 | aliguori | smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid); |
4412 | b6f6e3d3 | aliguori | #endif
|
4413 | b6f6e3d3 | aliguori | |
4414 | 8fcb1b90 | blueswir1 | return 0; |
4415 | 8fcb1b90 | blueswir1 | } |
4416 | 8fcb1b90 | blueswir1 | |
4417 | 5b08fc10 | aliguori | #ifndef _WIN32
|
4418 | 5b08fc10 | aliguori | |
4419 | 5b08fc10 | aliguori | static void termsig_handler(int signal) |
4420 | 5b08fc10 | aliguori | { |
4421 | 5b08fc10 | aliguori | qemu_system_shutdown_request(); |
4422 | 5b08fc10 | aliguori | } |
4423 | 5b08fc10 | aliguori | |
4424 | 7c3370d4 | Jan Kiszka | static void sigchld_handler(int signal) |
4425 | 7c3370d4 | Jan Kiszka | { |
4426 | 7c3370d4 | Jan Kiszka | waitpid(-1, NULL, WNOHANG); |
4427 | 7c3370d4 | Jan Kiszka | } |
4428 | 7c3370d4 | Jan Kiszka | |
4429 | 7c3370d4 | Jan Kiszka | static void sighandler_setup(void) |
4430 | 5b08fc10 | aliguori | { |
4431 | 5b08fc10 | aliguori | struct sigaction act;
|
4432 | 5b08fc10 | aliguori | |
4433 | 5b08fc10 | aliguori | memset(&act, 0, sizeof(act)); |
4434 | 5b08fc10 | aliguori | act.sa_handler = termsig_handler; |
4435 | 5b08fc10 | aliguori | sigaction(SIGINT, &act, NULL);
|
4436 | 5b08fc10 | aliguori | sigaction(SIGHUP, &act, NULL);
|
4437 | 5b08fc10 | aliguori | sigaction(SIGTERM, &act, NULL);
|
4438 | 7c3370d4 | Jan Kiszka | |
4439 | 7c3370d4 | Jan Kiszka | act.sa_handler = sigchld_handler; |
4440 | 7c3370d4 | Jan Kiszka | act.sa_flags = SA_NOCLDSTOP; |
4441 | 7c3370d4 | Jan Kiszka | sigaction(SIGCHLD, &act, NULL);
|
4442 | 5b08fc10 | aliguori | } |
4443 | 5b08fc10 | aliguori | |
4444 | 5b08fc10 | aliguori | #endif
|
4445 | 5b08fc10 | aliguori | |
4446 | 5cea8590 | Paul Brook | #ifdef _WIN32
|
4447 | 5cea8590 | Paul Brook | /* Look for support files in the same directory as the executable. */
|
4448 | 5cea8590 | Paul Brook | static char *find_datadir(const char *argv0) |
4449 | 5cea8590 | Paul Brook | { |
4450 | 5cea8590 | Paul Brook | char *p;
|
4451 | 5cea8590 | Paul Brook | char buf[MAX_PATH];
|
4452 | 5cea8590 | Paul Brook | DWORD len; |
4453 | 5cea8590 | Paul Brook | |
4454 | 5cea8590 | Paul Brook | len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); |
4455 | 5cea8590 | Paul Brook | if (len == 0) { |
4456 | c5947808 | Blue Swirl | return NULL; |
4457 | 5cea8590 | Paul Brook | } |
4458 | 5cea8590 | Paul Brook | |
4459 | 5cea8590 | Paul Brook | buf[len] = 0;
|
4460 | 5cea8590 | Paul Brook | p = buf + len - 1;
|
4461 | 5cea8590 | Paul Brook | while (p != buf && *p != '\\') |
4462 | 5cea8590 | Paul Brook | p--; |
4463 | 5cea8590 | Paul Brook | *p = 0;
|
4464 | 5cea8590 | Paul Brook | if (access(buf, R_OK) == 0) { |
4465 | 5cea8590 | Paul Brook | return qemu_strdup(buf);
|
4466 | 5cea8590 | Paul Brook | } |
4467 | 5cea8590 | Paul Brook | return NULL; |
4468 | 5cea8590 | Paul Brook | } |
4469 | 5cea8590 | Paul Brook | #else /* !_WIN32 */ |
4470 | 5cea8590 | Paul Brook | |
4471 | 5cea8590 | Paul Brook | /* Find a likely location for support files using the location of the binary.
|
4472 | 5cea8590 | Paul Brook | For installed binaries this will be "$bindir/../share/qemu". When
|
4473 | 5cea8590 | Paul Brook | running from the build tree this will be "$bindir/../pc-bios". */
|
4474 | 5cea8590 | Paul Brook | #define SHARE_SUFFIX "/share/qemu" |
4475 | 5cea8590 | Paul Brook | #define BUILD_SUFFIX "/pc-bios" |
4476 | 5cea8590 | Paul Brook | static char *find_datadir(const char *argv0) |
4477 | 5cea8590 | Paul Brook | { |
4478 | 5cea8590 | Paul Brook | char *dir;
|
4479 | 5cea8590 | Paul Brook | char *p = NULL; |
4480 | 5cea8590 | Paul Brook | char *res;
|
4481 | 5cea8590 | Paul Brook | char buf[PATH_MAX];
|
4482 | 3a41759d | Blue Swirl | size_t max_len; |
4483 | 5cea8590 | Paul Brook | |
4484 | 5cea8590 | Paul Brook | #if defined(__linux__)
|
4485 | 5cea8590 | Paul Brook | { |
4486 | 5cea8590 | Paul Brook | int len;
|
4487 | 5cea8590 | Paul Brook | len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); |
4488 | 5cea8590 | Paul Brook | if (len > 0) { |
4489 | 5cea8590 | Paul Brook | buf[len] = 0;
|
4490 | 5cea8590 | Paul Brook | p = buf; |
4491 | 5cea8590 | Paul Brook | } |
4492 | 5cea8590 | Paul Brook | } |
4493 | 5cea8590 | Paul Brook | #elif defined(__FreeBSD__)
|
4494 | 5cea8590 | Paul Brook | { |
4495 | 5cea8590 | Paul Brook | int len;
|
4496 | 5cea8590 | Paul Brook | len = readlink("/proc/curproc/file", buf, sizeof(buf) - 1); |
4497 | 5cea8590 | Paul Brook | if (len > 0) { |
4498 | 5cea8590 | Paul Brook | buf[len] = 0;
|
4499 | 5cea8590 | Paul Brook | p = buf; |
4500 | 5cea8590 | Paul Brook | } |
4501 | 5cea8590 | Paul Brook | } |
4502 | 5cea8590 | Paul Brook | #endif
|
4503 | 5cea8590 | Paul Brook | /* If we don't have any way of figuring out the actual executable
|
4504 | 5cea8590 | Paul Brook | location then try argv[0]. */
|
4505 | 5cea8590 | Paul Brook | if (!p) {
|
4506 | 4d224196 | Jean-Christophe DUBOIS | p = realpath(argv0, buf); |
4507 | 5cea8590 | Paul Brook | if (!p) {
|
4508 | 5cea8590 | Paul Brook | return NULL; |
4509 | 5cea8590 | Paul Brook | } |
4510 | 5cea8590 | Paul Brook | } |
4511 | 5cea8590 | Paul Brook | dir = dirname(p); |
4512 | 5cea8590 | Paul Brook | dir = dirname(dir); |
4513 | 5cea8590 | Paul Brook | |
4514 | 3a41759d | Blue Swirl | max_len = strlen(dir) + |
4515 | 3a41759d | Blue Swirl | MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
|
4516 | 3a41759d | Blue Swirl | res = qemu_mallocz(max_len); |
4517 | 3a41759d | Blue Swirl | snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
|
4518 | 5cea8590 | Paul Brook | if (access(res, R_OK)) {
|
4519 | 3a41759d | Blue Swirl | snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
|
4520 | 5cea8590 | Paul Brook | if (access(res, R_OK)) {
|
4521 | 5cea8590 | Paul Brook | qemu_free(res); |
4522 | 5cea8590 | Paul Brook | res = NULL;
|
4523 | 5cea8590 | Paul Brook | } |
4524 | 5cea8590 | Paul Brook | } |
4525 | 4d224196 | Jean-Christophe DUBOIS | |
4526 | 5cea8590 | Paul Brook | return res;
|
4527 | 5cea8590 | Paul Brook | } |
4528 | 5cea8590 | Paul Brook | #undef SHARE_SUFFIX
|
4529 | 5cea8590 | Paul Brook | #undef BUILD_SUFFIX
|
4530 | 5cea8590 | Paul Brook | #endif
|
4531 | 5cea8590 | Paul Brook | |
4532 | 5cea8590 | Paul Brook | char *qemu_find_file(int type, const char *name) |
4533 | 5cea8590 | Paul Brook | { |
4534 | 5cea8590 | Paul Brook | int len;
|
4535 | 5cea8590 | Paul Brook | const char *subdir; |
4536 | 5cea8590 | Paul Brook | char *buf;
|
4537 | 5cea8590 | Paul Brook | |
4538 | 5cea8590 | Paul Brook | /* If name contains path separators then try it as a straight path. */
|
4539 | 5cea8590 | Paul Brook | if ((strchr(name, '/') || strchr(name, '\\')) |
4540 | 5cea8590 | Paul Brook | && access(name, R_OK) == 0) {
|
4541 | 73ffc805 | Jean-Christophe DUBOIS | return qemu_strdup(name);
|
4542 | 5cea8590 | Paul Brook | } |
4543 | 5cea8590 | Paul Brook | switch (type) {
|
4544 | 5cea8590 | Paul Brook | case QEMU_FILE_TYPE_BIOS:
|
4545 | 5cea8590 | Paul Brook | subdir = "";
|
4546 | 5cea8590 | Paul Brook | break;
|
4547 | 5cea8590 | Paul Brook | case QEMU_FILE_TYPE_KEYMAP:
|
4548 | 5cea8590 | Paul Brook | subdir = "keymaps/";
|
4549 | 5cea8590 | Paul Brook | break;
|
4550 | 5cea8590 | Paul Brook | default:
|
4551 | 5cea8590 | Paul Brook | abort(); |
4552 | 5cea8590 | Paul Brook | } |
4553 | 5cea8590 | Paul Brook | len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
|
4554 | 5cea8590 | Paul Brook | buf = qemu_mallocz(len); |
4555 | 3a41759d | Blue Swirl | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
|
4556 | 5cea8590 | Paul Brook | if (access(buf, R_OK)) {
|
4557 | 5cea8590 | Paul Brook | qemu_free(buf); |
4558 | 5cea8590 | Paul Brook | return NULL; |
4559 | 5cea8590 | Paul Brook | } |
4560 | 5cea8590 | Paul Brook | return buf;
|
4561 | 5cea8590 | Paul Brook | } |
4562 | 5cea8590 | Paul Brook | |
4563 | ff952ba2 | Markus Armbruster | static int device_help_func(QemuOpts *opts, void *opaque) |
4564 | ff952ba2 | Markus Armbruster | { |
4565 | ff952ba2 | Markus Armbruster | return qdev_device_help(opts);
|
4566 | ff952ba2 | Markus Armbruster | } |
4567 | ff952ba2 | Markus Armbruster | |
4568 | f31d07d1 | Gerd Hoffmann | static int device_init_func(QemuOpts *opts, void *opaque) |
4569 | f31d07d1 | Gerd Hoffmann | { |
4570 | f31d07d1 | Gerd Hoffmann | DeviceState *dev; |
4571 | f31d07d1 | Gerd Hoffmann | |
4572 | f31d07d1 | Gerd Hoffmann | dev = qdev_device_add(opts); |
4573 | f31d07d1 | Gerd Hoffmann | if (!dev)
|
4574 | f31d07d1 | Gerd Hoffmann | return -1; |
4575 | f31d07d1 | Gerd Hoffmann | return 0; |
4576 | f31d07d1 | Gerd Hoffmann | } |
4577 | f31d07d1 | Gerd Hoffmann | |
4578 | 1a688d3b | Gerd Hoffmann | static int chardev_init_func(QemuOpts *opts, void *opaque) |
4579 | 1a688d3b | Gerd Hoffmann | { |
4580 | 1a688d3b | Gerd Hoffmann | CharDriverState *chr; |
4581 | 1a688d3b | Gerd Hoffmann | |
4582 | 1a688d3b | Gerd Hoffmann | chr = qemu_chr_open_opts(opts, NULL);
|
4583 | 1a688d3b | Gerd Hoffmann | if (!chr)
|
4584 | 1a688d3b | Gerd Hoffmann | return -1; |
4585 | 1a688d3b | Gerd Hoffmann | return 0; |
4586 | 1a688d3b | Gerd Hoffmann | } |
4587 | 1a688d3b | Gerd Hoffmann | |
4588 | 88589343 | Gerd Hoffmann | static int mon_init_func(QemuOpts *opts, void *opaque) |
4589 | 88589343 | Gerd Hoffmann | { |
4590 | 88589343 | Gerd Hoffmann | CharDriverState *chr; |
4591 | 88589343 | Gerd Hoffmann | const char *chardev; |
4592 | 88589343 | Gerd Hoffmann | const char *mode; |
4593 | 88589343 | Gerd Hoffmann | int flags;
|
4594 | 88589343 | Gerd Hoffmann | |
4595 | 88589343 | Gerd Hoffmann | mode = qemu_opt_get(opts, "mode");
|
4596 | 88589343 | Gerd Hoffmann | if (mode == NULL) { |
4597 | 88589343 | Gerd Hoffmann | mode = "readline";
|
4598 | 88589343 | Gerd Hoffmann | } |
4599 | 88589343 | Gerd Hoffmann | if (strcmp(mode, "readline") == 0) { |
4600 | 88589343 | Gerd Hoffmann | flags = MONITOR_USE_READLINE; |
4601 | 88589343 | Gerd Hoffmann | } else if (strcmp(mode, "control") == 0) { |
4602 | 88589343 | Gerd Hoffmann | flags = MONITOR_USE_CONTROL; |
4603 | 88589343 | Gerd Hoffmann | } else {
|
4604 | 88589343 | Gerd Hoffmann | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode);
|
4605 | 88589343 | Gerd Hoffmann | exit(1);
|
4606 | 88589343 | Gerd Hoffmann | } |
4607 | 88589343 | Gerd Hoffmann | |
4608 | 88589343 | Gerd Hoffmann | if (qemu_opt_get_bool(opts, "default", 0)) |
4609 | 88589343 | Gerd Hoffmann | flags |= MONITOR_IS_DEFAULT; |
4610 | 88589343 | Gerd Hoffmann | |
4611 | 88589343 | Gerd Hoffmann | chardev = qemu_opt_get(opts, "chardev");
|
4612 | 88589343 | Gerd Hoffmann | chr = qemu_chr_find(chardev); |
4613 | 88589343 | Gerd Hoffmann | if (chr == NULL) { |
4614 | 88589343 | Gerd Hoffmann | fprintf(stderr, "chardev \"%s\" not found\n", chardev);
|
4615 | 88589343 | Gerd Hoffmann | exit(1);
|
4616 | 88589343 | Gerd Hoffmann | } |
4617 | 88589343 | Gerd Hoffmann | |
4618 | 88589343 | Gerd Hoffmann | monitor_init(chr, flags); |
4619 | 88589343 | Gerd Hoffmann | return 0; |
4620 | 88589343 | Gerd Hoffmann | } |
4621 | 88589343 | Gerd Hoffmann | |
4622 | 6ca5582d | Gerd Hoffmann | static void monitor_parse(const char *optarg, const char *mode) |
4623 | 88589343 | Gerd Hoffmann | { |
4624 | 88589343 | Gerd Hoffmann | static int monitor_device_index = 0; |
4625 | 88589343 | Gerd Hoffmann | QemuOpts *opts; |
4626 | 88589343 | Gerd Hoffmann | const char *p; |
4627 | 88589343 | Gerd Hoffmann | char label[32]; |
4628 | 88589343 | Gerd Hoffmann | int def = 0; |
4629 | 88589343 | Gerd Hoffmann | |
4630 | 88589343 | Gerd Hoffmann | if (strstart(optarg, "chardev:", &p)) { |
4631 | 88589343 | Gerd Hoffmann | snprintf(label, sizeof(label), "%s", p); |
4632 | 88589343 | Gerd Hoffmann | } else {
|
4633 | 88589343 | Gerd Hoffmann | if (monitor_device_index) {
|
4634 | 88589343 | Gerd Hoffmann | snprintf(label, sizeof(label), "monitor%d", |
4635 | 88589343 | Gerd Hoffmann | monitor_device_index); |
4636 | 88589343 | Gerd Hoffmann | } else {
|
4637 | 88589343 | Gerd Hoffmann | snprintf(label, sizeof(label), "monitor"); |
4638 | 88589343 | Gerd Hoffmann | def = 1;
|
4639 | 88589343 | Gerd Hoffmann | } |
4640 | 88589343 | Gerd Hoffmann | opts = qemu_chr_parse_compat(label, optarg); |
4641 | 88589343 | Gerd Hoffmann | if (!opts) {
|
4642 | 88589343 | Gerd Hoffmann | fprintf(stderr, "parse error: %s\n", optarg);
|
4643 | 88589343 | Gerd Hoffmann | exit(1);
|
4644 | 88589343 | Gerd Hoffmann | } |
4645 | 88589343 | Gerd Hoffmann | } |
4646 | 88589343 | Gerd Hoffmann | |
4647 | 88589343 | Gerd Hoffmann | opts = qemu_opts_create(&qemu_mon_opts, label, 1);
|
4648 | 88589343 | Gerd Hoffmann | if (!opts) {
|
4649 | 88589343 | Gerd Hoffmann | fprintf(stderr, "duplicate chardev: %s\n", label);
|
4650 | 88589343 | Gerd Hoffmann | exit(1);
|
4651 | 88589343 | Gerd Hoffmann | } |
4652 | 6ca5582d | Gerd Hoffmann | qemu_opt_set(opts, "mode", mode);
|
4653 | 88589343 | Gerd Hoffmann | qemu_opt_set(opts, "chardev", label);
|
4654 | 88589343 | Gerd Hoffmann | if (def)
|
4655 | 88589343 | Gerd Hoffmann | qemu_opt_set(opts, "default", "on"); |
4656 | 88589343 | Gerd Hoffmann | monitor_device_index++; |
4657 | 88589343 | Gerd Hoffmann | } |
4658 | 88589343 | Gerd Hoffmann | |
4659 | bd3c948d | Gerd Hoffmann | struct device_config {
|
4660 | bd3c948d | Gerd Hoffmann | enum {
|
4661 | aee1b935 | Gerd Hoffmann | DEV_USB, /* -usbdevice */
|
4662 | aee1b935 | Gerd Hoffmann | DEV_BT, /* -bt */
|
4663 | aee1b935 | Gerd Hoffmann | DEV_SERIAL, /* -serial */
|
4664 | aee1b935 | Gerd Hoffmann | DEV_PARALLEL, /* -parallel */
|
4665 | aee1b935 | Gerd Hoffmann | DEV_VIRTCON, /* -virtioconsole */
|
4666 | c9f398e5 | H. Peter Anvin | DEV_DEBUGCON, /* -debugcon */
|
4667 | bd3c948d | Gerd Hoffmann | } type; |
4668 | bd3c948d | Gerd Hoffmann | const char *cmdline; |
4669 | 72cf2d4f | Blue Swirl | QTAILQ_ENTRY(device_config) next; |
4670 | bd3c948d | Gerd Hoffmann | }; |
4671 | 72cf2d4f | Blue Swirl | QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs); |
4672 | bd3c948d | Gerd Hoffmann | |
4673 | bd3c948d | Gerd Hoffmann | static void add_device_config(int type, const char *cmdline) |
4674 | bd3c948d | Gerd Hoffmann | { |
4675 | bd3c948d | Gerd Hoffmann | struct device_config *conf;
|
4676 | bd3c948d | Gerd Hoffmann | |
4677 | bd3c948d | Gerd Hoffmann | conf = qemu_mallocz(sizeof(*conf));
|
4678 | bd3c948d | Gerd Hoffmann | conf->type = type; |
4679 | bd3c948d | Gerd Hoffmann | conf->cmdline = cmdline; |
4680 | 72cf2d4f | Blue Swirl | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
4681 | bd3c948d | Gerd Hoffmann | } |
4682 | bd3c948d | Gerd Hoffmann | |
4683 | bd3c948d | Gerd Hoffmann | static int foreach_device_config(int type, int (*func)(const char *cmdline)) |
4684 | bd3c948d | Gerd Hoffmann | { |
4685 | bd3c948d | Gerd Hoffmann | struct device_config *conf;
|
4686 | bd3c948d | Gerd Hoffmann | int rc;
|
4687 | bd3c948d | Gerd Hoffmann | |
4688 | 72cf2d4f | Blue Swirl | QTAILQ_FOREACH(conf, &device_configs, next) { |
4689 | bd3c948d | Gerd Hoffmann | if (conf->type != type)
|
4690 | bd3c948d | Gerd Hoffmann | continue;
|
4691 | bd3c948d | Gerd Hoffmann | rc = func(conf->cmdline); |
4692 | bd3c948d | Gerd Hoffmann | if (0 != rc) |
4693 | bd3c948d | Gerd Hoffmann | return rc;
|
4694 | bd3c948d | Gerd Hoffmann | } |
4695 | bd3c948d | Gerd Hoffmann | return 0; |
4696 | bd3c948d | Gerd Hoffmann | } |
4697 | bd3c948d | Gerd Hoffmann | |
4698 | 998bbd74 | Gerd Hoffmann | static int serial_parse(const char *devname) |
4699 | 998bbd74 | Gerd Hoffmann | { |
4700 | 998bbd74 | Gerd Hoffmann | static int index = 0; |
4701 | 998bbd74 | Gerd Hoffmann | char label[32]; |
4702 | 998bbd74 | Gerd Hoffmann | |
4703 | 998bbd74 | Gerd Hoffmann | if (strcmp(devname, "none") == 0) |
4704 | 998bbd74 | Gerd Hoffmann | return 0; |
4705 | 998bbd74 | Gerd Hoffmann | if (index == MAX_SERIAL_PORTS) {
|
4706 | 998bbd74 | Gerd Hoffmann | fprintf(stderr, "qemu: too many serial ports\n");
|
4707 | 998bbd74 | Gerd Hoffmann | exit(1);
|
4708 | 998bbd74 | Gerd Hoffmann | } |
4709 | 998bbd74 | Gerd Hoffmann | snprintf(label, sizeof(label), "serial%d", index); |
4710 | 998bbd74 | Gerd Hoffmann | serial_hds[index] = qemu_chr_open(label, devname, NULL);
|
4711 | 998bbd74 | Gerd Hoffmann | if (!serial_hds[index]) {
|
4712 | 998bbd74 | Gerd Hoffmann | fprintf(stderr, "qemu: could not open serial device '%s': %s\n",
|
4713 | 998bbd74 | Gerd Hoffmann | devname, strerror(errno)); |
4714 | 998bbd74 | Gerd Hoffmann | return -1; |
4715 | 998bbd74 | Gerd Hoffmann | } |
4716 | 998bbd74 | Gerd Hoffmann | index++; |
4717 | 998bbd74 | Gerd Hoffmann | return 0; |
4718 | 998bbd74 | Gerd Hoffmann | } |
4719 | 998bbd74 | Gerd Hoffmann | |
4720 | 6a5e8b0e | Gerd Hoffmann | static int parallel_parse(const char *devname) |
4721 | 6a5e8b0e | Gerd Hoffmann | { |
4722 | 6a5e8b0e | Gerd Hoffmann | static int index = 0; |
4723 | 6a5e8b0e | Gerd Hoffmann | char label[32]; |
4724 | 6a5e8b0e | Gerd Hoffmann | |
4725 | 6a5e8b0e | Gerd Hoffmann | if (strcmp(devname, "none") == 0) |
4726 | 6a5e8b0e | Gerd Hoffmann | return 0; |
4727 | 6a5e8b0e | Gerd Hoffmann | if (index == MAX_PARALLEL_PORTS) {
|
4728 | 6a5e8b0e | Gerd Hoffmann | fprintf(stderr, "qemu: too many parallel ports\n");
|
4729 | 6a5e8b0e | Gerd Hoffmann | exit(1);
|
4730 | 6a5e8b0e | Gerd Hoffmann | } |
4731 | 6a5e8b0e | Gerd Hoffmann | snprintf(label, sizeof(label), "parallel%d", index); |
4732 | 6a5e8b0e | Gerd Hoffmann | parallel_hds[index] = qemu_chr_open(label, devname, NULL);
|
4733 | 6a5e8b0e | Gerd Hoffmann | if (!parallel_hds[index]) {
|
4734 | 6a5e8b0e | Gerd Hoffmann | fprintf(stderr, "qemu: could not open parallel device '%s': %s\n",
|
4735 | 6a5e8b0e | Gerd Hoffmann | devname, strerror(errno)); |
4736 | 6a5e8b0e | Gerd Hoffmann | return -1; |
4737 | 6a5e8b0e | Gerd Hoffmann | } |
4738 | 6a5e8b0e | Gerd Hoffmann | index++; |
4739 | 6a5e8b0e | Gerd Hoffmann | return 0; |
4740 | 6a5e8b0e | Gerd Hoffmann | } |
4741 | 6a5e8b0e | Gerd Hoffmann | |
4742 | aee1b935 | Gerd Hoffmann | static int virtcon_parse(const char *devname) |
4743 | aee1b935 | Gerd Hoffmann | { |
4744 | aee1b935 | Gerd Hoffmann | static int index = 0; |
4745 | aee1b935 | Gerd Hoffmann | char label[32]; |
4746 | 392ecf54 | Amit Shah | QemuOpts *bus_opts, *dev_opts; |
4747 | aee1b935 | Gerd Hoffmann | |
4748 | aee1b935 | Gerd Hoffmann | if (strcmp(devname, "none") == 0) |
4749 | aee1b935 | Gerd Hoffmann | return 0; |
4750 | aee1b935 | Gerd Hoffmann | if (index == MAX_VIRTIO_CONSOLES) {
|
4751 | aee1b935 | Gerd Hoffmann | fprintf(stderr, "qemu: too many virtio consoles\n");
|
4752 | aee1b935 | Gerd Hoffmann | exit(1);
|
4753 | aee1b935 | Gerd Hoffmann | } |
4754 | 392ecf54 | Amit Shah | |
4755 | 392ecf54 | Amit Shah | bus_opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
4756 | 392ecf54 | Amit Shah | qemu_opt_set(bus_opts, "driver", "virtio-serial"); |
4757 | 392ecf54 | Amit Shah | |
4758 | 392ecf54 | Amit Shah | dev_opts = qemu_opts_create(&qemu_device_opts, NULL, 0); |
4759 | 392ecf54 | Amit Shah | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
4760 | 392ecf54 | Amit Shah | |
4761 | aee1b935 | Gerd Hoffmann | snprintf(label, sizeof(label), "virtcon%d", index); |
4762 | aee1b935 | Gerd Hoffmann | virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
|
4763 | aee1b935 | Gerd Hoffmann | if (!virtcon_hds[index]) {
|
4764 | aee1b935 | Gerd Hoffmann | fprintf(stderr, "qemu: could not open virtio console '%s': %s\n",
|
4765 | aee1b935 | Gerd Hoffmann | devname, strerror(errno)); |
4766 | aee1b935 | Gerd Hoffmann | return -1; |
4767 | aee1b935 | Gerd Hoffmann | } |
4768 | 392ecf54 | Amit Shah | qemu_opt_set(dev_opts, "chardev", label);
|
4769 | 392ecf54 | Amit Shah | |
4770 | aee1b935 | Gerd Hoffmann | index++; |
4771 | aee1b935 | Gerd Hoffmann | return 0; |
4772 | aee1b935 | Gerd Hoffmann | } |
4773 | aee1b935 | Gerd Hoffmann | |
4774 | c9f398e5 | H. Peter Anvin | static int debugcon_parse(const char *devname) |
4775 | c9f398e5 | H. Peter Anvin | { |
4776 | c9f398e5 | H. Peter Anvin | QemuOpts *opts; |
4777 | c9f398e5 | H. Peter Anvin | |
4778 | c9f398e5 | H. Peter Anvin | if (!qemu_chr_open("debugcon", devname, NULL)) { |
4779 | c9f398e5 | H. Peter Anvin | exit(1);
|
4780 | c9f398e5 | H. Peter Anvin | } |
4781 | c9f398e5 | H. Peter Anvin | opts = qemu_opts_create(&qemu_device_opts, "debugcon", 1); |
4782 | c9f398e5 | H. Peter Anvin | if (!opts) {
|
4783 | c9f398e5 | H. Peter Anvin | fprintf(stderr, "qemu: already have a debugcon device\n");
|
4784 | c9f398e5 | H. Peter Anvin | exit(1);
|
4785 | c9f398e5 | H. Peter Anvin | } |
4786 | c9f398e5 | H. Peter Anvin | qemu_opt_set(opts, "driver", "isa-debugcon"); |
4787 | c9f398e5 | H. Peter Anvin | qemu_opt_set(opts, "chardev", "debugcon"); |
4788 | c9f398e5 | H. Peter Anvin | return 0; |
4789 | c9f398e5 | H. Peter Anvin | } |
4790 | c9f398e5 | H. Peter Anvin | |
4791 | 6530a97b | Anthony Liguori | static const QEMUOption *lookup_opt(int argc, char **argv, |
4792 | 6530a97b | Anthony Liguori | const char **poptarg, int *poptind) |
4793 | 6530a97b | Anthony Liguori | { |
4794 | 6530a97b | Anthony Liguori | const QEMUOption *popt;
|
4795 | 6530a97b | Anthony Liguori | int optind = *poptind;
|
4796 | 6530a97b | Anthony Liguori | char *r = argv[optind];
|
4797 | 6530a97b | Anthony Liguori | const char *optarg; |
4798 | 6530a97b | Anthony Liguori | |
4799 | 6530a97b | Anthony Liguori | optind++; |
4800 | 6530a97b | Anthony Liguori | /* Treat --foo the same as -foo. */
|
4801 | 6530a97b | Anthony Liguori | if (r[1] == '-') |
4802 | 6530a97b | Anthony Liguori | r++; |
4803 | 6530a97b | Anthony Liguori | popt = qemu_options; |
4804 | 6530a97b | Anthony Liguori | for(;;) {
|
4805 | 6530a97b | Anthony Liguori | if (!popt->name) {
|
4806 | 6530a97b | Anthony Liguori | fprintf(stderr, "%s: invalid option -- '%s'\n",
|
4807 | 6530a97b | Anthony Liguori | argv[0], r);
|
4808 | 6530a97b | Anthony Liguori | exit(1);
|
4809 | 6530a97b | Anthony Liguori | } |
4810 | 6530a97b | Anthony Liguori | if (!strcmp(popt->name, r + 1)) |
4811 | 6530a97b | Anthony Liguori | break;
|
4812 | 6530a97b | Anthony Liguori | popt++; |
4813 | 6530a97b | Anthony Liguori | } |
4814 | 6530a97b | Anthony Liguori | if (popt->flags & HAS_ARG) {
|
4815 | 6530a97b | Anthony Liguori | if (optind >= argc) {
|
4816 | 6530a97b | Anthony Liguori | fprintf(stderr, "%s: option '%s' requires an argument\n",
|
4817 | 6530a97b | Anthony Liguori | argv[0], r);
|
4818 | 6530a97b | Anthony Liguori | exit(1);
|
4819 | 6530a97b | Anthony Liguori | } |
4820 | 6530a97b | Anthony Liguori | optarg = argv[optind++]; |
4821 | 6530a97b | Anthony Liguori | } else {
|
4822 | 6530a97b | Anthony Liguori | optarg = NULL;
|
4823 | 6530a97b | Anthony Liguori | } |
4824 | 6530a97b | Anthony Liguori | |
4825 | 6530a97b | Anthony Liguori | *poptarg = optarg; |
4826 | 6530a97b | Anthony Liguori | *poptind = optind; |
4827 | 6530a97b | Anthony Liguori | |
4828 | 6530a97b | Anthony Liguori | return popt;
|
4829 | 6530a97b | Anthony Liguori | } |
4830 | 6530a97b | Anthony Liguori | |
4831 | 902b3d5c | malc | int main(int argc, char **argv, char **envp) |
4832 | 0824d6fc | bellard | { |
4833 | 59030a8c | aliguori | const char *gdbstub_dev = NULL; |
4834 | 28c5af54 | j_mayer | uint32_t boot_devices_bitmap = 0;
|
4835 | e4bcb14c | ths | int i;
|
4836 | 28c5af54 | j_mayer | int snapshot, linux_boot, net_boot;
|
4837 | 7f7f9873 | bellard | const char *initrd_filename; |
4838 | a20dd508 | bellard | const char *kernel_filename, *kernel_cmdline; |
4839 | 195325a4 | Anthony Liguori | char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ |
4840 | 3023f332 | aliguori | DisplayState *ds; |
4841 | 7d957bd8 | aliguori | DisplayChangeListener *dcl; |
4842 | 46d4767d | bellard | int cyls, heads, secs, translation;
|
4843 | f31d07d1 | Gerd Hoffmann | QemuOpts *hda_opts = NULL, *opts;
|
4844 | cd6f1169 | bellard | int optind;
|
4845 | 6530a97b | Anthony Liguori | const char *optarg; |
4846 | d63d307f | bellard | const char *loadvm = NULL; |
4847 | cc1daa40 | bellard | QEMUMachine *machine; |
4848 | 94fc95cd | j_mayer | const char *cpu_model; |
4849 | b9e82a59 | blueswir1 | #ifndef _WIN32
|
4850 | 71e3ceb8 | ths | int fds[2]; |
4851 | b9e82a59 | blueswir1 | #endif
|
4852 | 26a5f13b | bellard | int tb_size;
|
4853 | 93815bc2 | ths | const char *pid_file = NULL; |
4854 | 5bb7910a | aliguori | const char *incoming = NULL; |
4855 | b9e82a59 | blueswir1 | #ifndef _WIN32
|
4856 | 54042bcf | aliguori | int fd = 0; |
4857 | 54042bcf | aliguori | struct passwd *pwd = NULL; |
4858 | 0858532e | aliguori | const char *chroot_dir = NULL; |
4859 | 0858532e | aliguori | const char *run_as = NULL; |
4860 | b9e82a59 | blueswir1 | #endif
|
4861 | 268a362c | aliguori | CPUState *env; |
4862 | 993fbfdb | Anthony Liguori | int show_vnc_port = 0; |
4863 | 292444cb | Anthony Liguori | int defconfig = 1; |
4864 | 0bd48850 | bellard | |
4865 | 6875204c | Jan Kiszka | init_clocks(); |
4866 | 6875204c | Jan Kiszka | |
4867 | ac7531ec | Gerd Hoffmann | qemu_errors_to_file(stderr); |
4868 | 902b3d5c | malc | qemu_cache_utils_init(envp); |
4869 | 902b3d5c | malc | |
4870 | 72cf2d4f | Blue Swirl | QLIST_INIT (&vm_change_state_head); |
4871 | be995c27 | bellard | #ifndef _WIN32
|
4872 | be995c27 | bellard | { |
4873 | be995c27 | bellard | struct sigaction act;
|
4874 | be995c27 | bellard | sigfillset(&act.sa_mask); |
4875 | be995c27 | bellard | act.sa_flags = 0;
|
4876 | be995c27 | bellard | act.sa_handler = SIG_IGN; |
4877 | be995c27 | bellard | sigaction(SIGPIPE, &act, NULL);
|
4878 | be995c27 | bellard | } |
4879 | 3587d7e6 | bellard | #else
|
4880 | 3587d7e6 | bellard | SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE); |
4881 | a8e5ac33 | bellard | /* Note: cpu_interrupt() is currently not SMP safe, so we force
|
4882 | a8e5ac33 | bellard | QEMU to run on a single CPU */
|
4883 | a8e5ac33 | bellard | { |
4884 | a8e5ac33 | bellard | HANDLE h; |
4885 | a8e5ac33 | bellard | DWORD mask, smask; |
4886 | a8e5ac33 | bellard | int i;
|
4887 | a8e5ac33 | bellard | h = GetCurrentProcess(); |
4888 | a8e5ac33 | bellard | if (GetProcessAffinityMask(h, &mask, &smask)) {
|
4889 | a8e5ac33 | bellard | for(i = 0; i < 32; i++) { |
4890 | a8e5ac33 | bellard | if (mask & (1 << i)) |
4891 | a8e5ac33 | bellard | break;
|
4892 | a8e5ac33 | bellard | } |
4893 | a8e5ac33 | bellard | if (i != 32) { |
4894 | a8e5ac33 | bellard | mask = 1 << i;
|
4895 | a8e5ac33 | bellard | SetProcessAffinityMask(h, mask); |
4896 | a8e5ac33 | bellard | } |
4897 | a8e5ac33 | bellard | } |
4898 | a8e5ac33 | bellard | } |
4899 | 67b915a5 | bellard | #endif
|
4900 | be995c27 | bellard | |
4901 | f80f9ec9 | Anthony Liguori | module_call_init(MODULE_INIT_MACHINE); |
4902 | 0c257437 | Anthony Liguori | machine = find_default_machine(); |
4903 | 94fc95cd | j_mayer | cpu_model = NULL;
|
4904 | fc01f7e7 | bellard | initrd_filename = NULL;
|
4905 | 4fc5d071 | aurel32 | ram_size = 0;
|
4906 | 33e3963e | bellard | snapshot = 0;
|
4907 | a20dd508 | bellard | kernel_filename = NULL;
|
4908 | a20dd508 | bellard | kernel_cmdline = "";
|
4909 | c4b1fcc0 | bellard | cyls = heads = secs = 0;
|
4910 | 46d4767d | bellard | translation = BIOS_ATA_TRANSLATION_AUTO; |
4911 | c4b1fcc0 | bellard | |
4912 | 268a362c | aliguori | for (i = 0; i < MAX_NODES; i++) { |
4913 | 268a362c | aliguori | node_mem[i] = 0;
|
4914 | 268a362c | aliguori | node_cpumask[i] = 0;
|
4915 | 268a362c | aliguori | } |
4916 | 268a362c | aliguori | |
4917 | 268a362c | aliguori | nb_numa_nodes = 0;
|
4918 | 7c9d8e07 | bellard | nb_nics = 0;
|
4919 | 3b46e624 | ths | |
4920 | 26a5f13b | bellard | tb_size = 0;
|
4921 | 41bd639b | blueswir1 | autostart= 1;
|
4922 | 41bd639b | blueswir1 | |
4923 | 292444cb | Anthony Liguori | /* first pass of option parsing */
|
4924 | 292444cb | Anthony Liguori | optind = 1;
|
4925 | 292444cb | Anthony Liguori | while (optind < argc) {
|
4926 | 292444cb | Anthony Liguori | if (argv[optind][0] != '-') { |
4927 | 292444cb | Anthony Liguori | /* disk image */
|
4928 | 28e68d68 | Anthony Liguori | optind++; |
4929 | 292444cb | Anthony Liguori | continue;
|
4930 | 292444cb | Anthony Liguori | } else {
|
4931 | 292444cb | Anthony Liguori | const QEMUOption *popt;
|
4932 | 292444cb | Anthony Liguori | |
4933 | 292444cb | Anthony Liguori | popt = lookup_opt(argc, argv, &optarg, &optind); |
4934 | 292444cb | Anthony Liguori | switch (popt->index) {
|
4935 | 292444cb | Anthony Liguori | case QEMU_OPTION_nodefconfig:
|
4936 | 292444cb | Anthony Liguori | defconfig=0;
|
4937 | 292444cb | Anthony Liguori | break;
|
4938 | 292444cb | Anthony Liguori | } |
4939 | 292444cb | Anthony Liguori | } |
4940 | 292444cb | Anthony Liguori | } |
4941 | 292444cb | Anthony Liguori | |
4942 | 292444cb | Anthony Liguori | if (defconfig) {
|
4943 | 292444cb | Anthony Liguori | FILE *fp; |
4944 | 292444cb | Anthony Liguori | fp = fopen(CONFIG_QEMU_CONFDIR "/qemu.conf", "r"); |
4945 | 292444cb | Anthony Liguori | if (fp) {
|
4946 | 292444cb | Anthony Liguori | if (qemu_config_parse(fp) != 0) { |
4947 | 292444cb | Anthony Liguori | exit(1);
|
4948 | 292444cb | Anthony Liguori | } |
4949 | 292444cb | Anthony Liguori | fclose(fp); |
4950 | 292444cb | Anthony Liguori | } |
4951 | 292444cb | Anthony Liguori | |
4952 | 292444cb | Anthony Liguori | fp = fopen(CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", "r"); |
4953 | 292444cb | Anthony Liguori | if (fp) {
|
4954 | 292444cb | Anthony Liguori | if (qemu_config_parse(fp) != 0) { |
4955 | 292444cb | Anthony Liguori | exit(1);
|
4956 | 292444cb | Anthony Liguori | } |
4957 | 292444cb | Anthony Liguori | fclose(fp); |
4958 | 292444cb | Anthony Liguori | } |
4959 | 292444cb | Anthony Liguori | } |
4960 | b5ec5ce0 | john cooper | #if defined(cpudef_setup)
|
4961 | b5ec5ce0 | john cooper | cpudef_setup(); /* parse cpu definitions in target config file */
|
4962 | b5ec5ce0 | john cooper | #endif
|
4963 | 292444cb | Anthony Liguori | |
4964 | 292444cb | Anthony Liguori | /* second pass of option parsing */
|
4965 | cd6f1169 | bellard | optind = 1;
|
4966 | 0824d6fc | bellard | for(;;) {
|
4967 | cd6f1169 | bellard | if (optind >= argc)
|
4968 | 0824d6fc | bellard | break;
|
4969 | 6530a97b | Anthony Liguori | if (argv[optind][0] != '-') { |
4970 | 9dfd7c7a | Gerd Hoffmann | hda_opts = drive_add(argv[optind++], HD_ALIAS, 0);
|
4971 | cd6f1169 | bellard | } else {
|
4972 | cd6f1169 | bellard | const QEMUOption *popt;
|
4973 | cd6f1169 | bellard | |
4974 | 6530a97b | Anthony Liguori | popt = lookup_opt(argc, argv, &optarg, &optind); |
4975 | cd6f1169 | bellard | switch(popt->index) {
|
4976 | cc1daa40 | bellard | case QEMU_OPTION_M:
|
4977 | cc1daa40 | bellard | machine = find_machine(optarg); |
4978 | cc1daa40 | bellard | if (!machine) {
|
4979 | cc1daa40 | bellard | QEMUMachine *m; |
4980 | cc1daa40 | bellard | printf("Supported machines are:\n");
|
4981 | cc1daa40 | bellard | for(m = first_machine; m != NULL; m = m->next) { |
4982 | 3f6599e6 | Mark McLoughlin | if (m->alias)
|
4983 | 3f6599e6 | Mark McLoughlin | printf("%-10s %s (alias of %s)\n",
|
4984 | 3f6599e6 | Mark McLoughlin | m->alias, m->desc, m->name); |
4985 | cc1daa40 | bellard | printf("%-10s %s%s\n",
|
4986 | 5fafdf24 | ths | m->name, m->desc, |
4987 | 0c257437 | Anthony Liguori | m->is_default ? " (default)" : ""); |
4988 | cc1daa40 | bellard | } |
4989 | 15f82208 | ths | exit(*optarg != '?');
|
4990 | cc1daa40 | bellard | } |
4991 | cc1daa40 | bellard | break;
|
4992 | 94fc95cd | j_mayer | case QEMU_OPTION_cpu:
|
4993 | 94fc95cd | j_mayer | /* hw initialization will check this */
|
4994 | 15f82208 | ths | if (*optarg == '?') { |
4995 | c732abe2 | j_mayer | /* XXX: implement xxx_cpu_list for targets that still miss it */
|
4996 | b5ec5ce0 | john cooper | #if defined(cpu_list_id)
|
4997 | b5ec5ce0 | john cooper | cpu_list_id(stdout, &fprintf, optarg); |
4998 | b5ec5ce0 | john cooper | #elif defined(cpu_list)
|
4999 | b5ec5ce0 | john cooper | cpu_list(stdout, &fprintf); /* deprecated */
|
5000 | 94fc95cd | j_mayer | #endif
|
5001 | 15f82208 | ths | exit(0);
|
5002 | 94fc95cd | j_mayer | } else {
|
5003 | 94fc95cd | j_mayer | cpu_model = optarg; |
5004 | 94fc95cd | j_mayer | } |
5005 | 94fc95cd | j_mayer | break;
|
5006 | cd6f1169 | bellard | case QEMU_OPTION_initrd:
|
5007 | fc01f7e7 | bellard | initrd_filename = optarg; |
5008 | fc01f7e7 | bellard | break;
|
5009 | cd6f1169 | bellard | case QEMU_OPTION_hda:
|
5010 | e4bcb14c | ths | if (cyls == 0) |
5011 | 9dfd7c7a | Gerd Hoffmann | hda_opts = drive_add(optarg, HD_ALIAS, 0);
|
5012 | e4bcb14c | ths | else
|
5013 | 9dfd7c7a | Gerd Hoffmann | hda_opts = drive_add(optarg, HD_ALIAS |
5014 | e4bcb14c | ths | ",cyls=%d,heads=%d,secs=%d%s",
|
5015 | 609497ab | balrog | 0, cyls, heads, secs,
|
5016 | e4bcb14c | ths | translation == BIOS_ATA_TRANSLATION_LBA ? |
5017 | e4bcb14c | ths | ",trans=lba" :
|
5018 | e4bcb14c | ths | translation == BIOS_ATA_TRANSLATION_NONE ? |
5019 | e4bcb14c | ths | ",trans=none" : ""); |
5020 | e4bcb14c | ths | break;
|
5021 | cd6f1169 | bellard | case QEMU_OPTION_hdb:
|
5022 | cc1daa40 | bellard | case QEMU_OPTION_hdc:
|
5023 | cc1daa40 | bellard | case QEMU_OPTION_hdd:
|
5024 | 609497ab | balrog | drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda); |
5025 | fc01f7e7 | bellard | break;
|
5026 | e4bcb14c | ths | case QEMU_OPTION_drive:
|
5027 | 609497ab | balrog | drive_add(NULL, "%s", optarg); |
5028 | e4bcb14c | ths | break;
|
5029 | d058fe03 | Gerd Hoffmann | case QEMU_OPTION_set:
|
5030 | d058fe03 | Gerd Hoffmann | if (qemu_set_option(optarg) != 0) |
5031 | d058fe03 | Gerd Hoffmann | exit(1);
|
5032 | d058fe03 | Gerd Hoffmann | break;
|
5033 | d0fef6fb | Gerd Hoffmann | case QEMU_OPTION_global:
|
5034 | d0fef6fb | Gerd Hoffmann | if (qemu_global_option(optarg) != 0) |
5035 | d0fef6fb | Gerd Hoffmann | exit(1);
|
5036 | d0fef6fb | Gerd Hoffmann | break;
|
5037 | 3e3d5815 | balrog | case QEMU_OPTION_mtdblock:
|
5038 | 609497ab | balrog | drive_add(optarg, MTD_ALIAS); |
5039 | 3e3d5815 | balrog | break;
|
5040 | a1bb27b1 | pbrook | case QEMU_OPTION_sd:
|
5041 | 609497ab | balrog | drive_add(optarg, SD_ALIAS); |
5042 | a1bb27b1 | pbrook | break;
|
5043 | 86f55663 | j_mayer | case QEMU_OPTION_pflash:
|
5044 | 609497ab | balrog | drive_add(optarg, PFLASH_ALIAS); |
5045 | 86f55663 | j_mayer | break;
|
5046 | cd6f1169 | bellard | case QEMU_OPTION_snapshot:
|
5047 | 33e3963e | bellard | snapshot = 1;
|
5048 | 33e3963e | bellard | break;
|
5049 | cd6f1169 | bellard | case QEMU_OPTION_hdachs:
|
5050 | 330d0414 | bellard | { |
5051 | 330d0414 | bellard | const char *p; |
5052 | 330d0414 | bellard | p = optarg; |
5053 | 330d0414 | bellard | cyls = strtol(p, (char **)&p, 0); |
5054 | 46d4767d | bellard | if (cyls < 1 || cyls > 16383) |
5055 | 46d4767d | bellard | goto chs_fail;
|
5056 | 330d0414 | bellard | if (*p != ',') |
5057 | 330d0414 | bellard | goto chs_fail;
|
5058 | 330d0414 | bellard | p++; |
5059 | 330d0414 | bellard | heads = strtol(p, (char **)&p, 0); |
5060 | 46d4767d | bellard | if (heads < 1 || heads > 16) |
5061 | 46d4767d | bellard | goto chs_fail;
|
5062 | 330d0414 | bellard | if (*p != ',') |
5063 | 330d0414 | bellard | goto chs_fail;
|
5064 | 330d0414 | bellard | p++; |
5065 | 330d0414 | bellard | secs = strtol(p, (char **)&p, 0); |
5066 | 46d4767d | bellard | if (secs < 1 || secs > 63) |
5067 | 46d4767d | bellard | goto chs_fail;
|
5068 | 46d4767d | bellard | if (*p == ',') { |
5069 | 46d4767d | bellard | p++; |
5070 | 46d4767d | bellard | if (!strcmp(p, "none")) |
5071 | 46d4767d | bellard | translation = BIOS_ATA_TRANSLATION_NONE; |
5072 | 46d4767d | bellard | else if (!strcmp(p, "lba")) |
5073 | 46d4767d | bellard | translation = BIOS_ATA_TRANSLATION_LBA; |
5074 | 46d4767d | bellard | else if (!strcmp(p, "auto")) |
5075 | 46d4767d | bellard | translation = BIOS_ATA_TRANSLATION_AUTO; |
5076 | 46d4767d | bellard | else
|
5077 | 46d4767d | bellard | goto chs_fail;
|
5078 | 46d4767d | bellard | } else if (*p != '\0') { |
5079 | c4b1fcc0 | bellard | chs_fail:
|
5080 | 46d4767d | bellard | fprintf(stderr, "qemu: invalid physical CHS format\n");
|
5081 | 46d4767d | bellard | exit(1);
|
5082 | c4b1fcc0 | bellard | } |
5083 | 9dfd7c7a | Gerd Hoffmann | if (hda_opts != NULL) { |
5084 | 9dfd7c7a | Gerd Hoffmann | char num[16]; |
5085 | 9dfd7c7a | Gerd Hoffmann | snprintf(num, sizeof(num), "%d", cyls); |
5086 | 9dfd7c7a | Gerd Hoffmann | qemu_opt_set(hda_opts, "cyls", num);
|
5087 | 9dfd7c7a | Gerd Hoffmann | snprintf(num, sizeof(num), "%d", heads); |
5088 | 9dfd7c7a | Gerd Hoffmann | qemu_opt_set(hda_opts, "heads", num);
|
5089 | 9dfd7c7a | Gerd Hoffmann | snprintf(num, sizeof(num), "%d", secs); |
5090 | 9dfd7c7a | Gerd Hoffmann | qemu_opt_set(hda_opts, "secs", num);
|
5091 | 9dfd7c7a | Gerd Hoffmann | if (translation == BIOS_ATA_TRANSLATION_LBA)
|
5092 | 9dfd7c7a | Gerd Hoffmann | qemu_opt_set(hda_opts, "trans", "lba"); |
5093 | 9dfd7c7a | Gerd Hoffmann | if (translation == BIOS_ATA_TRANSLATION_NONE)
|
5094 | 9dfd7c7a | Gerd Hoffmann | qemu_opt_set(hda_opts, "trans", "none"); |
5095 | 9dfd7c7a | Gerd Hoffmann | } |
5096 | 330d0414 | bellard | } |
5097 | 330d0414 | bellard | break;
|
5098 | 268a362c | aliguori | case QEMU_OPTION_numa:
|
5099 | 268a362c | aliguori | if (nb_numa_nodes >= MAX_NODES) {
|
5100 | 268a362c | aliguori | fprintf(stderr, "qemu: too many NUMA nodes\n");
|
5101 | 268a362c | aliguori | exit(1);
|
5102 | 268a362c | aliguori | } |
5103 | 268a362c | aliguori | numa_add(optarg); |
5104 | 268a362c | aliguori | break;
|
5105 | cd6f1169 | bellard | case QEMU_OPTION_nographic:
|
5106 | 993fbfdb | Anthony Liguori | display_type = DT_NOGRAPHIC; |
5107 | a20dd508 | bellard | break;
|
5108 | 4d3b6f6e | balrog | #ifdef CONFIG_CURSES
|
5109 | 4d3b6f6e | balrog | case QEMU_OPTION_curses:
|
5110 | 993fbfdb | Anthony Liguori | display_type = DT_CURSES; |
5111 | 4d3b6f6e | balrog | break;
|
5112 | 4d3b6f6e | balrog | #endif
|
5113 | a171fe39 | balrog | case QEMU_OPTION_portrait:
|
5114 | a171fe39 | balrog | graphic_rotate = 1;
|
5115 | a171fe39 | balrog | break;
|
5116 | cd6f1169 | bellard | case QEMU_OPTION_kernel:
|
5117 | a20dd508 | bellard | kernel_filename = optarg; |
5118 | a20dd508 | bellard | break;
|
5119 | cd6f1169 | bellard | case QEMU_OPTION_append:
|
5120 | a20dd508 | bellard | kernel_cmdline = optarg; |
5121 | 313aa567 | bellard | break;
|
5122 | cd6f1169 | bellard | case QEMU_OPTION_cdrom:
|
5123 | 609497ab | balrog | drive_add(optarg, CDROM_ALIAS); |
5124 | 36b486bb | bellard | break;
|
5125 | cd6f1169 | bellard | case QEMU_OPTION_boot:
|
5126 | 28c5af54 | j_mayer | { |
5127 | ef3adf68 | Jan Kiszka | static const char * const params[] = { |
5128 | 95387491 | Jan Kiszka | "order", "once", "menu", NULL |
5129 | ef3adf68 | Jan Kiszka | }; |
5130 | ef3adf68 | Jan Kiszka | char buf[sizeof(boot_devices)]; |
5131 | e0f084bf | Jan Kiszka | char *standard_boot_devices;
|
5132 | ef3adf68 | Jan Kiszka | int legacy = 0; |
5133 | ef3adf68 | Jan Kiszka | |
5134 | ef3adf68 | Jan Kiszka | if (!strchr(optarg, '=')) { |
5135 | ef3adf68 | Jan Kiszka | legacy = 1;
|
5136 | ef3adf68 | Jan Kiszka | pstrcpy(buf, sizeof(buf), optarg);
|
5137 | ef3adf68 | Jan Kiszka | } else if (check_params(buf, sizeof(buf), params, optarg) < 0) { |
5138 | ef3adf68 | Jan Kiszka | fprintf(stderr, |
5139 | ef3adf68 | Jan Kiszka | "qemu: unknown boot parameter '%s' in '%s'\n",
|
5140 | ef3adf68 | Jan Kiszka | buf, optarg); |
5141 | ef3adf68 | Jan Kiszka | exit(1);
|
5142 | ef3adf68 | Jan Kiszka | } |
5143 | ef3adf68 | Jan Kiszka | |
5144 | ef3adf68 | Jan Kiszka | if (legacy ||
|
5145 | ef3adf68 | Jan Kiszka | get_param_value(buf, sizeof(buf), "order", optarg)) { |
5146 | ef3adf68 | Jan Kiszka | boot_devices_bitmap = parse_bootdevices(buf); |
5147 | ef3adf68 | Jan Kiszka | pstrcpy(boot_devices, sizeof(boot_devices), buf);
|
5148 | 28c5af54 | j_mayer | } |
5149 | e0f084bf | Jan Kiszka | if (!legacy) {
|
5150 | e0f084bf | Jan Kiszka | if (get_param_value(buf, sizeof(buf), |
5151 | e0f084bf | Jan Kiszka | "once", optarg)) {
|
5152 | e0f084bf | Jan Kiszka | boot_devices_bitmap |= parse_bootdevices(buf); |
5153 | e0f084bf | Jan Kiszka | standard_boot_devices = qemu_strdup(boot_devices); |
5154 | e0f084bf | Jan Kiszka | pstrcpy(boot_devices, sizeof(boot_devices), buf);
|
5155 | e0f084bf | Jan Kiszka | qemu_register_reset(restore_boot_devices, |
5156 | e0f084bf | Jan Kiszka | standard_boot_devices); |
5157 | e0f084bf | Jan Kiszka | } |
5158 | 95387491 | Jan Kiszka | if (get_param_value(buf, sizeof(buf), |
5159 | 95387491 | Jan Kiszka | "menu", optarg)) {
|
5160 | 95387491 | Jan Kiszka | if (!strcmp(buf, "on")) { |
5161 | 95387491 | Jan Kiszka | boot_menu = 1;
|
5162 | 95387491 | Jan Kiszka | } else if (!strcmp(buf, "off")) { |
5163 | 95387491 | Jan Kiszka | boot_menu = 0;
|
5164 | 95387491 | Jan Kiszka | } else {
|
5165 | 95387491 | Jan Kiszka | fprintf(stderr, |
5166 | 95387491 | Jan Kiszka | "qemu: invalid option value '%s'\n",
|
5167 | 95387491 | Jan Kiszka | buf); |
5168 | 95387491 | Jan Kiszka | exit(1);
|
5169 | 95387491 | Jan Kiszka | } |
5170 | 95387491 | Jan Kiszka | } |
5171 | e0f084bf | Jan Kiszka | } |
5172 | 36b486bb | bellard | } |
5173 | 36b486bb | bellard | break;
|
5174 | cd6f1169 | bellard | case QEMU_OPTION_fda:
|
5175 | cd6f1169 | bellard | case QEMU_OPTION_fdb:
|
5176 | 609497ab | balrog | drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda); |
5177 | c45886db | bellard | break;
|
5178 | 52ca8d6a | bellard | #ifdef TARGET_I386
|
5179 | 52ca8d6a | bellard | case QEMU_OPTION_no_fd_bootchk:
|
5180 | 52ca8d6a | bellard | fd_bootchk = 0;
|
5181 | 52ca8d6a | bellard | break;
|
5182 | 52ca8d6a | bellard | #endif
|
5183 | a1ea458f | Mark McLoughlin | case QEMU_OPTION_netdev:
|
5184 | a1ea458f | Mark McLoughlin | if (net_client_parse(&qemu_netdev_opts, optarg) == -1) { |
5185 | a1ea458f | Mark McLoughlin | exit(1);
|
5186 | a1ea458f | Mark McLoughlin | } |
5187 | a1ea458f | Mark McLoughlin | break;
|
5188 | 7c9d8e07 | bellard | case QEMU_OPTION_net:
|
5189 | 7f161aae | Mark McLoughlin | if (net_client_parse(&qemu_net_opts, optarg) == -1) { |
5190 | c4b1fcc0 | bellard | exit(1);
|
5191 | c4b1fcc0 | bellard | } |
5192 | 702c651c | bellard | break;
|
5193 | c7f74643 | bellard | #ifdef CONFIG_SLIRP
|
5194 | c7f74643 | bellard | case QEMU_OPTION_tftp:
|
5195 | ad196a9d | Jan Kiszka | legacy_tftp_prefix = optarg; |
5196 | 9bf05444 | bellard | break;
|
5197 | 47d5d01a | ths | case QEMU_OPTION_bootp:
|
5198 | ad196a9d | Jan Kiszka | legacy_bootp_filename = optarg; |
5199 | 47d5d01a | ths | break;
|
5200 | c94c8d64 | bellard | #ifndef _WIN32
|
5201 | 9d728e8c | bellard | case QEMU_OPTION_smb:
|
5202 | 0752706d | Markus Armbruster | if (net_slirp_smb(optarg) < 0) |
5203 | 0752706d | Markus Armbruster | exit(1);
|
5204 | 9d728e8c | bellard | break;
|
5205 | c94c8d64 | bellard | #endif
|
5206 | 9bf05444 | bellard | case QEMU_OPTION_redir:
|
5207 | 0752706d | Markus Armbruster | if (net_slirp_redir(optarg) < 0) |
5208 | 0752706d | Markus Armbruster | exit(1);
|
5209 | 9bf05444 | bellard | break;
|
5210 | c7f74643 | bellard | #endif
|
5211 | dc72ac14 | balrog | case QEMU_OPTION_bt:
|
5212 | bd3c948d | Gerd Hoffmann | add_device_config(DEV_BT, optarg); |
5213 | dc72ac14 | balrog | break;
|
5214 | 1d14ffa9 | bellard | #ifdef HAS_AUDIO
|
5215 | 1d14ffa9 | bellard | case QEMU_OPTION_audio_help:
|
5216 | 1d14ffa9 | bellard | AUD_help (); |
5217 | 1d14ffa9 | bellard | exit (0);
|
5218 | 1d14ffa9 | bellard | break;
|
5219 | 1d14ffa9 | bellard | case QEMU_OPTION_soundhw:
|
5220 | 1d14ffa9 | bellard | select_soundhw (optarg); |
5221 | 1d14ffa9 | bellard | break;
|
5222 | 1d14ffa9 | bellard | #endif
|
5223 | cd6f1169 | bellard | case QEMU_OPTION_h:
|
5224 | 15f82208 | ths | help(0);
|
5225 | cd6f1169 | bellard | break;
|
5226 | 9bd7e6d9 | pbrook | case QEMU_OPTION_version:
|
5227 | 9bd7e6d9 | pbrook | version(); |
5228 | 9bd7e6d9 | pbrook | exit(0);
|
5229 | 9bd7e6d9 | pbrook | break;
|
5230 | 00f82b8a | aurel32 | case QEMU_OPTION_m: {
|
5231 | 00f82b8a | aurel32 | uint64_t value; |
5232 | 00f82b8a | aurel32 | char *ptr;
|
5233 | 00f82b8a | aurel32 | |
5234 | 00f82b8a | aurel32 | value = strtoul(optarg, &ptr, 10);
|
5235 | 00f82b8a | aurel32 | switch (*ptr) {
|
5236 | 00f82b8a | aurel32 | case 0: case 'M': case 'm': |
5237 | 00f82b8a | aurel32 | value <<= 20;
|
5238 | 00f82b8a | aurel32 | break;
|
5239 | 00f82b8a | aurel32 | case 'G': case 'g': |
5240 | 00f82b8a | aurel32 | value <<= 30;
|
5241 | 00f82b8a | aurel32 | break;
|
5242 | 00f82b8a | aurel32 | default:
|
5243 | 00f82b8a | aurel32 | fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
|
5244 | cd6f1169 | bellard | exit(1);
|
5245 | cd6f1169 | bellard | } |
5246 | 00f82b8a | aurel32 | |
5247 | 00f82b8a | aurel32 | /* On 32-bit hosts, QEMU is limited by virtual address space */
|
5248 | 4a1418e0 | Anthony Liguori | if (value > (2047 << 20) && HOST_LONG_BITS == 32) { |
5249 | 00f82b8a | aurel32 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n");
|
5250 | 00f82b8a | aurel32 | exit(1);
|
5251 | 00f82b8a | aurel32 | } |
5252 | c227f099 | Anthony Liguori | if (value != (uint64_t)(ram_addr_t)value) {
|
5253 | 00f82b8a | aurel32 | fprintf(stderr, "qemu: ram size too large\n");
|
5254 | 00f82b8a | aurel32 | exit(1);
|
5255 | 00f82b8a | aurel32 | } |
5256 | 00f82b8a | aurel32 | ram_size = value; |
5257 | cd6f1169 | bellard | break;
|
5258 | 00f82b8a | aurel32 | } |
5259 | c902760f | Marcelo Tosatti | case QEMU_OPTION_mempath:
|
5260 | c902760f | Marcelo Tosatti | mem_path = optarg; |
5261 | c902760f | Marcelo Tosatti | break;
|
5262 | c902760f | Marcelo Tosatti | #ifdef MAP_POPULATE
|
5263 | c902760f | Marcelo Tosatti | case QEMU_OPTION_mem_prealloc:
|
5264 | c902760f | Marcelo Tosatti | mem_prealloc = 1;
|
5265 | c902760f | Marcelo Tosatti | break;
|
5266 | c902760f | Marcelo Tosatti | #endif
|
5267 | cd6f1169 | bellard | case QEMU_OPTION_d:
|
5268 | cd6f1169 | bellard | { |
5269 | cd6f1169 | bellard | int mask;
|
5270 | c7cd6a37 | blueswir1 | const CPULogItem *item;
|
5271 | 3b46e624 | ths | |
5272 | cd6f1169 | bellard | mask = cpu_str_to_log_mask(optarg); |
5273 | cd6f1169 | bellard | if (!mask) {
|
5274 | cd6f1169 | bellard | printf("Log items (comma separated):\n");
|
5275 | f193c797 | bellard | for(item = cpu_log_items; item->mask != 0; item++) { |
5276 | f193c797 | bellard | printf("%-10s %s\n", item->name, item->help);
|
5277 | f193c797 | bellard | } |
5278 | f193c797 | bellard | exit(1);
|
5279 | cd6f1169 | bellard | } |
5280 | cd6f1169 | bellard | cpu_set_log(mask); |
5281 | f193c797 | bellard | } |
5282 | cd6f1169 | bellard | break;
|
5283 | cd6f1169 | bellard | case QEMU_OPTION_s:
|
5284 | 59030a8c | aliguori | gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
|
5285 | cd6f1169 | bellard | break;
|
5286 | 59030a8c | aliguori | case QEMU_OPTION_gdb:
|
5287 | 59030a8c | aliguori | gdbstub_dev = optarg; |
5288 | cd6f1169 | bellard | break;
|
5289 | cd6f1169 | bellard | case QEMU_OPTION_L:
|
5290 | 5cea8590 | Paul Brook | data_dir = optarg; |
5291 | cd6f1169 | bellard | break;
|
5292 | 1192dad8 | j_mayer | case QEMU_OPTION_bios:
|
5293 | 1192dad8 | j_mayer | bios_name = optarg; |
5294 | 1192dad8 | j_mayer | break;
|
5295 | 1b530a6d | aurel32 | case QEMU_OPTION_singlestep:
|
5296 | 1b530a6d | aurel32 | singlestep = 1;
|
5297 | 1b530a6d | aurel32 | break;
|
5298 | cd6f1169 | bellard | case QEMU_OPTION_S:
|
5299 | 3c07f8e8 | pbrook | autostart = 0;
|
5300 | cd6f1169 | bellard | break;
|
5301 | 3d11d0eb | bellard | case QEMU_OPTION_k:
|
5302 | 3d11d0eb | bellard | keyboard_layout = optarg; |
5303 | 3d11d0eb | bellard | break;
|
5304 | ee22c2f7 | bellard | case QEMU_OPTION_localtime:
|
5305 | ee22c2f7 | bellard | rtc_utc = 0;
|
5306 | ee22c2f7 | bellard | break;
|
5307 | 3893c124 | malc | case QEMU_OPTION_vga:
|
5308 | 3893c124 | malc | select_vgahw (optarg); |
5309 | 1bfe856e | bellard | break;
|
5310 | 5824d651 | blueswir1 | #if defined(TARGET_PPC) || defined(TARGET_SPARC)
|
5311 | e9b137c2 | bellard | case QEMU_OPTION_g:
|
5312 | e9b137c2 | bellard | { |
5313 | e9b137c2 | bellard | const char *p; |
5314 | e9b137c2 | bellard | int w, h, depth;
|
5315 | e9b137c2 | bellard | p = optarg; |
5316 | e9b137c2 | bellard | w = strtol(p, (char **)&p, 10); |
5317 | e9b137c2 | bellard | if (w <= 0) { |
5318 | e9b137c2 | bellard | graphic_error:
|
5319 | e9b137c2 | bellard | fprintf(stderr, "qemu: invalid resolution or depth\n");
|
5320 | e9b137c2 | bellard | exit(1);
|
5321 | e9b137c2 | bellard | } |
5322 | e9b137c2 | bellard | if (*p != 'x') |
5323 | e9b137c2 | bellard | goto graphic_error;
|
5324 | e9b137c2 | bellard | p++; |
5325 | e9b137c2 | bellard | h = strtol(p, (char **)&p, 10); |
5326 | e9b137c2 | bellard | if (h <= 0) |
5327 | e9b137c2 | bellard | goto graphic_error;
|
5328 | e9b137c2 | bellard | if (*p == 'x') { |
5329 | e9b137c2 | bellard | p++; |
5330 | e9b137c2 | bellard | depth = strtol(p, (char **)&p, 10); |
5331 | 5fafdf24 | ths | if (depth != 8 && depth != 15 && depth != 16 && |
5332 | e9b137c2 | bellard | depth != 24 && depth != 32) |
5333 | e9b137c2 | bellard | goto graphic_error;
|
5334 | e9b137c2 | bellard | } else if (*p == '\0') { |
5335 | e9b137c2 | bellard | depth = graphic_depth; |
5336 | e9b137c2 | bellard | } else {
|
5337 | e9b137c2 | bellard | goto graphic_error;
|
5338 | e9b137c2 | bellard | } |
5339 | 3b46e624 | ths | |
5340 | e9b137c2 | bellard | graphic_width = w; |
5341 | e9b137c2 | bellard | graphic_height = h; |
5342 | e9b137c2 | bellard | graphic_depth = depth; |
5343 | e9b137c2 | bellard | } |
5344 | e9b137c2 | bellard | break;
|
5345 | 5824d651 | blueswir1 | #endif
|
5346 | 20d8a3ed | ths | case QEMU_OPTION_echr:
|
5347 | 20d8a3ed | ths | { |
5348 | 20d8a3ed | ths | char *r;
|
5349 | 20d8a3ed | ths | term_escape_char = strtol(optarg, &r, 0);
|
5350 | 20d8a3ed | ths | if (r == optarg)
|
5351 | 20d8a3ed | ths | printf("Bad argument to echr\n");
|
5352 | 20d8a3ed | ths | break;
|
5353 | 20d8a3ed | ths | } |
5354 | 82c643ff | bellard | case QEMU_OPTION_monitor:
|
5355 | 6ca5582d | Gerd Hoffmann | monitor_parse(optarg, "readline");
|
5356 | 6ca5582d | Gerd Hoffmann | default_monitor = 0;
|
5357 | 6ca5582d | Gerd Hoffmann | break;
|
5358 | 6ca5582d | Gerd Hoffmann | case QEMU_OPTION_qmp:
|
5359 | 6ca5582d | Gerd Hoffmann | monitor_parse(optarg, "control");
|
5360 | abdeed06 | Gerd Hoffmann | default_monitor = 0;
|
5361 | 82c643ff | bellard | break;
|
5362 | 22a0e04b | Gerd Hoffmann | case QEMU_OPTION_mon:
|
5363 | 22a0e04b | Gerd Hoffmann | opts = qemu_opts_parse(&qemu_mon_opts, optarg, "chardev");
|
5364 | 22a0e04b | Gerd Hoffmann | if (!opts) {
|
5365 | 22a0e04b | Gerd Hoffmann | fprintf(stderr, "parse error: %s\n", optarg);
|
5366 | 22a0e04b | Gerd Hoffmann | exit(1);
|
5367 | 22a0e04b | Gerd Hoffmann | } |
5368 | 22a0e04b | Gerd Hoffmann | default_monitor = 0;
|
5369 | 22a0e04b | Gerd Hoffmann | break;
|
5370 | 191bc01b | Gerd Hoffmann | case QEMU_OPTION_chardev:
|
5371 | 191bc01b | Gerd Hoffmann | opts = qemu_opts_parse(&qemu_chardev_opts, optarg, "backend");
|
5372 | 191bc01b | Gerd Hoffmann | if (!opts) {
|
5373 | 191bc01b | Gerd Hoffmann | fprintf(stderr, "parse error: %s\n", optarg);
|
5374 | 191bc01b | Gerd Hoffmann | exit(1);
|
5375 | 191bc01b | Gerd Hoffmann | } |
5376 | 191bc01b | Gerd Hoffmann | break;
|
5377 | 82c643ff | bellard | case QEMU_OPTION_serial:
|
5378 | 998bbd74 | Gerd Hoffmann | add_device_config(DEV_SERIAL, optarg); |
5379 | 998bbd74 | Gerd Hoffmann | default_serial = 0;
|
5380 | 82c643ff | bellard | break;
|
5381 | 9dd986cc | Richard W.M. Jones | case QEMU_OPTION_watchdog:
|
5382 | 09aaa160 | Markus Armbruster | if (watchdog) {
|
5383 | 09aaa160 | Markus Armbruster | fprintf(stderr, |
5384 | 09aaa160 | Markus Armbruster | "qemu: only one watchdog option may be given\n");
|
5385 | 09aaa160 | Markus Armbruster | return 1; |
5386 | 09aaa160 | Markus Armbruster | } |
5387 | 09aaa160 | Markus Armbruster | watchdog = optarg; |
5388 | 9dd986cc | Richard W.M. Jones | break;
|
5389 | 9dd986cc | Richard W.M. Jones | case QEMU_OPTION_watchdog_action:
|
5390 | 9dd986cc | Richard W.M. Jones | if (select_watchdog_action(optarg) == -1) { |
5391 | 9dd986cc | Richard W.M. Jones | fprintf(stderr, "Unknown -watchdog-action parameter\n");
|
5392 | 9dd986cc | Richard W.M. Jones | exit(1);
|
5393 | 9dd986cc | Richard W.M. Jones | } |
5394 | 9dd986cc | Richard W.M. Jones | break;
|
5395 | 51ecf136 | aliguori | case QEMU_OPTION_virtiocon:
|
5396 | aee1b935 | Gerd Hoffmann | add_device_config(DEV_VIRTCON, optarg); |
5397 | aee1b935 | Gerd Hoffmann | default_virtcon = 0;
|
5398 | 51ecf136 | aliguori | break;
|
5399 | 6508fe59 | bellard | case QEMU_OPTION_parallel:
|
5400 | 6a5e8b0e | Gerd Hoffmann | add_device_config(DEV_PARALLEL, optarg); |
5401 | 6a5e8b0e | Gerd Hoffmann | default_parallel = 0;
|
5402 | 6508fe59 | bellard | break;
|
5403 | c9f398e5 | H. Peter Anvin | case QEMU_OPTION_debugcon:
|
5404 | c9f398e5 | H. Peter Anvin | add_device_config(DEV_DEBUGCON, optarg); |
5405 | c9f398e5 | H. Peter Anvin | break;
|
5406 | d63d307f | bellard | case QEMU_OPTION_loadvm:
|
5407 | d63d307f | bellard | loadvm = optarg; |
5408 | d63d307f | bellard | break;
|
5409 | d63d307f | bellard | case QEMU_OPTION_full_screen:
|
5410 | d63d307f | bellard | full_screen = 1;
|
5411 | d63d307f | bellard | break;
|
5412 | 667accab | ths | #ifdef CONFIG_SDL
|
5413 | 43523e93 | ths | case QEMU_OPTION_no_frame:
|
5414 | 43523e93 | ths | no_frame = 1;
|
5415 | 43523e93 | ths | break;
|
5416 | 3780e197 | ths | case QEMU_OPTION_alt_grab:
|
5417 | 3780e197 | ths | alt_grab = 1;
|
5418 | 3780e197 | ths | break;
|
5419 | 0ca9f8a4 | Dustin Kirkland | case QEMU_OPTION_ctrl_grab:
|
5420 | 0ca9f8a4 | Dustin Kirkland | ctrl_grab = 1;
|
5421 | 0ca9f8a4 | Dustin Kirkland | break;
|
5422 | 667accab | ths | case QEMU_OPTION_no_quit:
|
5423 | 667accab | ths | no_quit = 1;
|
5424 | 667accab | ths | break;
|
5425 | 7d957bd8 | aliguori | case QEMU_OPTION_sdl:
|
5426 | 993fbfdb | Anthony Liguori | display_type = DT_SDL; |
5427 | 7d957bd8 | aliguori | break;
|
5428 | 667accab | ths | #endif
|
5429 | f7cce898 | bellard | case QEMU_OPTION_pidfile:
|
5430 | 93815bc2 | ths | pid_file = optarg; |
5431 | f7cce898 | bellard | break;
|
5432 | a09db21f | bellard | #ifdef TARGET_I386
|
5433 | a09db21f | bellard | case QEMU_OPTION_win2k_hack:
|
5434 | a09db21f | bellard | win2k_install_hack = 1;
|
5435 | a09db21f | bellard | break;
|
5436 | 73822ec8 | aliguori | case QEMU_OPTION_rtc_td_hack:
|
5437 | 73822ec8 | aliguori | rtc_td_hack = 1;
|
5438 | 73822ec8 | aliguori | break;
|
5439 | 8a92ea2f | aliguori | case QEMU_OPTION_acpitable:
|
5440 | 8a92ea2f | aliguori | if(acpi_table_add(optarg) < 0) { |
5441 | 8a92ea2f | aliguori | fprintf(stderr, "Wrong acpi table provided\n");
|
5442 | 8a92ea2f | aliguori | exit(1);
|
5443 | 8a92ea2f | aliguori | } |
5444 | 8a92ea2f | aliguori | break;
|
5445 | b6f6e3d3 | aliguori | case QEMU_OPTION_smbios:
|
5446 | b6f6e3d3 | aliguori | if(smbios_entry_add(optarg) < 0) { |
5447 | b6f6e3d3 | aliguori | fprintf(stderr, "Wrong smbios provided\n");
|
5448 | b6f6e3d3 | aliguori | exit(1);
|
5449 | b6f6e3d3 | aliguori | } |
5450 | b6f6e3d3 | aliguori | break;
|
5451 | a09db21f | bellard | #endif
|
5452 | 7ba1e619 | aliguori | #ifdef CONFIG_KVM
|
5453 | 7ba1e619 | aliguori | case QEMU_OPTION_enable_kvm:
|
5454 | 7ba1e619 | aliguori | kvm_allowed = 1;
|
5455 | 7ba1e619 | aliguori | break;
|
5456 | 7ba1e619 | aliguori | #endif
|
5457 | bb36d470 | bellard | case QEMU_OPTION_usb:
|
5458 | bb36d470 | bellard | usb_enabled = 1;
|
5459 | bb36d470 | bellard | break;
|
5460 | a594cfbf | bellard | case QEMU_OPTION_usbdevice:
|
5461 | a594cfbf | bellard | usb_enabled = 1;
|
5462 | bd3c948d | Gerd Hoffmann | add_device_config(DEV_USB, optarg); |
5463 | bd3c948d | Gerd Hoffmann | break;
|
5464 | bd3c948d | Gerd Hoffmann | case QEMU_OPTION_device:
|
5465 | b386becf | Mark McLoughlin | if (!qemu_opts_parse(&qemu_device_opts, optarg, "driver")) { |
5466 | f31d07d1 | Gerd Hoffmann | exit(1);
|
5467 | f31d07d1 | Gerd Hoffmann | } |
5468 | a594cfbf | bellard | break;
|
5469 | 6a00d601 | bellard | case QEMU_OPTION_smp:
|
5470 | dc6b1c09 | Andre Przywara | smp_parse(optarg); |
5471 | b2097003 | aliguori | if (smp_cpus < 1) { |
5472 | 6a00d601 | bellard | fprintf(stderr, "Invalid number of CPUs\n");
|
5473 | 6a00d601 | bellard | exit(1);
|
5474 | 6a00d601 | bellard | } |
5475 | 6be68d7e | Jes Sorensen | if (max_cpus < smp_cpus) {
|
5476 | 6be68d7e | Jes Sorensen | fprintf(stderr, "maxcpus must be equal to or greater than "
|
5477 | 6be68d7e | Jes Sorensen | "smp\n");
|
5478 | 6be68d7e | Jes Sorensen | exit(1);
|
5479 | 6be68d7e | Jes Sorensen | } |
5480 | 6be68d7e | Jes Sorensen | if (max_cpus > 255) { |
5481 | 6be68d7e | Jes Sorensen | fprintf(stderr, "Unsupported number of maxcpus\n");
|
5482 | 6be68d7e | Jes Sorensen | exit(1);
|
5483 | 6be68d7e | Jes Sorensen | } |
5484 | 6a00d601 | bellard | break;
|
5485 | 24236869 | bellard | case QEMU_OPTION_vnc:
|
5486 | 993fbfdb | Anthony Liguori | display_type = DT_VNC; |
5487 | 73fc9742 | ths | vnc_display = optarg; |
5488 | 24236869 | bellard | break;
|
5489 | 5824d651 | blueswir1 | #ifdef TARGET_I386
|
5490 | 6515b203 | bellard | case QEMU_OPTION_no_acpi:
|
5491 | 6515b203 | bellard | acpi_enabled = 0;
|
5492 | 6515b203 | bellard | break;
|
5493 | 16b29ae1 | aliguori | case QEMU_OPTION_no_hpet:
|
5494 | 16b29ae1 | aliguori | no_hpet = 1;
|
5495 | 16b29ae1 | aliguori | break;
|
5496 | 7d4c3d53 | Markus Armbruster | case QEMU_OPTION_balloon:
|
5497 | 7d4c3d53 | Markus Armbruster | if (balloon_parse(optarg) < 0) { |
5498 | 7d4c3d53 | Markus Armbruster | fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
|
5499 | 7d4c3d53 | Markus Armbruster | exit(1);
|
5500 | 7d4c3d53 | Markus Armbruster | } |
5501 | df97b920 | Eduardo Habkost | break;
|
5502 | 5824d651 | blueswir1 | #endif
|
5503 | d1beab82 | bellard | case QEMU_OPTION_no_reboot:
|
5504 | d1beab82 | bellard | no_reboot = 1;
|
5505 | d1beab82 | bellard | break;
|
5506 | b2f76161 | aurel32 | case QEMU_OPTION_no_shutdown:
|
5507 | b2f76161 | aurel32 | no_shutdown = 1;
|
5508 | b2f76161 | aurel32 | break;
|
5509 | 9467cd46 | balrog | case QEMU_OPTION_show_cursor:
|
5510 | 9467cd46 | balrog | cursor_hide = 0;
|
5511 | 9467cd46 | balrog | break;
|
5512 | 8fcb1b90 | blueswir1 | case QEMU_OPTION_uuid:
|
5513 | 8fcb1b90 | blueswir1 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { |
5514 | 8fcb1b90 | blueswir1 | fprintf(stderr, "Fail to parse UUID string."
|
5515 | 8fcb1b90 | blueswir1 | " Wrong format.\n");
|
5516 | 8fcb1b90 | blueswir1 | exit(1);
|
5517 | 8fcb1b90 | blueswir1 | } |
5518 | 8fcb1b90 | blueswir1 | break;
|
5519 | 5824d651 | blueswir1 | #ifndef _WIN32
|
5520 | 71e3ceb8 | ths | case QEMU_OPTION_daemonize:
|
5521 | 71e3ceb8 | ths | daemonize = 1;
|
5522 | 71e3ceb8 | ths | break;
|
5523 | 5824d651 | blueswir1 | #endif
|
5524 | 9ae02555 | ths | case QEMU_OPTION_option_rom:
|
5525 | 9ae02555 | ths | if (nb_option_roms >= MAX_OPTION_ROMS) {
|
5526 | 9ae02555 | ths | fprintf(stderr, "Too many option ROMs\n");
|
5527 | 9ae02555 | ths | exit(1);
|
5528 | 9ae02555 | ths | } |
5529 | 9ae02555 | ths | option_rom[nb_option_roms] = optarg; |
5530 | 9ae02555 | ths | nb_option_roms++; |
5531 | 9ae02555 | ths | break;
|
5532 | 5824d651 | blueswir1 | #if defined(TARGET_ARM) || defined(TARGET_M68K)
|
5533 | 8e71621f | pbrook | case QEMU_OPTION_semihosting:
|
5534 | 8e71621f | pbrook | semihosting_enabled = 1;
|
5535 | 8e71621f | pbrook | break;
|
5536 | 5824d651 | blueswir1 | #endif
|
5537 | c35734b2 | ths | case QEMU_OPTION_name:
|
5538 | 1889465a | Andi Kleen | qemu_name = qemu_strdup(optarg); |
5539 | 1889465a | Andi Kleen | { |
5540 | 1889465a | Andi Kleen | char *p = strchr(qemu_name, ','); |
5541 | 1889465a | Andi Kleen | if (p != NULL) { |
5542 | 1889465a | Andi Kleen | *p++ = 0;
|
5543 | 1889465a | Andi Kleen | if (strncmp(p, "process=", 8)) { |
5544 | 1889465a | Andi Kleen | fprintf(stderr, "Unknown subargument %s to -name", p);
|
5545 | 1889465a | Andi Kleen | exit(1);
|
5546 | 1889465a | Andi Kleen | } |
5547 | 1889465a | Andi Kleen | p += 8;
|
5548 | 1889465a | Andi Kleen | set_proc_name(p); |
5549 | 1889465a | Andi Kleen | } |
5550 | 1889465a | Andi Kleen | } |
5551 | c35734b2 | ths | break;
|
5552 | 95efd11c | blueswir1 | #if defined(TARGET_SPARC) || defined(TARGET_PPC)
|
5553 | 66508601 | blueswir1 | case QEMU_OPTION_prom_env:
|
5554 | 66508601 | blueswir1 | if (nb_prom_envs >= MAX_PROM_ENVS) {
|
5555 | 66508601 | blueswir1 | fprintf(stderr, "Too many prom variables\n");
|
5556 | 66508601 | blueswir1 | exit(1);
|
5557 | 66508601 | blueswir1 | } |
5558 | 66508601 | blueswir1 | prom_envs[nb_prom_envs] = optarg; |
5559 | 66508601 | blueswir1 | nb_prom_envs++; |
5560 | 66508601 | blueswir1 | break;
|
5561 | 66508601 | blueswir1 | #endif
|
5562 | 2b8f2d41 | balrog | #ifdef TARGET_ARM
|
5563 | 2b8f2d41 | balrog | case QEMU_OPTION_old_param:
|
5564 | 2b8f2d41 | balrog | old_param = 1;
|
5565 | 05ebd537 | ths | break;
|
5566 | 2b8f2d41 | balrog | #endif
|
5567 | f3dcfada | ths | case QEMU_OPTION_clock:
|
5568 | f3dcfada | ths | configure_alarms(optarg); |
5569 | f3dcfada | ths | break;
|
5570 | 7e0af5d0 | bellard | case QEMU_OPTION_startdate:
|
5571 | 1ed2fc1f | Jan Kiszka | configure_rtc_date_offset(optarg, 1);
|
5572 | 1ed2fc1f | Jan Kiszka | break;
|
5573 | 1ed2fc1f | Jan Kiszka | case QEMU_OPTION_rtc:
|
5574 | 1ed2fc1f | Jan Kiszka | opts = qemu_opts_parse(&qemu_rtc_opts, optarg, NULL);
|
5575 | 1ed2fc1f | Jan Kiszka | if (!opts) {
|
5576 | 1ed2fc1f | Jan Kiszka | fprintf(stderr, "parse error: %s\n", optarg);
|
5577 | 1ed2fc1f | Jan Kiszka | exit(1);
|
5578 | 7e0af5d0 | bellard | } |
5579 | 1ed2fc1f | Jan Kiszka | configure_rtc(opts); |
5580 | 7e0af5d0 | bellard | break;
|
5581 | 26a5f13b | bellard | case QEMU_OPTION_tb_size:
|
5582 | 26a5f13b | bellard | tb_size = strtol(optarg, NULL, 0); |
5583 | 26a5f13b | bellard | if (tb_size < 0) |
5584 | 26a5f13b | bellard | tb_size = 0;
|
5585 | 26a5f13b | bellard | break;
|
5586 | 2e70f6ef | pbrook | case QEMU_OPTION_icount:
|
5587 | 2e70f6ef | pbrook | use_icount = 1;
|
5588 | 2e70f6ef | pbrook | if (strcmp(optarg, "auto") == 0) { |
5589 | 2e70f6ef | pbrook | icount_time_shift = -1;
|
5590 | 2e70f6ef | pbrook | } else {
|
5591 | 2e70f6ef | pbrook | icount_time_shift = strtol(optarg, NULL, 0); |
5592 | 2e70f6ef | pbrook | } |
5593 | 2e70f6ef | pbrook | break;
|
5594 | 5bb7910a | aliguori | case QEMU_OPTION_incoming:
|
5595 | 5bb7910a | aliguori | incoming = optarg; |
5596 | 5bb7910a | aliguori | break;
|
5597 | d8c208dd | Gerd Hoffmann | case QEMU_OPTION_nodefaults:
|
5598 | d8c208dd | Gerd Hoffmann | default_serial = 0;
|
5599 | d8c208dd | Gerd Hoffmann | default_parallel = 0;
|
5600 | aee1b935 | Gerd Hoffmann | default_virtcon = 0;
|
5601 | d8c208dd | Gerd Hoffmann | default_monitor = 0;
|
5602 | d8c208dd | Gerd Hoffmann | default_vga = 0;
|
5603 | cb4522cc | Gerd Hoffmann | default_net = 0;
|
5604 | ac33f8fa | Gerd Hoffmann | default_floppy = 0;
|
5605 | ac33f8fa | Gerd Hoffmann | default_cdrom = 0;
|
5606 | ac33f8fa | Gerd Hoffmann | default_sdcard = 0;
|
5607 | d8c208dd | Gerd Hoffmann | break;
|
5608 | 5824d651 | blueswir1 | #ifndef _WIN32
|
5609 | 0858532e | aliguori | case QEMU_OPTION_chroot:
|
5610 | 0858532e | aliguori | chroot_dir = optarg; |
5611 | 0858532e | aliguori | break;
|
5612 | 0858532e | aliguori | case QEMU_OPTION_runas:
|
5613 | 0858532e | aliguori | run_as = optarg; |
5614 | 0858532e | aliguori | break;
|
5615 | 5824d651 | blueswir1 | #endif
|
5616 | e37630ca | aliguori | #ifdef CONFIG_XEN
|
5617 | e37630ca | aliguori | case QEMU_OPTION_xen_domid:
|
5618 | e37630ca | aliguori | xen_domid = atoi(optarg); |
5619 | e37630ca | aliguori | break;
|
5620 | e37630ca | aliguori | case QEMU_OPTION_xen_create:
|
5621 | e37630ca | aliguori | xen_mode = XEN_CREATE; |
5622 | e37630ca | aliguori | break;
|
5623 | e37630ca | aliguori | case QEMU_OPTION_xen_attach:
|
5624 | e37630ca | aliguori | xen_mode = XEN_ATTACH; |
5625 | e37630ca | aliguori | break;
|
5626 | e37630ca | aliguori | #endif
|
5627 | 715a664a | Gerd Hoffmann | case QEMU_OPTION_readconfig:
|
5628 | 715a664a | Gerd Hoffmann | { |
5629 | 715a664a | Gerd Hoffmann | FILE *fp; |
5630 | 715a664a | Gerd Hoffmann | fp = fopen(optarg, "r");
|
5631 | 715a664a | Gerd Hoffmann | if (fp == NULL) { |
5632 | 715a664a | Gerd Hoffmann | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
|
5633 | 715a664a | Gerd Hoffmann | exit(1);
|
5634 | 715a664a | Gerd Hoffmann | } |
5635 | 715a664a | Gerd Hoffmann | if (qemu_config_parse(fp) != 0) { |
5636 | 715a664a | Gerd Hoffmann | exit(1);
|
5637 | 715a664a | Gerd Hoffmann | } |
5638 | 715a664a | Gerd Hoffmann | fclose(fp); |
5639 | 715a664a | Gerd Hoffmann | break;
|
5640 | 715a664a | Gerd Hoffmann | } |
5641 | 715a664a | Gerd Hoffmann | case QEMU_OPTION_writeconfig:
|
5642 | 715a664a | Gerd Hoffmann | { |
5643 | 715a664a | Gerd Hoffmann | FILE *fp; |
5644 | 715a664a | Gerd Hoffmann | if (strcmp(optarg, "-") == 0) { |
5645 | 715a664a | Gerd Hoffmann | fp = stdout; |
5646 | 715a664a | Gerd Hoffmann | } else {
|
5647 | 715a664a | Gerd Hoffmann | fp = fopen(optarg, "w");
|
5648 | 715a664a | Gerd Hoffmann | if (fp == NULL) { |
5649 | 715a664a | Gerd Hoffmann | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
|
5650 | 715a664a | Gerd Hoffmann | exit(1);
|
5651 | 715a664a | Gerd Hoffmann | } |
5652 | 715a664a | Gerd Hoffmann | } |
5653 | 715a664a | Gerd Hoffmann | qemu_config_write(fp); |
5654 | 715a664a | Gerd Hoffmann | fclose(fp); |
5655 | 715a664a | Gerd Hoffmann | break;
|
5656 | 715a664a | Gerd Hoffmann | } |
5657 | cd6f1169 | bellard | } |
5658 | 0824d6fc | bellard | } |
5659 | 0824d6fc | bellard | } |
5660 | 330d0414 | bellard | |
5661 | 5cea8590 | Paul Brook | /* If no data_dir is specified then try to find it relative to the
|
5662 | 5cea8590 | Paul Brook | executable path. */
|
5663 | 5cea8590 | Paul Brook | if (!data_dir) {
|
5664 | 5cea8590 | Paul Brook | data_dir = find_datadir(argv[0]);
|
5665 | 5cea8590 | Paul Brook | } |
5666 | 5cea8590 | Paul Brook | /* If all else fails use the install patch specified when building. */
|
5667 | 5cea8590 | Paul Brook | if (!data_dir) {
|
5668 | 5cea8590 | Paul Brook | data_dir = CONFIG_QEMU_SHAREDIR; |
5669 | 5cea8590 | Paul Brook | } |
5670 | 5cea8590 | Paul Brook | |
5671 | 6be68d7e | Jes Sorensen | /*
|
5672 | 6be68d7e | Jes Sorensen | * Default to max_cpus = smp_cpus, in case the user doesn't
|
5673 | 6be68d7e | Jes Sorensen | * specify a max_cpus value.
|
5674 | 6be68d7e | Jes Sorensen | */
|
5675 | 6be68d7e | Jes Sorensen | if (!max_cpus)
|
5676 | 6be68d7e | Jes Sorensen | max_cpus = smp_cpus; |
5677 | 6be68d7e | Jes Sorensen | |
5678 | 3d878caa | balrog | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
5679 | b2097003 | aliguori | if (smp_cpus > machine->max_cpus) {
|
5680 | b2097003 | aliguori | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
|
5681 | b2097003 | aliguori | "supported by machine `%s' (%d)\n", smp_cpus, machine->name,
|
5682 | b2097003 | aliguori | machine->max_cpus); |
5683 | b2097003 | aliguori | exit(1);
|
5684 | b2097003 | aliguori | } |
5685 | b2097003 | aliguori | |
5686 | 998bbd74 | Gerd Hoffmann | qemu_opts_foreach(&qemu_device_opts, default_driver_check, NULL, 0); |
5687 | d8bcbabf | Gerd Hoffmann | qemu_opts_foreach(&qemu_global_opts, default_driver_check, NULL, 0); |
5688 | 998bbd74 | Gerd Hoffmann | |
5689 | 986c5f78 | Gerd Hoffmann | if (machine->no_serial) {
|
5690 | 986c5f78 | Gerd Hoffmann | default_serial = 0;
|
5691 | 986c5f78 | Gerd Hoffmann | } |
5692 | 986c5f78 | Gerd Hoffmann | if (machine->no_parallel) {
|
5693 | 986c5f78 | Gerd Hoffmann | default_parallel = 0;
|
5694 | 986c5f78 | Gerd Hoffmann | } |
5695 | 986c5f78 | Gerd Hoffmann | if (!machine->use_virtcon) {
|
5696 | 986c5f78 | Gerd Hoffmann | default_virtcon = 0;
|
5697 | 986c5f78 | Gerd Hoffmann | } |
5698 | 986c5f78 | Gerd Hoffmann | if (machine->no_vga) {
|
5699 | 986c5f78 | Gerd Hoffmann | default_vga = 0;
|
5700 | 986c5f78 | Gerd Hoffmann | } |
5701 | ac33f8fa | Gerd Hoffmann | if (machine->no_floppy) {
|
5702 | ac33f8fa | Gerd Hoffmann | default_floppy = 0;
|
5703 | ac33f8fa | Gerd Hoffmann | } |
5704 | ac33f8fa | Gerd Hoffmann | if (machine->no_cdrom) {
|
5705 | ac33f8fa | Gerd Hoffmann | default_cdrom = 0;
|
5706 | ac33f8fa | Gerd Hoffmann | } |
5707 | ac33f8fa | Gerd Hoffmann | if (machine->no_sdcard) {
|
5708 | ac33f8fa | Gerd Hoffmann | default_sdcard = 0;
|
5709 | ac33f8fa | Gerd Hoffmann | } |
5710 | 986c5f78 | Gerd Hoffmann | |
5711 | 993fbfdb | Anthony Liguori | if (display_type == DT_NOGRAPHIC) {
|
5712 | 6a5e8b0e | Gerd Hoffmann | if (default_parallel)
|
5713 | 6a5e8b0e | Gerd Hoffmann | add_device_config(DEV_PARALLEL, "null");
|
5714 | e1c09175 | Gerd Hoffmann | if (default_serial && default_monitor) {
|
5715 | e1c09175 | Gerd Hoffmann | add_device_config(DEV_SERIAL, "mon:stdio");
|
5716 | 986c5f78 | Gerd Hoffmann | } else if (default_virtcon && default_monitor) { |
5717 | 986c5f78 | Gerd Hoffmann | add_device_config(DEV_VIRTCON, "mon:stdio");
|
5718 | e1c09175 | Gerd Hoffmann | } else {
|
5719 | e1c09175 | Gerd Hoffmann | if (default_serial)
|
5720 | e1c09175 | Gerd Hoffmann | add_device_config(DEV_SERIAL, "stdio");
|
5721 | 986c5f78 | Gerd Hoffmann | if (default_virtcon)
|
5722 | 986c5f78 | Gerd Hoffmann | add_device_config(DEV_VIRTCON, "stdio");
|
5723 | e1c09175 | Gerd Hoffmann | if (default_monitor)
|
5724 | 6ca5582d | Gerd Hoffmann | monitor_parse("stdio", "readline"); |
5725 | e1c09175 | Gerd Hoffmann | } |
5726 | 998bbd74 | Gerd Hoffmann | } else {
|
5727 | 998bbd74 | Gerd Hoffmann | if (default_serial)
|
5728 | 998bbd74 | Gerd Hoffmann | add_device_config(DEV_SERIAL, "vc:80Cx24C");
|
5729 | 6a5e8b0e | Gerd Hoffmann | if (default_parallel)
|
5730 | 6a5e8b0e | Gerd Hoffmann | add_device_config(DEV_PARALLEL, "vc:80Cx24C");
|
5731 | abdeed06 | Gerd Hoffmann | if (default_monitor)
|
5732 | 6ca5582d | Gerd Hoffmann | monitor_parse("vc:80Cx24C", "readline"); |
5733 | 38536da1 | Alexander Graf | if (default_virtcon)
|
5734 | 38536da1 | Alexander Graf | add_device_config(DEV_VIRTCON, "vc:80Cx24C");
|
5735 | bc0129d9 | aliguori | } |
5736 | 64465297 | Gerd Hoffmann | if (default_vga)
|
5737 | 64465297 | Gerd Hoffmann | vga_interface_type = VGA_CIRRUS; |
5738 | bc0129d9 | aliguori | |
5739 | 1a688d3b | Gerd Hoffmann | if (qemu_opts_foreach(&qemu_chardev_opts, chardev_init_func, NULL, 1) != 0) |
5740 | 1a688d3b | Gerd Hoffmann | exit(1);
|
5741 | 1a688d3b | Gerd Hoffmann | |
5742 | 71e3ceb8 | ths | #ifndef _WIN32
|
5743 | 71e3ceb8 | ths | if (daemonize) {
|
5744 | 71e3ceb8 | ths | pid_t pid; |
5745 | 71e3ceb8 | ths | |
5746 | 71e3ceb8 | ths | if (pipe(fds) == -1) |
5747 | 71e3ceb8 | ths | exit(1);
|
5748 | 71e3ceb8 | ths | |
5749 | 71e3ceb8 | ths | pid = fork(); |
5750 | 71e3ceb8 | ths | if (pid > 0) { |
5751 | 71e3ceb8 | ths | uint8_t status; |
5752 | 71e3ceb8 | ths | ssize_t len; |
5753 | 71e3ceb8 | ths | |
5754 | 71e3ceb8 | ths | close(fds[1]);
|
5755 | 71e3ceb8 | ths | |
5756 | 71e3ceb8 | ths | again:
|
5757 | 93815bc2 | ths | len = read(fds[0], &status, 1); |
5758 | 93815bc2 | ths | if (len == -1 && (errno == EINTR)) |
5759 | 93815bc2 | ths | goto again;
|
5760 | 93815bc2 | ths | |
5761 | 93815bc2 | ths | if (len != 1) |
5762 | 93815bc2 | ths | exit(1);
|
5763 | 93815bc2 | ths | else if (status == 1) { |
5764 | 850810d0 | Justin M. Forbes | fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno));
|
5765 | 93815bc2 | ths | exit(1);
|
5766 | 93815bc2 | ths | } else
|
5767 | 93815bc2 | ths | exit(0);
|
5768 | 71e3ceb8 | ths | } else if (pid < 0) |
5769 | 93815bc2 | ths | exit(1);
|
5770 | 71e3ceb8 | ths | |
5771 | 40ff6d7e | Kevin Wolf | close(fds[0]);
|
5772 | 40ff6d7e | Kevin Wolf | qemu_set_cloexec(fds[1]);
|
5773 | 40ff6d7e | Kevin Wolf | |
5774 | 71e3ceb8 | ths | setsid(); |
5775 | 71e3ceb8 | ths | |
5776 | 71e3ceb8 | ths | pid = fork(); |
5777 | 71e3ceb8 | ths | if (pid > 0) |
5778 | 71e3ceb8 | ths | exit(0);
|
5779 | 71e3ceb8 | ths | else if (pid < 0) |
5780 | 71e3ceb8 | ths | exit(1);
|
5781 | 71e3ceb8 | ths | |
5782 | 71e3ceb8 | ths | umask(027);
|
5783 | 71e3ceb8 | ths | |
5784 | 71e3ceb8 | ths | signal(SIGTSTP, SIG_IGN); |
5785 | 71e3ceb8 | ths | signal(SIGTTOU, SIG_IGN); |
5786 | 71e3ceb8 | ths | signal(SIGTTIN, SIG_IGN); |
5787 | 71e3ceb8 | ths | } |
5788 | 099fe236 | Juha Riihimรคki | #endif
|
5789 | 71e3ceb8 | ths | |
5790 | aa26bb2d | ths | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
5791 | 099fe236 | Juha Riihimรคki | #ifndef _WIN32
|
5792 | 93815bc2 | ths | if (daemonize) {
|
5793 | 93815bc2 | ths | uint8_t status = 1;
|
5794 | dc330e28 | Kirill A. Shutemov | if (write(fds[1], &status, 1) != 1) { |
5795 | dc330e28 | Kirill A. Shutemov | perror("daemonize. Writing to pipe\n");
|
5796 | dc330e28 | Kirill A. Shutemov | } |
5797 | 93815bc2 | ths | } else
|
5798 | 099fe236 | Juha Riihimรคki | #endif
|
5799 | 850810d0 | Justin M. Forbes | fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
|
5800 | 93815bc2 | ths | exit(1);
|
5801 | 93815bc2 | ths | } |
5802 | 93815bc2 | ths | |
5803 | 214910a7 | Marcelo Tosatti | if (kvm_enabled()) {
|
5804 | 214910a7 | Marcelo Tosatti | int ret;
|
5805 | 214910a7 | Marcelo Tosatti | |
5806 | 214910a7 | Marcelo Tosatti | ret = kvm_init(smp_cpus); |
5807 | 214910a7 | Marcelo Tosatti | if (ret < 0) { |
5808 | 214910a7 | Marcelo Tosatti | fprintf(stderr, "failed to initialize KVM\n");
|
5809 | 214910a7 | Marcelo Tosatti | exit(1);
|
5810 | 214910a7 | Marcelo Tosatti | } |
5811 | 214910a7 | Marcelo Tosatti | } |
5812 | 214910a7 | Marcelo Tosatti | |
5813 | 3fcf7b6b | aliguori | if (qemu_init_main_loop()) {
|
5814 | 3fcf7b6b | aliguori | fprintf(stderr, "qemu_init_main_loop failed\n");
|
5815 | 3fcf7b6b | aliguori | exit(1);
|
5816 | 3fcf7b6b | aliguori | } |
5817 | a20dd508 | bellard | linux_boot = (kernel_filename != NULL);
|
5818 | 6c41b272 | balrog | |
5819 | f8d39c01 | ths | if (!linux_boot && *kernel_cmdline != '\0') { |
5820 | f8d39c01 | ths | fprintf(stderr, "-append only allowed with -kernel option\n");
|
5821 | f8d39c01 | ths | exit(1);
|
5822 | f8d39c01 | ths | } |
5823 | f8d39c01 | ths | |
5824 | f8d39c01 | ths | if (!linux_boot && initrd_filename != NULL) { |
5825 | f8d39c01 | ths | fprintf(stderr, "-initrd only allowed with -kernel option\n");
|
5826 | f8d39c01 | ths | exit(1);
|
5827 | f8d39c01 | ths | } |
5828 | f8d39c01 | ths | |
5829 | bf65f53f | Filip Navara | #ifndef _WIN32
|
5830 | bf65f53f | Filip Navara | /* Win32 doesn't support line-buffering and requires size >= 2 */
|
5831 | b118d61e | bellard | setvbuf(stdout, NULL, _IOLBF, 0); |
5832 | bf65f53f | Filip Navara | #endif
|
5833 | 3b46e624 | ths | |
5834 | 7183b4b4 | aliguori | if (init_timer_alarm() < 0) { |
5835 | 7183b4b4 | aliguori | fprintf(stderr, "could not initialize alarm timer\n");
|
5836 | 7183b4b4 | aliguori | exit(1);
|
5837 | 7183b4b4 | aliguori | } |
5838 | 2e70f6ef | pbrook | if (use_icount && icount_time_shift < 0) { |
5839 | 2e70f6ef | pbrook | use_icount = 2;
|
5840 | 2e70f6ef | pbrook | /* 125MIPS seems a reasonable initial guess at the guest speed.
|
5841 | 2e70f6ef | pbrook | It will be corrected fairly quickly anyway. */
|
5842 | 2e70f6ef | pbrook | icount_time_shift = 3;
|
5843 | 2e70f6ef | pbrook | init_icount_adjust(); |
5844 | 2e70f6ef | pbrook | } |
5845 | 634fce96 | pbrook | |
5846 | fd1dff4b | bellard | #ifdef _WIN32
|
5847 | fd1dff4b | bellard | socket_init(); |
5848 | fd1dff4b | bellard | #endif
|
5849 | fd1dff4b | bellard | |
5850 | dc1c9fe8 | Mark McLoughlin | if (net_init_clients() < 0) { |
5851 | dc1c9fe8 | Mark McLoughlin | exit(1);
|
5852 | 702c651c | bellard | } |
5853 | f1510b2c | bellard | |
5854 | 406c8df3 | Glauber Costa | net_boot = (boot_devices_bitmap >> ('n' - 'a')) & 0xF; |
5855 | 406c8df3 | Glauber Costa | net_set_boot_mask(net_boot); |
5856 | 406c8df3 | Glauber Costa | |
5857 | dc72ac14 | balrog | /* init the bluetooth world */
|
5858 | bd3c948d | Gerd Hoffmann | if (foreach_device_config(DEV_BT, bt_parse))
|
5859 | bd3c948d | Gerd Hoffmann | exit(1);
|
5860 | dc72ac14 | balrog | |
5861 | 0824d6fc | bellard | /* init the memory */
|
5862 | 94a6b54f | pbrook | if (ram_size == 0) |
5863 | 94a6b54f | pbrook | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; |
5864 | 9ae02555 | ths | |
5865 | 26a5f13b | bellard | /* init the dynamic translator */
|
5866 | 26a5f13b | bellard | cpu_exec_init_all(tb_size * 1024 * 1024); |
5867 | 26a5f13b | bellard | |
5868 | eb852011 | Markus Armbruster | bdrv_init_with_whitelist(); |
5869 | c4b1fcc0 | bellard | |
5870 | c163b5ca | lirans@il.ibm.com | blk_mig_init(); |
5871 | c163b5ca | lirans@il.ibm.com | |
5872 | ac33f8fa | Gerd Hoffmann | if (default_cdrom) {
|
5873 | aa40fc9c | Gerd Hoffmann | /* we always create the cdrom drive, even if no disk is there */
|
5874 | aa40fc9c | Gerd Hoffmann | drive_add(NULL, CDROM_ALIAS);
|
5875 | ac33f8fa | Gerd Hoffmann | } |
5876 | c4b1fcc0 | bellard | |
5877 | ac33f8fa | Gerd Hoffmann | if (default_floppy) {
|
5878 | aa40fc9c | Gerd Hoffmann | /* we always create at least one floppy */
|
5879 | aa40fc9c | Gerd Hoffmann | drive_add(NULL, FD_ALIAS, 0); |
5880 | ac33f8fa | Gerd Hoffmann | } |
5881 | 86f55663 | j_mayer | |
5882 | ac33f8fa | Gerd Hoffmann | if (default_sdcard) {
|
5883 | aa40fc9c | Gerd Hoffmann | /* we always create one sd slot, even if no card is in it */
|
5884 | aa40fc9c | Gerd Hoffmann | drive_add(NULL, SD_ALIAS);
|
5885 | aa40fc9c | Gerd Hoffmann | } |
5886 | 9d413d1d | balrog | |
5887 | e4bcb14c | ths | /* open the virtual block devices */
|
5888 | 9dfd7c7a | Gerd Hoffmann | if (snapshot)
|
5889 | 7282a033 | Gerd Hoffmann | qemu_opts_foreach(&qemu_drive_opts, drive_enable_snapshot, NULL, 0); |
5890 | 7282a033 | Gerd Hoffmann | if (qemu_opts_foreach(&qemu_drive_opts, drive_init_func, machine, 1) != 0) |
5891 | 9dfd7c7a | Gerd Hoffmann | exit(1);
|
5892 | 3e3d5815 | balrog | |
5893 | 2faf58cd | Juan Quintela | vmstate_register(0, &vmstate_timers ,&timers_state);
|
5894 | c163b5ca | lirans@il.ibm.com | register_savevm_live("ram", 0, 3, NULL, ram_save_live, NULL, |
5895 | c163b5ca | lirans@il.ibm.com | ram_load, NULL);
|
5896 | 8a7ddc38 | bellard | |
5897 | 268a362c | aliguori | if (nb_numa_nodes > 0) { |
5898 | 268a362c | aliguori | int i;
|
5899 | 268a362c | aliguori | |
5900 | 268a362c | aliguori | if (nb_numa_nodes > smp_cpus) {
|
5901 | 268a362c | aliguori | nb_numa_nodes = smp_cpus; |
5902 | 268a362c | aliguori | } |
5903 | 268a362c | aliguori | |
5904 | 268a362c | aliguori | /* If no memory size if given for any node, assume the default case
|
5905 | 268a362c | aliguori | * and distribute the available memory equally across all nodes
|
5906 | 268a362c | aliguori | */
|
5907 | 268a362c | aliguori | for (i = 0; i < nb_numa_nodes; i++) { |
5908 | 268a362c | aliguori | if (node_mem[i] != 0) |
5909 | 268a362c | aliguori | break;
|
5910 | 268a362c | aliguori | } |
5911 | 268a362c | aliguori | if (i == nb_numa_nodes) {
|
5912 | 268a362c | aliguori | uint64_t usedmem = 0;
|
5913 | 268a362c | aliguori | |
5914 | 268a362c | aliguori | /* On Linux, the each node's border has to be 8MB aligned,
|
5915 | 268a362c | aliguori | * the final node gets the rest.
|
5916 | 268a362c | aliguori | */
|
5917 | 268a362c | aliguori | for (i = 0; i < nb_numa_nodes - 1; i++) { |
5918 | 268a362c | aliguori | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); |
5919 | 268a362c | aliguori | usedmem += node_mem[i]; |
5920 | 268a362c | aliguori | } |
5921 | 268a362c | aliguori | node_mem[i] = ram_size - usedmem; |
5922 | 268a362c | aliguori | } |
5923 | 268a362c | aliguori | |
5924 | 268a362c | aliguori | for (i = 0; i < nb_numa_nodes; i++) { |
5925 | 268a362c | aliguori | if (node_cpumask[i] != 0) |
5926 | 268a362c | aliguori | break;
|
5927 | 268a362c | aliguori | } |
5928 | 268a362c | aliguori | /* assigning the VCPUs round-robin is easier to implement, guest OSes
|
5929 | 268a362c | aliguori | * must cope with this anyway, because there are BIOSes out there in
|
5930 | 268a362c | aliguori | * real machines which also use this scheme.
|
5931 | 268a362c | aliguori | */
|
5932 | 268a362c | aliguori | if (i == nb_numa_nodes) {
|
5933 | 268a362c | aliguori | for (i = 0; i < smp_cpus; i++) { |
5934 | 268a362c | aliguori | node_cpumask[i % nb_numa_nodes] |= 1 << i;
|
5935 | 268a362c | aliguori | } |
5936 | 268a362c | aliguori | } |
5937 | 268a362c | aliguori | } |
5938 | 268a362c | aliguori | |
5939 | 998bbd74 | Gerd Hoffmann | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
5940 | 998bbd74 | Gerd Hoffmann | exit(1);
|
5941 | 6a5e8b0e | Gerd Hoffmann | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
5942 | 6a5e8b0e | Gerd Hoffmann | exit(1);
|
5943 | aee1b935 | Gerd Hoffmann | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
5944 | aee1b935 | Gerd Hoffmann | exit(1);
|
5945 | c9f398e5 | H. Peter Anvin | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
5946 | c9f398e5 | H. Peter Anvin | exit(1);
|
5947 | 2796dae0 | aliguori | |
5948 | aae9460e | Paul Brook | module_call_init(MODULE_INIT_DEVICE); |
5949 | aae9460e | Paul Brook | |
5950 | ff952ba2 | Markus Armbruster | if (qemu_opts_foreach(&qemu_device_opts, device_help_func, NULL, 0) != 0) |
5951 | ff952ba2 | Markus Armbruster | exit(0);
|
5952 | ff952ba2 | Markus Armbruster | |
5953 | 09aaa160 | Markus Armbruster | if (watchdog) {
|
5954 | 09aaa160 | Markus Armbruster | i = select_watchdog(watchdog); |
5955 | 09aaa160 | Markus Armbruster | if (i > 0) |
5956 | 09aaa160 | Markus Armbruster | exit (i == 1 ? 1 : 0); |
5957 | 09aaa160 | Markus Armbruster | } |
5958 | 09aaa160 | Markus Armbruster | |
5959 | b6b61144 | Gerd Hoffmann | if (machine->compat_props) {
|
5960 | 458fb679 | Gerd Hoffmann | qdev_prop_register_global_list(machine->compat_props); |
5961 | b6b61144 | Gerd Hoffmann | } |
5962 | d0fef6fb | Gerd Hoffmann | qemu_add_globals(); |
5963 | d0fef6fb | Gerd Hoffmann | |
5964 | fbe1b595 | Paul Brook | machine->init(ram_size, boot_devices, |
5965 | 3023f332 | aliguori | kernel_filename, kernel_cmdline, initrd_filename, cpu_model); |
5966 | 3023f332 | aliguori | |
5967 | ea375f9a | Jan Kiszka | cpu_synchronize_all_post_init(); |
5968 | 268a362c | aliguori | |
5969 | 67b3b71d | Juan Quintela | #ifndef _WIN32
|
5970 | 67b3b71d | Juan Quintela | /* must be after terminal init, SDL library changes signal handlers */
|
5971 | 67b3b71d | Juan Quintela | sighandler_setup(); |
5972 | 67b3b71d | Juan Quintela | #endif
|
5973 | 67b3b71d | Juan Quintela | |
5974 | 268a362c | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
5975 | 268a362c | aliguori | for (i = 0; i < nb_numa_nodes; i++) { |
5976 | 268a362c | aliguori | if (node_cpumask[i] & (1 << env->cpu_index)) { |
5977 | 268a362c | aliguori | env->numa_node = i; |
5978 | 268a362c | aliguori | } |
5979 | 268a362c | aliguori | } |
5980 | 268a362c | aliguori | } |
5981 | 268a362c | aliguori | |
5982 | 6f338c34 | aliguori | current_machine = machine; |
5983 | 6f338c34 | aliguori | |
5984 | 3023f332 | aliguori | /* init USB devices */
|
5985 | 3023f332 | aliguori | if (usb_enabled) {
|
5986 | 0752706d | Markus Armbruster | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
5987 | 0752706d | Markus Armbruster | exit(1);
|
5988 | 3023f332 | aliguori | } |
5989 | 3023f332 | aliguori | |
5990 | bd3c948d | Gerd Hoffmann | /* init generic devices */
|
5991 | f31d07d1 | Gerd Hoffmann | if (qemu_opts_foreach(&qemu_device_opts, device_init_func, NULL, 1) != 0) |
5992 | bd3c948d | Gerd Hoffmann | exit(1);
|
5993 | bd3c948d | Gerd Hoffmann | |
5994 | 668680f7 | Markus Armbruster | net_check_clients(); |
5995 | 668680f7 | Markus Armbruster | |
5996 | 3023f332 | aliguori | /* just use the first displaystate for the moment */
|
5997 | b473df6e | Paolo Bonzini | ds = get_displaystate(); |
5998 | 993fbfdb | Anthony Liguori | |
5999 | 993fbfdb | Anthony Liguori | if (display_type == DT_DEFAULT) {
|
6000 | 993fbfdb | Anthony Liguori | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
|
6001 | 993fbfdb | Anthony Liguori | display_type = DT_SDL; |
6002 | 993fbfdb | Anthony Liguori | #else
|
6003 | 993fbfdb | Anthony Liguori | display_type = DT_VNC; |
6004 | 993fbfdb | Anthony Liguori | vnc_display = "localhost:0,to=99";
|
6005 | 993fbfdb | Anthony Liguori | show_vnc_port = 1;
|
6006 | 993fbfdb | Anthony Liguori | #endif
|
6007 | 993fbfdb | Anthony Liguori | } |
6008 | 993fbfdb | Anthony Liguori | |
6009 | 993fbfdb | Anthony Liguori | |
6010 | 993fbfdb | Anthony Liguori | switch (display_type) {
|
6011 | 993fbfdb | Anthony Liguori | case DT_NOGRAPHIC:
|
6012 | 993fbfdb | Anthony Liguori | break;
|
6013 | 4d3b6f6e | balrog | #if defined(CONFIG_CURSES)
|
6014 | 993fbfdb | Anthony Liguori | case DT_CURSES:
|
6015 | 993fbfdb | Anthony Liguori | curses_display_init(ds, full_screen); |
6016 | 993fbfdb | Anthony Liguori | break;
|
6017 | 4d3b6f6e | balrog | #endif
|
6018 | 5b0753e0 | bellard | #if defined(CONFIG_SDL)
|
6019 | 993fbfdb | Anthony Liguori | case DT_SDL:
|
6020 | 993fbfdb | Anthony Liguori | sdl_display_init(ds, full_screen, no_frame); |
6021 | 993fbfdb | Anthony Liguori | break;
|
6022 | 5b0753e0 | bellard | #elif defined(CONFIG_COCOA)
|
6023 | 993fbfdb | Anthony Liguori | case DT_SDL:
|
6024 | 993fbfdb | Anthony Liguori | cocoa_display_init(ds, full_screen); |
6025 | 993fbfdb | Anthony Liguori | break;
|
6026 | 313aa567 | bellard | #endif
|
6027 | 993fbfdb | Anthony Liguori | case DT_VNC:
|
6028 | 993fbfdb | Anthony Liguori | vnc_display_init(ds); |
6029 | 993fbfdb | Anthony Liguori | if (vnc_display_open(ds, vnc_display) < 0) |
6030 | 993fbfdb | Anthony Liguori | exit(1);
|
6031 | f92f8afe | Anthony Liguori | |
6032 | 993fbfdb | Anthony Liguori | if (show_vnc_port) {
|
6033 | 993fbfdb | Anthony Liguori | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
|
6034 | f92f8afe | Anthony Liguori | } |
6035 | 993fbfdb | Anthony Liguori | break;
|
6036 | 993fbfdb | Anthony Liguori | default:
|
6037 | 993fbfdb | Anthony Liguori | break;
|
6038 | 313aa567 | bellard | } |
6039 | 7d957bd8 | aliguori | dpy_resize(ds); |
6040 | 5b08fc10 | aliguori | |
6041 | 3023f332 | aliguori | dcl = ds->listeners; |
6042 | 3023f332 | aliguori | while (dcl != NULL) { |
6043 | 3023f332 | aliguori | if (dcl->dpy_refresh != NULL) { |
6044 | 3023f332 | aliguori | ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds); |
6045 | 3023f332 | aliguori | qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock)); |
6046 | 20d8a3ed | ths | } |
6047 | 3023f332 | aliguori | dcl = dcl->next; |
6048 | 20d8a3ed | ths | } |
6049 | 3023f332 | aliguori | |
6050 | 993fbfdb | Anthony Liguori | if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
|
6051 | 9043b62d | blueswir1 | nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
|
6052 | 9043b62d | blueswir1 | qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock)); |
6053 | 9043b62d | blueswir1 | } |
6054 | 9043b62d | blueswir1 | |
6055 | b473df6e | Paolo Bonzini | text_consoles_set_display(ds); |
6056 | 2796dae0 | aliguori | |
6057 | 88589343 | Gerd Hoffmann | if (qemu_opts_foreach(&qemu_mon_opts, mon_init_func, NULL, 1) != 0) |
6058 | 88589343 | Gerd Hoffmann | exit(1);
|
6059 | 82c643ff | bellard | |
6060 | 59030a8c | aliguori | if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) { |
6061 | 59030a8c | aliguori | fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
|
6062 | 59030a8c | aliguori | gdbstub_dev); |
6063 | 59030a8c | aliguori | exit(1);
|
6064 | 45669e00 | balrog | } |
6065 | 45669e00 | balrog | |
6066 | 3418bd25 | Gerd Hoffmann | qdev_machine_creation_done(); |
6067 | 3418bd25 | Gerd Hoffmann | |
6068 | 15ff7705 | Gerd Hoffmann | if (rom_load_all() != 0) { |
6069 | 15ff7705 | Gerd Hoffmann | fprintf(stderr, "rom loading failed\n");
|
6070 | 15ff7705 | Gerd Hoffmann | exit(1);
|
6071 | 15ff7705 | Gerd Hoffmann | } |
6072 | 45a50b16 | Gerd Hoffmann | |
6073 | 504c2948 | Juan Quintela | qemu_system_reset(); |
6074 | 05f2401e | Juan Quintela | if (loadvm) {
|
6075 | 05f2401e | Juan Quintela | if (load_vmstate(cur_mon, loadvm) < 0) { |
6076 | 05f2401e | Juan Quintela | autostart = 0;
|
6077 | 05f2401e | Juan Quintela | } |
6078 | 05f2401e | Juan Quintela | } |
6079 | d63d307f | bellard | |
6080 | 2bb8c10c | Glauber Costa | if (incoming) {
|
6081 | 5bb7910a | aliguori | qemu_start_incoming_migration(incoming); |
6082 | 6b99dadc | Avi Kivity | } else if (autostart) { |
6083 | c0f4ce77 | aliguori | vm_start(); |
6084 | 6b99dadc | Avi Kivity | } |
6085 | ffd843bc | ths | |
6086 | b9e82a59 | blueswir1 | #ifndef _WIN32
|
6087 | 71e3ceb8 | ths | if (daemonize) {
|
6088 | 71e3ceb8 | ths | uint8_t status = 0;
|
6089 | 71e3ceb8 | ths | ssize_t len; |
6090 | 71e3ceb8 | ths | |
6091 | 71e3ceb8 | ths | again1:
|
6092 | 71e3ceb8 | ths | len = write(fds[1], &status, 1); |
6093 | 71e3ceb8 | ths | if (len == -1 && (errno == EINTR)) |
6094 | 71e3ceb8 | ths | goto again1;
|
6095 | 71e3ceb8 | ths | |
6096 | 71e3ceb8 | ths | if (len != 1) |
6097 | 71e3ceb8 | ths | exit(1);
|
6098 | 71e3ceb8 | ths | |
6099 | dc330e28 | Kirill A. Shutemov | if (chdir("/")) { |
6100 | dc330e28 | Kirill A. Shutemov | perror("not able to chdir to /");
|
6101 | dc330e28 | Kirill A. Shutemov | exit(1);
|
6102 | dc330e28 | Kirill A. Shutemov | } |
6103 | 40ff6d7e | Kevin Wolf | TFR(fd = qemu_open("/dev/null", O_RDWR));
|
6104 | 71e3ceb8 | ths | if (fd == -1) |
6105 | 71e3ceb8 | ths | exit(1);
|
6106 | 0858532e | aliguori | } |
6107 | 71e3ceb8 | ths | |
6108 | 0858532e | aliguori | if (run_as) {
|
6109 | 0858532e | aliguori | pwd = getpwnam(run_as); |
6110 | 0858532e | aliguori | if (!pwd) {
|
6111 | 0858532e | aliguori | fprintf(stderr, "User \"%s\" doesn't exist\n", run_as);
|
6112 | 0858532e | aliguori | exit(1);
|
6113 | 0858532e | aliguori | } |
6114 | 0858532e | aliguori | } |
6115 | 0858532e | aliguori | |
6116 | 0858532e | aliguori | if (chroot_dir) {
|
6117 | 0858532e | aliguori | if (chroot(chroot_dir) < 0) { |
6118 | 0858532e | aliguori | fprintf(stderr, "chroot failed\n");
|
6119 | 0858532e | aliguori | exit(1);
|
6120 | 0858532e | aliguori | } |
6121 | dc330e28 | Kirill A. Shutemov | if (chdir("/")) { |
6122 | dc330e28 | Kirill A. Shutemov | perror("not able to chdir to /");
|
6123 | dc330e28 | Kirill A. Shutemov | exit(1);
|
6124 | dc330e28 | Kirill A. Shutemov | } |
6125 | 0858532e | aliguori | } |
6126 | 0858532e | aliguori | |
6127 | 0858532e | aliguori | if (run_as) {
|
6128 | 0858532e | aliguori | if (setgid(pwd->pw_gid) < 0) { |
6129 | 0858532e | aliguori | fprintf(stderr, "Failed to setgid(%d)\n", pwd->pw_gid);
|
6130 | 0858532e | aliguori | exit(1);
|
6131 | 0858532e | aliguori | } |
6132 | 0858532e | aliguori | if (setuid(pwd->pw_uid) < 0) { |
6133 | 0858532e | aliguori | fprintf(stderr, "Failed to setuid(%d)\n", pwd->pw_uid);
|
6134 | 0858532e | aliguori | exit(1);
|
6135 | 0858532e | aliguori | } |
6136 | 0858532e | aliguori | if (setuid(0) != -1) { |
6137 | 0858532e | aliguori | fprintf(stderr, "Dropping privileges failed\n");
|
6138 | 0858532e | aliguori | exit(1);
|
6139 | 0858532e | aliguori | } |
6140 | 0858532e | aliguori | } |
6141 | 0858532e | aliguori | |
6142 | 0858532e | aliguori | if (daemonize) {
|
6143 | 0858532e | aliguori | dup2(fd, 0);
|
6144 | 0858532e | aliguori | dup2(fd, 1);
|
6145 | 0858532e | aliguori | dup2(fd, 2);
|
6146 | 71e3ceb8 | ths | |
6147 | 0858532e | aliguori | close(fd); |
6148 | 71e3ceb8 | ths | } |
6149 | b9e82a59 | blueswir1 | #endif
|
6150 | 71e3ceb8 | ths | |
6151 | 8a7ddc38 | bellard | main_loop(); |
6152 | 40c3bac3 | bellard | quit_timers(); |
6153 | 63a01ef8 | aliguori | net_cleanup(); |
6154 | b46a8906 | ths | |
6155 | 0824d6fc | bellard | return 0; |
6156 | 0824d6fc | bellard | } |