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.


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