OpenAtom  Version1.5a
timebase.c
1 
2 #define SPRN_TBRL 0x10C // Time Base Read Lower Register (user & sup R/O)
3 #define SPRN_TBRU 0x10D // Time Base Read Upper Register (user & sup R/O)
4 
5 #define _bgp_mfspr( SPRN )\
6 ({\
7  unsigned int tmp;\
8  do {\
9  asm volatile ("mfspr %0,%1" : "=&r" (tmp) : "i" (SPRN) : "memory" );\
10  }\
11  while(0);\
12  tmp;\
13 })\
14 
15 unsigned long long timebase( void )
16 {
17  union {
18  unsigned int ul[2];
19  unsigned long long ull;
20  }
21  hack;
22  unsigned int utmp;
23 
24  do {
25  utmp = _bgp_mfspr( SPRN_TBRU );
26  hack.ul[1] = _bgp_mfspr( SPRN_TBRL );
27  hack.ul[0] = _bgp_mfspr( SPRN_TBRU );
28  }
29  while( utmp != hack.ul[0] );
30 
31  return( hack.ull );
32 }
33 
34 double getTime( void )
35 {
36  union {
37  unsigned int ul[2];
38  unsigned long long ull;
39  }
40  hack;
41  unsigned int utmp;
42 
43  do {
44  utmp = _bgp_mfspr( SPRN_TBRU );
45  hack.ul[1] = _bgp_mfspr( SPRN_TBRL );
46  hack.ul[0] = _bgp_mfspr( SPRN_TBRU );
47  }
48  while( utmp != hack.ul[0] );
49 
50  return( (1.0/850000000.0) * ((double) hack.ull) );
51 }
52