2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Peter Dinda <pdinda@northwestern.edu>
11 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
12 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
13 * All rights reserved.
15 * Author: Peter Dinda <pdinda@northwestern.edu>
17 * This is free software. You are permitted to use,
18 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #include <palacios/vmm_halt.h>
22 #include <palacios/vmm_intr.h>
25 #ifndef CONFIG_DEBUG_HALT
27 #define PrintDebug(fmt, args...)
33 // This should trigger a #GP if cpl != 0, otherwise, yield to host
36 int v3_handle_halt(struct guest_info * info) {
39 v3_raise_exception(info, GPF_EXCEPTION);
42 uint64_t yield_start = 0;
43 uint64_t yield_stop = 0;
46 PrintDebug("CPU Yield\n");
55 //v3_update_time(info, yield_stop - yield_start);
56 gap = yield_stop - yield_start;
58 If we got here, either an interrupt has occured or
59 sufficient time has passed that we may need to inject
61 First, we will update time, which may or may not inject an
64 v3_update_time(info, gap);
65 info->time_state.cached_hlt_tsc += gap;
67 /* At this point, we either have some combination of
68 interrupts, including perhaps a timer interrupt, or
71 if (!v3_intr_pending(info)) {
72 /* if no interrupt, then we yield again */
77 /* WARNING!!! WARNING!!!
79 * DO NOT REMOVE THIS CONDITIONAL!!!
81 * It is common for an OS to issue an IO op, and then sit in a halt loop
82 * waiting for the device to complete and raise an irq.
83 * If you remove this then the timer interrupt will ALWAYS subvert the completion
84 * interrupt and stall the guest.
86 if (!v3_intr_pending(info)) {
87 v3_advance_time(info);
91 //PrintError("HLT instruction issued\n");
93 PrintDebug("CPU Yield Done (%d cycles)\n", gap);