delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/02/14/23:35:24

From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10302150437.AA19004@clio.rice.edu>
Subject: Re: _rdtsc proposal
To: djgpp-workers AT delorie DOT com
Date: Fri, 14 Feb 2003 22:37:38 -0600 (CST)
In-Reply-To: <3E4B442E.6B87CC24@yahoo.com> from "CBFalconer" at Feb 13, 2003 02:07:26 AM
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> What I worry about is that the instruction will slip into
> something critical or other, and just lie there until someone with
> a 486 (like me) tries to use it.  It should be hard to access it,
> and the access should only be via a routine that can protect it. 
> So timer resolution falls - tough.

Here's my example.  It returns 0 on my 386.

#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <setjmp.h>
#include <sys/exceptn.h>

/* Catch rdtsc exception and always return 0LL */
void catch_rdtsc(int val)
{
  short *eip = (short *)__djgpp_exception_state->__eip;
  if(*eip == 0x310f) {
    __djgpp_exception_state->__eip += 2;
    __djgpp_exception_state->__edx = 0;		/* High longword */
    longjmp(__djgpp_exception_state, 0);	/* EAX = 0 */
  }
  return;
}

int main(void)
{
  long long t;

  signal(SIGILL, catch_rdtsc);
  t = _rdtsc();
  printf("Timer value: %lld\n",t);

  return 0;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019