Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Minor fix to the halt handler
[palacios.git] / palacios / src / palacios / vmm_halt.c
1 /* 
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
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.
14  *
15  * Author: Peter Dinda <pdinda@northwestern.edu>
16  *
17  * This is free software.  You are permitted to use,
18  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19  */
20
21 #include <palacios/vmm_halt.h>
22 #include <palacios/vmm_intr.h>
23
24
25 #ifndef CONFIG_DEBUG_HALT
26 #undef PrintDebug
27 #define PrintDebug(fmt, args...)
28 #endif
29
30
31
32 //
33 // This should trigger a #GP if cpl != 0, otherwise, yield to host
34 //
35
36 int v3_handle_halt(struct guest_info * info) {
37
38     if (info->cpl != 0) { 
39         v3_raise_exception(info, GPF_EXCEPTION);
40     } else {
41     
42         uint64_t yield_start = 0;
43         uint64_t yield_stop = 0;
44         uint32_t gap = 0;
45         
46         PrintDebug("CPU Yield\n");
47
48         while(1){
49                 if (v3_intr_pending(info)) {
50                /* if there is pending interrupt, just return */
51                     break;
52                 }
53
54                 rdtscll(yield_start);
55                 v3_yield(info);
56                 rdtscll(yield_stop);
57
58                 gap = yield_stop - yield_start;
59                  /*
60                    If we got here, either an interrupt has occured or
61                    sufficient time has passed that we may need to inject 
62                    a timer interrupt.  
63                    First, we will update time, which may or may not inject an
64                    interrupt 
65                 */
66                 v3_update_time(info, gap);
67                 info->time_state.cached_hlt_tsc += gap;
68
69                 /* At this point, we either have some combination of 
70                    interrupts, including perhaps a timer interrupt, or 
71                    no interrupt.
72                 */
73                 if (!v3_intr_pending(info)) {
74                /* if no interrupt, then we do halt*/
75                     asm("hlt");
76                 }
77         }
78
79 #if 0
80         /*  WARNING!!! WARNING!!!
81          *  
82          * DO NOT REMOVE THIS CONDITIONAL!!!
83          *
84          * It is common for an OS to issue an IO op, and then sit in a halt loop
85          * waiting for the device to complete and raise an irq.
86          * If you remove this then the timer interrupt will ALWAYS subvert the completion 
87          * interrupt and stall the guest.
88          */
89         if (!v3_intr_pending(info)) {
90             v3_advance_time(info);
91         }
92 #endif
93
94       //PrintError("HLT instruction issued\n");
95         
96         PrintDebug("CPU Yield Done (%d cycles)\n", gap);
97         
98         info->rip += 1;
99     }
100
101     return 0;
102 }