]> hydra-www.ietfng.org Git - xv6-public/commitdiff
The rdtsc(p) instruction.
authorPeter H. Froehlich <peter.hans.froehlich@gmail.com>
Wed, 21 Oct 2015 22:43:02 +0000 (18:43 -0400)
committerPeter H. Froehlich <peter.hans.froehlich@gmail.com>
Wed, 21 Oct 2015 22:43:02 +0000 (18:43 -0400)
x86.h

diff --git a/x86.h b/x86.h
index 3949900bc8eb7e9afb334ca862a921ad63a6ea24..c171527516485f42e1dba63fe52f01b3dba0b92c 100644 (file)
--- a/x86.h
+++ b/x86.h
@@ -1,4 +1,5 @@
 // Routines to let C code use special x86 instructions.
+// Syntax reminder: (instructions : output : input : clobber)
 
 static inline uchar
 inb(ushort port)
@@ -121,7 +122,7 @@ static inline uint
 xchg(volatile uint *addr, uint newval)
 {
   uint result;
-  
+
   // The + in "+m" denotes a read-modify-write operand.
   asm volatile("lock; xchgl %0, %1" :
                "+m" (*addr), "=a" (result) :
@@ -139,11 +140,17 @@ rcr2(void)
 }
 
 static inline void
-lcr3(uint val) 
+lcr3(uint val)
 {
   asm volatile("movl %0,%%cr3" : : "r" (val));
 }
 
+static inline void
+rdtsc(uint *hi, uint *lo)
+{
+  asm volatile("rdtscp" : "=d" (*hi), "=a" (*lo) : : "%ecx");
+}
+
 //PAGEBREAK: 36
 // Layout of the trap frame built on the stack by the
 // hardware and by trapasm.S, and passed to trap().