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.


71af1051247b400ae923ac43cc9d9c63c92a165f
[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
27 #ifdef __V3_32BIT__
28
29 static void __inline__ v3_cpuid(uint_t target, addr_t * eax, addr_t * ebx, addr_t * ecx, addr_t * edx) {
30     __asm__ __volatile__ (
31                           "cpuid\n\t"
32                           : "=a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx)
33                           : "0" (target), "2" (*ecx)
34                           );
35     return;
36 }
37
38 #elif __V3_64BIT__
39
40 static void __inline__ v3_cpuid(uint_t target, addr_t * eax, addr_t * ebx, addr_t * ecx, addr_t * edx) {
41     __asm__ __volatile__ (
42                           "cpuid\n\t"
43                           : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
44                           : "0" (target), "2" (*ecx)
45                           );
46     return;
47 }
48
49 #endif
50
51
52 static void __inline__ v3_set_msr(uint_t msr, uint_t high_byte, uint_t low_byte) {
53     __asm__ __volatile__ (
54                           "wrmsr"
55                           : 
56                           : "c" (msr), "d" (high_byte), "a" (low_byte)
57                           );
58
59
60 }
61
62
63
64 static void __inline__ v3_get_msr(uint_t msr, uint_t * high_byte, uint_t * low_byte) {
65     __asm__ __volatile__ (
66                           "rdmsr"
67                           : "=d" (*high_byte), "=a" (*low_byte) 
68                           : "c" (msr)
69                           );
70 }
71
72
73
74 static void __inline__ v3_enable_ints() {
75     __asm__ __volatile__ ("sti");
76 }
77
78 static void __inline__ v3_disable_ints() {
79     __asm__ __volatile__ ("cli");
80 }
81
82
83
84
85 #ifdef __V3_32BIT__
86
87 static addr_t __inline__ v3_irq_save() {
88     addr_t state;
89
90     __asm__ __volatile__ ("pushf \n\t"
91                           "popl %0 \n\t"
92                           "cli \n\t"
93                           :"=g" (state)
94                           : 
95                           :"memory"
96                           ); 
97     return state;
98 }
99
100 static void __inline__ v3_irq_restore(addr_t state) {
101     __asm__ __volatile__("pushl %0 \n\t"
102                          "popfl \n\t"
103                          : 
104                          :"g" (state)
105                          :"memory", "cc"
106                          );
107 }
108
109 #elif __V3_64BIT__
110
111 static addr_t __inline__ v3_irq_save() {
112     addr_t state; 
113
114     __asm__ __volatile__ ("pushfq \n\t"
115                           "popq %0 \n\t"
116                           "cli \n\t"
117                           :"=g" (state)
118                           : 
119                           :"memory"
120                           ); 
121
122     return state;
123 }
124
125
126 static void __inline__ v3_irq_restore(addr_t state) {
127     __asm__ __volatile__("pushq %0 \n\t"
128                          "popfq \n\t"
129                          : 
130                          :"g" (state)
131                          :"memory", "cc"
132                          );
133 }
134
135 #endif