ReactOS  0.4.15-dev-3294-ge98684e
misc.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Hardware Abstraction Layer (HAL)
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * PURPOSE: I/O Mapping and x86 Subs
5  * PROGRAMMERS: ReactOS Portable Systems Group
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include <hal.h>
11 
12 #define NDEBUG
13 #include <debug.h>
14 
15 /* GLOBALS *******************************************************************/
16 
19 
20 /* PRIVATE FUNCTIONS **********************************************************/
21 
22 #ifndef _MINIHAL_
23 CODE_SEG("INIT")
24 VOID
25 NTAPI
27 {
29  UNICODE_STRING KeyString;
30  HANDLE Handle;
31 
32  /* Make sure there is a serial number */
33  if (!HalpSerialLen) return;
34 
35  /* Open the system key */
36  RtlInitUnicodeString(&KeyString, L"\\Registry\\Machine\\Hardware\\Description\\System");
38  if (NT_SUCCESS(Status))
39  {
40  /* Add the serial number */
41  RtlInitUnicodeString(&KeyString, L"Serial Number");
42  ZwSetValueKey(Handle,
43  &KeyString,
44  0,
45  REG_BINARY,
48 
49  /* Close the handle */
50  ZwClose(Handle);
51  }
52 }
53 
54 CODE_SEG("INIT")
56 NTAPI
58 {
60  UNICODE_STRING KeyString;
62  HANDLE Handle;
64 
65  /* Open the control set key */
66  RtlInitUnicodeString(&KeyString,
67  L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET");
69  if (NT_SUCCESS(Status))
70  {
71  /* Open the PNP key */
72  RtlInitUnicodeString(&KeyString, L"Control\\Pnp");
74  Handle,
75  &KeyString,
77  TRUE);
78  /* Close root key */
79  ZwClose(Handle);
80 
81  /* Check if PNP BIOS key exists */
82  if (NT_SUCCESS(Status))
83  {
84  /* Set the disable value to false -- we need the mapper */
85  RtlInitUnicodeString(&KeyString, L"DisableFirmwareMapper");
86  Status = ZwSetValueKey(KeyHandle,
87  &KeyString,
88  0,
89  REG_DWORD,
90  &Value,
91  sizeof(Value));
92 
93  /* Close subkey */
95  }
96  }
97 
98  /* Return status */
99  return Status;
100 }
101 
102 NTSTATUS
103 NTAPI
105  IN HANDLE RootKey,
108  IN BOOLEAN Create)
109 {
113 
114  /* Setup the attributes we received */
116  KeyName,
118  RootKey,
119  NULL);
120 
121  /* What to do? */
122  if ( Create )
123  {
124  /* Create the key */
125  Status = ZwCreateKey(KeyHandle,
128  0,
129  NULL,
131  &Disposition);
132  }
133  else
134  {
135  /* Open the key */
137  }
138 
139  /* We're done */
140  return Status;
141 }
142 #endif /* !_MINIHAL_ */
143 
144 VOID
145 NTAPI
147 {
148  //
149  // Nothing to do on non-ACPI
150  //
151  return;
152 }
153 
154 VOID
155 NTAPI
157 {
158  ULONG_PTR Flags, Cr4;
159  INT CpuInfo[4];
160  ULONG_PTR PageDirectory;
161 
162  //
163  // Disable interrupts
164  //
165  Flags = __readeflags();
166  _disable();
167 
168  //
169  // Get page table directory base
170  //
171  PageDirectory = __readcr3();
172 
173  //
174  // Check for CPUID support
175  //
176  if (KeGetCurrentPrcb()->CpuID)
177  {
178  //
179  // Check for global bit in CPU features
180  //
181  __cpuid(CpuInfo, 1);
182  if (CpuInfo[3] & 0x2000)
183  {
184  //
185  // Get current CR4 value
186  //
187  Cr4 = __readcr4();
188 
189  //
190  // Disable global bit
191  //
192  __writecr4(Cr4 & ~CR4_PGE);
193 
194  //
195  // Flush TLB and re-enable global bit
196  //
197  __writecr3(PageDirectory);
198  __writecr4(Cr4);
199 
200  //
201  // Restore interrupts
202  //
204  return;
205  }
206  }
207 
208  //
209  // Legacy: just flush TLB
210  //
211  __writecr3(PageDirectory);
213 }
214 
215 /* FUNCTIONS *****************************************************************/
216 
217 /*
218  * @implemented
219  */
220 UCHAR
221 FASTCALL
223  OUT PKINTERRUPT_ROUTINE **FlatDispatch,
224  OUT PKINTERRUPT_ROUTINE *NoConnection)
225 {
226  //
227  // Not implemented on x86
228  //
229  return 0;
230 }
231 
232 /*
233  * @implemented
234  */
235 VOID
236 NTAPI
238 {
239  //
240  // Not implemented on x86
241  //
242  return;
243 }
244 
245 #ifdef _M_IX86
246 /* x86 fastcall wrappers */
247 
248 #undef KeRaiseIrql
249 /*
250  * @implemented
251  */
252 VOID
253 NTAPI
255  PKIRQL OldIrql)
256 {
257  /* Call the fastcall function */
259 }
260 
261 #undef KeLowerIrql
262 /*
263  * @implemented
264  */
265 VOID
266 NTAPI
268 {
269  /* Call the fastcall function */
271 }
272 
273 #undef KeAcquireSpinLock
274 /*
275  * @implemented
276  */
277 VOID
278 NTAPI
280  PKIRQL OldIrql)
281 {
282  /* Call the fastcall function */
284 }
285 
286 #undef KeReleaseSpinLock
287 /*
288  * @implemented
289  */
290 VOID
291 NTAPI
293  KIRQL NewIrql)
294 {
295  /* Call the fastcall function */
297 }
298 
299 #endif /* _M_IX86 */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1800
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
static PMEMKEY RootKey
Definition: registry.c:55
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define REG_BINARY
Definition: nt_native.h:1496
#define TRUE
Definition: types.h:120
VOID NTAPI HalpFlushTLB(VOID)
Definition: misc.c:156
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ BOOLEAN Create
Definition: pstypes.h:527
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1819
#define FASTCALL
Definition: nt_native.h:50
int32_t INT
Definition: typedefs.h:58
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CR4_PGE
Definition: ketypes.h:91
UCHAR KIRQL
Definition: env_spec_w32.h:591
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1795
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1675
VOID NTAPI HalpCheckPowerButton(VOID)
Definition: misc.c:146
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI HalpOpenRegistryKey(IN PHANDLE KeyHandle, IN HANDLE RootKey, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN BOOLEAN Create)
Definition: misc.c:104
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
unsigned char BOOLEAN
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
KIRQL OldIrql
Definition: mm.h:1502
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
VOID(NTAPI * PKINTERRUPT_ROUTINE)(VOID)
Definition: ketypes.h:490
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI HalpMarkAcpiHal(VOID)
Definition: misc.c:57
UCHAR HalpSerialLen
Definition: misc.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql)
Definition: spinlock.c:96
UCHAR FASTCALL HalSystemVectorDispatchEntry(IN ULONG Vector, OUT PKINTERRUPT_ROUTINE **FlatDispatch, OUT PKINTERRUPT_ROUTINE *NoConnection)
Definition: misc.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1670
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1826
VOID NTAPI KeFlushWriteBuffer(VOID)
Definition: misc.c:39
CHAR HalpSerialNumber[31]
Definition: misc.c:18
BOOLEAN HalDisableFirmwareMapper
Definition: halacpi.c:43
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
VOID NTAPI HalpReportSerialNumber(VOID)
Definition: misc.c:26
_In_ HANDLE Handle
Definition: extypes.h:390
#define OUT
Definition: typedefs.h:40
KIRQL FASTCALL KfAcquireSpinLock(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:85
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
#define REG_DWORD
Definition: sdbapi.c:596
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
ULONG ACCESS_MASK
Definition: nt_native.h:40
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114