1 /* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
2 /* (c) 2008, The V3VEE Project <http://www.v3vee.org> */
9 #include <palacios/vmm_types.h>
13 #define PAGE_SIZE 4096
17 typedef union reg_ex {
28 // These are the GPRs layed out according to 'pusha'
41 #define GET_LOW_32(x) (*((uint_t*)(&(x))))
42 #define GET_HIGH_32(x) (*((uint_t*)(((char*)(&(x)))+4)))
45 void PrintTraceHex(unsigned char x);
46 void PrintTraceLL(ullong_t num);
47 void PrintTraceMemDump(unsigned char * start, int n);
52 #define rdtsc(low,high) \
53 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
56 __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
60 #define rdtscll(val) \
61 __asm__ __volatile__("rdtsc" : "=A" (val))
63 #elif defined(__x86_64__)
65 #define rdtscll(val) do { \
67 asm volatile("rdtsc" : "=a" (a), "=d" (d)); \
68 (val) = ((unsigned long)a) | (((unsigned long)d)<<32); \
83 # define do_div(n,base) ({ \
84 uint32_t __base = (base); \
86 __rem = ((uint64_t)(n)) % __base; \
87 (n) = ((uint64_t)(n)) / __base; \
94 * do_div() is NOT a C function. It wants to return
95 * two values (the quotient and the remainder), but
96 * since that doesn't work very well in C, what it
99 * - modifies the 64-bit dividend _in_place_
100 * - returns the 32-bit remainder
102 * This ends up being the most efficient "calling
103 * convention" on x86.
105 #define do_div(n,base) ({ \
106 unsigned long __upper, __low, __high, __mod, __base; \
108 asm("":"=a" (__low), "=d" (__high):"A" (n)); \
111 __upper = __high % (__base); \
112 __high = __high / (__base); \
114 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
115 asm("":"=A" (n):"a" (__low),"d" (__high)); \
121 /* This divides two 64bit unsigned ints
122 * The previous version only allows 32 bit bases(?)...
124 * NOTE: This absolutely sucks... there has to be a better way....
126 #define do_divll(n, base) ({ \
127 ullong_t __rem = 0; \
128 ullong_t __num = 0; \
144 #endif // ! __V3VEE__