Revision 5905b2e5
b/vl.c | ||
---|---|---|
982 | 982 |
va_end(ap); |
983 | 983 |
} |
984 | 984 |
|
985 |
void qemu_chr_send_event(CharDriverState *s, int event) |
|
986 |
{ |
|
987 |
if (s->chr_send_event) |
|
988 |
s->chr_send_event(s, event); |
|
989 |
} |
|
990 |
|
|
985 | 991 |
void qemu_chr_add_read_handler(CharDriverState *s, |
986 | 992 |
IOCanRWHandler *fd_can_read, |
987 | 993 |
IOReadHandler *fd_read, void *opaque) |
... | ... | |
2179 | 2185 |
#endif |
2180 | 2186 |
} |
2181 | 2187 |
|
2182 |
int main_loop(void)
|
|
2188 |
void main_loop_wait(int timeout)
|
|
2183 | 2189 |
{ |
2184 | 2190 |
#ifndef _WIN32 |
2185 | 2191 |
struct pollfd ufds[MAX_IO_HANDLERS + 1], *pf; |
... | ... | |
2187 | 2193 |
uint8_t buf[4096]; |
2188 | 2194 |
int n, max_size; |
2189 | 2195 |
#endif |
2190 |
int ret, timeout; |
|
2191 |
CPUState *env = global_env; |
|
2192 |
|
|
2193 |
for(;;) { |
|
2194 |
if (vm_running) { |
|
2195 |
ret = cpu_exec(env); |
|
2196 |
if (shutdown_requested) { |
|
2197 |
ret = EXCP_INTERRUPT; |
|
2198 |
break; |
|
2199 |
} |
|
2200 |
if (reset_requested) { |
|
2201 |
reset_requested = 0; |
|
2202 |
qemu_system_reset(); |
|
2203 |
ret = EXCP_INTERRUPT; |
|
2204 |
} |
|
2205 |
if (ret == EXCP_DEBUG) { |
|
2206 |
vm_stop(EXCP_DEBUG); |
|
2207 |
} |
|
2208 |
/* if hlt instruction, we wait until the next IRQ */ |
|
2209 |
/* XXX: use timeout computed from timers */ |
|
2210 |
if (ret == EXCP_HLT) |
|
2211 |
timeout = 10; |
|
2212 |
else |
|
2213 |
timeout = 0; |
|
2214 |
} else { |
|
2215 |
timeout = 10; |
|
2216 |
} |
|
2196 |
int ret; |
|
2217 | 2197 |
|
2218 | 2198 |
#ifdef _WIN32 |
2219 | 2199 |
if (timeout > 0) |
2220 | 2200 |
Sleep(timeout); |
2221 | 2201 |
#else |
2222 |
|
|
2223 | 2202 |
/* poll any events */ |
2224 | 2203 |
/* XXX: separate device handlers from system ones */ |
2225 | 2204 |
pf = ufds; |
... | ... | |
2269 | 2248 |
} |
2270 | 2249 |
} |
2271 | 2250 |
} |
2272 |
|
|
2251 |
#endif /* !defined(_WIN32) */ |
|
2273 | 2252 |
#if defined(CONFIG_SLIRP) |
2274 | 2253 |
/* XXX: merge with poll() */ |
2275 | 2254 |
if (slirp_inited) { |
... | ... | |
2291 | 2270 |
} |
2292 | 2271 |
#endif |
2293 | 2272 |
|
2294 |
#endif |
|
2295 |
|
|
2296 | 2273 |
if (vm_running) { |
2297 | 2274 |
qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], |
2298 | 2275 |
qemu_get_clock(vm_clock)); |
... | ... | |
2309 | 2286 |
/* real time timers */ |
2310 | 2287 |
qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME], |
2311 | 2288 |
qemu_get_clock(rt_clock)); |
2289 |
} |
|
2290 |
|
|
2291 |
int main_loop(void) |
|
2292 |
{ |
|
2293 |
int ret, timeout; |
|
2294 |
CPUState *env = global_env; |
|
2295 |
|
|
2296 |
for(;;) { |
|
2297 |
if (vm_running) { |
|
2298 |
ret = cpu_exec(env); |
|
2299 |
if (shutdown_requested) { |
|
2300 |
ret = EXCP_INTERRUPT; |
|
2301 |
break; |
|
2302 |
} |
|
2303 |
if (reset_requested) { |
|
2304 |
reset_requested = 0; |
|
2305 |
qemu_system_reset(); |
|
2306 |
ret = EXCP_INTERRUPT; |
|
2307 |
} |
|
2308 |
if (ret == EXCP_DEBUG) { |
|
2309 |
vm_stop(EXCP_DEBUG); |
|
2310 |
} |
|
2311 |
/* if hlt instruction, we wait until the next IRQ */ |
|
2312 |
/* XXX: use timeout computed from timers */ |
|
2313 |
if (ret == EXCP_HLT) |
|
2314 |
timeout = 10; |
|
2315 |
else |
|
2316 |
timeout = 0; |
|
2317 |
} else { |
|
2318 |
timeout = 10; |
|
2319 |
} |
|
2320 |
main_loop_wait(timeout); |
|
2312 | 2321 |
} |
2313 | 2322 |
cpu_disable_ticks(); |
2314 | 2323 |
return ret; |
... | ... | |
2509 | 2518 |
|
2510 | 2519 |
#endif |
2511 | 2520 |
|
2521 |
/* password input */ |
|
2522 |
|
|
2523 |
static BlockDriverState *get_bdrv(int index) |
|
2524 |
{ |
|
2525 |
BlockDriverState *bs; |
|
2526 |
|
|
2527 |
if (index < 4) { |
|
2528 |
bs = bs_table[index]; |
|
2529 |
} else if (index < 6) { |
|
2530 |
bs = fd_table[index - 4]; |
|
2531 |
} else { |
|
2532 |
bs = NULL; |
|
2533 |
} |
|
2534 |
return bs; |
|
2535 |
} |
|
2536 |
|
|
2537 |
static void read_passwords(void) |
|
2538 |
{ |
|
2539 |
BlockDriverState *bs; |
|
2540 |
int i, j; |
|
2541 |
char password[256]; |
|
2542 |
|
|
2543 |
for(i = 0; i < 6; i++) { |
|
2544 |
bs = get_bdrv(i); |
|
2545 |
if (bs && bdrv_is_encrypted(bs)) { |
|
2546 |
term_printf("%s is encrypted.\n", bdrv_get_device_name(bs)); |
|
2547 |
for(j = 0; j < 3; j++) { |
|
2548 |
monitor_readline("Password: ", |
|
2549 |
1, password, sizeof(password)); |
|
2550 |
if (bdrv_set_key(bs, password) == 0) |
|
2551 |
break; |
|
2552 |
term_printf("invalid password\n"); |
|
2553 |
} |
|
2554 |
} |
|
2555 |
} |
|
2556 |
} |
|
2557 |
|
|
2512 | 2558 |
#define NET_IF_TUN 0 |
2513 | 2559 |
#define NET_IF_USER 1 |
2514 | 2560 |
#define NET_IF_DUMMY 2 |
... | ... | |
2952 | 2998 |
#endif |
2953 | 2999 |
|
2954 | 3000 |
/* we always create the cdrom drive, even if no disk is there */ |
3001 |
bdrv_init(); |
|
2955 | 3002 |
if (has_cdrom) { |
2956 | 3003 |
bs_table[2] = bdrv_new("cdrom"); |
2957 | 3004 |
bdrv_set_type_hint(bs_table[2], BDRV_TYPE_CDROM); |
... | ... | |
2966 | 3013 |
bs_table[i] = bdrv_new(buf); |
2967 | 3014 |
} |
2968 | 3015 |
if (bdrv_open(bs_table[i], hd_filename[i], snapshot) < 0) { |
2969 |
fprintf(stderr, "qemu: could not open hard disk image '%s\n", |
|
3016 |
fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
|
|
2970 | 3017 |
hd_filename[i]); |
2971 | 3018 |
exit(1); |
2972 | 3019 |
} |
... | ... | |
3106 | 3153 |
} else { |
3107 | 3154 |
printf("Waiting gdb connection on port %d\n", gdbstub_port); |
3108 | 3155 |
} |
3156 |
term_init(); |
|
3109 | 3157 |
} else |
3110 | 3158 |
#endif |
3111 |
if (start_emulation) |
|
3112 | 3159 |
{ |
3113 |
vm_start(); |
|
3160 |
term_init(); |
|
3161 |
/* XXX: simplify init */ |
|
3162 |
read_passwords(); |
|
3163 |
if (start_emulation) { |
|
3164 |
vm_start(); |
|
3165 |
} |
|
3114 | 3166 |
} |
3115 |
term_init(); |
|
3116 | 3167 |
main_loop(); |
3117 | 3168 |
quit_timers(); |
3118 | 3169 |
return 0; |
Also available in: Unified diff