[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / arch / i386 / include / gpxe / rdtsc_timer.h
blob67ba22f004432ccb108d050d5fed9de0ae8ca7d9
1 #ifndef _GPXE_RDTSC_TIMER_H
2 #define _GPXE_RDTSC_TIMER_H
4 /** @file
6 * RDTSC timer
8 */
10 FILE_LICENCE ( GPL2_OR_LATER );
12 #ifdef TIMER_RDTSC
13 #define TIMER_PREFIX_rdtsc
14 #else
15 #define TIMER_PREFIX_rdtsc __rdtsc_
16 #endif
18 /**
19 * RDTSC values can easily overflow an unsigned long. We discard the
20 * low-order bits in order to obtain sensibly-scaled values.
22 #define TSC_SHIFT 8
24 /**
25 * Get current system time in ticks
27 * @ret ticks Current time, in ticks
29 static inline __always_inline unsigned long
30 TIMER_INLINE ( rdtsc, currticks ) ( void ) {
31 unsigned long ticks;
33 __asm__ __volatile__ ( "rdtsc\n\t"
34 "shrdl %1, %%edx, %%eax\n\t"
35 : "=a" ( ticks ) : "i" ( TSC_SHIFT ) : "edx" );
36 return ticks;
39 #endif /* _GPXE_RDTSC_TIMER_H */