[HAL]
[reactos.git] / reactos / hal / halx86 / generic / amd64 / misc.c
1 /*
2 * PROJECT: ReactOS HAL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: hal/halx86/generic/misc.c
5 * PURPOSE: Miscellanous Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Eric Kohl (ekohl@abo.rhein-zeitung.de)
8 * Timo Kreuzer (timo.kreuzer@reactos.org)
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <hal.h>
14 #define NDEBUG
15 #include <debug.h>
16
17 LARGE_INTEGER HalpPerformanceFrequency;
18
19 /* PRIVATE FUNCTIONS *********************************************************/
20
21 VOID
22 NTAPI
23 HalpCheckPowerButton(VOID)
24 {
25 /* Nothing to do on non-ACPI */
26 return;
27 }
28
29 PVOID
30 NTAPI
31 HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress,
32 IN ULONG NumberPage)
33 {
34 /* Use kernel memory manager I/O map facilities */
35 return MmMapIoSpace(PhysicalAddress,
36 NumberPage << PAGE_SHIFT,
37 MmNonCached);
38 }
39
40 VOID
41 NTAPI
42 HalpUnmapVirtualAddress(IN PVOID VirtualAddress,
43 IN ULONG NumberPages)
44 {
45 /* Use kernel memory manager I/O map facilities */
46 MmUnmapIoSpace(VirtualAddress, NumberPages << PAGE_SHIFT);
47 }
48
49 VOID
50 NTAPI
51 HalpInitIdtEntry(PKIDTENTRY64 Idt, PVOID Address)
52 {
53 Idt->OffsetLow = (ULONG_PTR)Address & 0xffff;
54 Idt->OffsetMiddle = ((ULONG_PTR)Address >> 16) & 0xffff;
55 Idt->OffsetHigh = (ULONG_PTR)Address >> 32;
56 Idt->Selector = KGDT_64_R0_CODE;
57 Idt->IstIndex = 0;
58 Idt->Type = 0x0e;
59 Idt->Dpl = 0;
60 Idt->Present = 1;
61 Idt->Reserved0 = 0;
62 Idt->Reserved1 = 0;
63 }
64
65 VOID
66 NTAPI
67 HalpSetInterruptGate(ULONG Index, PVOID Address)
68 {
69 ULONG_PTR Flags;
70
71 /* Disable interupts */
72 Flags = __readeflags();
73 _disable();
74
75 /* Initialize the entry */
76 HalpInitIdtEntry(&KeGetPcr()->IdtBase[Index], Address);
77
78 /* Enable interrupts if they were enabled previously */
79 __writeeflags(Flags);
80 }
81
82
83 /* FUNCTIONS *****************************************************************/
84
85 /*
86 * @implemented
87 */
88 VOID
89 NTAPI
90 HalHandleNMI(IN PVOID NmiInfo)
91 {
92 UCHAR ucStatus;
93
94 /* Get the NMI Flag */
95 ucStatus = READ_PORT_UCHAR((PUCHAR)0x61);
96
97 /* Display NMI failure string */
98 HalDisplayString ("\n*** Hardware Malfunction\n\n");
99 HalDisplayString ("Call your hardware vendor for support\n\n");
100
101 /* Check for parity error */
102 if (ucStatus & 0x80)
103 {
104 /* Display message */
105 HalDisplayString ("NMI: Parity Check / Memory Parity Error\n");
106 }
107
108 /* Check for I/O failure */
109 if (ucStatus & 0x40)
110 {
111 /* Display message */
112 HalDisplayString ("NMI: Channel Check / IOCHK\n");
113 }
114
115 /* Halt the system */
116 HalDisplayString("\n*** The system has halted ***\n");
117 //KeEnterKernelDebugger();
118 }
119
120 /*
121 * @implemented
122 */
123 UCHAR
124 FASTCALL
125 HalSystemVectorDispatchEntry(IN ULONG Vector,
126 OUT PKINTERRUPT_ROUTINE **FlatDispatch,
127 OUT PKINTERRUPT_ROUTINE *NoConnection)
128 {
129 /* Not implemented on x86 */
130 return FALSE;
131 }
132
133 VOID
134 NTAPI
135 HalBugCheckSystem (PVOID ErrorRecord)
136 {
137 UNIMPLEMENTED;
138 }
139
140
141 /*
142 * @implemented
143 */
144 VOID
145 NTAPI
146 KeFlushWriteBuffer(VOID)
147 {
148 /* Not implemented on x86 */
149 return;
150 }
151
152 LARGE_INTEGER
153 NTAPI
154 KeQueryPerformanceCounter(
155 OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL)
156 {
157 LARGE_INTEGER Result;
158
159 ASSERT(HalpPerformanceFrequency.QuadPart != 0);
160
161 /* Does the caller want the frequency? */
162 if (PerformanceFrequency)
163 {
164 /* Return value */
165 *PerformanceFrequency = HalpPerformanceFrequency;
166 }
167
168 Result.QuadPart = __rdtsc();
169 return Result;
170 }
171