Mail Archives: djgpp-workers/2003/02/14/23:35:24
> 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 -