]>
Commit | Line | Data |
---|---|---|
0824d6fc | 1 | /* |
80cabfad | 2 | * QEMU System Emulator |
5fafdf24 | 3 | * |
68d0f70e | 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
5fafdf24 | 5 | * |
1df912cf FB |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
0824d6fc | 23 | */ |
0824d6fc | 24 | #include <unistd.h> |
0824d6fc FB |
25 | #include <fcntl.h> |
26 | #include <signal.h> | |
27 | #include <time.h> | |
0824d6fc | 28 | #include <errno.h> |
67b915a5 | 29 | #include <sys/time.h> |
c88676f8 | 30 | #include <zlib.h> |
ee785fed | 31 | #include "bitmap.h" |
67b915a5 | 32 | |
71e72a19 | 33 | /* Needed early for CONFIG_BSD etc. */ |
d40cdb10 BS |
34 | #include "config-host.h" |
35 | ||
67b915a5 | 36 | #ifndef _WIN32 |
5cea8590 | 37 | #include <libgen.h> |
67b915a5 | 38 | #include <sys/times.h> |
f1510b2c | 39 | #include <sys/wait.h> |
67b915a5 | 40 | #include <termios.h> |
67b915a5 | 41 | #include <sys/mman.h> |
f1510b2c | 42 | #include <sys/ioctl.h> |
24646c7e | 43 | #include <sys/resource.h> |
f1510b2c | 44 | #include <sys/socket.h> |
c94c8d64 | 45 | #include <netinet/in.h> |
24646c7e | 46 | #include <net/if.h> |
24646c7e | 47 | #include <arpa/inet.h> |
9d728e8c | 48 | #include <dirent.h> |
7c9d8e07 | 49 | #include <netdb.h> |
cb4b976b | 50 | #include <sys/select.h> |
ab6540d5 | 51 | |
71e72a19 | 52 | #ifdef CONFIG_BSD |
7d3505c5 | 53 | #include <sys/stat.h> |
a167ba50 | 54 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
92c0e657 | 55 | #include <sys/sysctl.h> |
24646c7e BS |
56 | #else |
57 | #include <util.h> | |
128ab2ff | 58 | #endif |
bbe813a2 | 59 | #else |
223f0d72 | 60 | #ifdef __linux__ |
7d3505c5 | 61 | #include <malloc.h> |
bd494f4c | 62 | |
e57a8c0e | 63 | #include <linux/ppdev.h> |
5867c88a | 64 | #include <linux/parport.h> |
223f0d72 | 65 | #endif |
452dfbef EO |
66 | |
67 | #ifdef CONFIG_SECCOMP | |
68 | #include "qemu-seccomp.h" | |
69 | #endif | |
70 | ||
223f0d72 | 71 | #ifdef __sun__ |
d5d10bc3 TS |
72 | #include <sys/stat.h> |
73 | #include <sys/ethernet.h> | |
74 | #include <sys/sockio.h> | |
d5d10bc3 | 75 | #include <netinet/arp.h> |
d5d10bc3 TS |
76 | #include <netinet/in_systm.h> |
77 | #include <netinet/ip.h> | |
78 | #include <netinet/ip_icmp.h> // must come after ip.h | |
79 | #include <netinet/udp.h> | |
80 | #include <netinet/tcp.h> | |
81 | #include <net/if.h> | |
82 | #include <syslog.h> | |
83 | #include <stropts.h> | |
67b915a5 | 84 | #endif |
7d3505c5 | 85 | #endif |
ec530c81 | 86 | #endif |
67b915a5 | 87 | |
8a16d273 TS |
88 | #if defined(CONFIG_VDE) |
89 | #include <libvdeplug.h> | |
90 | #endif | |
91 | ||
67b915a5 | 92 | #ifdef _WIN32 |
49dc768d | 93 | #include <windows.h> |
67b915a5 FB |
94 | #endif |
95 | ||
73332e5c | 96 | #ifdef CONFIG_SDL |
59a36a2f | 97 | #if defined(__APPLE__) || defined(main) |
6693665a | 98 | #include <SDL.h> |
880fec5d | 99 | int qemu_main(int argc, char **argv, char **envp); |
100 | int main(int argc, char **argv) | |
101 | { | |
59a36a2f | 102 | return qemu_main(argc, argv, NULL); |
880fec5d | 103 | } |
104 | #undef main | |
105 | #define main qemu_main | |
96bcd4f8 | 106 | #endif |
73332e5c | 107 | #endif /* CONFIG_SDL */ |
0824d6fc | 108 | |
5b0753e0 FB |
109 | #ifdef CONFIG_COCOA |
110 | #undef main | |
111 | #define main qemu_main | |
112 | #endif /* CONFIG_COCOA */ | |
113 | ||
69e5bb68 AL |
114 | #include <glib.h> |
115 | ||
511d2b14 BS |
116 | #include "hw/hw.h" |
117 | #include "hw/boards.h" | |
118 | #include "hw/usb.h" | |
119 | #include "hw/pcmcia.h" | |
120 | #include "hw/pc.h" | |
511d2b14 BS |
121 | #include "hw/isa.h" |
122 | #include "hw/baum.h" | |
123 | #include "hw/bt.h" | |
9dd986cc | 124 | #include "hw/watchdog.h" |
b6f6e3d3 | 125 | #include "hw/smbios.h" |
e37630ca | 126 | #include "hw/xen.h" |
bd3c948d | 127 | #include "hw/qdev.h" |
45a50b16 | 128 | #include "hw/loader.h" |
5ef4efa4 | 129 | #include "bt-host.h" |
511d2b14 | 130 | #include "net.h" |
68ac40d2 | 131 | #include "net/slirp.h" |
511d2b14 BS |
132 | #include "monitor.h" |
133 | #include "console.h" | |
134 | #include "sysemu.h" | |
135 | #include "gdbstub.h" | |
136 | #include "qemu-timer.h" | |
137 | #include "qemu-char.h" | |
138 | #include "cache-utils.h" | |
666daa68 | 139 | #include "blockdev.h" |
2b584959 | 140 | #include "hw/block-common.h" |
c163b5ca | 141 | #include "block-migration.h" |
a718acec | 142 | #include "dma.h" |
511d2b14 BS |
143 | #include "audio/audio.h" |
144 | #include "migration.h" | |
145 | #include "kvm.h" | |
f795e743 | 146 | #include "qjson.h" |
d3f24367 | 147 | #include "qemu-option.h" |
7282a033 | 148 | #include "qemu-config.h" |
59a5264b | 149 | #include "qemu-options.h" |
1fa9a5e4 | 150 | #include "qmp-commands.h" |
44a9b356 | 151 | #include "main-loop.h" |
758e8e38 | 152 | #ifdef CONFIG_VIRTFS |
74db920c GS |
153 | #include "fsdev/qemu-fsdev.h" |
154 | #endif | |
c7f0f3b1 | 155 | #include "qtest.h" |
511d2b14 | 156 | |
0824d6fc | 157 | #include "disas.h" |
fc01f7e7 | 158 | |
511d2b14 BS |
159 | #include "qemu_socket.h" |
160 | ||
d918f23e | 161 | #include "slirp/libslirp.h" |
511d2b14 | 162 | |
94b0b5ff | 163 | #include "trace.h" |
e4858974 | 164 | #include "trace/control.h" |
72cf2d4f | 165 | #include "qemu-queue.h" |
296af7c9 | 166 | #include "cpus.h" |
ad96090a | 167 | #include "arch_init.h" |
0f66998f | 168 | #include "osdep.h" |
72cf2d4f | 169 | |
29b0040b GH |
170 | #include "ui/qemu-spice.h" |
171 | ||
9dc63a1e BS |
172 | //#define DEBUG_NET |
173 | //#define DEBUG_SLIRP | |
330d0414 | 174 | |
1bfe856e | 175 | #define DEFAULT_RAM_SIZE 128 |
313aa567 | 176 | |
98b19252 AS |
177 | #define MAX_VIRTIO_CONSOLES 1 |
178 | ||
5cea8590 | 179 | static const char *data_dir; |
1192dad8 | 180 | const char *bios_name = NULL; |
cb5a7aa8 | 181 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
993fbfdb | 182 | DisplayType display_type = DT_DEFAULT; |
6b62dc2d | 183 | int display_remote = 0; |
3d11d0eb | 184 | const char* keyboard_layout = NULL; |
c227f099 | 185 | ram_addr_t ram_size; |
c902760f MT |
186 | const char *mem_path = NULL; |
187 | #ifdef MAP_POPULATE | |
188 | int mem_prealloc = 0; /* force preallocation of physical target memory */ | |
189 | #endif | |
c4b1fcc0 | 190 | int nb_nics; |
7c9d8e07 | 191 | NICInfo nd_table[MAX_NICS]; |
d399f677 | 192 | int autostart; |
f6503059 AZ |
193 | static int rtc_utc = 1; |
194 | static int rtc_date_offset = -1; /* -1 means no change */ | |
6875204c | 195 | QEMUClock *rtc_clock; |
64465297 | 196 | int vga_interface_type = VGA_NONE; |
dbed7e40 | 197 | static int full_screen = 0; |
634a21f6 | 198 | #ifdef CONFIG_SDL |
dbed7e40 | 199 | static int no_frame = 0; |
634a21f6 | 200 | #endif |
667accab | 201 | int no_quit = 0; |
8d11df9e | 202 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
6508fe59 | 203 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
9ede2fde | 204 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
a09db21f | 205 | int win2k_install_hack = 0; |
bb36d470 | 206 | int usb_enabled = 0; |
1b530a6d | 207 | int singlestep = 0; |
6a00d601 | 208 | int smp_cpus = 1; |
6be68d7e | 209 | int max_cpus = 0; |
dc6b1c09 AP |
210 | int smp_cores = 1; |
211 | int smp_threads = 1; | |
821601ea | 212 | #ifdef CONFIG_VNC |
73fc9742 | 213 | const char *vnc_display; |
821601ea | 214 | #endif |
6515b203 | 215 | int acpi_enabled = 1; |
16b29ae1 | 216 | int no_hpet = 0; |
52ca8d6a | 217 | int fd_bootchk = 1; |
d1beab82 | 218 | int no_reboot = 0; |
b2f76161 | 219 | int no_shutdown = 0; |
9467cd46 | 220 | int cursor_hide = 1; |
a171fe39 | 221 | int graphic_rotate = 0; |
09aaa160 | 222 | const char *watchdog; |
2e55e842 | 223 | QEMUOptionRom option_rom[MAX_OPTION_ROMS]; |
9ae02555 | 224 | int nb_option_roms; |
8e71621f | 225 | int semihosting_enabled = 0; |
2b8f2d41 | 226 | int old_param = 0; |
c35734b2 | 227 | const char *qemu_name; |
3780e197 | 228 | int alt_grab = 0; |
0ca9f8a4 | 229 | int ctrl_grab = 0; |
66508601 BS |
230 | unsigned int nb_prom_envs = 0; |
231 | const char *prom_envs[MAX_PROM_ENVS]; | |
95387491 | 232 | int boot_menu; |
3d3b8303 | 233 | uint8_t *boot_splash_filedata; |
234 | int boot_splash_filedata_size; | |
235 | uint8_t qemu_extra_params_fw[2]; | |
0824d6fc | 236 | |
1ca4d09a GN |
237 | typedef struct FWBootEntry FWBootEntry; |
238 | ||
239 | struct FWBootEntry { | |
240 | QTAILQ_ENTRY(FWBootEntry) link; | |
241 | int32_t bootindex; | |
242 | DeviceState *dev; | |
243 | char *suffix; | |
244 | }; | |
245 | ||
246 | QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order); | |
247 | ||
268a362c AL |
248 | int nb_numa_nodes; |
249 | uint64_t node_mem[MAX_NODES]; | |
ee785fed | 250 | unsigned long *node_cpumask[MAX_NODES]; |
268a362c | 251 | |
8fcb1b90 BS |
252 | uint8_t qemu_uuid[16]; |
253 | ||
76e30d0f JK |
254 | static QEMUBootSetHandler *boot_set_handler; |
255 | static void *boot_set_opaque; | |
256 | ||
fd42deeb GH |
257 | static NotifierList exit_notifiers = |
258 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); | |
259 | ||
4cab946a GN |
260 | static NotifierList machine_init_done_notifiers = |
261 | NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); | |
262 | ||
303d4e86 | 263 | static int tcg_allowed = 1; |
d745bef8 | 264 | int kvm_allowed = 0; |
3285cf4f | 265 | int xen_allowed = 0; |
d745bef8 BS |
266 | uint32_t xen_domid; |
267 | enum xen_mode xen_mode = XEN_EMULATE; | |
d5ab9713 | 268 | static int tcg_tb_size; |
d745bef8 | 269 | |
998bbd74 | 270 | static int default_serial = 1; |
6a5e8b0e | 271 | static int default_parallel = 1; |
986c5f78 | 272 | static int default_virtcon = 1; |
abdeed06 | 273 | static int default_monitor = 1; |
ac33f8fa GH |
274 | static int default_floppy = 1; |
275 | static int default_cdrom = 1; | |
276 | static int default_sdcard = 1; | |
7f1b17f2 | 277 | static int default_vga = 1; |
998bbd74 GH |
278 | |
279 | static struct { | |
280 | const char *driver; | |
281 | int *flag; | |
282 | } default_list[] = { | |
6a5e8b0e GH |
283 | { .driver = "isa-serial", .flag = &default_serial }, |
284 | { .driver = "isa-parallel", .flag = &default_parallel }, | |
d8bcbabf | 285 | { .driver = "isa-fdc", .flag = &default_floppy }, |
af6bf132 MA |
286 | { .driver = "ide-cd", .flag = &default_cdrom }, |
287 | { .driver = "ide-hd", .flag = &default_cdrom }, | |
d8bcbabf | 288 | { .driver = "ide-drive", .flag = &default_cdrom }, |
af6bf132 | 289 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
392ecf54 AS |
290 | { .driver = "virtio-serial-pci", .flag = &default_virtcon }, |
291 | { .driver = "virtio-serial-s390", .flag = &default_virtcon }, | |
292 | { .driver = "virtio-serial", .flag = &default_virtcon }, | |
7f1b17f2 PB |
293 | { .driver = "VGA", .flag = &default_vga }, |
294 | { .driver = "isa-vga", .flag = &default_vga }, | |
295 | { .driver = "cirrus-vga", .flag = &default_vga }, | |
296 | { .driver = "isa-cirrus-vga", .flag = &default_vga }, | |
297 | { .driver = "vmware-svga", .flag = &default_vga }, | |
298 | { .driver = "qxl-vga", .flag = &default_vga }, | |
998bbd74 GH |
299 | }; |
300 | ||
31459f46 RS |
301 | const char *qemu_get_vm_name(void) |
302 | { | |
303 | return qemu_name; | |
304 | } | |
305 | ||
3d3b8303 | 306 | static void res_free(void) |
307 | { | |
308 | if (boot_splash_filedata != NULL) { | |
7267c094 | 309 | g_free(boot_splash_filedata); |
3d3b8303 | 310 | boot_splash_filedata = NULL; |
311 | } | |
312 | } | |
313 | ||
998bbd74 GH |
314 | static int default_driver_check(QemuOpts *opts, void *opaque) |
315 | { | |
316 | const char *driver = qemu_opt_get(opts, "driver"); | |
317 | int i; | |
318 | ||
319 | if (!driver) | |
320 | return 0; | |
321 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { | |
322 | if (strcmp(default_list[i].driver, driver) != 0) | |
323 | continue; | |
324 | *(default_list[i].flag) = 0; | |
325 | } | |
326 | return 0; | |
327 | } | |
328 | ||
f5bbfba1 LC |
329 | /***********************************************************/ |
330 | /* QEMU state */ | |
331 | ||
0461d5a6 | 332 | static RunState current_run_state = RUN_STATE_PRELAUNCH; |
f5bbfba1 | 333 | |
5db9d4d1 LC |
334 | typedef struct { |
335 | RunState from; | |
336 | RunState to; | |
337 | } RunStateTransition; | |
338 | ||
339 | static const RunStateTransition runstate_transitions_def[] = { | |
340 | /* from -> to */ | |
0461d5a6 | 341 | { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, |
5db9d4d1 | 342 | |
0461d5a6 LC |
343 | { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING }, |
344 | { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH }, | |
5db9d4d1 | 345 | |
0461d5a6 | 346 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, |
8a9236f1 | 347 | { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 348 | |
0461d5a6 | 349 | { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING }, |
8a9236f1 | 350 | { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 351 | |
0461d5a6 | 352 | { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, |
8a9236f1 | 353 | { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 354 | |
0461d5a6 | 355 | { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, |
8a9236f1 | 356 | { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 357 | |
0461d5a6 | 358 | { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING }, |
8a9236f1 | 359 | { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE }, |
0461d5a6 | 360 | { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, |
5db9d4d1 | 361 | |
0461d5a6 LC |
362 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING }, |
363 | { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE }, | |
5db9d4d1 | 364 | |
0461d5a6 | 365 | { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, |
5db9d4d1 | 366 | |
0461d5a6 LC |
367 | { RUN_STATE_RUNNING, RUN_STATE_DEBUG }, |
368 | { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR }, | |
369 | { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR }, | |
370 | { RUN_STATE_RUNNING, RUN_STATE_PAUSED }, | |
371 | { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE }, | |
372 | { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM }, | |
373 | { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM }, | |
374 | { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN }, | |
375 | { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, | |
5db9d4d1 | 376 | |
0461d5a6 | 377 | { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, |
5db9d4d1 | 378 | |
0461d5a6 | 379 | { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED }, |
8a9236f1 | 380 | { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 381 | |
ad02b96a LC |
382 | { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED }, |
383 | { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED }, | |
384 | { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING }, | |
385 | { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE }, | |
386 | ||
0461d5a6 | 387 | { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, |
8a9236f1 | 388 | { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE }, |
5db9d4d1 | 389 | |
0461d5a6 | 390 | { RUN_STATE_MAX, RUN_STATE_MAX }, |
5db9d4d1 LC |
391 | }; |
392 | ||
0461d5a6 LC |
393 | static bool runstate_valid_transitions[RUN_STATE_MAX][RUN_STATE_MAX]; |
394 | ||
f5bbfba1 LC |
395 | bool runstate_check(RunState state) |
396 | { | |
397 | return current_run_state == state; | |
398 | } | |
399 | ||
5db9d4d1 LC |
400 | void runstate_init(void) |
401 | { | |
402 | const RunStateTransition *p; | |
403 | ||
404 | memset(&runstate_valid_transitions, 0, sizeof(runstate_valid_transitions)); | |
405 | ||
0461d5a6 | 406 | for (p = &runstate_transitions_def[0]; p->from != RUN_STATE_MAX; p++) { |
5db9d4d1 LC |
407 | runstate_valid_transitions[p->from][p->to] = true; |
408 | } | |
409 | } | |
410 | ||
411 | /* This function will abort() on invalid state transitions */ | |
f5bbfba1 LC |
412 | void runstate_set(RunState new_state) |
413 | { | |
207c5cd2 LC |
414 | assert(new_state < RUN_STATE_MAX); |
415 | ||
416 | if (!runstate_valid_transitions[current_run_state][new_state]) { | |
417 | fprintf(stderr, "ERROR: invalid runstate transition: '%s' -> '%s'\n", | |
418 | RunState_lookup[current_run_state], | |
419 | RunState_lookup[new_state]); | |
5db9d4d1 LC |
420 | abort(); |
421 | } | |
422 | ||
f5bbfba1 LC |
423 | current_run_state = new_state; |
424 | } | |
425 | ||
1fa9a5e4 | 426 | int runstate_is_running(void) |
9e37b9dc | 427 | { |
1fa9a5e4 | 428 | return runstate_check(RUN_STATE_RUNNING); |
9e37b9dc LC |
429 | } |
430 | ||
1fa9a5e4 | 431 | StatusInfo *qmp_query_status(Error **errp) |
1354869c | 432 | { |
1fa9a5e4 LC |
433 | StatusInfo *info = g_malloc0(sizeof(*info)); |
434 | ||
435 | info->running = runstate_is_running(); | |
436 | info->singlestep = singlestep; | |
437 | info->status = current_run_state; | |
438 | ||
439 | return info; | |
1354869c LC |
440 | } |
441 | ||
8f0056b7 PB |
442 | /***********************************************************/ |
443 | /* real time host monotonic timer */ | |
09b26c5e | 444 | |
f6503059 AZ |
445 | /***********************************************************/ |
446 | /* host time/date access */ | |
447 | void qemu_get_timedate(struct tm *tm, int offset) | |
448 | { | |
449 | time_t ti; | |
450 | struct tm *ret; | |
451 | ||
452 | time(&ti); | |
453 | ti += offset; | |
454 | if (rtc_date_offset == -1) { | |
455 | if (rtc_utc) | |
456 | ret = gmtime(&ti); | |
457 | else | |
458 | ret = localtime(&ti); | |
459 | } else { | |
460 | ti -= rtc_date_offset; | |
461 | ret = gmtime(&ti); | |
462 | } | |
463 | ||
464 | memcpy(tm, ret, sizeof(struct tm)); | |
465 | } | |
466 | ||
467 | int qemu_timedate_diff(struct tm *tm) | |
468 | { | |
469 | time_t seconds; | |
470 | ||
471 | if (rtc_date_offset == -1) | |
472 | if (rtc_utc) | |
473 | seconds = mktimegm(tm); | |
f54c556c GN |
474 | else { |
475 | struct tm tmp = *tm; | |
476 | tmp.tm_isdst = -1; /* use timezone to figure it out */ | |
477 | seconds = mktime(&tmp); | |
478 | } | |
f6503059 AZ |
479 | else |
480 | seconds = mktimegm(tm) + rtc_date_offset; | |
481 | ||
482 | return seconds - time(NULL); | |
483 | } | |
484 | ||
80cd3478 LC |
485 | void rtc_change_mon_event(struct tm *tm) |
486 | { | |
487 | QObject *data; | |
488 | ||
489 | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); | |
490 | monitor_protocol_event(QEVENT_RTC_CHANGE, data); | |
491 | qobject_decref(data); | |
492 | } | |
493 | ||
1ed2fc1f JK |
494 | static void configure_rtc_date_offset(const char *startdate, int legacy) |
495 | { | |
496 | time_t rtc_start_date; | |
497 | struct tm tm; | |
498 | ||
499 | if (!strcmp(startdate, "now") && legacy) { | |
500 | rtc_date_offset = -1; | |
501 | } else { | |
502 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", | |
503 | &tm.tm_year, | |
504 | &tm.tm_mon, | |
505 | &tm.tm_mday, | |
506 | &tm.tm_hour, | |
507 | &tm.tm_min, | |
508 | &tm.tm_sec) == 6) { | |
509 | /* OK */ | |
510 | } else if (sscanf(startdate, "%d-%d-%d", | |
511 | &tm.tm_year, | |
512 | &tm.tm_mon, | |
513 | &tm.tm_mday) == 3) { | |
514 | tm.tm_hour = 0; | |
515 | tm.tm_min = 0; | |
516 | tm.tm_sec = 0; | |
517 | } else { | |
518 | goto date_fail; | |
519 | } | |
520 | tm.tm_year -= 1900; | |
521 | tm.tm_mon--; | |
522 | rtc_start_date = mktimegm(&tm); | |
523 | if (rtc_start_date == -1) { | |
524 | date_fail: | |
525 | fprintf(stderr, "Invalid date format. Valid formats are:\n" | |
526 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); | |
527 | exit(1); | |
528 | } | |
529 | rtc_date_offset = time(NULL) - rtc_start_date; | |
530 | } | |
531 | } | |
532 | ||
533 | static void configure_rtc(QemuOpts *opts) | |
534 | { | |
535 | const char *value; | |
536 | ||
537 | value = qemu_opt_get(opts, "base"); | |
538 | if (value) { | |
539 | if (!strcmp(value, "utc")) { | |
540 | rtc_utc = 1; | |
541 | } else if (!strcmp(value, "localtime")) { | |
542 | rtc_utc = 0; | |
543 | } else { | |
544 | configure_rtc_date_offset(value, 0); | |
545 | } | |
546 | } | |
6875204c JK |
547 | value = qemu_opt_get(opts, "clock"); |
548 | if (value) { | |
549 | if (!strcmp(value, "host")) { | |
550 | rtc_clock = host_clock; | |
78808141 PB |
551 | } else if (!strcmp(value, "rt")) { |
552 | rtc_clock = rt_clock; | |
6875204c JK |
553 | } else if (!strcmp(value, "vm")) { |
554 | rtc_clock = vm_clock; | |
555 | } else { | |
556 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); | |
557 | exit(1); | |
558 | } | |
559 | } | |
1ed2fc1f JK |
560 | value = qemu_opt_get(opts, "driftfix"); |
561 | if (value) { | |
7e4c0336 | 562 | if (!strcmp(value, "slew")) { |
433acf0d JK |
563 | static GlobalProperty slew_lost_ticks[] = { |
564 | { | |
565 | .driver = "mc146818rtc", | |
566 | .property = "lost_tick_policy", | |
567 | .value = "slew", | |
568 | }, | |
569 | { /* end of list */ } | |
570 | }; | |
571 | ||
572 | qdev_prop_register_global_list(slew_lost_ticks); | |
7e4c0336 | 573 | } else if (!strcmp(value, "none")) { |
433acf0d | 574 | /* discard is default */ |
1ed2fc1f JK |
575 | } else { |
576 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); | |
577 | exit(1); | |
578 | } | |
579 | } | |
1ed2fc1f JK |
580 | } |
581 | ||
1ae26a18 AZ |
582 | /***********************************************************/ |
583 | /* Bluetooth support */ | |
584 | static int nb_hcis; | |
585 | static int cur_hci; | |
586 | static struct HCIInfo *hci_table[MAX_NICS]; | |
dc72ac14 | 587 | |
1ae26a18 AZ |
588 | static struct bt_vlan_s { |
589 | struct bt_scatternet_s net; | |
590 | int id; | |
591 | struct bt_vlan_s *next; | |
592 | } *first_bt_vlan; | |
593 | ||
594 | /* find or alloc a new bluetooth "VLAN" */ | |
674bb261 | 595 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
1ae26a18 AZ |
596 | { |
597 | struct bt_vlan_s **pvlan, *vlan; | |
598 | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { | |
599 | if (vlan->id == id) | |
600 | return &vlan->net; | |
601 | } | |
7267c094 | 602 | vlan = g_malloc0(sizeof(struct bt_vlan_s)); |
1ae26a18 AZ |
603 | vlan->id = id; |
604 | pvlan = &first_bt_vlan; | |
605 | while (*pvlan != NULL) | |
606 | pvlan = &(*pvlan)->next; | |
607 | *pvlan = vlan; | |
608 | return &vlan->net; | |
609 | } | |
610 | ||
611 | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) | |
612 | { | |
613 | } | |
614 | ||
615 | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) | |
616 | { | |
617 | return -ENOTSUP; | |
618 | } | |
619 | ||
620 | static struct HCIInfo null_hci = { | |
621 | .cmd_send = null_hci_send, | |
622 | .sco_send = null_hci_send, | |
623 | .acl_send = null_hci_send, | |
624 | .bdaddr_set = null_hci_addr_set, | |
625 | }; | |
626 | ||
627 | struct HCIInfo *qemu_next_hci(void) | |
628 | { | |
629 | if (cur_hci == nb_hcis) | |
630 | return &null_hci; | |
631 | ||
632 | return hci_table[cur_hci++]; | |
633 | } | |
634 | ||
dc72ac14 AZ |
635 | static struct HCIInfo *hci_init(const char *str) |
636 | { | |
637 | char *endp; | |
638 | struct bt_scatternet_s *vlan = 0; | |
639 | ||
640 | if (!strcmp(str, "null")) | |
641 | /* null */ | |
642 | return &null_hci; | |
643 | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) | |
644 | /* host[:hciN] */ | |
645 | return bt_host_hci(str[4] ? str + 5 : "hci0"); | |
646 | else if (!strncmp(str, "hci", 3)) { | |
647 | /* hci[,vlan=n] */ | |
648 | if (str[3]) { | |
649 | if (!strncmp(str + 3, ",vlan=", 6)) { | |
650 | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); | |
651 | if (*endp) | |
652 | vlan = 0; | |
653 | } | |
654 | } else | |
655 | vlan = qemu_find_bt_vlan(0); | |
656 | if (vlan) | |
657 | return bt_new_hci(vlan); | |
658 | } | |
659 | ||
660 | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); | |
661 | ||
662 | return 0; | |
663 | } | |
664 | ||
665 | static int bt_hci_parse(const char *str) | |
666 | { | |
667 | struct HCIInfo *hci; | |
c227f099 | 668 | bdaddr_t bdaddr; |
dc72ac14 AZ |
669 | |
670 | if (nb_hcis >= MAX_NICS) { | |
671 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); | |
672 | return -1; | |
673 | } | |
674 | ||
675 | hci = hci_init(str); | |
676 | if (!hci) | |
677 | return -1; | |
678 | ||
679 | bdaddr.b[0] = 0x52; | |
680 | bdaddr.b[1] = 0x54; | |
681 | bdaddr.b[2] = 0x00; | |
682 | bdaddr.b[3] = 0x12; | |
683 | bdaddr.b[4] = 0x34; | |
684 | bdaddr.b[5] = 0x56 + nb_hcis; | |
685 | hci->bdaddr_set(hci, bdaddr.b); | |
686 | ||
687 | hci_table[nb_hcis++] = hci; | |
688 | ||
689 | return 0; | |
690 | } | |
691 | ||
692 | static void bt_vhci_add(int vlan_id) | |
693 | { | |
694 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); | |
695 | ||
696 | if (!vlan->slave) | |
697 | fprintf(stderr, "qemu: warning: adding a VHCI to " | |
698 | "an empty scatternet %i\n", vlan_id); | |
699 | ||
700 | bt_vhci_init(bt_new_hci(vlan)); | |
701 | } | |
702 | ||
703 | static struct bt_device_s *bt_device_add(const char *opt) | |
704 | { | |
705 | struct bt_scatternet_s *vlan; | |
706 | int vlan_id = 0; | |
707 | char *endp = strstr(opt, ",vlan="); | |
708 | int len = (endp ? endp - opt : strlen(opt)) + 1; | |
709 | char devname[10]; | |
710 | ||
711 | pstrcpy(devname, MIN(sizeof(devname), len), opt); | |
712 | ||
713 | if (endp) { | |
714 | vlan_id = strtol(endp + 6, &endp, 0); | |
715 | if (*endp) { | |
716 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); | |
717 | return 0; | |
718 | } | |
719 | } | |
720 | ||
721 | vlan = qemu_find_bt_vlan(vlan_id); | |
722 | ||
723 | if (!vlan->slave) | |
724 | fprintf(stderr, "qemu: warning: adding a slave device to " | |
725 | "an empty scatternet %i\n", vlan_id); | |
726 | ||
727 | if (!strcmp(devname, "keyboard")) | |
728 | return bt_keyboard_init(vlan); | |
729 | ||
730 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); | |
731 | return 0; | |
732 | } | |
733 | ||
734 | static int bt_parse(const char *opt) | |
735 | { | |
736 | const char *endp, *p; | |
737 | int vlan; | |
738 | ||
739 | if (strstart(opt, "hci", &endp)) { | |
740 | if (!*endp || *endp == ',') { | |
741 | if (*endp) | |
742 | if (!strstart(endp, ",vlan=", 0)) | |
743 | opt = endp + 1; | |
744 | ||
745 | return bt_hci_parse(opt); | |
746 | } | |
747 | } else if (strstart(opt, "vhci", &endp)) { | |
748 | if (!*endp || *endp == ',') { | |
749 | if (*endp) { | |
750 | if (strstart(endp, ",vlan=", &p)) { | |
751 | vlan = strtol(p, (char **) &endp, 0); | |
752 | if (*endp) { | |
753 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); | |
754 | return 1; | |
755 | } | |
756 | } else { | |
757 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); | |
758 | return 1; | |
759 | } | |
760 | } else | |
761 | vlan = 0; | |
762 | ||
763 | bt_vhci_add(vlan); | |
764 | return 0; | |
765 | } | |
766 | } else if (strstart(opt, "device:", &endp)) | |
767 | return !bt_device_add(endp); | |
768 | ||
769 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); | |
770 | return 1; | |
771 | } | |
772 | ||
7d76ad4f EO |
773 | static int parse_sandbox(QemuOpts *opts, void *opaque) |
774 | { | |
775 | /* FIXME: change this to true for 1.3 */ | |
776 | if (qemu_opt_get_bool(opts, "enable", false)) { | |
777 | #ifdef CONFIG_SECCOMP | |
778 | if (seccomp_start() < 0) { | |
779 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
780 | "failed to install seccomp syscall filter in the kernel"); | |
781 | return -1; | |
782 | } | |
783 | #else | |
784 | qerror_report(ERROR_CLASS_GENERIC_ERROR, | |
785 | "sandboxing request but seccomp is not compiled into this build"); | |
786 | return -1; | |
787 | #endif | |
788 | } | |
789 | ||
790 | return 0; | |
791 | } | |
792 | ||
1ae26a18 AZ |
793 | /***********************************************************/ |
794 | /* QEMU Block devices */ | |
795 | ||
2292ddae MA |
796 | #define HD_OPTS "media=disk" |
797 | #define CDROM_OPTS "media=cdrom" | |
798 | #define FD_OPTS "" | |
799 | #define PFLASH_OPTS "" | |
800 | #define MTD_OPTS "" | |
801 | #define SD_OPTS "" | |
e4bcb14c | 802 | |
9dfd7c7a GH |
803 | static int drive_init_func(QemuOpts *opts, void *opaque) |
804 | { | |
a803cb8e | 805 | int *use_scsi = opaque; |
9dfd7c7a | 806 | |
319ae529 | 807 | return drive_init(opts, *use_scsi) == NULL; |
9dfd7c7a GH |
808 | } |
809 | ||
810 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) | |
811 | { | |
812 | if (NULL == qemu_opt_get(opts, "snapshot")) { | |
813 | qemu_opt_set(opts, "snapshot", "on"); | |
814 | } | |
815 | return 0; | |
816 | } | |
817 | ||
4e5d9b57 MA |
818 | static void default_drive(int enable, int snapshot, int use_scsi, |
819 | BlockInterfaceType type, int index, | |
820 | const char *optstr) | |
821 | { | |
822 | QemuOpts *opts; | |
823 | ||
824 | if (type == IF_DEFAULT) { | |
825 | type = use_scsi ? IF_SCSI : IF_IDE; | |
826 | } | |
827 | ||
828 | if (!enable || drive_get_by_index(type, index)) { | |
829 | return; | |
830 | } | |
831 | ||
832 | opts = drive_add(type, index, NULL, optstr); | |
833 | if (snapshot) { | |
834 | drive_enable_snapshot(opts, NULL); | |
835 | } | |
319ae529 | 836 | if (!drive_init(opts, use_scsi)) { |
4e5d9b57 MA |
837 | exit(1); |
838 | } | |
839 | } | |
840 | ||
76e30d0f JK |
841 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
842 | { | |
843 | boot_set_handler = func; | |
844 | boot_set_opaque = opaque; | |
845 | } | |
846 | ||
847 | int qemu_boot_set(const char *boot_devices) | |
848 | { | |
849 | if (!boot_set_handler) { | |
850 | return -EINVAL; | |
851 | } | |
852 | return boot_set_handler(boot_set_opaque, boot_devices); | |
853 | } | |
854 | ||
4e9e9d6e | 855 | static void validate_bootdevices(char *devices) |
ef3adf68 JK |
856 | { |
857 | /* We just do some generic consistency checks */ | |
858 | const char *p; | |
859 | int bitmap = 0; | |
860 | ||
861 | for (p = devices; *p != '\0'; p++) { | |
862 | /* Allowed boot devices are: | |
863 | * a-b: floppy disk drives | |
864 | * c-f: IDE disk drives | |
07f35073 | 865 | * g-m: machine implementation dependent drives |
ef3adf68 JK |
866 | * n-p: network devices |
867 | * It's up to each machine implementation to check if the given boot | |
868 | * devices match the actual hardware implementation and firmware | |
869 | * features. | |
870 | */ | |
871 | if (*p < 'a' || *p > 'p') { | |
872 | fprintf(stderr, "Invalid boot device '%c'\n", *p); | |
873 | exit(1); | |
874 | } | |
875 | if (bitmap & (1 << (*p - 'a'))) { | |
876 | fprintf(stderr, "Boot device '%c' was given twice\n", *p); | |
877 | exit(1); | |
878 | } | |
879 | bitmap |= 1 << (*p - 'a'); | |
880 | } | |
ef3adf68 JK |
881 | } |
882 | ||
e0f084bf JK |
883 | static void restore_boot_devices(void *opaque) |
884 | { | |
885 | char *standard_boot_devices = opaque; | |
37905d6a AW |
886 | static int first = 1; |
887 | ||
888 | /* Restore boot order and remove ourselves after the first boot */ | |
889 | if (first) { | |
890 | first = 0; | |
891 | return; | |
892 | } | |
e0f084bf JK |
893 | |
894 | qemu_boot_set(standard_boot_devices); | |
895 | ||
896 | qemu_unregister_reset(restore_boot_devices, standard_boot_devices); | |
7267c094 | 897 | g_free(standard_boot_devices); |
e0f084bf JK |
898 | } |
899 | ||
1ca4d09a GN |
900 | void add_boot_device_path(int32_t bootindex, DeviceState *dev, |
901 | const char *suffix) | |
902 | { | |
903 | FWBootEntry *node, *i; | |
904 | ||
905 | if (bootindex < 0) { | |
906 | return; | |
907 | } | |
908 | ||
909 | assert(dev != NULL || suffix != NULL); | |
910 | ||
7267c094 | 911 | node = g_malloc0(sizeof(FWBootEntry)); |
1ca4d09a | 912 | node->bootindex = bootindex; |
7267c094 | 913 | node->suffix = suffix ? g_strdup(suffix) : NULL; |
1ca4d09a GN |
914 | node->dev = dev; |
915 | ||
916 | QTAILQ_FOREACH(i, &fw_boot_order, link) { | |
917 | if (i->bootindex == bootindex) { | |
918 | fprintf(stderr, "Two devices with same boot index %d\n", bootindex); | |
919 | exit(1); | |
920 | } else if (i->bootindex < bootindex) { | |
921 | continue; | |
922 | } | |
923 | QTAILQ_INSERT_BEFORE(i, node, link); | |
924 | return; | |
925 | } | |
926 | QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); | |
927 | } | |
928 | ||
962630f2 GN |
929 | /* |
930 | * This function returns null terminated string that consist of new line | |
71785aba | 931 | * separated device paths. |
962630f2 GN |
932 | * |
933 | * memory pointed by "size" is assigned total length of the array in bytes | |
934 | * | |
935 | */ | |
936 | char *get_boot_devices_list(uint32_t *size) | |
937 | { | |
938 | FWBootEntry *i; | |
939 | uint32_t total = 0; | |
940 | char *list = NULL; | |
941 | ||
942 | QTAILQ_FOREACH(i, &fw_boot_order, link) { | |
943 | char *devpath = NULL, *bootpath; | |
944 | int len; | |
945 | ||
946 | if (i->dev) { | |
947 | devpath = qdev_get_fw_dev_path(i->dev); | |
948 | assert(devpath); | |
949 | } | |
950 | ||
951 | if (i->suffix && devpath) { | |
4fd37a98 BS |
952 | size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1; |
953 | ||
7267c094 | 954 | bootpath = g_malloc(bootpathlen); |
4fd37a98 | 955 | snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix); |
7267c094 | 956 | g_free(devpath); |
962630f2 GN |
957 | } else if (devpath) { |
958 | bootpath = devpath; | |
959 | } else { | |
1bf6ccd3 | 960 | assert(i->suffix); |
7267c094 | 961 | bootpath = g_strdup(i->suffix); |
962630f2 GN |
962 | } |
963 | ||
964 | if (total) { | |
965 | list[total-1] = '\n'; | |
966 | } | |
967 | len = strlen(bootpath) + 1; | |
7267c094 | 968 | list = g_realloc(list, total + len); |
962630f2 GN |
969 | memcpy(&list[total], bootpath, len); |
970 | total += len; | |
7267c094 | 971 | g_free(bootpath); |
962630f2 GN |
972 | } |
973 | ||
974 | *size = total; | |
975 | ||
976 | return list; | |
977 | } | |
978 | ||
268a362c AL |
979 | static void numa_add(const char *optarg) |
980 | { | |
981 | char option[128]; | |
982 | char *endptr; | |
983 | unsigned long long value, endvalue; | |
984 | int nodenr; | |
985 | ||
ee785fed CV |
986 | value = endvalue = 0ULL; |
987 | ||
268a362c AL |
988 | optarg = get_opt_name(option, 128, optarg, ',') + 1; |
989 | if (!strcmp(option, "node")) { | |
990 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { | |
991 | nodenr = nb_numa_nodes; | |
992 | } else { | |
993 | nodenr = strtoull(option, NULL, 10); | |
994 | } | |
995 | ||
996 | if (get_param_value(option, 128, "mem", optarg) == 0) { | |
997 | node_mem[nodenr] = 0; | |
998 | } else { | |
70b4f4bb | 999 | int64_t sval; |
c03417b4 MA |
1000 | sval = strtosz(option, &endptr); |
1001 | if (sval < 0 || *endptr) { | |
9f9b17a4 JS |
1002 | fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg); |
1003 | exit(1); | |
268a362c | 1004 | } |
9f9b17a4 | 1005 | node_mem[nodenr] = sval; |
268a362c | 1006 | } |
ee785fed | 1007 | if (get_param_value(option, 128, "cpus", optarg) != 0) { |
268a362c | 1008 | value = strtoull(option, &endptr, 10); |
ee785fed CV |
1009 | if (*endptr == '-') { |
1010 | endvalue = strtoull(endptr+1, &endptr, 10); | |
268a362c | 1011 | } else { |
ee785fed CV |
1012 | endvalue = value; |
1013 | } | |
1014 | ||
1015 | if (!(endvalue < MAX_CPUMASK_BITS)) { | |
1016 | endvalue = MAX_CPUMASK_BITS - 1; | |
1017 | fprintf(stderr, | |
1018 | "A max of %d CPUs are supported in a guest\n", | |
1019 | MAX_CPUMASK_BITS); | |
268a362c | 1020 | } |
ee785fed CV |
1021 | |
1022 | bitmap_set(node_cpumask[nodenr], value, endvalue-value+1); | |
268a362c AL |
1023 | } |
1024 | nb_numa_nodes++; | |
1025 | } | |
268a362c AL |
1026 | } |
1027 | ||
dc6b1c09 AP |
1028 | static void smp_parse(const char *optarg) |
1029 | { | |
1030 | int smp, sockets = 0, threads = 0, cores = 0; | |
1031 | char *endptr; | |
1032 | char option[128]; | |
1033 | ||
1034 | smp = strtoul(optarg, &endptr, 10); | |
1035 | if (endptr != optarg) { | |
1036 | if (*endptr == ',') { | |
1037 | endptr++; | |
1038 | } | |
1039 | } | |
1040 | if (get_param_value(option, 128, "sockets", endptr) != 0) | |
1041 | sockets = strtoull(option, NULL, 10); | |
1042 | if (get_param_value(option, 128, "cores", endptr) != 0) | |
1043 | cores = strtoull(option, NULL, 10); | |
1044 | if (get_param_value(option, 128, "threads", endptr) != 0) | |
1045 | threads = strtoull(option, NULL, 10); | |
1046 | if (get_param_value(option, 128, "maxcpus", endptr) != 0) | |
1047 | max_cpus = strtoull(option, NULL, 10); | |
1048 | ||
1049 | /* compute missing values, prefer sockets over cores over threads */ | |
1050 | if (smp == 0 || sockets == 0) { | |
1051 | sockets = sockets > 0 ? sockets : 1; | |
1052 | cores = cores > 0 ? cores : 1; | |
1053 | threads = threads > 0 ? threads : 1; | |
1054 | if (smp == 0) { | |
1055 | smp = cores * threads * sockets; | |
dc6b1c09 AP |
1056 | } |
1057 | } else { | |
1058 | if (cores == 0) { | |
1059 | threads = threads > 0 ? threads : 1; | |
1060 | cores = smp / (sockets * threads); | |
1061 | } else { | |
dca98169 | 1062 | threads = smp / (cores * sockets); |
dc6b1c09 AP |
1063 | } |
1064 | } | |
1065 | smp_cpus = smp; | |
1066 | smp_cores = cores > 0 ? cores : 1; | |
1067 | smp_threads = threads > 0 ? threads : 1; | |
1068 | if (max_cpus == 0) | |
1069 | max_cpus = smp_cpus; | |
1070 | } | |
1071 | ||
a594cfbf FB |
1072 | /***********************************************************/ |
1073 | /* USB devices */ | |
1074 | ||
fb08000c | 1075 | static int usb_device_add(const char *devname) |
a594cfbf FB |
1076 | { |
1077 | const char *p; | |
a5d2f727 | 1078 | USBDevice *dev = NULL; |
a594cfbf | 1079 | |
a5d2f727 | 1080 | if (!usb_enabled) |
a594cfbf FB |
1081 | return -1; |
1082 | ||
0958b4cc GH |
1083 | /* drivers with .usbdevice_name entry in USBDeviceInfo */ |
1084 | dev = usbdevice_create(devname); | |
1085 | if (dev) | |
1086 | goto done; | |
1087 | ||
a5d2f727 | 1088 | /* the other ones */ |
e447fc63 GH |
1089 | #ifndef CONFIG_LINUX |
1090 | /* only the linux version is qdev-ified, usb-bsd still needs this */ | |
a594cfbf | 1091 | if (strstart(devname, "host:", &p)) { |
3741715c | 1092 | dev = usb_host_device_open(usb_bus_find(-1), p); |
e447fc63 GH |
1093 | } else |
1094 | #endif | |
1095 | if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { | |
3741715c JK |
1096 | dev = usb_bt_init(usb_bus_find(-1), |
1097 | devname[2] ? hci_init(p) | |
1098 | : bt_new_hci(qemu_find_bt_vlan(0))); | |
a594cfbf FB |
1099 | } else { |
1100 | return -1; | |
1101 | } | |
0d92ed30 PB |
1102 | if (!dev) |
1103 | return -1; | |
1104 | ||
a5d2f727 | 1105 | done: |
a594cfbf FB |
1106 | return 0; |
1107 | } | |
1108 | ||
1f3870ab AL |
1109 | static int usb_device_del(const char *devname) |
1110 | { | |
1111 | int bus_num, addr; | |
1112 | const char *p; | |
1113 | ||
5d0c5750 AL |
1114 | if (strstart(devname, "host:", &p)) |
1115 | return usb_host_device_close(p); | |
1116 | ||
a5d2f727 | 1117 | if (!usb_enabled) |
1f3870ab AL |
1118 | return -1; |
1119 | ||
1120 | p = strchr(devname, '.'); | |
1121 | if (!p) | |
1122 | return -1; | |
1123 | bus_num = strtoul(devname, NULL, 0); | |
1124 | addr = strtoul(p + 1, NULL, 0); | |
1125 | ||
a5d2f727 | 1126 | return usb_device_delete_addr(bus_num, addr); |
1f3870ab AL |
1127 | } |
1128 | ||
bd3c948d GH |
1129 | static int usb_parse(const char *cmdline) |
1130 | { | |
59d1c1c2 | 1131 | int r; |
fb08000c | 1132 | r = usb_device_add(cmdline); |
59d1c1c2 ST |
1133 | if (r < 0) { |
1134 | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline); | |
1135 | } | |
1136 | return r; | |
bd3c948d GH |
1137 | } |
1138 | ||
d54908a5 | 1139 | void do_usb_add(Monitor *mon, const QDict *qdict) |
a594cfbf | 1140 | { |
59d1c1c2 | 1141 | const char *devname = qdict_get_str(qdict, "devname"); |
fb08000c | 1142 | if (usb_device_add(devname) < 0) { |
1ecda02b | 1143 | error_report("could not add USB device '%s'", devname); |
59d1c1c2 | 1144 | } |
a594cfbf FB |
1145 | } |
1146 | ||
d54908a5 | 1147 | void do_usb_del(Monitor *mon, const QDict *qdict) |
a594cfbf | 1148 | { |
59d1c1c2 ST |
1149 | const char *devname = qdict_get_str(qdict, "devname"); |
1150 | if (usb_device_del(devname) < 0) { | |
1ecda02b | 1151 | error_report("could not delete USB device '%s'", devname); |
59d1c1c2 | 1152 | } |
a594cfbf FB |
1153 | } |
1154 | ||
201a51fc AZ |
1155 | /***********************************************************/ |
1156 | /* PCMCIA/Cardbus */ | |
1157 | ||
1158 | static struct pcmcia_socket_entry_s { | |
bc24a225 | 1159 | PCMCIASocket *socket; |
201a51fc AZ |
1160 | struct pcmcia_socket_entry_s *next; |
1161 | } *pcmcia_sockets = 0; | |
1162 | ||
bc24a225 | 1163 | void pcmcia_socket_register(PCMCIASocket *socket) |
201a51fc AZ |
1164 | { |
1165 | struct pcmcia_socket_entry_s *entry; | |
1166 | ||
7267c094 | 1167 | entry = g_malloc(sizeof(struct pcmcia_socket_entry_s)); |
201a51fc AZ |
1168 | entry->socket = socket; |
1169 | entry->next = pcmcia_sockets; | |
1170 | pcmcia_sockets = entry; | |
1171 | } | |
1172 | ||
bc24a225 | 1173 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
201a51fc AZ |
1174 | { |
1175 | struct pcmcia_socket_entry_s *entry, **ptr; | |
1176 | ||
1177 | ptr = &pcmcia_sockets; | |
1178 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) | |
1179 | if (entry->socket == socket) { | |
1180 | *ptr = entry->next; | |
7267c094 | 1181 | g_free(entry); |
201a51fc AZ |
1182 | } |
1183 | } | |
1184 | ||
376253ec | 1185 | void pcmcia_info(Monitor *mon) |
201a51fc AZ |
1186 | { |
1187 | struct pcmcia_socket_entry_s *iter; | |
376253ec | 1188 | |
201a51fc | 1189 | if (!pcmcia_sockets) |
376253ec | 1190 | monitor_printf(mon, "No PCMCIA sockets\n"); |
201a51fc AZ |
1191 | |
1192 | for (iter = pcmcia_sockets; iter; iter = iter->next) | |
376253ec AL |
1193 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
1194 | iter->socket->attached ? iter->socket->card_string : | |
1195 | "Empty"); | |
201a51fc AZ |
1196 | } |
1197 | ||
cc1daa40 FB |
1198 | /***********************************************************/ |
1199 | /* machine registration */ | |
1200 | ||
bdaf78e0 | 1201 | static QEMUMachine *first_machine = NULL; |
6f338c34 | 1202 | QEMUMachine *current_machine = NULL; |
cc1daa40 FB |
1203 | |
1204 | int qemu_register_machine(QEMUMachine *m) | |
1205 | { | |
1206 | QEMUMachine **pm; | |
1207 | pm = &first_machine; | |
1208 | while (*pm != NULL) | |
1209 | pm = &(*pm)->next; | |
1210 | m->next = NULL; | |
1211 | *pm = m; | |
1212 | return 0; | |
1213 | } | |
1214 | ||
9596ebb7 | 1215 | static QEMUMachine *find_machine(const char *name) |
cc1daa40 FB |
1216 | { |
1217 | QEMUMachine *m; | |
1218 | ||
1219 | for(m = first_machine; m != NULL; m = m->next) { | |
1220 | if (!strcmp(m->name, name)) | |
1221 | return m; | |
3f6599e6 MM |
1222 | if (m->alias && !strcmp(m->alias, name)) |
1223 | return m; | |
cc1daa40 FB |
1224 | } |
1225 | return NULL; | |
1226 | } | |
1227 | ||
2c8cffa5 | 1228 | QEMUMachine *find_default_machine(void) |
0c257437 AL |
1229 | { |
1230 | QEMUMachine *m; | |
1231 | ||
1232 | for(m = first_machine; m != NULL; m = m->next) { | |
1233 | if (m->is_default) { | |
1234 | return m; | |
1235 | } | |
1236 | } | |
1237 | return NULL; | |
1238 | } | |
1239 | ||
01d3c80d AL |
1240 | MachineInfoList *qmp_query_machines(Error **errp) |
1241 | { | |
1242 | MachineInfoList *mach_list = NULL; | |
1243 | QEMUMachine *m; | |
1244 | ||
1245 | for (m = first_machine; m; m = m->next) { | |
1246 | MachineInfoList *entry; | |
1247 | MachineInfo *info; | |
1248 | ||
1249 | info = g_malloc0(sizeof(*info)); | |
1250 | if (m->is_default) { | |
1251 | info->has_is_default = true; | |
1252 | info->is_default = true; | |
1253 | } | |
1254 | ||
1255 | if (m->alias) { | |
1256 | info->has_alias = true; | |
1257 | info->alias = g_strdup(m->alias); | |
1258 | } | |
1259 | ||
1260 | info->name = g_strdup(m->name); | |
1261 | ||
1262 | entry = g_malloc0(sizeof(*entry)); | |
1263 | entry->value = info; | |
1264 | entry->next = mach_list; | |
1265 | mach_list = entry; | |
1266 | } | |
1267 | ||
1268 | return mach_list; | |
1269 | } | |
1270 | ||
8a7ddc38 FB |
1271 | /***********************************************************/ |
1272 | /* main execution loop */ | |
1273 | ||
9596ebb7 | 1274 | static void gui_update(void *opaque) |
8a7ddc38 | 1275 | { |
7d957bd8 | 1276 | uint64_t interval = GUI_REFRESH_INTERVAL; |
740733bb | 1277 | DisplayState *ds = opaque; |
7d957bd8 AL |
1278 | DisplayChangeListener *dcl = ds->listeners; |
1279 | ||
1280 | dpy_refresh(ds); | |
1281 | ||
1282 | while (dcl != NULL) { | |
1283 | if (dcl->gui_timer_interval && | |
1284 | dcl->gui_timer_interval < interval) | |
1285 | interval = dcl->gui_timer_interval; | |
1286 | dcl = dcl->next; | |
1287 | } | |
7bd427d8 | 1288 | qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock)); |
8a7ddc38 FB |
1289 | } |
1290 | ||
0bd48850 FB |
1291 | struct vm_change_state_entry { |
1292 | VMChangeStateHandler *cb; | |
1293 | void *opaque; | |
72cf2d4f | 1294 | QLIST_ENTRY (vm_change_state_entry) entries; |
0bd48850 FB |
1295 | }; |
1296 | ||
72cf2d4f | 1297 | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; |
0bd48850 FB |
1298 | |
1299 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, | |
1300 | void *opaque) | |
1301 | { | |
1302 | VMChangeStateEntry *e; | |
1303 | ||
7267c094 | 1304 | e = g_malloc0(sizeof (*e)); |
0bd48850 FB |
1305 | |
1306 | e->cb = cb; | |
1307 | e->opaque = opaque; | |
72cf2d4f | 1308 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
0bd48850 FB |
1309 | return e; |
1310 | } | |
1311 | ||
1312 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) | |
1313 | { | |
72cf2d4f | 1314 | QLIST_REMOVE (e, entries); |
7267c094 | 1315 | g_free (e); |
0bd48850 FB |
1316 | } |
1317 | ||
1dfb4dd9 | 1318 | void vm_state_notify(int running, RunState state) |
0bd48850 FB |
1319 | { |
1320 | VMChangeStateEntry *e; | |
1321 | ||
1dfb4dd9 | 1322 | trace_vm_state_notify(running, state); |
94b0b5ff | 1323 | |
0bd48850 | 1324 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
1dfb4dd9 | 1325 | e->cb(e->opaque, running, state); |
0bd48850 FB |
1326 | } |
1327 | } | |
1328 | ||
8a7ddc38 FB |
1329 | void vm_start(void) |
1330 | { | |
1354869c | 1331 | if (!runstate_is_running()) { |
8a7ddc38 | 1332 | cpu_enable_ticks(); |
0461d5a6 LC |
1333 | runstate_set(RUN_STATE_RUNNING); |
1334 | vm_state_notify(1, RUN_STATE_RUNNING); | |
d6dc3d42 | 1335 | resume_all_vcpus(); |
6ed2c484 | 1336 | monitor_protocol_event(QEVENT_RESUME, NULL); |
8a7ddc38 FB |
1337 | } |
1338 | } | |
1339 | ||
bb0c6722 FB |
1340 | /* reset/shutdown handler */ |
1341 | ||
1342 | typedef struct QEMUResetEntry { | |
72cf2d4f | 1343 | QTAILQ_ENTRY(QEMUResetEntry) entry; |
bb0c6722 FB |
1344 | QEMUResetHandler *func; |
1345 | void *opaque; | |
bb0c6722 FB |
1346 | } QEMUResetEntry; |
1347 | ||
72cf2d4f BS |
1348 | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = |
1349 | QTAILQ_HEAD_INITIALIZER(reset_handlers); | |
bb0c6722 | 1350 | static int reset_requested; |
f64622c4 GN |
1351 | static int shutdown_requested, shutdown_signal = -1; |
1352 | static pid_t shutdown_pid; | |
3475187d | 1353 | static int powerdown_requested; |
8cf71710 | 1354 | static int debug_requested; |
95b363b5 | 1355 | static int suspend_requested; |
14058196 | 1356 | static int wakeup_requested; |
a9552c8e IM |
1357 | static NotifierList powerdown_notifiers = |
1358 | NOTIFIER_LIST_INITIALIZER(powerdown_notifiers); | |
95b363b5 GH |
1359 | static NotifierList suspend_notifiers = |
1360 | NOTIFIER_LIST_INITIALIZER(suspend_notifiers); | |
1361 | static NotifierList wakeup_notifiers = | |
1362 | NOTIFIER_LIST_INITIALIZER(wakeup_notifiers); | |
1363 | static uint32_t wakeup_reason_mask = ~0; | |
0461d5a6 | 1364 | static RunState vmstop_requested = RUN_STATE_MAX; |
bb0c6722 | 1365 | |
1291eb35 AP |
1366 | int qemu_shutdown_requested_get(void) |
1367 | { | |
1368 | return shutdown_requested; | |
1369 | } | |
1370 | ||
1371 | int qemu_reset_requested_get(void) | |
1372 | { | |
1373 | return reset_requested; | |
1374 | } | |
1375 | ||
cf7a2fe2 AJ |
1376 | int qemu_shutdown_requested(void) |
1377 | { | |
1378 | int r = shutdown_requested; | |
1379 | shutdown_requested = 0; | |
1380 | return r; | |
1381 | } | |
1382 | ||
f64622c4 GN |
1383 | void qemu_kill_report(void) |
1384 | { | |
c7f0f3b1 | 1385 | if (!qtest_enabled() && shutdown_signal != -1) { |
f1d3fb04 PM |
1386 | fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal); |
1387 | if (shutdown_pid == 0) { | |
1388 | /* This happens for eg ^C at the terminal, so it's worth | |
1389 | * avoiding printing an odd message in that case. | |
1390 | */ | |
1391 | fputc('\n', stderr); | |
1392 | } else { | |
953ffe0f | 1393 | fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid); |
f1d3fb04 | 1394 | } |
f64622c4 GN |
1395 | shutdown_signal = -1; |
1396 | } | |
1397 | } | |
1398 | ||
cf7a2fe2 AJ |
1399 | int qemu_reset_requested(void) |
1400 | { | |
1401 | int r = reset_requested; | |
1402 | reset_requested = 0; | |
1403 | return r; | |
1404 | } | |
1405 | ||
95b363b5 GH |
1406 | static int qemu_suspend_requested(void) |
1407 | { | |
1408 | int r = suspend_requested; | |
1409 | suspend_requested = 0; | |
1410 | return r; | |
1411 | } | |
1412 | ||
14058196 LC |
1413 | static int qemu_wakeup_requested(void) |
1414 | { | |
1415 | int r = wakeup_requested; | |
1416 | wakeup_requested = 0; | |
1417 | return r; | |
1418 | } | |
1419 | ||
cf7a2fe2 AJ |
1420 | int qemu_powerdown_requested(void) |
1421 | { | |
1422 | int r = powerdown_requested; | |
1423 | powerdown_requested = 0; | |
1424 | return r; | |
1425 | } | |
1426 | ||
e568902a AL |
1427 | static int qemu_debug_requested(void) |
1428 | { | |
1429 | int r = debug_requested; | |
1430 | debug_requested = 0; | |
1431 | return r; | |
1432 | } | |
1433 | ||
0461d5a6 | 1434 | /* We use RUN_STATE_MAX but any invalid value will do */ |
0d45b702 | 1435 | static bool qemu_vmstop_requested(RunState *r) |
6e29f5da | 1436 | { |
0461d5a6 | 1437 | if (vmstop_requested < RUN_STATE_MAX) { |
0d45b702 | 1438 | *r = vmstop_requested; |
0461d5a6 | 1439 | vmstop_requested = RUN_STATE_MAX; |
0d45b702 LC |
1440 | return true; |
1441 | } | |
1442 | ||
1443 | return false; | |
6e29f5da AL |
1444 | } |
1445 | ||
a08d4367 | 1446 | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
bb0c6722 | 1447 | { |
7267c094 | 1448 | QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry)); |
bb0c6722 | 1449 | |
bb0c6722 FB |
1450 | re->func = func; |
1451 | re->opaque = opaque; | |
72cf2d4f | 1452 | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
bb0c6722 FB |
1453 | } |
1454 | ||
dda9b29f | 1455 | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
bb0c6722 FB |
1456 | { |
1457 | QEMUResetEntry *re; | |
1458 | ||
72cf2d4f | 1459 | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
dda9b29f | 1460 | if (re->func == func && re->opaque == opaque) { |
72cf2d4f | 1461 | QTAILQ_REMOVE(&reset_handlers, re, entry); |
7267c094 | 1462 | g_free(re); |
dda9b29f JK |
1463 | return; |
1464 | } | |
1465 | } | |
1466 | } | |
1467 | ||
be522029 | 1468 | void qemu_devices_reset(void) |
dda9b29f JK |
1469 | { |
1470 | QEMUResetEntry *re, *nre; | |
1471 | ||
1472 | /* reset all devices */ | |
72cf2d4f | 1473 | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
bb0c6722 FB |
1474 | re->func(re->opaque); |
1475 | } | |
be522029 DG |
1476 | } |
1477 | ||
1478 | void qemu_system_reset(bool report) | |
1479 | { | |
1480 | if (current_machine && current_machine->reset) { | |
1481 | current_machine->reset(); | |
1482 | } else { | |
1483 | qemu_devices_reset(); | |
1484 | } | |
e063eb1f JK |
1485 | if (report) { |
1486 | monitor_protocol_event(QEVENT_RESET, NULL); | |
1487 | } | |
ea375f9a | 1488 | cpu_synchronize_all_post_reset(); |
bb0c6722 FB |
1489 | } |
1490 | ||
1491 | void qemu_system_reset_request(void) | |
1492 | { | |
d1beab82 FB |
1493 | if (no_reboot) { |
1494 | shutdown_requested = 1; | |
1495 | } else { | |
1496 | reset_requested = 1; | |
1497 | } | |
b4a3d965 | 1498 | cpu_stop_current(); |
d9f75a4e | 1499 | qemu_notify_event(); |
bb0c6722 FB |
1500 | } |
1501 | ||
95b363b5 GH |
1502 | static void qemu_system_suspend(void) |
1503 | { | |
1504 | pause_all_vcpus(); | |
1505 | notifier_list_notify(&suspend_notifiers, NULL); | |
ad02b96a | 1506 | runstate_set(RUN_STATE_SUSPENDED); |
53370b78 | 1507 | monitor_protocol_event(QEVENT_SUSPEND, NULL); |
95b363b5 GH |
1508 | } |
1509 | ||
1510 | void qemu_system_suspend_request(void) | |
1511 | { | |
9abc62f6 | 1512 | if (runstate_check(RUN_STATE_SUSPENDED)) { |
95b363b5 GH |
1513 | return; |
1514 | } | |
1515 | suspend_requested = 1; | |
1516 | cpu_stop_current(); | |
1517 | qemu_notify_event(); | |
1518 | } | |
1519 | ||
1520 | void qemu_register_suspend_notifier(Notifier *notifier) | |
1521 | { | |
1522 | notifier_list_add(&suspend_notifiers, notifier); | |
1523 | } | |
1524 | ||
1525 | void qemu_system_wakeup_request(WakeupReason reason) | |
1526 | { | |
9abc62f6 | 1527 | if (!runstate_check(RUN_STATE_SUSPENDED)) { |
95b363b5 GH |
1528 | return; |
1529 | } | |
1530 | if (!(wakeup_reason_mask & (1 << reason))) { | |
1531 | return; | |
1532 | } | |
ad02b96a | 1533 | runstate_set(RUN_STATE_RUNNING); |
95b363b5 | 1534 | notifier_list_notify(&wakeup_notifiers, &reason); |
14058196 | 1535 | wakeup_requested = 1; |
95b363b5 | 1536 | qemu_notify_event(); |
95b363b5 GH |
1537 | } |
1538 | ||
1539 | void qemu_system_wakeup_enable(WakeupReason reason, bool enabled) | |
1540 | { | |
1541 | if (enabled) { | |
1542 | wakeup_reason_mask |= (1 << reason); | |
1543 | } else { | |
1544 | wakeup_reason_mask &= ~(1 << reason); | |
1545 | } | |
1546 | } | |
1547 | ||
1548 | void qemu_register_wakeup_notifier(Notifier *notifier) | |
1549 | { | |
1550 | notifier_list_add(&wakeup_notifiers, notifier); | |
1551 | } | |
1552 | ||
f64622c4 GN |
1553 | void qemu_system_killed(int signal, pid_t pid) |
1554 | { | |
1555 | shutdown_signal = signal; | |
1556 | shutdown_pid = pid; | |
d9389b96 | 1557 | no_shutdown = 0; |
f64622c4 GN |
1558 | qemu_system_shutdown_request(); |
1559 | } | |
1560 | ||
bb0c6722 FB |
1561 | void qemu_system_shutdown_request(void) |
1562 | { | |
1563 | shutdown_requested = 1; | |
d9f75a4e | 1564 | qemu_notify_event(); |
bb0c6722 FB |
1565 | } |
1566 | ||
013c2f15 IM |
1567 | static void qemu_system_powerdown(void) |
1568 | { | |
1569 | monitor_protocol_event(QEVENT_POWERDOWN, NULL); | |
1570 | notifier_list_notify(&powerdown_notifiers, NULL); | |
1571 | } | |
1572 | ||
3475187d FB |
1573 | void qemu_system_powerdown_request(void) |
1574 | { | |
1575 | powerdown_requested = 1; | |
d9f75a4e AL |
1576 | qemu_notify_event(); |
1577 | } | |
1578 | ||
a9552c8e IM |
1579 | void qemu_register_powerdown_notifier(Notifier *notifier) |
1580 | { | |
1581 | notifier_list_add(&powerdown_notifiers, notifier); | |
1582 | } | |
1583 | ||
8cf71710 JK |
1584 | void qemu_system_debug_request(void) |
1585 | { | |
1586 | debug_requested = 1; | |
83f338f7 | 1587 | qemu_notify_event(); |
8cf71710 JK |
1588 | } |
1589 | ||
1dfb4dd9 | 1590 | void qemu_system_vmstop_request(RunState state) |
8cf71710 | 1591 | { |
1dfb4dd9 | 1592 | vmstop_requested = state; |
8cf71710 JK |
1593 | qemu_notify_event(); |
1594 | } | |
1595 | ||
99435906 PB |
1596 | static bool main_loop_should_exit(void) |
1597 | { | |
1598 | RunState r; | |
1599 | if (qemu_debug_requested()) { | |
1600 | vm_stop(RUN_STATE_DEBUG); | |
1601 | } | |
95b363b5 GH |
1602 | if (qemu_suspend_requested()) { |
1603 | qemu_system_suspend(); | |
1604 | } | |
99435906 PB |
1605 | if (qemu_shutdown_requested()) { |
1606 | qemu_kill_report(); | |
1607 | monitor_protocol_event(QEVENT_SHUTDOWN, NULL); | |
1608 | if (no_shutdown) { | |
1609 | vm_stop(RUN_STATE_SHUTDOWN); | |
1610 | } else { | |
1611 | return true; | |
1612 | } | |
1613 | } | |
1614 | if (qemu_reset_requested()) { | |
1615 | pause_all_vcpus(); | |
1616 | cpu_synchronize_all_states(); | |
1617 | qemu_system_reset(VMRESET_REPORT); | |
1618 | resume_all_vcpus(); | |
1619 | if (runstate_check(RUN_STATE_INTERNAL_ERROR) || | |
1620 | runstate_check(RUN_STATE_SHUTDOWN)) { | |
1621 | runstate_set(RUN_STATE_PAUSED); | |
1622 | } | |
1623 | } | |
14058196 LC |
1624 | if (qemu_wakeup_requested()) { |
1625 | pause_all_vcpus(); | |
1626 | cpu_synchronize_all_states(); | |
1627 | qemu_system_reset(VMRESET_SILENT); | |
1628 | resume_all_vcpus(); | |
17c8660b | 1629 | monitor_protocol_event(QEVENT_WAKEUP, NULL); |
14058196 | 1630 | } |
99435906 | 1631 | if (qemu_powerdown_requested()) { |
013c2f15 | 1632 | qemu_system_powerdown(); |
99435906 PB |
1633 | } |
1634 | if (qemu_vmstop_requested(&r)) { | |
1635 | vm_stop(r); | |
1636 | } | |
1637 | return false; | |
1638 | } | |
1639 | ||
43b96858 AL |
1640 | static void main_loop(void) |
1641 | { | |
c9f711a5 | 1642 | bool nonblocking; |
99435906 | 1643 | int last_io = 0; |
8e1b90ec JK |
1644 | #ifdef CONFIG_PROFILER |
1645 | int64_t ti; | |
1646 | #endif | |
99435906 | 1647 | do { |
c9f711a5 | 1648 | nonblocking = !kvm_enabled() && last_io > 0; |
89bfc105 | 1649 | #ifdef CONFIG_PROFILER |
46481d39 | 1650 | ti = profile_getclock(); |
89bfc105 | 1651 | #endif |
c9f711a5 | 1652 | last_io = main_loop_wait(nonblocking); |
89bfc105 | 1653 | #ifdef CONFIG_PROFILER |
46481d39 | 1654 | dev_time += profile_getclock() - ti; |
89bfc105 | 1655 | #endif |
99435906 | 1656 | } while (!main_loop_should_exit()); |
b4608c04 FB |
1657 | } |
1658 | ||
9bd7e6d9 PB |
1659 | static void version(void) |
1660 | { | |
f75ca1ae | 1661 | printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
9bd7e6d9 PB |
1662 | } |
1663 | ||
15f82208 | 1664 | static void help(int exitcode) |
0824d6fc | 1665 | { |
a3adb7ad ME |
1666 | version(); |
1667 | printf("usage: %s [options] [disk_image]\n\n" | |
1668 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n", | |
1669 | error_get_progname()); | |
1670 | ||
77bd1119 ME |
1671 | #define QEMU_OPTIONS_GENERATE_HELP |
1672 | #include "qemu-options-wrapper.h" | |
a3adb7ad ME |
1673 | |
1674 | printf("\nDuring emulation, the following keys are useful:\n" | |
3f020d70 | 1675 | "ctrl-alt-f toggle full screen\n" |
1676 | "ctrl-alt-n switch to virtual console 'n'\n" | |
1677 | "ctrl-alt toggle mouse and keyboard grab\n" | |
1678 | "\n" | |
a3adb7ad ME |
1679 | "When using -nographic, press 'ctrl-a h' to get some help.\n"); |
1680 | ||
15f82208 | 1681 | exit(exitcode); |
0824d6fc FB |
1682 | } |
1683 | ||
cd6f1169 FB |
1684 | #define HAS_ARG 0x0001 |
1685 | ||
cd6f1169 FB |
1686 | typedef struct QEMUOption { |
1687 | const char *name; | |
1688 | int flags; | |
1689 | int index; | |
ad96090a | 1690 | uint32_t arch_mask; |
cd6f1169 FB |
1691 | } QEMUOption; |
1692 | ||
dbed7e40 | 1693 | static const QEMUOption qemu_options[] = { |
ad96090a | 1694 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
77bd1119 ME |
1695 | #define QEMU_OPTIONS_GENERATE_OPTIONS |
1696 | #include "qemu-options-wrapper.h" | |
cd6f1169 | 1697 | { NULL }, |
fc01f7e7 | 1698 | }; |
a369da5f BS |
1699 | |
1700 | static bool vga_available(void) | |
1701 | { | |
1702 | return qdev_exists("VGA") || qdev_exists("isa-vga"); | |
1703 | } | |
1704 | ||
1705 | static bool cirrus_vga_available(void) | |
1706 | { | |
1707 | return qdev_exists("cirrus-vga") || qdev_exists("isa-cirrus-vga"); | |
1708 | } | |
1709 | ||
1710 | static bool vmware_vga_available(void) | |
1711 | { | |
1712 | return qdev_exists("vmware-svga"); | |
1713 | } | |
1714 | ||
3893c124 | 1715 | static void select_vgahw (const char *p) |
1716 | { | |
1717 | const char *opts; | |
1718 | ||
86176759 | 1719 | vga_interface_type = VGA_NONE; |
3893c124 | 1720 | if (strstart(p, "std", &opts)) { |
a369da5f BS |
1721 | if (vga_available()) { |
1722 | vga_interface_type = VGA_STD; | |
1723 | } else { | |
1724 | fprintf(stderr, "Error: standard VGA not available\n"); | |
1725 | exit(0); | |
1726 | } | |
3893c124 | 1727 | } else if (strstart(p, "cirrus", &opts)) { |
a369da5f BS |
1728 | if (cirrus_vga_available()) { |
1729 | vga_interface_type = VGA_CIRRUS; | |
1730 | } else { | |
1731 | fprintf(stderr, "Error: Cirrus VGA not available\n"); | |
1732 | exit(0); | |
1733 | } | |
3893c124 | 1734 | } else if (strstart(p, "vmware", &opts)) { |
a369da5f BS |
1735 | if (vmware_vga_available()) { |
1736 | vga_interface_type = VGA_VMWARE; | |
1737 | } else { | |
1738 | fprintf(stderr, "Error: VMWare SVGA not available\n"); | |
1739 | exit(0); | |
1740 | } | |
94909d9f | 1741 | } else if (strstart(p, "xenfb", &opts)) { |
86176759 | 1742 | vga_interface_type = VGA_XENFB; |
a19cbfb3 GH |
1743 | } else if (strstart(p, "qxl", &opts)) { |
1744 | vga_interface_type = VGA_QXL; | |
28b85ed8 | 1745 | } else if (!strstart(p, "none", &opts)) { |
3893c124 | 1746 | invalid_vga: |
1747 | fprintf(stderr, "Unknown vga type: %s\n", p); | |
1748 | exit(1); | |
1749 | } | |
cb5a7aa8 | 1750 | while (*opts) { |
1751 | const char *nextopt; | |
1752 | ||
1753 | if (strstart(opts, ",retrace=", &nextopt)) { | |
1754 | opts = nextopt; | |
1755 | if (strstart(opts, "dumb", &nextopt)) | |
1756 | vga_retrace_method = VGA_RETRACE_DUMB; | |
1757 | else if (strstart(opts, "precise", &nextopt)) | |
1758 | vga_retrace_method = VGA_RETRACE_PRECISE; | |
1759 | else goto invalid_vga; | |
1760 | } else goto invalid_vga; | |
1761 | opts = nextopt; | |
1762 | } | |
3893c124 | 1763 | } |
1764 | ||
1472a95b JS |
1765 | static DisplayType select_display(const char *p) |
1766 | { | |
1767 | const char *opts; | |
1768 | DisplayType display = DT_DEFAULT; | |
1769 | ||
1770 | if (strstart(p, "sdl", &opts)) { | |
1771 | #ifdef CONFIG_SDL | |
1772 | display = DT_SDL; | |
1773 | while (*opts) { | |
1774 | const char *nextopt; | |
1775 | ||
1776 | if (strstart(opts, ",frame=", &nextopt)) { | |
1777 | opts = nextopt; | |
1778 | if (strstart(opts, "on", &nextopt)) { | |
1779 | no_frame = 0; | |
1780 | } else if (strstart(opts, "off", &nextopt)) { | |
1781 | no_frame = 1; | |
1782 | } else { | |
05175535 | 1783 | goto invalid_sdl_args; |
1472a95b JS |
1784 | } |
1785 | } else if (strstart(opts, ",alt_grab=", &nextopt)) { | |
1786 | opts = nextopt; | |
1787 | if (strstart(opts, "on", &nextopt)) { | |
1788 | alt_grab = 1; | |
1789 | } else if (strstart(opts, "off", &nextopt)) { | |
1790 | alt_grab = 0; | |
1791 | } else { | |
05175535 | 1792 | goto invalid_sdl_args; |
1472a95b JS |
1793 | } |
1794 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { | |
1795 | opts = nextopt; | |
1796 | if (strstart(opts, "on", &nextopt)) { | |
1797 | ctrl_grab = 1; | |
1798 | } else if (strstart(opts, "off", &nextopt)) { | |
1799 | ctrl_grab = 0; | |
1800 | } else { | |
05175535 | 1801 | goto invalid_sdl_args; |
1472a95b JS |
1802 | } |
1803 | } else if (strstart(opts, ",window_close=", &nextopt)) { | |
1804 | opts = nextopt; | |
1805 | if (strstart(opts, "on", &nextopt)) { | |
1806 | no_quit = 0; | |
1807 | } else if (strstart(opts, "off", &nextopt)) { | |
1808 | no_quit = 1; | |
1809 | } else { | |
05175535 | 1810 | goto invalid_sdl_args; |
1472a95b JS |
1811 | } |
1812 | } else { | |
05175535 PM |
1813 | invalid_sdl_args: |
1814 | fprintf(stderr, "Invalid SDL option string: %s\n", p); | |
1815 | exit(1); | |
1472a95b JS |
1816 | } |
1817 | opts = nextopt; | |
1818 | } | |
1819 | #else | |
1820 | fprintf(stderr, "SDL support is disabled\n"); | |
1821 | exit(1); | |
1822 | #endif | |
3264ff12 | 1823 | } else if (strstart(p, "vnc", &opts)) { |
821601ea | 1824 | #ifdef CONFIG_VNC |
3264ff12 JS |
1825 | display_remote++; |
1826 | ||
1827 | if (*opts) { | |
1828 | const char *nextopt; | |
1829 | ||
1830 | if (strstart(opts, "=", &nextopt)) { | |
1831 | vnc_display = nextopt; | |
1832 | } | |
1833 | } | |
1834 | if (!vnc_display) { | |
1835 | fprintf(stderr, "VNC requires a display argument vnc=<display>\n"); | |
1836 | exit(1); | |
1837 | } | |
821601ea JS |
1838 | #else |
1839 | fprintf(stderr, "VNC support is disabled\n"); | |
1840 | exit(1); | |
1841 | #endif | |
1472a95b JS |
1842 | } else if (strstart(p, "curses", &opts)) { |
1843 | #ifdef CONFIG_CURSES | |
1844 | display = DT_CURSES; | |
1845 | #else | |
1846 | fprintf(stderr, "Curses support is disabled\n"); | |
1847 | exit(1); | |
1848 | #endif | |
4171d32e JS |
1849 | } else if (strstart(p, "none", &opts)) { |
1850 | display = DT_NONE; | |
1472a95b | 1851 | } else { |
1472a95b JS |
1852 | fprintf(stderr, "Unknown display type: %s\n", p); |
1853 | exit(1); | |
1854 | } | |
1855 | ||
1856 | return display; | |
1857 | } | |
1858 | ||
7d4c3d53 MA |
1859 | static int balloon_parse(const char *arg) |
1860 | { | |
382f0743 | 1861 | QemuOpts *opts; |
7d4c3d53 | 1862 | |
382f0743 GH |
1863 | if (strcmp(arg, "none") == 0) { |
1864 | return 0; | |
1865 | } | |
1866 | ||
1867 | if (!strncmp(arg, "virtio", 6)) { | |
1868 | if (arg[6] == ',') { | |
1869 | /* have params -> parse them */ | |
3329f07b | 1870 | opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); |
382f0743 GH |
1871 | if (!opts) |
1872 | return -1; | |
1873 | } else { | |
1874 | /* create empty opts */ | |
8be7e7e4 | 1875 | opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL); |
7d4c3d53 | 1876 | } |
29f82b37 | 1877 | qemu_opt_set(opts, "driver", "virtio-balloon"); |
382f0743 | 1878 | return 0; |
7d4c3d53 | 1879 | } |
382f0743 GH |
1880 | |
1881 | return -1; | |
7d4c3d53 | 1882 | } |
7d4c3d53 | 1883 | |
5cea8590 PB |
1884 | char *qemu_find_file(int type, const char *name) |
1885 | { | |
1886 | int len; | |
1887 | const char *subdir; | |
1888 | char *buf; | |
1889 | ||
31783203 PM |
1890 | /* Try the name as a straight path first */ |
1891 | if (access(name, R_OK) == 0) { | |
7267c094 | 1892 | return g_strdup(name); |
5cea8590 PB |
1893 | } |
1894 | switch (type) { | |
1895 | case QEMU_FILE_TYPE_BIOS: | |
1896 | subdir = ""; | |
1897 | break; | |
1898 | case QEMU_FILE_TYPE_KEYMAP: | |
1899 | subdir = "keymaps/"; | |
1900 | break; | |
1901 | default: | |
1902 | abort(); | |
1903 | } | |
1904 | len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; | |
7267c094 | 1905 | buf = g_malloc0(len); |
3a41759d | 1906 | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); |
5cea8590 | 1907 | if (access(buf, R_OK)) { |
7267c094 | 1908 | g_free(buf); |
5cea8590 PB |
1909 | return NULL; |
1910 | } | |
1911 | return buf; | |
1912 | } | |
1913 | ||
ff952ba2 MA |
1914 | static int device_help_func(QemuOpts *opts, void *opaque) |
1915 | { | |
1916 | return qdev_device_help(opts); | |
1917 | } | |
1918 | ||
f31d07d1 GH |
1919 | static int device_init_func(QemuOpts *opts, void *opaque) |
1920 | { | |
1921 | DeviceState *dev; | |
1922 | ||
1923 | dev = qdev_device_add(opts); | |
1924 | if (!dev) | |
1925 | return -1; | |
1926 | return 0; | |
1927 | } | |
1928 | ||
1a688d3b GH |
1929 | static int chardev_init_func(QemuOpts *opts, void *opaque) |
1930 | { | |
1931 | CharDriverState *chr; | |
1932 | ||
f69554b9 | 1933 | chr = qemu_chr_new_from_opts(opts, NULL); |
1a688d3b GH |
1934 | if (!chr) |
1935 | return -1; | |
1936 | return 0; | |
1937 | } | |
1938 | ||
758e8e38 | 1939 | #ifdef CONFIG_VIRTFS |
74db920c GS |
1940 | static int fsdev_init_func(QemuOpts *opts, void *opaque) |
1941 | { | |
1942 | int ret; | |
1943 | ret = qemu_fsdev_add(opts); | |
1944 | ||
1945 | return ret; | |
1946 | } | |
1947 | #endif | |
1948 | ||
88589343 GH |
1949 | static int mon_init_func(QemuOpts *opts, void *opaque) |
1950 | { | |
1951 | CharDriverState *chr; | |
1952 | const char *chardev; | |
1953 | const char *mode; | |
1954 | int flags; | |
1955 | ||
1956 | mode = qemu_opt_get(opts, "mode"); | |
1957 | if (mode == NULL) { | |
1958 | mode = "readline"; | |
1959 | } | |
1960 | if (strcmp(mode, "readline") == 0) { | |
1961 | flags = MONITOR_USE_READLINE; | |
1962 | } else if (strcmp(mode, "control") == 0) { | |
1963 | flags = MONITOR_USE_CONTROL; | |
1964 | } else { | |
1965 | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); | |
1966 | exit(1); | |
1967 | } | |
1968 | ||
39eaab9a DB |
1969 | if (qemu_opt_get_bool(opts, "pretty", 0)) |
1970 | flags |= MONITOR_USE_PRETTY; | |
1971 | ||
88589343 GH |
1972 | if (qemu_opt_get_bool(opts, "default", 0)) |
1973 | flags |= MONITOR_IS_DEFAULT; | |
1974 | ||
1975 | chardev = qemu_opt_get(opts, "chardev"); | |
1976 | chr = qemu_chr_find(chardev); | |
1977 | if (chr == NULL) { | |
1978 | fprintf(stderr, "chardev \"%s\" not found\n", chardev); | |
1979 | exit(1); | |
1980 | } | |
1981 | ||
1982 | monitor_init(chr, flags); | |
1983 | return 0; | |
1984 | } | |
1985 | ||
6ca5582d | 1986 | static void monitor_parse(const char *optarg, const char *mode) |
88589343 GH |
1987 | { |
1988 | static int monitor_device_index = 0; | |
1989 | QemuOpts *opts; | |
1990 | const char *p; | |
1991 | char label[32]; | |
1992 | int def = 0; | |
1993 | ||
1994 | if (strstart(optarg, "chardev:", &p)) { | |
1995 | snprintf(label, sizeof(label), "%s", p); | |
1996 | } else { | |
140e065d JK |
1997 | snprintf(label, sizeof(label), "compat_monitor%d", |
1998 | monitor_device_index); | |
1999 | if (monitor_device_index == 0) { | |
88589343 GH |
2000 | def = 1; |
2001 | } | |
2002 | opts = qemu_chr_parse_compat(label, optarg); | |
2003 | if (!opts) { | |
2004 | fprintf(stderr, "parse error: %s\n", optarg); | |
2005 | exit(1); | |
2006 | } | |
2007 | } | |
2008 | ||
8be7e7e4 | 2009 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, NULL); |
88589343 GH |
2010 | if (!opts) { |
2011 | fprintf(stderr, "duplicate chardev: %s\n", label); | |
2012 | exit(1); | |
2013 | } | |
6ca5582d | 2014 | qemu_opt_set(opts, "mode", mode); |
88589343 GH |
2015 | qemu_opt_set(opts, "chardev", label); |
2016 | if (def) | |
2017 | qemu_opt_set(opts, "default", "on"); | |
2018 | monitor_device_index++; | |
2019 | } | |
2020 | ||
bd3c948d GH |
2021 | struct device_config { |
2022 | enum { | |
aee1b935 GH |
2023 | DEV_USB, /* -usbdevice */ |
2024 | DEV_BT, /* -bt */ | |
2025 | DEV_SERIAL, /* -serial */ | |
2026 | DEV_PARALLEL, /* -parallel */ | |
2027 | DEV_VIRTCON, /* -virtioconsole */ | |
c9f398e5 | 2028 | DEV_DEBUGCON, /* -debugcon */ |
ef0c4a0d | 2029 | DEV_GDB, /* -gdb, -s */ |
bd3c948d GH |
2030 | } type; |
2031 | const char *cmdline; | |
d9a5954d | 2032 | Location loc; |
72cf2d4f | 2033 | QTAILQ_ENTRY(device_config) next; |
bd3c948d | 2034 | }; |
72cf2d4f | 2035 | QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs); |
bd3c948d GH |
2036 | |
2037 | static void add_device_config(int type, const char *cmdline) | |
2038 | { | |
2039 | struct device_config *conf; | |
2040 | ||
7267c094 | 2041 | conf = g_malloc0(sizeof(*conf)); |
bd3c948d GH |
2042 | conf->type = type; |
2043 | conf->cmdline = cmdline; | |
d9a5954d | 2044 | loc_save(&conf->loc); |
72cf2d4f | 2045 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
bd3c948d GH |
2046 | } |
2047 | ||
2048 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) | |
2049 | { | |
2050 | struct device_config *conf; | |
2051 | int rc; | |
2052 | ||
72cf2d4f | 2053 | QTAILQ_FOREACH(conf, &device_configs, next) { |
bd3c948d GH |
2054 | if (conf->type != type) |
2055 | continue; | |
d9a5954d | 2056 | loc_push_restore(&conf->loc); |
bd3c948d | 2057 | rc = func(conf->cmdline); |
d9a5954d | 2058 | loc_pop(&conf->loc); |
bd3c948d GH |
2059 | if (0 != rc) |
2060 | return rc; | |
2061 | } | |
2062 | return 0; | |
2063 | } | |
2064 | ||
998bbd74 GH |
2065 | static int serial_parse(const char *devname) |
2066 | { | |
2067 | static int index = 0; | |
2068 | char label[32]; | |
2069 | ||
2070 | if (strcmp(devname, "none") == 0) | |
2071 | return 0; | |
2072 | if (index == MAX_SERIAL_PORTS) { | |
2073 | fprintf(stderr, "qemu: too many serial ports\n"); | |
2074 | exit(1); | |
2075 | } | |
2076 | snprintf(label, sizeof(label), "serial%d", index); | |
27143a44 | 2077 | serial_hds[index] = qemu_chr_new(label, devname, NULL); |
998bbd74 | 2078 | if (!serial_hds[index]) { |
52d06136 PM |
2079 | fprintf(stderr, "qemu: could not connect serial device" |
2080 | " to character backend '%s'\n", devname); | |
998bbd74 GH |
2081 | return -1; |
2082 | } | |
2083 | index++; | |
2084 | return 0; | |
2085 | } | |
2086 | ||
6a5e8b0e GH |
2087 | static int parallel_parse(const char *devname) |
2088 | { | |
2089 | static int index = 0; | |
2090 | char label[32]; | |
2091 | ||
2092 | if (strcmp(devname, "none") == 0) | |
2093 | return 0; | |
2094 | if (index == MAX_PARALLEL_PORTS) { | |
2095 | fprintf(stderr, "qemu: too many parallel ports\n"); | |
2096 | exit(1); | |
2097 | } | |
2098 | snprintf(label, sizeof(label), "parallel%d", index); | |
27143a44 | 2099 | parallel_hds[index] = qemu_chr_new(label, devname, NULL); |
6a5e8b0e | 2100 | if (!parallel_hds[index]) { |
52d06136 PM |
2101 | fprintf(stderr, "qemu: could not connect parallel device" |
2102 | " to character backend '%s'\n", devname); | |
6a5e8b0e GH |
2103 | return -1; |
2104 | } | |
2105 | index++; | |
2106 | return 0; | |
2107 | } | |
2108 | ||
aee1b935 GH |
2109 | static int virtcon_parse(const char *devname) |
2110 | { | |
3329f07b | 2111 | QemuOptsList *device = qemu_find_opts("device"); |
aee1b935 GH |
2112 | static int index = 0; |
2113 | char label[32]; | |
392ecf54 | 2114 | QemuOpts *bus_opts, *dev_opts; |
aee1b935 GH |
2115 | |
2116 | if (strcmp(devname, "none") == 0) | |
2117 | return 0; | |
2118 | if (index == MAX_VIRTIO_CONSOLES) { | |
2119 | fprintf(stderr, "qemu: too many virtio consoles\n"); | |
2120 | exit(1); | |
2121 | } | |
392ecf54 | 2122 | |
8be7e7e4 | 2123 | bus_opts = qemu_opts_create(device, NULL, 0, NULL); |
e87f7fc6 AL |
2124 | if (arch_type == QEMU_ARCH_S390X) { |
2125 | qemu_opt_set(bus_opts, "driver", "virtio-serial-s390"); | |
2126 | } else { | |
2127 | qemu_opt_set(bus_opts, "driver", "virtio-serial-pci"); | |
2128 | } | |
392ecf54 | 2129 | |
8be7e7e4 | 2130 | dev_opts = qemu_opts_create(device, NULL, 0, NULL); |
392ecf54 AS |
2131 | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
2132 | ||
aee1b935 | 2133 | snprintf(label, sizeof(label), "virtcon%d", index); |
27143a44 | 2134 | virtcon_hds[index] = qemu_chr_new(label, devname, NULL); |
aee1b935 | 2135 | if (!virtcon_hds[index]) { |
52d06136 PM |
2136 | fprintf(stderr, "qemu: could not connect virtio console" |
2137 | " to character backend '%s'\n", devname); | |
aee1b935 GH |
2138 | return -1; |
2139 | } | |
392ecf54 AS |
2140 | qemu_opt_set(dev_opts, "chardev", label); |
2141 | ||
aee1b935 GH |
2142 | index++; |
2143 | return 0; | |
2144 | } | |
2145 | ||
c9f398e5 PA |
2146 | static int debugcon_parse(const char *devname) |
2147 | { | |
2148 | QemuOpts *opts; | |
2149 | ||
27143a44 | 2150 | if (!qemu_chr_new("debugcon", devname, NULL)) { |
c9f398e5 PA |
2151 | exit(1); |
2152 | } | |
8be7e7e4 | 2153 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL); |
c9f398e5 PA |
2154 | if (!opts) { |
2155 | fprintf(stderr, "qemu: already have a debugcon device\n"); | |
2156 | exit(1); | |
2157 | } | |
2158 | qemu_opt_set(opts, "driver", "isa-debugcon"); | |
2159 | qemu_opt_set(opts, "chardev", "debugcon"); | |
2160 | return 0; | |
2161 | } | |
2162 | ||
9052ea6b JK |
2163 | static QEMUMachine *machine_parse(const char *name) |
2164 | { | |
2165 | QEMUMachine *m, *machine = NULL; | |
2166 | ||
2167 | if (name) { | |
2168 | machine = find_machine(name); | |
2169 | } | |
2170 | if (machine) { | |
2171 | return machine; | |
2172 | } | |
2173 | printf("Supported machines are:\n"); | |
2174 | for (m = first_machine; m != NULL; m = m->next) { | |
2175 | if (m->alias) { | |
3b26486a | 2176 | printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name); |
9052ea6b | 2177 | } |
3b26486a | 2178 | printf("%-20s %s%s\n", m->name, m->desc, |
9052ea6b JK |
2179 | m->is_default ? " (default)" : ""); |
2180 | } | |
c8057f95 | 2181 | exit(!name || !is_help_option(name)); |
9052ea6b JK |
2182 | } |
2183 | ||
303d4e86 AP |
2184 | static int tcg_init(void) |
2185 | { | |
d5ab9713 | 2186 | tcg_exec_init(tcg_tb_size * 1024 * 1024); |
303d4e86 AP |
2187 | return 0; |
2188 | } | |
2189 | ||
2190 | static struct { | |
2191 | const char *opt_name; | |
2192 | const char *name; | |
2193 | int (*available)(void); | |
2194 | int (*init)(void); | |
2195 | int *allowed; | |
2196 | } accel_list[] = { | |
2197 | { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, | |
3285cf4f | 2198 | { "xen", "Xen", xen_available, xen_init, &xen_allowed }, |
303d4e86 | 2199 | { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, |
c7f0f3b1 | 2200 | { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed }, |
303d4e86 AP |
2201 | }; |
2202 | ||
2203 | static int configure_accelerator(void) | |
2204 | { | |
2205 | const char *p = NULL; | |
2206 | char buf[10]; | |
2207 | int i, ret; | |
1b785a97 | 2208 | bool accel_initialised = 0; |
303d4e86 AP |
2209 | bool init_failed = 0; |
2210 | ||
2211 | QemuOptsList *list = qemu_find_opts("machine"); | |
2212 | if (!QTAILQ_EMPTY(&list->head)) { | |
2213 | p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel"); | |
2214 | } | |
2215 | ||
2216 | if (p == NULL) { | |
2217 | /* Use the default "accelerator", tcg */ | |
2218 | p = "tcg"; | |
2219 | } | |
2220 | ||
1b785a97 | 2221 | while (!accel_initialised && *p != '\0') { |
303d4e86 AP |
2222 | if (*p == ':') { |
2223 | p++; | |
2224 | } | |
2225 | p = get_opt_name(buf, sizeof (buf), p, ':'); | |
2226 | for (i = 0; i < ARRAY_SIZE(accel_list); i++) { | |
2227 | if (strcmp(accel_list[i].opt_name, buf) == 0) { | |
a16c53b1 | 2228 | *(accel_list[i].allowed) = 1; |
303d4e86 AP |
2229 | ret = accel_list[i].init(); |
2230 | if (ret < 0) { | |
2231 | init_failed = 1; | |
2232 | if (!accel_list[i].available()) { | |
2233 | printf("%s not supported for this target\n", | |
2234 | accel_list[i].name); | |
2235 | } else { | |
2236 | fprintf(stderr, "failed to initialize %s: %s\n", | |
2237 | accel_list[i].name, | |
2238 | strerror(-ret)); | |
2239 | } | |
a16c53b1 | 2240 | *(accel_list[i].allowed) = 0; |
303d4e86 | 2241 | } else { |
1b785a97 | 2242 | accel_initialised = 1; |
303d4e86 AP |
2243 | } |
2244 | break; | |
2245 | } | |
2246 | } | |
2247 | if (i == ARRAY_SIZE(accel_list)) { | |
2248 | fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); | |
2249 | } | |
2250 | } | |
2251 | ||
1b785a97 | 2252 | if (!accel_initialised) { |
303d4e86 AP |
2253 | fprintf(stderr, "No accelerator found!\n"); |
2254 | exit(1); | |
2255 | } | |
2256 | ||
2257 | if (init_failed) { | |
2258 | fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); | |
2259 | } | |
2260 | ||
1b785a97 | 2261 | return !accel_initialised; |
303d4e86 AP |
2262 | } |
2263 | ||
fd42deeb GH |
2264 | void qemu_add_exit_notifier(Notifier *notify) |
2265 | { | |
2266 | notifier_list_add(&exit_notifiers, notify); | |
2267 | } | |
2268 | ||
2269 | void qemu_remove_exit_notifier(Notifier *notify) | |
2270 | { | |
31552529 | 2271 | notifier_remove(notify); |
fd42deeb GH |
2272 | } |
2273 | ||
2274 | static void qemu_run_exit_notifiers(void) | |
2275 | { | |
9e8dd451 | 2276 | notifier_list_notify(&exit_notifiers, NULL); |
fd42deeb GH |
2277 | } |
2278 | ||
4cab946a GN |
2279 | void qemu_add_machine_init_done_notifier(Notifier *notify) |
2280 | { | |
2281 | notifier_list_add(&machine_init_done_notifiers, notify); | |
2282 | } | |
2283 | ||
2284 | static void qemu_run_machine_init_done_notifiers(void) | |
2285 | { | |
9e8dd451 | 2286 | notifier_list_notify(&machine_init_done_notifiers, NULL); |
4cab946a GN |
2287 | } |
2288 | ||
6530a97b AL |
2289 | static const QEMUOption *lookup_opt(int argc, char **argv, |
2290 | const char **poptarg, int *poptind) | |
2291 | { | |
2292 | const QEMUOption *popt; | |
2293 | int optind = *poptind; | |
2294 | char *r = argv[optind]; | |
2295 | const char *optarg; | |
2296 | ||
0f0bc3f1 | 2297 | loc_set_cmdline(argv, optind, 1); |
6530a97b AL |
2298 | optind++; |
2299 | /* Treat --foo the same as -foo. */ | |
2300 | if (r[1] == '-') | |
2301 | r++; | |
2302 | popt = qemu_options; | |
2303 | for(;;) { | |
2304 | if (!popt->name) { | |
0f0bc3f1 | 2305 | error_report("invalid option"); |
6530a97b AL |
2306 | exit(1); |
2307 | } | |
2308 | if (!strcmp(popt->name, r + 1)) | |
2309 | break; | |
2310 | popt++; | |
2311 | } | |
2312 | if (popt->flags & HAS_ARG) { | |
2313 | if (optind >= argc) { | |
0f0bc3f1 | 2314 | error_report("requires an argument"); |
6530a97b AL |
2315 | exit(1); |
2316 | } | |
2317 | optarg = argv[optind++]; | |
0f0bc3f1 | 2318 | loc_set_cmdline(argv, optind - 2, 2); |
6530a97b AL |
2319 | } else { |
2320 | optarg = NULL; | |
2321 | } | |
2322 | ||
2323 | *poptarg = optarg; | |
2324 | *poptind = optind; | |
2325 | ||
2326 | return popt; | |
2327 | } | |
2328 | ||
0750112a AL |
2329 | static gpointer malloc_and_trace(gsize n_bytes) |
2330 | { | |
2331 | void *ptr = malloc(n_bytes); | |
a74cd8cc | 2332 | trace_g_malloc(n_bytes, ptr); |
0750112a AL |
2333 | return ptr; |
2334 | } | |
2335 | ||
2336 | static gpointer realloc_and_trace(gpointer mem, gsize n_bytes) | |
2337 | { | |
2338 | void *ptr = realloc(mem, n_bytes); | |
a74cd8cc | 2339 | trace_g_realloc(mem, n_bytes, ptr); |
0750112a AL |
2340 | return ptr; |
2341 | } | |
2342 | ||
2343 | static void free_and_trace(gpointer mem) | |
2344 | { | |
a74cd8cc | 2345 | trace_g_free(mem); |
0750112a AL |
2346 | free(mem); |
2347 | } | |
2348 | ||
d34e8f6e MR |
2349 | int qemu_init_main_loop(void) |
2350 | { | |
2351 | return main_loop_init(); | |
2352 | } | |
2353 | ||
902b3d5c | 2354 | int main(int argc, char **argv, char **envp) |
0824d6fc | 2355 | { |
e4bcb14c | 2356 | int i; |
da1fcfda | 2357 | int snapshot, linux_boot; |
4e3de9e9 | 2358 | const char *icount_option = NULL; |
7f7f9873 | 2359 | const char *initrd_filename; |
a20dd508 | 2360 | const char *kernel_filename, *kernel_cmdline; |
195325a4 | 2361 | char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ |
3023f332 | 2362 | DisplayState *ds; |
7d957bd8 | 2363 | DisplayChangeListener *dcl; |
9f227bc3 | 2364 | int cyls, heads, secs, translation; |
2365 | QemuOpts *hda_opts = NULL, *opts, *machine_opts; | |
03b0ba70 | 2366 | QemuOptsList *olist; |
cd6f1169 | 2367 | int optind; |
6530a97b | 2368 | const char *optarg; |
d63d307f | 2369 | const char *loadvm = NULL; |
cc1daa40 | 2370 | QEMUMachine *machine; |
94fc95cd | 2371 | const char *cpu_model; |
7f1b17f2 | 2372 | const char *vga_model = "none"; |
93815bc2 | 2373 | const char *pid_file = NULL; |
5bb7910a | 2374 | const char *incoming = NULL; |
821601ea | 2375 | #ifdef CONFIG_VNC |
993fbfdb | 2376 | int show_vnc_port = 0; |
821601ea | 2377 | #endif |
3ed2d9ee | 2378 | bool defconfig = true; |
f29a5614 | 2379 | bool userconfig = true; |
c235d738 MF |
2380 | const char *log_mask = NULL; |
2381 | const char *log_file = NULL; | |
0750112a AL |
2382 | GMemVTable mem_trace = { |
2383 | .malloc = malloc_and_trace, | |
2384 | .realloc = realloc_and_trace, | |
2385 | .free = free_and_trace, | |
2386 | }; | |
23d15e86 | 2387 | const char *trace_events = NULL; |
e4858974 | 2388 | const char *trace_file = NULL; |
0b5538c3 | 2389 | |
fd42deeb | 2390 | atexit(qemu_run_exit_notifiers); |
65abca0a MA |
2391 | error_set_progname(argv[0]); |
2392 | ||
0750112a | 2393 | g_mem_set_vtable(&mem_trace); |
db529aab | 2394 | if (!g_thread_supported()) { |
42ed3727 | 2395 | #if !GLIB_CHECK_VERSION(2, 31, 0) |
db529aab | 2396 | g_thread_init(NULL); |
42ed3727 AL |
2397 | #else |
2398 | fprintf(stderr, "glib threading failed to initialize.\n"); | |
2399 | exit(1); | |
2400 | #endif | |
db529aab | 2401 | } |
0750112a | 2402 | |
1b71f7c1 AF |
2403 | module_call_init(MODULE_INIT_QOM); |
2404 | ||
5db9d4d1 LC |
2405 | runstate_init(); |
2406 | ||
6875204c | 2407 | init_clocks(); |
2ff68d07 | 2408 | rtc_clock = host_clock; |
6875204c | 2409 | |
902b3d5c | 2410 | qemu_cache_utils_init(envp); |
2411 | ||
72cf2d4f | 2412 | QLIST_INIT (&vm_change_state_head); |
fe98ac14 | 2413 | os_setup_early_signal_handling(); |
be995c27 | 2414 | |
f80f9ec9 | 2415 | module_call_init(MODULE_INIT_MACHINE); |
0c257437 | 2416 | machine = find_default_machine(); |
94fc95cd | 2417 | cpu_model = NULL; |
4fc5d071 | 2418 | ram_size = 0; |
33e3963e | 2419 | snapshot = 0; |
9f227bc3 | 2420 | cyls = heads = secs = 0; |
2421 | translation = BIOS_ATA_TRANSLATION_AUTO; | |
c4b1fcc0 | 2422 | |
268a362c AL |
2423 | for (i = 0; i < MAX_NODES; i++) { |
2424 | node_mem[i] = 0; | |
ee785fed | 2425 | node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS); |
268a362c AL |
2426 | } |
2427 | ||
268a362c | 2428 | nb_numa_nodes = 0; |
7c9d8e07 | 2429 | nb_nics = 0; |
3b46e624 | 2430 | |
41bd639b BS |
2431 | autostart= 1; |
2432 | ||
292444cb AL |
2433 | /* first pass of option parsing */ |
2434 | optind = 1; | |
2435 | while (optind < argc) { | |
2436 | if (argv[optind][0] != '-') { | |
2437 | /* disk image */ | |
28e68d68 | 2438 | optind++; |
292444cb AL |
2439 | continue; |
2440 | } else { | |
2441 | const QEMUOption *popt; | |
2442 | ||
2443 | popt = lookup_opt(argc, argv, &optarg, &optind); | |
2444 | switch (popt->index) { | |
2445 | case QEMU_OPTION_nodefconfig: | |
3ed2d9ee | 2446 | defconfig = false; |
292444cb | 2447 | break; |
f29a5614 EH |
2448 | case QEMU_OPTION_nouserconfig: |
2449 | userconfig = false; | |
2450 | break; | |
292444cb AL |
2451 | } |
2452 | } | |
2453 | } | |
2454 | ||
2455 | if (defconfig) { | |
dcfb0939 | 2456 | int ret; |
f29a5614 | 2457 | ret = qemu_read_default_config_files(userconfig); |
b5a8fe5e | 2458 | if (ret < 0) { |
dcfb0939 | 2459 | exit(1); |
292444cb AL |
2460 | } |
2461 | } | |
2462 | ||
2463 | /* second pass of option parsing */ | |
cd6f1169 | 2464 | optind = 1; |
0824d6fc | 2465 | for(;;) { |
cd6f1169 | 2466 | if (optind >= argc) |
0824d6fc | 2467 | break; |
6530a97b | 2468 | if (argv[optind][0] != '-') { |
9f227bc3 | 2469 | hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
cd6f1169 FB |
2470 | } else { |
2471 | const QEMUOption *popt; | |
2472 | ||
6530a97b | 2473 | popt = lookup_opt(argc, argv, &optarg, &optind); |
ad96090a BS |
2474 | if (!(popt->arch_mask & arch_type)) { |
2475 | printf("Option %s not supported for this target\n", popt->name); | |
2476 | exit(1); | |
2477 | } | |
cd6f1169 | 2478 | switch(popt->index) { |
cc1daa40 | 2479 | case QEMU_OPTION_M: |
9052ea6b | 2480 | machine = machine_parse(optarg); |
cc1daa40 | 2481 | break; |
94fc95cd JM |
2482 | case QEMU_OPTION_cpu: |
2483 | /* hw initialization will check this */ | |
ecf40bea | 2484 | cpu_model = optarg; |
94fc95cd | 2485 | break; |
cd6f1169 | 2486 | case QEMU_OPTION_hda: |
9f227bc3 | 2487 | { |
2488 | char buf[256]; | |
2489 | if (cyls == 0) | |
2490 | snprintf(buf, sizeof(buf), "%s", HD_OPTS); | |
2491 | else | |
2492 | snprintf(buf, sizeof(buf), | |
2493 | "%s,cyls=%d,heads=%d,secs=%d%s", | |
2494 | HD_OPTS , cyls, heads, secs, | |
2495 | translation == BIOS_ATA_TRANSLATION_LBA ? | |
2496 | ",trans=lba" : | |
2497 | translation == BIOS_ATA_TRANSLATION_NONE ? | |
2498 | ",trans=none" : ""); | |
2499 | drive_add(IF_DEFAULT, 0, optarg, buf); | |
2500 | break; | |
2501 | } | |
cd6f1169 | 2502 | case QEMU_OPTION_hdb: |
cc1daa40 FB |
2503 | case QEMU_OPTION_hdc: |
2504 | case QEMU_OPTION_hdd: | |
2292ddae MA |
2505 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
2506 | HD_OPTS); | |
fc01f7e7 | 2507 | break; |
e4bcb14c | 2508 | case QEMU_OPTION_drive: |
e2982c3a MT |
2509 | if (drive_def(optarg) == NULL) { |
2510 | exit(1); | |
2511 | } | |
e4bcb14c | 2512 | break; |
d058fe03 GH |
2513 | case QEMU_OPTION_set: |
2514 | if (qemu_set_option(optarg) != 0) | |
2515 | exit(1); | |
2516 | break; | |
d0fef6fb GH |
2517 | case QEMU_OPTION_global: |
2518 | if (qemu_global_option(optarg) != 0) | |
2519 | exit(1); | |
2520 | break; | |
3e3d5815 | 2521 | case QEMU_OPTION_mtdblock: |
2292ddae | 2522 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
3e3d5815 | 2523 | break; |
a1bb27b1 | 2524 | case QEMU_OPTION_sd: |
2292ddae | 2525 | drive_add(IF_SD, 0, optarg, SD_OPTS); |
a1bb27b1 | 2526 | break; |
86f55663 | 2527 | case QEMU_OPTION_pflash: |
2292ddae | 2528 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
86f55663 | 2529 | break; |
cd6f1169 | 2530 | case QEMU_OPTION_snapshot: |
33e3963e FB |
2531 | snapshot = 1; |
2532 | break; | |
cd6f1169 | 2533 | case QEMU_OPTION_hdachs: |
330d0414 | 2534 | { |
330d0414 FB |
2535 | const char *p; |
2536 | p = optarg; | |
2537 | cyls = strtol(p, (char **)&p, 0); | |
46d4767d FB |
2538 | if (cyls < 1 || cyls > 16383) |
2539 | goto chs_fail; | |
330d0414 FB |
2540 | if (*p != ',') |
2541 | goto chs_fail; | |
2542 | p++; | |
2543 | heads = strtol(p, (char **)&p, 0); | |
46d4767d FB |
2544 | if (heads < 1 || heads > 16) |
2545 | goto chs_fail; | |
330d0414 FB |
2546 | if (*p != ',') |
2547 | goto chs_fail; | |
2548 | p++; | |
2549 | secs = strtol(p, (char **)&p, 0); | |
46d4767d FB |
2550 | if (secs < 1 || secs > 63) |
2551 | goto chs_fail; | |
2552 | if (*p == ',') { | |
2553 | p++; | |
2554 | if (!strcmp(p, "none")) | |
2555 | translation = BIOS_ATA_TRANSLATION_NONE; | |
2556 | else if (!strcmp(p, "lba")) | |
2557 | translation = BIOS_ATA_TRANSLATION_LBA; | |
2558 | else if (!strcmp(p, "auto")) | |
2559 | translation = BIOS_ATA_TRANSLATION_AUTO; | |
2560 | else | |
2561 | goto chs_fail; | |
2562 | } else if (*p != '\0') { | |
c4b1fcc0 | 2563 | chs_fail: |
46d4767d FB |
2564 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
2565 | exit(1); | |
c4b1fcc0 | 2566 | } |
9f227bc3 | 2567 | if (hda_opts != NULL) { |
9dfd7c7a GH |
2568 | char num[16]; |
2569 | snprintf(num, sizeof(num), "%d", cyls); | |
2570 | qemu_opt_set(hda_opts, "cyls", num); | |
2571 | snprintf(num, sizeof(num), "%d", heads); | |
2572 | qemu_opt_set(hda_opts, "heads", num); | |
2573 | snprintf(num, sizeof(num), "%d", secs); | |
2574 | qemu_opt_set(hda_opts, "secs", num); | |
2575 | if (translation == BIOS_ATA_TRANSLATION_LBA) | |
2576 | qemu_opt_set(hda_opts, "trans", "lba"); | |
2577 | if (translation == BIOS_ATA_TRANSLATION_NONE) | |
2578 | qemu_opt_set(hda_opts, "trans", "none"); | |
2579 | } | |
330d0414 FB |
2580 | } |
2581 | break; | |
268a362c AL |
2582 | case QEMU_OPTION_numa: |
2583 | if (nb_numa_nodes >= MAX_NODES) { | |
2584 | fprintf(stderr, "qemu: too many NUMA nodes\n"); | |
2585 | exit(1); | |
2586 | } | |
2587 | numa_add(optarg); | |
2588 | break; | |
1472a95b JS |
2589 | case QEMU_OPTION_display: |
2590 | display_type = select_display(optarg); | |
2591 | break; | |
cd6f1169 | 2592 | case QEMU_OPTION_nographic: |
993fbfdb | 2593 | display_type = DT_NOGRAPHIC; |
a20dd508 | 2594 | break; |
4d3b6f6e | 2595 | case QEMU_OPTION_curses: |
47b05369 | 2596 | #ifdef CONFIG_CURSES |
993fbfdb | 2597 | display_type = DT_CURSES; |
47b05369 JS |
2598 | #else |
2599 | fprintf(stderr, "Curses support is disabled\n"); | |
2600 | exit(1); | |
4d3b6f6e | 2601 | #endif |
47b05369 | 2602 | break; |
a171fe39 | 2603 | case QEMU_OPTION_portrait: |
9312805d VK |
2604 | graphic_rotate = 90; |
2605 | break; | |
2606 | case QEMU_OPTION_rotate: | |
2607 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); | |
2608 | if (graphic_rotate != 0 && graphic_rotate != 90 && | |
2609 | graphic_rotate != 180 && graphic_rotate != 270) { | |
2610 | fprintf(stderr, | |
2611 | "qemu: only 90, 180, 270 deg rotation is available\n"); | |
2612 | exit(1); | |
2613 | } | |
a171fe39 | 2614 | break; |
cd6f1169 | 2615 | case QEMU_OPTION_kernel: |
a0abe474 PM |
2616 | qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg); |
2617 | break; | |
2618 | case QEMU_OPTION_initrd: | |
2619 | qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg); | |
a20dd508 | 2620 | break; |
cd6f1169 | 2621 | case QEMU_OPTION_append: |
a0abe474 | 2622 | qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg); |
313aa567 | 2623 | break; |
412beee6 GL |
2624 | case QEMU_OPTION_dtb: |
2625 | qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg); | |
2626 | break; | |
cd6f1169 | 2627 | case QEMU_OPTION_cdrom: |
2292ddae | 2628 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
36b486bb | 2629 | break; |
cd6f1169 | 2630 | case QEMU_OPTION_boot: |
28c5af54 | 2631 | { |
ef3adf68 | 2632 | static const char * const params[] = { |
3d3b8303 | 2633 | "order", "once", "menu", |
ac05f349 AK |
2634 | "splash", "splash-time", |
2635 | "reboot-timeout", NULL | |
ef3adf68 JK |
2636 | }; |
2637 | char buf[sizeof(boot_devices)]; | |
e0f084bf | 2638 | char *standard_boot_devices; |
ef3adf68 JK |
2639 | int legacy = 0; |
2640 | ||
2641 | if (!strchr(optarg, '=')) { | |
2642 | legacy = 1; | |
2643 | pstrcpy(buf, sizeof(buf), optarg); | |
2644 | } else if (check_params(buf, sizeof(buf), params, optarg) < 0) { | |
2645 | fprintf(stderr, | |
2646 | "qemu: unknown boot parameter '%s' in '%s'\n", | |
2647 | buf, optarg); | |
2648 | exit(1); | |
2649 | } | |
2650 | ||
2651 | if (legacy || | |
2652 | get_param_value(buf, sizeof(buf), "order", optarg)) { | |
4e9e9d6e | 2653 | validate_bootdevices(buf); |
ef3adf68 | 2654 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
28c5af54 | 2655 | } |
e0f084bf JK |
2656 | if (!legacy) { |
2657 | if (get_param_value(buf, sizeof(buf), | |
2658 | "once", optarg)) { | |
4e9e9d6e | 2659 | validate_bootdevices(buf); |
7267c094 | 2660 | standard_boot_devices = g_strdup(boot_devices); |
e0f084bf JK |
2661 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
2662 | qemu_register_reset(restore_boot_devices, | |
2663 | standard_boot_devices); | |
2664 | } | |
95387491 JK |
2665 | if (get_param_value(buf, sizeof(buf), |
2666 | "menu", optarg)) { | |
2667 | if (!strcmp(buf, "on")) { | |
2668 | boot_menu = 1; | |
2669 | } else if (!strcmp(buf, "off")) { | |
2670 | boot_menu = 0; | |
2671 | } else { | |
2672 | fprintf(stderr, | |
2673 | "qemu: invalid option value '%s'\n", | |
2674 | buf); | |
2675 | exit(1); | |
2676 | } | |
2677 | } | |
3d3b8303 | 2678 | qemu_opts_parse(qemu_find_opts("boot-opts"), |
2679 | optarg, 0); | |
e0f084bf | 2680 | } |
36b486bb FB |
2681 | } |
2682 | break; | |
cd6f1169 | 2683 | case QEMU_OPTION_fda: |
cd6f1169 | 2684 | case QEMU_OPTION_fdb: |
2292ddae MA |
2685 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
2686 | optarg, FD_OPTS); | |
c45886db | 2687 | break; |
52ca8d6a FB |
2688 | case QEMU_OPTION_no_fd_bootchk: |
2689 | fd_bootchk = 0; | |
2690 | break; | |
a1ea458f | 2691 | case QEMU_OPTION_netdev: |
3329f07b | 2692 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
a1ea458f MM |
2693 | exit(1); |
2694 | } | |
2695 | break; | |
7c9d8e07 | 2696 | case QEMU_OPTION_net: |
3329f07b | 2697 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
c4b1fcc0 FB |
2698 | exit(1); |
2699 | } | |
702c651c | 2700 | break; |
f9dadc98 RS |
2701 | #ifdef CONFIG_LIBISCSI |
2702 | case QEMU_OPTION_iscsi: | |
2703 | opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0); | |
2704 | if (!opts) { | |
2705 | exit(1); | |
2706 | } | |
2707 | break; | |
2708 | #endif | |
c7f74643 FB |
2709 | #ifdef CONFIG_SLIRP |
2710 | case QEMU_OPTION_tftp: | |
ad196a9d | 2711 | legacy_tftp_prefix = optarg; |
9bf05444 | 2712 | break; |
47d5d01a | 2713 | case QEMU_OPTION_bootp: |
ad196a9d | 2714 | legacy_bootp_filename = optarg; |
47d5d01a | 2715 | break; |
9bf05444 | 2716 | case QEMU_OPTION_redir: |
0752706d MA |
2717 | if (net_slirp_redir(optarg) < 0) |
2718 | exit(1); | |
9bf05444 | 2719 | break; |
c7f74643 | 2720 | #endif |
dc72ac14 | 2721 | case QEMU_OPTION_bt: |
bd3c948d | 2722 | add_device_config(DEV_BT, optarg); |
dc72ac14 | 2723 | break; |
1d14ffa9 | 2724 | case QEMU_OPTION_audio_help: |
ad96090a BS |
2725 | if (!(audio_available())) { |
2726 | printf("Option %s not supported for this target\n", popt->name); | |
2727 | exit(1); | |
2728 | } | |
1d14ffa9 FB |
2729 | AUD_help (); |
2730 | exit (0); | |
2731 | break; | |
2732 | case QEMU_OPTION_soundhw: | |
ad96090a BS |
2733 | if (!(audio_available())) { |
2734 | printf("Option %s not supported for this target\n", popt->name); | |
2735 | exit(1); | |
2736 | } | |
1d14ffa9 FB |
2737 | select_soundhw (optarg); |
2738 | break; | |
cd6f1169 | 2739 | case QEMU_OPTION_h: |
15f82208 | 2740 | help(0); |
cd6f1169 | 2741 | break; |
9bd7e6d9 PB |
2742 | case QEMU_OPTION_version: |
2743 | version(); | |
2744 | exit(0); | |
2745 | break; | |
00f82b8a | 2746 | case QEMU_OPTION_m: { |
70b4f4bb | 2747 | int64_t value; |
ff961015 | 2748 | uint64_t sz; |
961b42b9 | 2749 | char *end; |
9f9b17a4 | 2750 | |
961b42b9 MA |
2751 | value = strtosz(optarg, &end); |
2752 | if (value < 0 || *end) { | |
00f82b8a | 2753 | fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); |
cd6f1169 FB |
2754 | exit(1); |
2755 | } | |
ff961015 MA |
2756 | sz = QEMU_ALIGN_UP((uint64_t)value, 8192); |
2757 | ram_size = sz; | |
2758 | if (ram_size != sz) { | |
00f82b8a AJ |
2759 | fprintf(stderr, "qemu: ram size too large\n"); |
2760 | exit(1); | |
2761 | } | |
cd6f1169 | 2762 | break; |
00f82b8a | 2763 | } |
c902760f MT |
2764 | case QEMU_OPTION_mempath: |
2765 | mem_path = optarg; | |
2766 | break; | |
2767 | #ifdef MAP_POPULATE | |
2768 | case QEMU_OPTION_mem_prealloc: | |
2769 | mem_prealloc = 1; | |
2770 | break; | |
2771 | #endif | |
cd6f1169 | 2772 | case QEMU_OPTION_d: |
c235d738 MF |
2773 | log_mask = optarg; |
2774 | break; | |
2775 | case QEMU_OPTION_D: | |
2776 | log_file = optarg; | |
cd6f1169 | 2777 | break; |
cd6f1169 | 2778 | case QEMU_OPTION_s: |
ef0c4a0d | 2779 | add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); |
cd6f1169 | 2780 | break; |
59030a8c | 2781 | case QEMU_OPTION_gdb: |
ef0c4a0d | 2782 | add_device_config(DEV_GDB, optarg); |
cd6f1169 | 2783 | break; |
cd6f1169 | 2784 | case QEMU_OPTION_L: |
5cea8590 | 2785 | data_dir = optarg; |
cd6f1169 | 2786 | break; |
1192dad8 JM |
2787 | case QEMU_OPTION_bios: |
2788 | bios_name = optarg; | |
2789 | break; | |
1b530a6d AJ |
2790 | case QEMU_OPTION_singlestep: |
2791 | singlestep = 1; | |
2792 | break; | |
cd6f1169 | 2793 | case QEMU_OPTION_S: |
3c07f8e8 | 2794 | autostart = 0; |
cd6f1169 | 2795 | break; |
3d11d0eb FB |
2796 | case QEMU_OPTION_k: |
2797 | keyboard_layout = optarg; | |
2798 | break; | |
ee22c2f7 FB |
2799 | case QEMU_OPTION_localtime: |
2800 | rtc_utc = 0; | |
2801 | break; | |
3893c124 | 2802 | case QEMU_OPTION_vga: |
a369da5f | 2803 | vga_model = optarg; |
7f1b17f2 | 2804 | default_vga = 0; |
1bfe856e | 2805 | break; |
e9b137c2 FB |
2806 | case QEMU_OPTION_g: |
2807 | { | |
2808 | const char *p; | |
2809 | int w, h, depth; | |
2810 | p = optarg; | |
2811 | w = strtol(p, (char **)&p, 10); | |
2812 | if (w <= 0) { | |
2813 | graphic_error: | |
2814 | fprintf(stderr, "qemu: invalid resolution or depth\n"); | |
2815 | exit(1); | |
2816 | } | |
2817 | if (*p != 'x') | |
2818 | goto graphic_error; | |
2819 | p++; | |
2820 | h = strtol(p, (char **)&p, 10); | |
2821 | if (h <= 0) | |
2822 | goto graphic_error; | |
2823 | if (*p == 'x') { | |
2824 | p++; | |
2825 | depth = strtol(p, (char **)&p, 10); | |
5fafdf24 | 2826 | if (depth != 8 && depth != 15 && depth != 16 && |
e9b137c2 FB |
2827 | depth != 24 && depth != 32) |
2828 | goto graphic_error; | |
2829 | } else if (*p == '\0') { | |
2830 | depth = graphic_depth; | |
2831 | } else { | |
2832 | goto graphic_error; | |
2833 | } | |
3b46e624 | 2834 | |
e9b137c2 FB |
2835 | graphic_width = w; |
2836 | graphic_height = h; | |
2837 | graphic_depth = depth; | |
2838 | } | |
2839 | break; | |
20d8a3ed TS |
2840 | case QEMU_OPTION_echr: |
2841 | { | |
2842 | char *r; | |
2843 | term_escape_char = strtol(optarg, &r, 0); | |
2844 | if (r == optarg) | |
2845 | printf("Bad argument to echr\n"); | |
2846 | break; | |
2847 | } | |
82c643ff | 2848 | case QEMU_OPTION_monitor: |
6ca5582d GH |
2849 | monitor_parse(optarg, "readline"); |
2850 | default_monitor = 0; | |
2851 | break; | |
2852 | case QEMU_OPTION_qmp: | |
2853 | monitor_parse(optarg, "control"); | |
2d114dc1 | 2854 | default_monitor = 0; |
82c643ff | 2855 | break; |
22a0e04b | 2856 | case QEMU_OPTION_mon: |
3329f07b | 2857 | opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); |
22a0e04b | 2858 | if (!opts) { |
22a0e04b GH |
2859 | exit(1); |
2860 | } | |
2d114dc1 | 2861 | default_monitor = 0; |
22a0e04b | 2862 | break; |
191bc01b | 2863 | case QEMU_OPTION_chardev: |
3329f07b | 2864 | opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); |
191bc01b | 2865 | if (!opts) { |
191bc01b GH |
2866 | exit(1); |
2867 | } | |
191bc01b | 2868 | break; |
74db920c | 2869 | case QEMU_OPTION_fsdev: |
03b0ba70 GH |
2870 | olist = qemu_find_opts("fsdev"); |
2871 | if (!olist) { | |
2872 | fprintf(stderr, "fsdev is not supported by this qemu build.\n"); | |
2873 | exit(1); | |
2874 | } | |
2875 | opts = qemu_opts_parse(olist, optarg, 1); | |
74db920c GS |
2876 | if (!opts) { |
2877 | fprintf(stderr, "parse error: %s\n", optarg); | |
2878 | exit(1); | |
2879 | } | |
2880 | break; | |
3d54abc7 | 2881 | case QEMU_OPTION_virtfs: { |
e14ea479 SH |
2882 | QemuOpts *fsdev; |
2883 | QemuOpts *device; | |
84a87cc4 | 2884 | const char *writeout, *sock_fd, *socket; |
3d54abc7 | 2885 | |
03b0ba70 GH |
2886 | olist = qemu_find_opts("virtfs"); |
2887 | if (!olist) { | |
2888 | fprintf(stderr, "virtfs is not supported by this qemu build.\n"); | |
2889 | exit(1); | |
2890 | } | |
2891 | opts = qemu_opts_parse(olist, optarg, 1); | |
3d54abc7 GS |
2892 | if (!opts) { |
2893 | fprintf(stderr, "parse error: %s\n", optarg); | |
2894 | exit(1); | |
2895 | } | |
2896 | ||
fbcbf101 | 2897 | if (qemu_opt_get(opts, "fsdriver") == NULL || |
99519f0a AK |
2898 | qemu_opt_get(opts, "mount_tag") == NULL) { |
2899 | fprintf(stderr, "Usage: -virtfs fsdriver,mount_tag=tag.\n"); | |
9ce56db6 VJJ |
2900 | exit(1); |
2901 | } | |
e14ea479 | 2902 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
8be7e7e4 LC |
2903 | qemu_opt_get(opts, "mount_tag"), |
2904 | 1, NULL); | |
e14ea479 SH |
2905 | if (!fsdev) { |
2906 | fprintf(stderr, "duplicate fsdev id: %s\n", | |
2907 | qemu_opt_get(opts, "mount_tag")); | |
3d54abc7 GS |
2908 | exit(1); |
2909 | } | |
d3ab98e6 AK |
2910 | |
2911 | writeout = qemu_opt_get(opts, "writeout"); | |
2912 | if (writeout) { | |
2913 | #ifdef CONFIG_SYNC_FILE_RANGE | |
2914 | qemu_opt_set(fsdev, "writeout", writeout); | |
2915 | #else | |
2916 | fprintf(stderr, "writeout=immediate not supported on " | |
2917 | "this platform\n"); | |
2918 | exit(1); | |
2919 | #endif | |
2920 | } | |
fbcbf101 | 2921 | qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver")); |
e14ea479 SH |
2922 | qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); |
2923 | qemu_opt_set(fsdev, "security_model", | |
2924 | qemu_opt_get(opts, "security_model")); | |
84a87cc4 MK |
2925 | socket = qemu_opt_get(opts, "socket"); |
2926 | if (socket) { | |
2927 | qemu_opt_set(fsdev, "socket", socket); | |
2928 | } | |
4c793dda MK |
2929 | sock_fd = qemu_opt_get(opts, "sock_fd"); |
2930 | if (sock_fd) { | |
2931 | qemu_opt_set(fsdev, "sock_fd", sock_fd); | |
2932 | } | |
e14ea479 | 2933 | |
2c74c2cb MK |
2934 | qemu_opt_set_bool(fsdev, "readonly", |
2935 | qemu_opt_get_bool(opts, "readonly", 0)); | |
8be7e7e4 LC |
2936 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
2937 | NULL); | |
e14ea479 SH |
2938 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
2939 | qemu_opt_set(device, "fsdev", | |
2940 | qemu_opt_get(opts, "mount_tag")); | |
2941 | qemu_opt_set(device, "mount_tag", | |
2942 | qemu_opt_get(opts, "mount_tag")); | |
3d54abc7 GS |
2943 | break; |
2944 | } | |
9db221ae AK |
2945 | case QEMU_OPTION_virtfs_synth: { |
2946 | QemuOpts *fsdev; | |
2947 | QemuOpts *device; | |
2948 | ||
8be7e7e4 LC |
2949 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth", |
2950 | 1, NULL); | |
9db221ae AK |
2951 | if (!fsdev) { |
2952 | fprintf(stderr, "duplicate option: %s\n", "virtfs_synth"); | |
2953 | exit(1); | |
2954 | } | |
2955 | qemu_opt_set(fsdev, "fsdriver", "synth"); | |
9db221ae | 2956 | |
8be7e7e4 LC |
2957 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0, |
2958 | NULL); | |
9db221ae AK |
2959 | qemu_opt_set(device, "driver", "virtio-9p-pci"); |
2960 | qemu_opt_set(device, "fsdev", "v_synth"); | |
2961 | qemu_opt_set(device, "mount_tag", "v_synth"); | |
2962 | break; | |
2963 | } | |
82c643ff | 2964 | case QEMU_OPTION_serial: |
998bbd74 GH |
2965 | add_device_config(DEV_SERIAL, optarg); |
2966 | default_serial = 0; | |
18141ed6 JK |
2967 | if (strncmp(optarg, "mon:", 4) == 0) { |
2968 | default_monitor = 0; | |
2969 | } | |
82c643ff | 2970 | break; |
9dd986cc | 2971 | case QEMU_OPTION_watchdog: |
09aaa160 MA |
2972 | if (watchdog) { |
2973 | fprintf(stderr, | |
2974 | "qemu: only one watchdog option may be given\n"); | |
2975 | return 1; | |
2976 | } | |
2977 | watchdog = optarg; | |
9dd986cc RJ |
2978 | break; |
2979 | case QEMU_OPTION_watchdog_action: | |
2980 | if (select_watchdog_action(optarg) == -1) { | |
2981 | fprintf(stderr, "Unknown -watchdog-action parameter\n"); | |
2982 | exit(1); | |
2983 | } | |
2984 | break; | |
51ecf136 | 2985 | case QEMU_OPTION_virtiocon: |
aee1b935 GH |
2986 | add_device_config(DEV_VIRTCON, optarg); |
2987 | default_virtcon = 0; | |
18141ed6 JK |
2988 | if (strncmp(optarg, "mon:", 4) == 0) { |
2989 | default_monitor = 0; | |
2990 | } | |
51ecf136 | 2991 | break; |
6508fe59 | 2992 | case QEMU_OPTION_parallel: |
6a5e8b0e GH |
2993 | add_device_config(DEV_PARALLEL, optarg); |
2994 | default_parallel = 0; | |
18141ed6 JK |
2995 | if (strncmp(optarg, "mon:", 4) == 0) { |
2996 | default_monitor = 0; | |
2997 | } | |
6508fe59 | 2998 | break; |
c9f398e5 PA |
2999 | case QEMU_OPTION_debugcon: |
3000 | add_device_config(DEV_DEBUGCON, optarg); | |
3001 | break; | |
d63d307f FB |
3002 | case QEMU_OPTION_loadvm: |
3003 | loadvm = optarg; | |
3004 | break; | |
3005 | case QEMU_OPTION_full_screen: | |
3006 | full_screen = 1; | |
3007 | break; | |
667accab | 3008 | #ifdef CONFIG_SDL |
43523e93 TS |
3009 | case QEMU_OPTION_no_frame: |
3010 | no_frame = 1; | |
3011 | break; | |
3780e197 TS |
3012 | case QEMU_OPTION_alt_grab: |
3013 | alt_grab = 1; | |
3014 | break; | |
0ca9f8a4 DK |
3015 | case QEMU_OPTION_ctrl_grab: |
3016 | ctrl_grab = 1; | |
3017 | break; | |
667accab TS |
3018 | case QEMU_OPTION_no_quit: |
3019 | no_quit = 1; | |
3020 | break; | |
7d957bd8 | 3021 | case QEMU_OPTION_sdl: |
993fbfdb | 3022 | display_type = DT_SDL; |
7d957bd8 | 3023 | break; |
58fc096c JS |
3024 | #else |
3025 | case QEMU_OPTION_no_frame: | |
3026 | case QEMU_OPTION_alt_grab: | |
3027 | case QEMU_OPTION_ctrl_grab: | |
3028 | case QEMU_OPTION_no_quit: | |
3029 | case QEMU_OPTION_sdl: | |
3030 | fprintf(stderr, "SDL support is disabled\n"); | |
3031 | exit(1); | |
667accab | 3032 | #endif |
f7cce898 | 3033 | case QEMU_OPTION_pidfile: |
93815bc2 | 3034 | pid_file = optarg; |
f7cce898 | 3035 | break; |
a09db21f FB |
3036 | case QEMU_OPTION_win2k_hack: |
3037 | win2k_install_hack = 1; | |
3038 | break; | |
433acf0d JK |
3039 | case QEMU_OPTION_rtc_td_hack: { |
3040 | static GlobalProperty slew_lost_ticks[] = { | |
3041 | { | |
3042 | .driver = "mc146818rtc", | |
3043 | .property = "lost_tick_policy", | |
3044 | .value = "slew", | |
3045 | }, | |
3046 | { /* end of list */ } | |
3047 | }; | |
3048 | ||
3049 | qdev_prop_register_global_list(slew_lost_ticks); | |
73822ec8 | 3050 | break; |
433acf0d | 3051 | } |
8a92ea2f | 3052 | case QEMU_OPTION_acpitable: |
de06f8d1 | 3053 | do_acpitable_option(optarg); |
8a92ea2f | 3054 | break; |
b6f6e3d3 | 3055 | case QEMU_OPTION_smbios: |
de06f8d1 | 3056 | do_smbios_option(optarg); |
b6f6e3d3 | 3057 | break; |
7ba1e619 | 3058 | case QEMU_OPTION_enable_kvm: |
303d4e86 | 3059 | olist = qemu_find_opts("machine"); |
303d4e86 AP |
3060 | qemu_opts_parse(olist, "accel=kvm", 0); |
3061 | break; | |
3062 | case QEMU_OPTION_machine: | |
3063 | olist = qemu_find_opts("machine"); | |
9052ea6b | 3064 | opts = qemu_opts_parse(olist, optarg, 1); |
303d4e86 AP |
3065 | if (!opts) { |
3066 | fprintf(stderr, "parse error: %s\n", optarg); | |
3067 | exit(1); | |
3068 | } | |
2645c6dc JK |
3069 | optarg = qemu_opt_get(opts, "type"); |
3070 | if (optarg) { | |
3071 | machine = machine_parse(optarg); | |
3072 | } | |
7ba1e619 | 3073 | break; |
bb36d470 FB |
3074 | case QEMU_OPTION_usb: |
3075 | usb_enabled = 1; | |
3076 | break; | |
a594cfbf FB |
3077 | case QEMU_OPTION_usbdevice: |
3078 | usb_enabled = 1; | |
bd3c948d GH |
3079 | add_device_config(DEV_USB, optarg); |
3080 | break; | |
3081 | case QEMU_OPTION_device: | |
3329f07b | 3082 | if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { |
f31d07d1 GH |
3083 | exit(1); |
3084 | } | |
a594cfbf | 3085 | break; |
6a00d601 | 3086 | case QEMU_OPTION_smp: |
dc6b1c09 | 3087 | smp_parse(optarg); |
b2097003 | 3088 | if (smp_cpus < 1) { |
6a00d601 FB |
3089 | fprintf(stderr, "Invalid number of CPUs\n"); |
3090 | exit(1); | |
3091 | } | |
6be68d7e JS |
3092 | if (max_cpus < smp_cpus) { |
3093 | fprintf(stderr, "maxcpus must be equal to or greater than " | |
3094 | "smp\n"); | |
3095 | exit(1); | |
3096 | } | |
3097 | if (max_cpus > 255) { | |
3098 | fprintf(stderr, "Unsupported number of maxcpus\n"); | |
3099 | exit(1); | |
3100 | } | |
6a00d601 | 3101 | break; |
24236869 | 3102 | case QEMU_OPTION_vnc: |
821601ea | 3103 | #ifdef CONFIG_VNC |
6b62dc2d | 3104 | display_remote++; |
821601ea JS |
3105 | vnc_display = optarg; |
3106 | #else | |
3107 | fprintf(stderr, "VNC support is disabled\n"); | |
3108 | exit(1); | |
3109 | #endif | |
3110 | break; | |
6515b203 FB |
3111 | case QEMU_OPTION_no_acpi: |
3112 | acpi_enabled = 0; | |
3113 | break; | |
16b29ae1 AL |
3114 | case QEMU_OPTION_no_hpet: |
3115 | no_hpet = 1; | |
3116 | break; | |
7d4c3d53 MA |
3117 | case QEMU_OPTION_balloon: |
3118 | if (balloon_parse(optarg) < 0) { | |
3119 | fprintf(stderr, "Unknown -balloon argument %s\n", optarg); | |
3120 | exit(1); | |
3121 | } | |
df97b920 | 3122 | break; |
d1beab82 FB |
3123 | case QEMU_OPTION_no_reboot: |
3124 | no_reboot = 1; | |
3125 | break; | |
b2f76161 AJ |
3126 | case QEMU_OPTION_no_shutdown: |
3127 | no_shutdown = 1; | |
3128 | break; | |
9467cd46 AZ |
3129 | case QEMU_OPTION_show_cursor: |
3130 | cursor_hide = 0; | |
3131 | break; | |
8fcb1b90 BS |
3132 | case QEMU_OPTION_uuid: |
3133 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { | |
3134 | fprintf(stderr, "Fail to parse UUID string." | |
3135 | " Wrong format.\n"); | |
3136 | exit(1); | |
3137 | } | |
3138 | break; | |
9ae02555 TS |
3139 | case QEMU_OPTION_option_rom: |
3140 | if (nb_option_roms >= MAX_OPTION_ROMS) { | |
3141 | fprintf(stderr, "Too many option ROMs\n"); | |
3142 | exit(1); | |
3143 | } | |
2e55e842 GN |
3144 | opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); |
3145 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); | |
3146 | option_rom[nb_option_roms].bootindex = | |
3147 | qemu_opt_get_number(opts, "bootindex", -1); | |
3148 | if (!option_rom[nb_option_roms].name) { | |
3149 | fprintf(stderr, "Option ROM file is not specified\n"); | |
3150 | exit(1); | |
3151 | } | |
9ae02555 TS |
3152 | nb_option_roms++; |
3153 | break; | |
8e71621f PB |
3154 | case QEMU_OPTION_semihosting: |
3155 | semihosting_enabled = 1; | |
3156 | break; | |
c35734b2 | 3157 | case QEMU_OPTION_name: |
7267c094 | 3158 | qemu_name = g_strdup(optarg); |
1889465a AK |
3159 | { |
3160 | char *p = strchr(qemu_name, ','); | |
3161 | if (p != NULL) { | |
3162 | *p++ = 0; | |
3163 | if (strncmp(p, "process=", 8)) { | |
5697f6ae | 3164 | fprintf(stderr, "Unknown subargument %s to -name\n", p); |
1889465a AK |
3165 | exit(1); |
3166 | } | |
3167 | p += 8; | |
ce798cf2 | 3168 | os_set_proc_name(p); |
1889465a AK |
3169 | } |
3170 | } | |
c35734b2 | 3171 | break; |
66508601 BS |
3172 | case QEMU_OPTION_prom_env: |
3173 | if (nb_prom_envs >= MAX_PROM_ENVS) { | |
3174 | fprintf(stderr, "Too many prom variables\n"); | |
3175 | exit(1); | |
3176 | } | |
3177 | prom_envs[nb_prom_envs] = optarg; | |
3178 | nb_prom_envs++; | |
3179 | break; | |
2b8f2d41 AZ |
3180 | case QEMU_OPTION_old_param: |
3181 | old_param = 1; | |
05ebd537 | 3182 | break; |
f3dcfada TS |
3183 | case QEMU_OPTION_clock: |
3184 | configure_alarms(optarg); | |
3185 | break; | |
7e0af5d0 | 3186 | case QEMU_OPTION_startdate: |
1ed2fc1f JK |
3187 | configure_rtc_date_offset(optarg, 1); |
3188 | break; | |
3189 | case QEMU_OPTION_rtc: | |
3329f07b | 3190 | opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); |
1ed2fc1f | 3191 | if (!opts) { |
1ed2fc1f | 3192 | exit(1); |
7e0af5d0 | 3193 | } |
1ed2fc1f | 3194 | configure_rtc(opts); |
7e0af5d0 | 3195 | break; |
26a5f13b | 3196 | case QEMU_OPTION_tb_size: |
d5ab9713 JK |
3197 | tcg_tb_size = strtol(optarg, NULL, 0); |
3198 | if (tcg_tb_size < 0) { | |
3199 | tcg_tb_size = 0; | |
3200 | } | |
26a5f13b | 3201 | break; |
2e70f6ef | 3202 | case QEMU_OPTION_icount: |
4e3de9e9 | 3203 | icount_option = optarg; |
2e70f6ef | 3204 | break; |
5bb7910a AL |
3205 | case QEMU_OPTION_incoming: |
3206 | incoming = optarg; | |
81323a6c | 3207 | runstate_set(RUN_STATE_INMIGRATE); |
5bb7910a | 3208 | break; |
d8c208dd GH |
3209 | case QEMU_OPTION_nodefaults: |
3210 | default_serial = 0; | |
3211 | default_parallel = 0; | |
aee1b935 | 3212 | default_virtcon = 0; |
d8c208dd | 3213 | default_monitor = 0; |
cb4522cc | 3214 | default_net = 0; |
ac33f8fa GH |
3215 | default_floppy = 0; |
3216 | default_cdrom = 0; | |
3217 | default_sdcard = 0; | |
7f1b17f2 | 3218 | default_vga = 0; |
d8c208dd | 3219 | break; |
e37630ca | 3220 | case QEMU_OPTION_xen_domid: |
ad96090a BS |
3221 | if (!(xen_available())) { |
3222 | printf("Option %s not supported for this target\n", popt->name); | |
3223 | exit(1); | |
3224 | } | |
e37630ca AL |
3225 | xen_domid = atoi(optarg); |
3226 | break; | |
3227 | case QEMU_OPTION_xen_create: | |
ad96090a BS |
3228 | if (!(xen_available())) { |
3229 | printf("Option %s not supported for this target\n", popt->name); | |
3230 | exit(1); | |
3231 | } | |
e37630ca AL |
3232 | xen_mode = XEN_CREATE; |
3233 | break; | |
3234 | case QEMU_OPTION_xen_attach: | |
ad96090a BS |
3235 | if (!(xen_available())) { |
3236 | printf("Option %s not supported for this target\n", popt->name); | |
3237 | exit(1); | |
3238 | } | |
e37630ca AL |
3239 | xen_mode = XEN_ATTACH; |
3240 | break; | |
ab6540d5 | 3241 | case QEMU_OPTION_trace: |
e4858974 | 3242 | { |
ab6540d5 | 3243 | opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); |
e4858974 L |
3244 | if (!opts) { |
3245 | exit(1); | |
ab6540d5 | 3246 | } |
23d15e86 | 3247 | trace_events = qemu_opt_get(opts, "events"); |
e4858974 | 3248 | trace_file = qemu_opt_get(opts, "file"); |
ab6540d5 | 3249 | break; |
e4858974 | 3250 | } |
715a664a GH |
3251 | case QEMU_OPTION_readconfig: |
3252 | { | |
dcfb0939 KW |
3253 | int ret = qemu_read_config_file(optarg); |
3254 | if (ret < 0) { | |
3255 | fprintf(stderr, "read config %s: %s\n", optarg, | |
3256 | strerror(-ret)); | |
715a664a GH |
3257 | exit(1); |
3258 | } | |
715a664a GH |
3259 | break; |
3260 | } | |
29b0040b GH |
3261 | case QEMU_OPTION_spice: |
3262 | olist = qemu_find_opts("spice"); | |
3263 | if (!olist) { | |
3264 | fprintf(stderr, "spice is not supported by this qemu build.\n"); | |
3265 | exit(1); | |
3266 | } | |
3267 | opts = qemu_opts_parse(olist, optarg, 0); | |
3268 | if (!opts) { | |
3269 | fprintf(stderr, "parse error: %s\n", optarg); | |
3270 | exit(1); | |
3271 | } | |
3272 | break; | |
715a664a GH |
3273 | case QEMU_OPTION_writeconfig: |
3274 | { | |
3275 | FILE *fp; | |
3276 | if (strcmp(optarg, "-") == 0) { | |
3277 | fp = stdout; | |
3278 | } else { | |
3279 | fp = fopen(optarg, "w"); | |
3280 | if (fp == NULL) { | |
3281 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); | |
3282 | exit(1); | |
3283 | } | |
3284 | } | |
3285 | qemu_config_write(fp); | |
3286 | fclose(fp); | |
3287 | break; | |
3288 | } | |
c7f0f3b1 AL |
3289 | case QEMU_OPTION_qtest: |
3290 | qtest_chrdev = optarg; | |
3291 | break; | |
3292 | case QEMU_OPTION_qtest_log: | |
3293 | qtest_log = optarg; | |
3294 | break; | |
7d76ad4f EO |
3295 | case QEMU_OPTION_sandbox: |
3296 | opts = qemu_opts_parse(qemu_find_opts("sandbox"), optarg, 1); | |
3297 | if (!opts) { | |
3298 | exit(0); | |
3299 | } | |
3300 | break; | |
59a5264b JS |
3301 | default: |
3302 | os_parse_cmd_args(popt->index, optarg); | |
cd6f1169 | 3303 | } |
0824d6fc FB |
3304 | } |
3305 | } | |
0f0bc3f1 | 3306 | loc_set_none(); |
c235d738 | 3307 | |
7d76ad4f EO |
3308 | if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) { |
3309 | exit(1); | |
3310 | } | |
3311 | ||
fb7c269e DH |
3312 | if (machine == NULL) { |
3313 | fprintf(stderr, "No machine found.\n"); | |
3314 | exit(1); | |
3315 | } | |
3316 | ||
93bfef4c CV |
3317 | if (machine->hw_version) { |
3318 | qemu_set_version(machine->hw_version); | |
3319 | } | |
3320 | ||
ecf40bea EH |
3321 | /* Init CPU def lists, based on config |
3322 | * - Must be called after all the qemu_read_config_file() calls | |
3323 | * - Must be called before list_cpus() | |
3324 | * - Must be called before machine->init() | |
3325 | */ | |
3326 | cpudef_init(); | |
3327 | ||
c8057f95 | 3328 | if (cpu_model && is_help_option(cpu_model)) { |
1d6528af | 3329 | list_cpus(stdout, &fprintf, cpu_model); |
ecf40bea EH |
3330 | exit(0); |
3331 | } | |
3332 | ||
c235d738 MF |
3333 | /* Open the logfile at this point, if necessary. We can't open the logfile |
3334 | * when encountering either of the logging options (-d or -D) because the | |
3335 | * other one may be encountered later on the command line, changing the | |
3336 | * location or level of logging. | |
3337 | */ | |
3338 | if (log_mask) { | |
3339 | if (log_file) { | |
3340 | set_cpu_log_filename(log_file); | |
3341 | } | |
3342 | set_cpu_log(log_mask); | |
3343 | } | |
330d0414 | 3344 | |
23d15e86 | 3345 | if (!trace_backend_init(trace_events, trace_file)) { |
e4858974 | 3346 | exit(1); |
31d3c9b8 | 3347 | } |
0b5538c3 | 3348 | |
5cea8590 PB |
3349 | /* If no data_dir is specified then try to find it relative to the |
3350 | executable path. */ | |
3351 | if (!data_dir) { | |
6170540b | 3352 | data_dir = os_find_datadir(argv[0]); |
5cea8590 | 3353 | } |
60474fb5 | 3354 | /* If all else fails use the install path specified when building. */ |
5cea8590 | 3355 | if (!data_dir) { |
1dabe05c | 3356 | data_dir = CONFIG_QEMU_DATADIR; |
5cea8590 PB |
3357 | } |
3358 | ||
6be68d7e JS |
3359 | /* |
3360 | * Default to max_cpus = smp_cpus, in case the user doesn't | |
3361 | * specify a max_cpus value. | |
3362 | */ | |
3363 | if (!max_cpus) | |
3364 | max_cpus = smp_cpus; | |
3365 | ||
3d878caa | 3366 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
b2097003 AL |
3367 | if (smp_cpus > machine->max_cpus) { |
3368 | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " | |
3369 | "supported by machine `%s' (%d)\n", smp_cpus, machine->name, | |
3370 | machine->max_cpus); | |
3371 | exit(1); | |
3372 | } | |
3373 | ||
67b724e6 AP |
3374 | /* |
3375 | * Get the default machine options from the machine if it is not already | |
3376 | * specified either by the configuration file or by the command line. | |
3377 | */ | |
3378 | if (machine->default_machine_opts) { | |
25de5935 JK |
3379 | qemu_opts_set_defaults(qemu_find_opts("machine"), |
3380 | machine->default_machine_opts, 0); | |
67b724e6 AP |
3381 | } |
3382 | ||
3329f07b GH |
3383 | qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0); |
3384 | qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0); | |
998bbd74 | 3385 | |
986c5f78 GH |
3386 | if (machine->no_serial) { |
3387 | default_serial = 0; | |
3388 | } | |
3389 | if (machine->no_parallel) { | |
3390 | default_parallel = 0; | |
3391 | } | |
3392 | if (!machine->use_virtcon) { | |
3393 | default_virtcon = 0; | |
3394 | } | |
ac33f8fa GH |
3395 | if (machine->no_floppy) { |
3396 | default_floppy = 0; | |
3397 | } | |
3398 | if (machine->no_cdrom) { | |
3399 | default_cdrom = 0; | |
3400 | } | |
3401 | if (machine->no_sdcard) { | |
3402 | default_sdcard = 0; | |
3403 | } | |
986c5f78 | 3404 | |
993fbfdb | 3405 | if (display_type == DT_NOGRAPHIC) { |
6a5e8b0e GH |
3406 | if (default_parallel) |
3407 | add_device_config(DEV_PARALLEL, "null"); | |
e1c09175 GH |
3408 | if (default_serial && default_monitor) { |
3409 | add_device_config(DEV_SERIAL, "mon:stdio"); | |
986c5f78 GH |
3410 | } else if (default_virtcon && default_monitor) { |
3411 | add_device_config(DEV_VIRTCON, "mon:stdio"); | |
e1c09175 GH |
3412 | } else { |
3413 | if (default_serial) | |
3414 | add_device_config(DEV_SERIAL, "stdio"); | |
986c5f78 GH |
3415 | if (default_virtcon) |
3416 | add_device_config(DEV_VIRTCON, "stdio"); | |
e1c09175 | 3417 | if (default_monitor) |
6ca5582d | 3418 | monitor_parse("stdio", "readline"); |
e1c09175 | 3419 | } |
998bbd74 GH |
3420 | } else { |
3421 | if (default_serial) | |
3422 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); | |
6a5e8b0e GH |
3423 | if (default_parallel) |
3424 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); | |
abdeed06 | 3425 | if (default_monitor) |
6ca5582d | 3426 | monitor_parse("vc:80Cx24C", "readline"); |
38536da1 AG |
3427 | if (default_virtcon) |
3428 | add_device_config(DEV_VIRTCON, "vc:80Cx24C"); | |
bc0129d9 AL |
3429 | } |
3430 | ||
a5829fd9 T |
3431 | socket_init(); |
3432 | ||
3329f07b | 3433 | if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) |
1a688d3b | 3434 | exit(1); |
758e8e38 | 3435 | #ifdef CONFIG_VIRTFS |
3329f07b | 3436 | if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) { |
74db920c GS |
3437 | exit(1); |
3438 | } | |
3439 | #endif | |
1a688d3b | 3440 | |
eb505be1 | 3441 | os_daemonize(); |
71e3ceb8 | 3442 | |
aa26bb2d | 3443 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
eb505be1 | 3444 | os_pidfile_error(); |
93815bc2 TS |
3445 | exit(1); |
3446 | } | |
3447 | ||
0ac543de JK |
3448 | /* init the memory */ |
3449 | if (ram_size == 0) { | |
3450 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; | |
3451 | } | |
3452 | ||
3d1d9652 BR |
3453 | if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) |
3454 | != 0) { | |
3455 | exit(0); | |
3456 | } | |
3457 | ||
303d4e86 | 3458 | configure_accelerator(); |
214910a7 | 3459 | |
d3b12f5d | 3460 | qemu_init_cpu_loop(); |
3fcf7b6b AL |
3461 | if (qemu_init_main_loop()) { |
3462 | fprintf(stderr, "qemu_init_main_loop failed\n"); | |
3463 | exit(1); | |
3464 | } | |
a0abe474 | 3465 | |
967c0da7 PM |
3466 | machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); |
3467 | if (machine_opts) { | |
3468 | kernel_filename = qemu_opt_get(machine_opts, "kernel"); | |
3469 | initrd_filename = qemu_opt_get(machine_opts, "initrd"); | |
3470 | kernel_cmdline = qemu_opt_get(machine_opts, "append"); | |
3471 | } else { | |
3472 | kernel_filename = initrd_filename = kernel_cmdline = NULL; | |
3473 | } | |
3474 | ||
a0abe474 PM |
3475 | if (!kernel_cmdline) { |
3476 | kernel_cmdline = ""; | |
3477 | } | |
3478 | ||
a20dd508 | 3479 | linux_boot = (kernel_filename != NULL); |
6c41b272 | 3480 | |
f8d39c01 TS |
3481 | if (!linux_boot && *kernel_cmdline != '\0') { |
3482 | fprintf(stderr, "-append only allowed with -kernel option\n"); | |
3483 | exit(1); | |
3484 | } | |
3485 | ||
3486 | if (!linux_boot && initrd_filename != NULL) { | |
3487 | fprintf(stderr, "-initrd only allowed with -kernel option\n"); | |
3488 | exit(1); | |
3489 | } | |
3490 | ||
412beee6 GL |
3491 | if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) { |
3492 | fprintf(stderr, "-dtb only allowed with -kernel option\n"); | |
3493 | exit(1); | |
3494 | } | |
3495 | ||
9156d763 | 3496 | os_set_line_buffering(); |
3b46e624 | 3497 | |
7183b4b4 AL |
3498 | if (init_timer_alarm() < 0) { |
3499 | fprintf(stderr, "could not initialize alarm timer\n"); | |
3500 | exit(1); | |
3501 | } | |
0abe905d | 3502 | |
ad1be899 AL |
3503 | #ifdef CONFIG_SPICE |
3504 | /* spice needs the timers to be initialized by this point */ | |
3505 | qemu_spice_init(); | |
3506 | #endif | |
3507 | ||
0abe905d MF |
3508 | if (icount_option && (kvm_enabled() || xen_enabled())) { |
3509 | fprintf(stderr, "-icount is not allowed with kvm or xen\n"); | |
3510 | exit(1); | |
3511 | } | |
4e3de9e9 | 3512 | configure_icount(icount_option); |
634fce96 | 3513 | |
dc1c9fe8 MM |
3514 | if (net_init_clients() < 0) { |
3515 | exit(1); | |
702c651c | 3516 | } |
f1510b2c | 3517 | |
dc72ac14 | 3518 | /* init the bluetooth world */ |
bd3c948d GH |
3519 | if (foreach_device_config(DEV_BT, bt_parse)) |
3520 | exit(1); | |
dc72ac14 | 3521 | |
834e76ea AP |
3522 | if (!xen_enabled()) { |
3523 | /* On 32-bit hosts, QEMU is limited by virtual address space */ | |
3524 | if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) { | |
3525 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n"); | |
3526 | exit(1); | |
3527 | } | |
3528 | } | |
9ae02555 | 3529 | |
d5ab9713 | 3530 | cpu_exec_init_all(); |
26a5f13b | 3531 | |
eb852011 | 3532 | bdrv_init_with_whitelist(); |
c4b1fcc0 | 3533 | |
c163b5ca | 3534 | blk_mig_init(); |
3535 | ||
e4bcb14c | 3536 | /* open the virtual block devices */ |
9dfd7c7a | 3537 | if (snapshot) |
3329f07b GH |
3538 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
3539 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0) | |
9dfd7c7a | 3540 | exit(1); |
3e3d5815 | 3541 | |
4e5d9b57 MA |
3542 | default_drive(default_cdrom, snapshot, machine->use_scsi, |
3543 | IF_DEFAULT, 2, CDROM_OPTS); | |
3544 | default_drive(default_floppy, snapshot, machine->use_scsi, | |
3545 | IF_FLOPPY, 0, FD_OPTS); | |
3546 | default_drive(default_sdcard, snapshot, machine->use_scsi, | |
3547 | IF_SD, 0, SD_OPTS); | |
3548 | ||
7908c78d | 3549 | register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL); |
8a7ddc38 | 3550 | |
268a362c AL |
3551 | if (nb_numa_nodes > 0) { |
3552 | int i; | |
3553 | ||
ea0e5418 SL |
3554 | if (nb_numa_nodes > MAX_NODES) { |
3555 | nb_numa_nodes = MAX_NODES; | |
268a362c AL |
3556 | } |
3557 | ||
3558 | /* If no memory size if given for any node, assume the default case | |
3559 | * and distribute the available memory equally across all nodes | |
3560 | */ | |
3561 | for (i = 0; i < nb_numa_nodes; i++) { | |
3562 | if (node_mem[i] != 0) | |
3563 | break; | |
3564 | } | |
3565 | if (i == nb_numa_nodes) { | |
3566 | uint64_t usedmem = 0; | |
3567 | ||
3568 | /* On Linux, the each node's border has to be 8MB aligned, | |
3569 | * the final node gets the rest. | |
3570 | */ | |
3571 | for (i = 0; i < nb_numa_nodes - 1; i++) { | |
3572 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); | |
3573 | usedmem += node_mem[i]; | |
3574 | } | |
3575 | node_mem[i] = ram_size - usedmem; | |
3576 | } | |
3577 | ||
3578 | for (i = 0; i < nb_numa_nodes; i++) { | |
ee785fed | 3579 | if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) { |
268a362c | 3580 | break; |
ee785fed | 3581 | } |
268a362c AL |
3582 | } |
3583 | /* assigning the VCPUs round-robin is easier to implement, guest OSes | |
3584 | * must cope with this anyway, because there are BIOSes out there in | |
3585 | * real machines which also use this scheme. | |
3586 | */ | |
3587 | if (i == nb_numa_nodes) { | |
991dfefd | 3588 | for (i = 0; i < max_cpus; i++) { |
ee785fed | 3589 | set_bit(i, node_cpumask[i % nb_numa_nodes]); |
268a362c AL |
3590 | } |
3591 | } | |
3592 | } | |
3593 | ||
3329f07b | 3594 | if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) { |
157b9319 JK |
3595 | exit(1); |
3596 | } | |
3597 | ||
998bbd74 GH |
3598 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
3599 | exit(1); | |
6a5e8b0e GH |
3600 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
3601 | exit(1); | |
aee1b935 GH |
3602 | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
3603 | exit(1); | |
c9f398e5 PA |
3604 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
3605 | exit(1); | |
2796dae0 | 3606 | |
7f1b17f2 PB |
3607 | /* If no default VGA is requested, the default is "none". */ |
3608 | if (default_vga && cirrus_vga_available()) { | |
3609 | vga_model = "cirrus"; | |
a369da5f | 3610 | } |
7f1b17f2 | 3611 | select_vgahw(vga_model); |
a369da5f | 3612 | |
09aaa160 MA |
3613 | if (watchdog) { |
3614 | i = select_watchdog(watchdog); | |
3615 | if (i > 0) | |
3616 | exit (i == 1 ? 1 : 0); | |
3617 | } | |
3618 | ||
b6b61144 | 3619 | if (machine->compat_props) { |
458fb679 | 3620 | qdev_prop_register_global_list(machine->compat_props); |
b6b61144 | 3621 | } |
d0fef6fb GH |
3622 | qemu_add_globals(); |
3623 | ||
1de81d28 AL |
3624 | qdev_machine_init(); |
3625 | ||
fbe1b595 | 3626 | machine->init(ram_size, boot_devices, |
3023f332 AL |
3627 | kernel_filename, kernel_cmdline, initrd_filename, cpu_model); |
3628 | ||
ea375f9a | 3629 | cpu_synchronize_all_post_init(); |
268a362c | 3630 | |
87d0a28e | 3631 | set_numa_modes(); |
268a362c | 3632 | |
6f338c34 AL |
3633 | current_machine = machine; |
3634 | ||
3023f332 AL |
3635 | /* init USB devices */ |
3636 | if (usb_enabled) { | |
0752706d MA |
3637 | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
3638 | exit(1); | |
3023f332 AL |
3639 | } |
3640 | ||
bd3c948d | 3641 | /* init generic devices */ |
3329f07b | 3642 | if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) |
bd3c948d GH |
3643 | exit(1); |
3644 | ||
668680f7 MA |
3645 | net_check_clients(); |
3646 | ||
3023f332 | 3647 | /* just use the first displaystate for the moment */ |
b473df6e | 3648 | ds = get_displaystate(); |
993fbfdb | 3649 | |
a3e22260 GH |
3650 | if (using_spice) |
3651 | display_remote++; | |
6b62dc2d | 3652 | if (display_type == DT_DEFAULT && !display_remote) { |
993fbfdb AL |
3653 | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
3654 | display_type = DT_SDL; | |
821601ea | 3655 | #elif defined(CONFIG_VNC) |
993fbfdb AL |
3656 | vnc_display = "localhost:0,to=99"; |
3657 | show_vnc_port = 1; | |
821601ea JS |
3658 | #else |
3659 | display_type = DT_NONE; | |
993fbfdb AL |
3660 | #endif |
3661 | } | |
821601ea | 3662 | |
993fbfdb | 3663 | |
6b62dc2d | 3664 | /* init local displays */ |
993fbfdb AL |
3665 | switch (display_type) { |
3666 | case DT_NOGRAPHIC: | |
3667 | break; | |
4d3b6f6e | 3668 | #if defined(CONFIG_CURSES) |
993fbfdb | 3669 | case DT_CURSES: |
995ee2bf HM |
3670 | if (!is_daemonized()) { |
3671 | curses_display_init(ds, full_screen); | |
3672 | } | |
993fbfdb | 3673 | break; |
4d3b6f6e | 3674 | #endif |
5b0753e0 | 3675 | #if defined(CONFIG_SDL) |
993fbfdb AL |
3676 | case DT_SDL: |
3677 | sdl_display_init(ds, full_screen, no_frame); | |
3678 | break; | |
5b0753e0 | 3679 | #elif defined(CONFIG_COCOA) |
993fbfdb AL |
3680 | case DT_SDL: |
3681 | cocoa_display_init(ds, full_screen); | |
3682 | break; | |
313aa567 | 3683 | #endif |
6b62dc2d GH |
3684 | default: |
3685 | break; | |
3686 | } | |
3687 | ||
0ce235a7 GN |
3688 | /* must be after terminal init, SDL library changes signal handlers */ |
3689 | os_setup_signal_handling(); | |
3690 | ||
821601ea | 3691 | #ifdef CONFIG_VNC |
6b62dc2d GH |
3692 | /* init remote displays */ |
3693 | if (vnc_display) { | |
993fbfdb | 3694 | vnc_display_init(ds); |
94b204ca AK |
3695 | if (vnc_display_open(ds, vnc_display) < 0) { |
3696 | fprintf(stderr, "Failed to start VNC server on `%s'\n", | |
3697 | vnc_display); | |
993fbfdb | 3698 | exit(1); |
94b204ca | 3699 | } |
f92f8afe | 3700 | |
993fbfdb AL |
3701 | if (show_vnc_port) { |
3702 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); | |
f92f8afe | 3703 | } |
313aa567 | 3704 | } |
821601ea | 3705 | #endif |
a3e22260 | 3706 | #ifdef CONFIG_SPICE |
a19cbfb3 | 3707 | if (using_spice && !qxl_enabled) { |
a3e22260 GH |
3708 | qemu_spice_display_init(ds); |
3709 | } | |
3710 | #endif | |
5b08fc10 | 3711 | |
6b62dc2d GH |
3712 | /* display setup */ |
3713 | dpy_resize(ds); | |
3023f332 AL |
3714 | dcl = ds->listeners; |
3715 | while (dcl != NULL) { | |
3716 | if (dcl->dpy_refresh != NULL) { | |
7bd427d8 PB |
3717 | ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds); |
3718 | qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock)); | |
0f2ad63f | 3719 | break; |
20d8a3ed | 3720 | } |
3023f332 | 3721 | dcl = dcl->next; |
20d8a3ed | 3722 | } |
b473df6e | 3723 | text_consoles_set_display(ds); |
2796dae0 | 3724 | |
ef0c4a0d | 3725 | if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { |
59030a8c | 3726 | exit(1); |
45669e00 | 3727 | } |
45669e00 | 3728 | |
3418bd25 GH |
3729 | qdev_machine_creation_done(); |
3730 | ||
15ff7705 GH |
3731 | if (rom_load_all() != 0) { |
3732 | fprintf(stderr, "rom loading failed\n"); | |
3733 | exit(1); | |
3734 | } | |
45a50b16 | 3735 | |
80376c3f IY |
3736 | /* TODO: once all bus devices are qdevified, this should be done |
3737 | * when bus is created by qdev.c */ | |
3738 | qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); | |
4cab946a GN |
3739 | qemu_run_machine_init_done_notifiers(); |
3740 | ||
e063eb1f | 3741 | qemu_system_reset(VMRESET_SILENT); |
05f2401e | 3742 | if (loadvm) { |
03cd4655 | 3743 | if (load_vmstate(loadvm) < 0) { |
05f2401e JQ |
3744 | autostart = 0; |
3745 | } | |
3746 | } | |
d63d307f | 3747 | |
2bb8c10c | 3748 | if (incoming) { |
d5c5dacc AK |
3749 | Error *errp = NULL; |
3750 | int ret = qemu_start_incoming_migration(incoming, &errp); | |
8ca5e801 | 3751 | if (ret < 0) { |
d5c5dacc AK |
3752 | if (error_is_set(&errp)) { |
3753 | fprintf(stderr, "Migrate: %s\n", error_get_pretty(errp)); | |
3754 | error_free(errp); | |
3755 | } | |
8ca5e801 JQ |
3756 | fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n", |
3757 | incoming, ret); | |
3758 | exit(ret); | |
3759 | } | |
6b99dadc | 3760 | } else if (autostart) { |
c0f4ce77 | 3761 | vm_start(); |
6b99dadc | 3762 | } |
ffd843bc | 3763 | |
eb505be1 | 3764 | os_setup_post(); |
71e3ceb8 | 3765 | |
99435906 | 3766 | resume_all_vcpus(); |
8a7ddc38 | 3767 | main_loop(); |
99435906 PB |
3768 | bdrv_close_all(); |
3769 | pause_all_vcpus(); | |
63a01ef8 | 3770 | net_cleanup(); |
3d3b8303 | 3771 | res_free(); |
b46a8906 | 3772 | |
0824d6fc FB |
3773 | return 0; |
3774 | } |