ReactOS  0.4.13-dev-259-g5ca9c9c
timer.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS HAL
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)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <hal.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 /* GLOBALS *******************************************************************/
16 
22 
24 {
25  {{1197, 10032}},
26  {{2394, 20064}},
27  {{3591, 30096}},
28  {{4767, 39952}},
29  {{5964, 49984}},
30  {{7161, 60016}},
31  {{8358, 70048}},
32  {{9555, 80080}},
33  {{10731, 89936}},
34  {{11949, 100144}},
35  {{13125, 110000}},
36  {{14322, 120032}},
37  {{15519, 130064}},
38  {{16695, 139920}},
39  {{17892, 149952}}
40 };
41 
42 /* PRIVATE FUNCTIONS *********************************************************/
43 
44 VOID
45 NTAPI
47 {
48  //PKPRCB Prcb = KeGetCurrentPrcb();
50  USHORT RollOver;
51  ULONG Flags = 0;
52 
53  /* Get increment and rollover for the largest time clock ms possible */
55  RollOver = (USHORT)HalpRolloverTable[HalpLargestClockMS - 1].LowPart;
56 
57  /* Set the maximum and minimum increment with the kernel */
60 
61  /* Disable interrupts */
62  Flags = __readmsr();
63  _disable();
64 
65  /* Set the rollover */
67  __outbyte(TIMER_DATA_PORT0, RollOver & 0xFF);
68  __outbyte(TIMER_DATA_PORT0, RollOver >> 8);
69 
70  /* Restore interrupts if they were previously enabled */
72 
73  /* Save rollover and return */
74  HalpCurrentRollOver = RollOver;
75 }
76 
77 /* PUBLIC FUNCTIONS ***********************************************************/
78 
79 /*
80  * @implemented
81  */
82 VOID
83 NTAPI
85  IN ULONGLONG NewCount)
86 {
87  ULONG Flags = 0;
88 
89  /* Disable interrupts */
90  Flags = __readmsr();
91  _disable();
92 
93  /* Do a decrement for this CPU */
95 
96  /* Wait for other CPUs */
97  while (*Count);
98 
99  /* Restore interrupts if they were previously enabled */
100  __writemsr(Flags);
101 }
102 
103 /*
104  * @implemented
105  */
106 ULONG
107 NTAPI
109 {
110  /* Round increment to ms */
111  Increment /= 10000;
112 
113  /* Normalize between our minimum (1 ms) and maximum (variable) setting */
115  if (Increment <= 0) Increment = 1;
116 
117  /* Set the rate and tell HAL we want to change it */
120 
121  /* Return the increment */
123 }
124 
125 VOID
126 NTHALAPI
128 {
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());
136 }
137 
138 /* EOF */
VOID NTAPI HalCalibratePerformanceCounter(IN volatile PLONG Count, IN ULONGLONG NewCount)
Definition: timer.c:90
#define IN
Definition: typedefs.h:38
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
#define TRUE
Definition: types.h:120
VOID NTAPI KeSetTimeIncrement(IN ULONG MaxIncrement, IN ULONG MinIncrement)
Definition: ntoskrnl.c:46
#define NTHALAPI
Definition: ntoskrnl.h:39
#define TIMER_MD2
Definition: halp.h:26
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
BOOLEAN HalpClockSetMSRate
Definition: timer.c:17
PPC_QUAL void __outbyte(unsigned long const Port, const unsigned char Data)
Definition: intrin_ppc.h:605
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ULONG HalpNextMSRate
Definition: timer.c:20
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned char BOOLEAN
NTSYSAPI ULONGLONG WINAPI RtlLargeIntegerDivide(ULONGLONG, ULONGLONG, ULONGLONG *)
long __cdecl _InterlockedDecrement(_Interlocked_operand_ long volatile *_Addend)
#define TIMER_CONTROL_PORT
Definition: halp.h:22
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
LARGE_INTEGER HalpRolloverTable[15]
Definition: timer.c:23
uint64_t ULONGLONG
Definition: typedefs.h:65
VOID HalpInitializeClock(VOID)
Definition: timer.c:54
Definition: partlist.h:33
ULONG HalpCurrentRollOver
Definition: timer.c:19
VOID NTAPI KeStallExecutionProcessor(IN ULONG Microseconds)
Definition: timer.c:114
#define TIMER_DATA_PORT0
Definition: halp.h:23
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
unsigned short USHORT
Definition: pedump.c:61
ULONG HalpCurrentTimeIncrement
Definition: timer.c:25
#define Freq
Definition: deflate.h:79
#define TIMER_BOTH
Definition: halp.h:25
void __cdecl _disable(void)
Definition: intrin_arm.h:365
ULONG HalpLargestClockMS
Definition: timer.c:21
unsigned int ULONG
Definition: retypes.h:1
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
signed int * PLONG
Definition: retypes.h:5
#define TIMER_SC0
Definition: halp.h:24
ULONG NTAPI HalSetTimeIncrement(IN ULONG Increment)
Definition: timer.c:102
LONGLONG QuadPart
Definition: typedefs.h:112
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3046