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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
25 #include <palacios/vmm_types.h>
28 typedef union reg_ex {
39 // These are the GPRs layed out according to 'pusha'
52 #define GET_LOW_32(x) (*((uint_t*)(&(x))))
53 #define GET_HIGH_32(x) (*((uint_t*)(((uchar_t*)(&(x)))+4)))
56 void PrintTraceHex(uchar_t x);
57 void PrintTraceLL(ullong_t num);
58 void PrintTraceMemDump(uchar_t * start, int n);
63 #define rdtsc(low,high) \
64 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
67 __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
71 #define rdtscll(val) \
72 __asm__ __volatile__("rdtsc" : "=A" (val))
74 #elif defined(__x86_64__)
76 #define rdtscll(val) do { \
78 asm volatile("rdtsc" : "=a" (a), "=d" (d)); \
79 (val) = ((unsigned long)a) | (((unsigned long)d)<<32); \
93 #define do_divll do_div
96 #define do_div(n,base) ({ \
97 uint32_t __base = (base); \
99 __rem = ((uint64_t)(n)) % __base; \
100 (n) = ((uint64_t)(n)) / __base; \
107 * do_div() is NOT a C function. It wants to return
108 * two values (the quotient and the remainder), but
109 * since that doesn't work very well in C, what it
112 * - modifies the 64-bit dividend _in_place_
113 * - returns the 32-bit remainder
115 * This ends up being the most efficient "calling
116 * convention" on x86.
118 #define do_div(n,base) ({ \
119 unsigned long __upper, __low, __high, __mod, __base; \
121 asm("":"=a" (__low), "=d" (__high):"A" (n)); \
124 __upper = __high % (__base); \
125 __high = __high / (__base); \
127 asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
128 asm("":"=A" (n):"a" (__low),"d" (__high)); \
134 /* This divides two 64bit unsigned ints
135 * The previous version only allows 32 bit bases(?)...
137 * NOTE: This absolutely sucks... there has to be a better way....
139 #define do_divll(n, base) ({ \
140 ullong_t __rem = 0; \
141 ullong_t __num = 0; \
157 #endif // ! __V3VEE__