13f31c649SGarrett Wollman /* 23f31c649SGarrett Wollman * Kernel interface to machine-dependent clock driver. 33f31c649SGarrett Wollman * Garrett Wollman, September 1994. 43f31c649SGarrett Wollman * This file is in the public domain. 53f31c649SGarrett Wollman */ 63f31c649SGarrett Wollman 73f31c649SGarrett Wollman #ifndef _MACHINE_CLOCK_H_ 83f31c649SGarrett Wollman #define _MACHINE_CLOCK_H_ 1 93f31c649SGarrett Wollman 103f31c649SGarrett Wollman extern int pentium_mhz; 113f31c649SGarrett Wollman 123f31c649SGarrett Wollman #ifdef I586_CPU 133f31c649SGarrett Wollman /* 143f31c649SGarrett Wollman * This resets the CPU cycle counter to zero, to make our 153f31c649SGarrett Wollman * job easier in microtime(). Some fancy ifdefs could speed 163f31c649SGarrett Wollman * this up for Pentium-only kernels. 173f31c649SGarrett Wollman * We want this to be done as close as possible to the actual 183f31c649SGarrett Wollman * timer incrementing in hardclock(), because there is a window 193f31c649SGarrett Wollman * between the two where the value is no longer valid. Experimentation 203f31c649SGarrett Wollman * may reveal a good precompensation to apply in microtime(). 213f31c649SGarrett Wollman */ 223f31c649SGarrett Wollman #define CPU_CLOCKUPDATE(otime, ntime) \ 233f31c649SGarrett Wollman do { \ 243f31c649SGarrett Wollman if(pentium_mhz) { \ 253f31c649SGarrett Wollman __asm __volatile("cli\n" \ 263f31c649SGarrett Wollman "movl (%2),%%eax\n" \ 273f31c649SGarrett Wollman "movl %%eax,(%1)\n" \ 283f31c649SGarrett Wollman "movl 4(%2),%%eax\n" \ 293f31c649SGarrett Wollman "movl %%eax,4(%1)\n" \ 303f31c649SGarrett Wollman "movl $0x10,%%ecx\n" \ 313f31c649SGarrett Wollman "xorl %%eax,%%eax\n" \ 323f31c649SGarrett Wollman "movl %%eax,%%edx\n" \ 333f31c649SGarrett Wollman ".byte 0x0f, 0x30\n" \ 343f31c649SGarrett Wollman "sti\n" \ 353f31c649SGarrett Wollman "#%0%1%2" \ 363f31c649SGarrett Wollman : "=m"(*otime) /* no outputs */ \ 373f31c649SGarrett Wollman : "c"(otime), "b"(ntime) /* fake input */ \ 383f31c649SGarrett Wollman : "ax", "cx", "dx"); \ 393f31c649SGarrett Wollman } else { \ 403f31c649SGarrett Wollman *(otime) = *(ntime); \ 413f31c649SGarrett Wollman } \ 423f31c649SGarrett Wollman } while(0) 433f31c649SGarrett Wollman 443f31c649SGarrett Wollman #else 453f31c649SGarrett Wollman #define CPU_CLOCKUPDATE(otime, ntime) \ 463f31c649SGarrett Wollman (*(otime) = *(ntime)) 473f31c649SGarrett Wollman #endif 483f31c649SGarrett Wollman 493f31c649SGarrett Wollman #endif /* _MACHINE_CLOCK_H_ */ 50