From: Peter H. Froehlich Date: Wed, 21 Oct 2015 22:43:02 +0000 (-0400) Subject: The rdtsc(p) instruction. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=6b7caa6c473674043d275f532b2f0253819bd612;p=xv6-public The rdtsc(p) instruction. --- diff --git a/x86.h b/x86.h index 3949900..c171527 100644 --- 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().