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