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.


lot of changes
[palacios.git] / palacios / include / palacios / vmm_util.h
1 #ifndef __VMM_UTIL_H
2 #define __VMM_UTIL_H
3
4 #include <palacios/vmm_types.h>
5
6
7 #ifndef PAGE_SIZE
8 #define PAGE_SIZE 4096
9 #endif
10
11
12 typedef union reg_ex {
13   ullong_t r_reg;
14   struct {
15     uint_t low;
16     uint_t high;
17   } e_reg;
18
19 } reg_ex_t;
20
21
22
23 // These are the GPRs layed out according to 'pusha'
24 struct VMM_GPRs {
25   uint_t edi;
26   uint_t esi;
27   uint_t ebp;
28   uint_t esp;
29   uint_t ebx;
30   uint_t edx;
31   uint_t ecx;
32   uint_t eax;
33 };
34
35
36 #define GET_LOW_32(x) (*((uint_t*)(&(x))))
37 #define GET_HIGH_32(x) (*((uint_t*)(((char*)(&(x)))+4)))
38
39
40 void PrintTraceHex(unsigned char x);
41
42 void PrintTraceMemDump(unsigned char * start, int n);
43
44
45
46
47 #define rdtsc(low,high)                                         \
48      __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
49
50 #define rdtscl(low)                                             \
51      __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
52
53 #if defined(__i386__)
54
55 #define rdtscll(val)                            \
56      __asm__ __volatile__("rdtsc" : "=A" (val))
57
58 #elif defined(__x86_64__)
59
60 #define rdtscll(val) do {                                   \
61     unsigned int a,d;                                       \
62     asm volatile("rdtsc" : "=a" (a), "=d" (d));             \
63     (val) = ((unsigned long)a) | (((unsigned long)d)<<32);  \
64   } while(0)
65
66 #endif
67
68
69
70
71
72
73
74
75
76 #ifdef __V3_64BIT__
77
78 # define do_div(n,base) ({                                      \
79         uint32_t __base = (base);                               \
80         uint32_t __rem;                                         \
81         __rem = ((uint64_t)(n)) % __base;                       \
82         (n) = ((uint64_t)(n)) / __base;                         \
83         __rem;                                                  \
84  })
85
86 #else
87
88 /*
89  * do_div() is NOT a C function. It wants to return
90  * two values (the quotient and the remainder), but
91  * since that doesn't work very well in C, what it
92  * does is:
93  *
94  * - modifies the 64-bit dividend _in_place_
95  * - returns the 32-bit remainder
96  *
97  * This ends up being the most efficient "calling
98  * convention" on x86.
99  */
100 #define do_div(n,base) ({ \
101         unsigned long __upper, __low, __high, __mod, __base; \
102         __base = (base); \
103         asm("":"=a" (__low), "=d" (__high):"A" (n)); \
104         __upper = __high; \
105         if (__high) { \
106                 __upper = __high % (__base); \
107                 __high = __high / (__base); \
108         } \
109         asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
110         asm("":"=A" (n):"a" (__low),"d" (__high)); \
111         __mod; \
112 })
113
114 #endif
115
116
117
118
119
120 #endif