From 6b7caa6c473674043d275f532b2f0253819bd612 Mon Sep 17 00:00:00 2001 From: "Peter H. Froehlich" Date: Wed, 21 Oct 2015 18:43:02 -0400 Subject: [PATCH] The rdtsc(p) instruction. --- x86.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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(). -- 2.50.1