3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: hal/halppc/generic/timer.c
5 * PURPOSE: HAL Timer Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
15 /* GLOBALS *******************************************************************/
17 BOOLEAN HalpClockSetMSRate
;
18 ULONG HalpCurrentTimeIncrement
;
19 ULONG HalpCurrentRollOver
;
20 ULONG HalpNextMSRate
= 14;
21 ULONG HalpLargestClockMS
= 15;
23 LARGE_INTEGER HalpRolloverTable
[15] =
42 /* PRIVATE FUNCTIONS *********************************************************/
46 HalpInitializeClock(VOID
)
48 //PKPRCB Prcb = KeGetCurrentPrcb();
53 /* Get increment and rollover for the largest time clock ms possible */
54 Increment
= HalpRolloverTable
[HalpLargestClockMS
- 1].HighPart
;
55 RollOver
= (USHORT
)HalpRolloverTable
[HalpLargestClockMS
- 1].LowPart
;
57 /* Set the maximum and minimum increment with the kernel */
58 HalpCurrentTimeIncrement
= Increment
;
59 KeSetTimeIncrement(Increment
, HalpRolloverTable
[0].HighPart
);
61 /* Disable interrupts */
65 /* Set the rollover */
66 __outbyte(TIMER_CONTROL_PORT
, TIMER_SC0
| TIMER_BOTH
| TIMER_MD2
);
67 __outbyte(TIMER_DATA_PORT0
, RollOver
& 0xFF);
68 __outbyte(TIMER_DATA_PORT0
, RollOver
>> 8);
70 /* Restore interrupts if they were previously enabled */
73 /* Save rollover and return */
74 HalpCurrentRollOver
= RollOver
;
77 /* PUBLIC FUNCTIONS ***********************************************************/
84 HalCalibratePerformanceCounter(IN
volatile PLONG Count
,
85 IN ULONGLONG NewCount
)
89 /* Disable interrupts */
93 /* Do a decrement for this CPU */
94 _InterlockedDecrement(Count
);
96 /* Wait for other CPUs */
99 /* Restore interrupts if they were previously enabled */
108 HalSetTimeIncrement(IN ULONG Increment
)
110 /* Round increment to ms */
113 /* Normalize between our minimum (1 ms) and maximum (variable) setting */
114 if (Increment
> HalpLargestClockMS
) Increment
= HalpLargestClockMS
;
115 if (Increment
<= 0) Increment
= 1;
117 /* Set the rate and tell HAL we want to change it */
118 HalpNextMSRate
= Increment
;
119 HalpClockSetMSRate
= TRUE
;
121 /* Return the increment */
122 return HalpRolloverTable
[Increment
- 1].HighPart
;
127 KeStallExecutionProcessor(ULONG USec
)
129 LARGE_INTEGER Freq
, Start
= KeQueryPerformanceCounter(&Freq
), End
;
130 LARGE_INTEGER Timebase
, Remainder
;
131 Timebase
.QuadPart
= 1000000;
132 Freq
.QuadPart
*= USec
;
133 End
= RtlLargeIntegerDivide(Freq
, Timebase
, &Remainder
);
134 End
.QuadPart
+= Start
.QuadPart
;
135 while(End
.QuadPart
> __rdtsc());