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.


Corrected RTC timer bug (nvram)
[palacios.git] / palacios / include / palacios / vmm_lowlevel.h
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, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #include <palacios/vmm_types.h>
21
22
23 #define CPUID_FEATURE_IDS 0x00000001
24 #define CPUID_EXT_FEATURE_IDS 0x80000001
25
26 struct seg_selector {
27     union {
28         uint16_t value;
29         struct {
30             uint8_t rpl     : 2;
31             uint8_t ti      : 1;
32             uint16_t si     : 13;
33         } __attribute__((packed));
34     } __attribute__((packed));
35 } __attribute__((packed));
36
37 struct gen_segment {
38     uint16_t limit_lo;
39     uint32_t base_lo     : 24;
40     uint8_t type         : 4;
41     uint8_t system       : 1;
42     uint8_t dpl          : 2;
43     uint8_t present      : 1;
44     uint8_t limit_hi     : 4;
45     uint8_t avail        : 1;
46     uint8_t long_mode    : 1;
47     uint8_t db           : 1;
48     uint8_t granularity  : 1;
49     uint8_t base_hi      : 8;
50 } __attribute__((packed));
51
52 struct sys_segment64 {
53     uint16_t limit_lo;
54     uint32_t base_lo     : 24;
55     uint8_t type         : 4;
56     uint8_t rsvd0        : 1;
57     uint8_t dpl          : 2;
58     uint8_t present      : 1;
59     uint8_t limit_hi     : 4;
60     uint8_t avail        : 1;
61     uint8_t rsvd1        : 3;
62     uint8_t granularity  : 1;
63     uint64_t base_hi     : 40;
64     uint32_t rsvd2;
65 } __attribute__((packed));
66
67
68
69 static void __inline__ v3_cpuid(uint32_t target, 
70                                 uint32_t * eax, uint32_t * ebx, 
71                                 uint32_t * ecx, uint32_t * edx) {
72 #ifdef __V3_64BIT__
73     __asm__ __volatile__ (
74                           "cpuid\n\t"
75                           : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
76                           : "0" (target), "2" (*ecx)
77                           );
78 #elif __V3_32BIT__
79     // 32 bit code compiled with -fPIC, cannot use ebx as an ouput reg. Fantastic.
80     __asm__ __volatile__ (
81                           "pushl %%ebx\n\t"
82                           "movl %%edi, %%ebx\n\t"
83                           "cpuid\n\t"
84                           "movl %%ebx, %%edi\n\t"
85                           "popl %%ebx\n\t"
86                           : "=a" (*eax), "=D" (*ebx), "=c" (*ecx), "=d" (*edx)
87                           : "0" (target), "2" (*ecx)
88                           );
89 #endif
90     return;
91 }
92
93
94 static void __inline__ v3_set_msr(uint_t msr, uint_t high_byte, uint_t low_byte) {
95     __asm__ __volatile__ (
96                           "wrmsr"
97                           : 
98                           : "c" (msr), "d" (high_byte), "a" (low_byte)
99                           );
100
101
102 }
103
104
105
106 static void __inline__ v3_get_msr(uint_t msr, uint_t * high_byte, uint_t * low_byte) {
107     __asm__ __volatile__ (
108                           "rdmsr"
109                           : "=d" (*high_byte), "=a" (*low_byte) 
110                           : "c" (msr)
111                           );
112 }
113
114
115
116 static void __inline__ v3_enable_ints() {
117     __asm__ __volatile__ ("sti");
118 }
119
120 static void __inline__ v3_disable_ints() {
121     __asm__ __volatile__ ("cli");
122 }
123
124
125
126
127 #ifdef __V3_32BIT__
128
129 static addr_t __inline__ v3_irq_save() {
130     addr_t state;
131
132     __asm__ __volatile__ ("pushf \n\t"
133                           "popl %0 \n\t"
134                           "cli \n\t"
135                           :"=g" (state)
136                           : 
137                           :"memory"
138                           ); 
139     return state;
140 }
141
142 static void __inline__ v3_irq_restore(addr_t state) {
143     __asm__ __volatile__("pushl %0 \n\t"
144                          "popfl \n\t"
145                          : 
146                          :"g" (state)
147                          :"memory", "cc"
148                          );
149 }
150
151 #elif __V3_64BIT__
152
153 static addr_t __inline__ v3_irq_save() {
154     addr_t state; 
155
156     __asm__ __volatile__ ("pushfq \n\t"
157                           "popq %0 \n\t"
158                           "cli \n\t"
159                           :"=g" (state)
160                           : 
161                           :"memory"
162                           ); 
163
164     return state;
165 }
166
167
168 static void __inline__ v3_irq_restore(addr_t state) {
169     __asm__ __volatile__("pushq %0 \n\t"
170                          "popfq \n\t"
171                          : 
172                          :"g" (state)
173                          :"memory", "cc"
174                          );
175 }
176
177 #endif