ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

misc.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Hardware Abstraction Layer (HAL)
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            halx86/generic/misc.c
00005  * PURPOSE:         NMI, I/O Mapping and x86 Subs
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 /* INCLUDES *******************************************************************/
00010 
00011 #include <hal.h>
00012 #define NDEBUG
00013 #include <debug.h>
00014 
00015 /* GLOBALS  *******************************************************************/
00016 
00017 BOOLEAN HalpNMIInProgress;
00018 
00019 UCHAR HalpSerialLen;
00020 CHAR HalpSerialNumber[31];
00021 
00022 /* PRIVATE FUNCTIONS **********************************************************/
00023 
00024 #ifndef _MINIHAL_
00025 VOID
00026 NTAPI
00027 INIT_FUNCTION
00028 HalpReportSerialNumber(VOID)
00029 {
00030     NTSTATUS Status;
00031     UNICODE_STRING KeyString;
00032     HANDLE Handle;
00033 
00034     /* Make sure there is a serial number */
00035     if (!HalpSerialLen) return;
00036 
00037     /* Open the system key */
00038     RtlInitUnicodeString(&KeyString, L"\\Registry\\Machine\\Hardware\\Description\\System");
00039     Status = HalpOpenRegistryKey(&Handle, 0, &KeyString, KEY_ALL_ACCESS, FALSE);
00040     if (NT_SUCCESS(Status))
00041     {
00042         /* Add the serial number */
00043         RtlInitUnicodeString(&KeyString, L"Serial Number");
00044         ZwSetValueKey(Handle,
00045                       &KeyString,
00046                       0,
00047                       REG_BINARY,
00048                       HalpSerialNumber,
00049                       HalpSerialLen);
00050 
00051         /* Close the handle */
00052         ZwClose(Handle);
00053     }
00054 }
00055 
00056 NTSTATUS
00057 NTAPI
00058 INIT_FUNCTION
00059 HalpMarkAcpiHal(VOID)
00060 {
00061     NTSTATUS Status;
00062     UNICODE_STRING KeyString;
00063     HANDLE KeyHandle;
00064     HANDLE Handle;
00065     ULONG Value = HalDisableFirmwareMapper ? 1 : 0;
00066 
00067     /* Open the control set key */
00068     RtlInitUnicodeString(&KeyString,
00069                          L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET");
00070     Status = HalpOpenRegistryKey(&Handle, 0, &KeyString, KEY_ALL_ACCESS, FALSE);
00071     if (NT_SUCCESS(Status))
00072     {
00073         /* Open the PNP key */
00074         RtlInitUnicodeString(&KeyString, L"Control\\Pnp");
00075         Status = HalpOpenRegistryKey(&KeyHandle,
00076                                      Handle,
00077                                      &KeyString,
00078                                      KEY_ALL_ACCESS,
00079                                      TRUE);
00080         /* Close root key */
00081         ZwClose(Handle);
00082 
00083         /* Check if PNP BIOS key exists */
00084         if (NT_SUCCESS(Status))
00085         {
00086             /* Set the disable value to false -- we need the mapper */
00087             RtlInitUnicodeString(&KeyString, L"DisableFirmwareMapper");
00088             Status = ZwSetValueKey(KeyHandle,
00089                                    &KeyString,
00090                                    0,
00091                                    REG_DWORD,
00092                                    &Value,
00093                                    sizeof(Value));
00094 
00095             /* Close subkey */
00096             ZwClose(KeyHandle);
00097         }
00098     }
00099 
00100     /* Return status */
00101     return Status;
00102 }
00103 
00104 NTSTATUS
00105 NTAPI
00106 HalpOpenRegistryKey(IN PHANDLE KeyHandle,
00107                     IN HANDLE RootKey,
00108                     IN PUNICODE_STRING KeyName,
00109                     IN ACCESS_MASK DesiredAccess,
00110                     IN BOOLEAN Create)
00111 {
00112     NTSTATUS Status;
00113     ULONG Disposition;
00114     OBJECT_ATTRIBUTES ObjectAttributes;
00115 
00116     /* Setup the attributes we received */
00117     InitializeObjectAttributes(&ObjectAttributes,
00118                                KeyName,
00119                                OBJ_CASE_INSENSITIVE,
00120                                RootKey,
00121                                NULL);
00122 
00123     /* What to do? */
00124     if ( Create )
00125     {
00126         /* Create the key */
00127         Status = ZwCreateKey(KeyHandle,
00128                              DesiredAccess,
00129                              &ObjectAttributes,
00130                              0,
00131                              NULL,
00132                              REG_OPTION_VOLATILE,
00133                              &Disposition);
00134     }
00135     else
00136     {
00137         /* Open the key */
00138         Status = ZwOpenKey(KeyHandle, DesiredAccess, &ObjectAttributes);
00139     }
00140 
00141     /* We're done */
00142     return Status;
00143 }
00144 #endif
00145 
00146 VOID
00147 NTAPI
00148 HalpCheckPowerButton(VOID)
00149 {
00150     //
00151     // Nothing to do on non-ACPI
00152     //
00153     return;
00154 }
00155 
00156 VOID
00157 NTAPI
00158 HalpFlushTLB(VOID)
00159 {
00160     ULONG_PTR Flags, Cr4;
00161     INT CpuInfo[4];
00162     ULONG_PTR PageDirectory;
00163 
00164     //
00165     // Disable interrupts
00166     //
00167     Flags = __readeflags();
00168     _disable();
00169 
00170     //
00171     // Get page table directory base
00172     //
00173     PageDirectory = __readcr3();
00174 
00175     //
00176     // Check for CPUID support
00177     //
00178     if (KeGetCurrentPrcb()->CpuID)
00179     {
00180         //
00181         // Check for global bit in CPU features
00182         //
00183         __cpuid(CpuInfo, 1);
00184         if (CpuInfo[3] & 0x2000)
00185         {
00186             //
00187             // Get current CR4 value
00188             //
00189             Cr4 = __readcr4();
00190 
00191             //
00192             // Disable global bit
00193             //
00194             __writecr4(Cr4 & ~CR4_PGE);
00195 
00196             //
00197             // Flush TLB and re-enable global bit
00198             //
00199             __writecr3(PageDirectory);
00200             __writecr4(Cr4);
00201 
00202             //
00203             // Restore interrupts
00204             //
00205             __writeeflags(Flags);
00206             return;
00207         }
00208     }
00209 
00210     //
00211     // Legacy: just flush TLB
00212     //
00213     __writecr3(PageDirectory);
00214     __writeeflags(Flags);
00215 }
00216 
00217 /* FUNCTIONS *****************************************************************/
00218 
00219 /*
00220  * @implemented
00221  */
00222 VOID
00223 NTAPI
00224 HalHandleNMI(IN PVOID NmiInfo)
00225 {
00226 #ifndef _MINIHAL_
00227     SYSTEM_CONTROL_PORT_B_REGISTER SystemControl;
00228 
00229     //
00230     // Don't recurse
00231     //
00232     if (HalpNMIInProgress++) while (TRUE);
00233 
00234     //
00235     // Read the system control register B
00236     //
00237     SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
00238 
00239     //
00240     // Switch to boot vieo
00241     //
00242     if (InbvIsBootDriverInstalled())
00243     {
00244         //
00245         // Acquire ownership
00246         //
00247         InbvAcquireDisplayOwnership();
00248         InbvResetDisplay();
00249 
00250         //
00251         // Fill the screen
00252         //
00253         InbvSolidColorFill(0, 0, 639, 479, 1);
00254         InbvSetScrollRegion(0, 0, 639, 479);
00255 
00256         //
00257         // Enable text
00258         //
00259         InbvSetTextColor(15);
00260         InbvInstallDisplayStringFilter(NULL);
00261         InbvEnableDisplayString(TRUE);
00262     }
00263 
00264     //
00265     // Display NMI failure string
00266     //
00267     InbvDisplayString("\n*** Hardware Malfunction\n\n");
00268     InbvDisplayString("Call your hardware vendor for support\n\n");
00269 
00270     //
00271     // Check for parity error
00272     //
00273     if (SystemControl.ParityCheck)
00274     {
00275         //
00276         // Display message
00277         //
00278         InbvDisplayString("NMI: Parity Check / Memory Parity Error\n");
00279     }
00280 
00281     //
00282     // Check for I/O failure
00283     //
00284     if (SystemControl.ChannelCheck)
00285     {
00286         //
00287         // Display message
00288         //
00289         InbvDisplayString("NMI: Channel Check / IOCHK\n");
00290     }
00291 
00292     //
00293     // Check for EISA systems
00294     //
00295     if (HalpBusType == MACHINE_TYPE_EISA)
00296     {
00297         //
00298         // FIXME: Not supported
00299         //
00300         UNIMPLEMENTED;
00301     }
00302 
00303     //
00304     // Halt the system
00305     //
00306     InbvDisplayString("\n*** The system has halted ***\n");
00307 
00308 
00309     //
00310     // Enter the debugger if possible
00311     //
00312     KiBugCheckData[0] = (ULONG_PTR)KeServiceDescriptorTable; /* NMI Corruption? */
00313     //if (!(KdDebuggerNotPresent) && (KdDebuggerEnabled)) KeEnterKernelDebugger();
00314 #endif
00315     //
00316     // Freeze the system
00317     //
00318     while (TRUE);
00319 }
00320 
00321 /*
00322  * @implemented
00323  */
00324 UCHAR
00325 FASTCALL
00326 HalSystemVectorDispatchEntry(IN ULONG Vector,
00327                              OUT PKINTERRUPT_ROUTINE **FlatDispatch,
00328                              OUT PKINTERRUPT_ROUTINE *NoConnection)
00329 {
00330     //
00331     // Not implemented on x86
00332     //
00333     return 0;
00334 }
00335 
00336 /*
00337  * @implemented
00338  */
00339 VOID
00340 NTAPI
00341 KeFlushWriteBuffer(VOID)
00342 {
00343     //
00344     // Not implemented on x86
00345     //
00346     return;
00347 }
00348 
00349 #ifdef _M_IX86
00350 /* x86 fastcall wrappers */
00351 
00352 #undef KeRaiseIrql
00353 /*
00354  * @implemented
00355  */
00356 VOID
00357 NTAPI
00358 KeRaiseIrql(KIRQL NewIrql,
00359             PKIRQL OldIrql)
00360 {
00361     /* Call the fastcall function */
00362     *OldIrql = KfRaiseIrql(NewIrql);
00363 }
00364 
00365 #undef KeLowerIrql
00366 /*
00367  * @implemented
00368  */
00369 VOID
00370 NTAPI
00371 KeLowerIrql(KIRQL NewIrql)
00372 {
00373     /* Call the fastcall function */
00374     KfLowerIrql(NewIrql);
00375 }
00376 
00377 #undef KeAcquireSpinLock
00378 /*
00379  * @implemented
00380  */
00381 VOID
00382 NTAPI
00383 KeAcquireSpinLock(PKSPIN_LOCK SpinLock,
00384                   PKIRQL OldIrql)
00385 {
00386     /* Call the fastcall function */
00387     *OldIrql = KfAcquireSpinLock(SpinLock);
00388 }
00389 
00390 #undef KeReleaseSpinLock
00391 /*
00392  * @implemented
00393  */
00394 VOID
00395 NTAPI
00396 KeReleaseSpinLock(PKSPIN_LOCK SpinLock,
00397                   KIRQL NewIrql)
00398 {
00399     /* Call the fastcall function */
00400     KfReleaseSpinLock(SpinLock, NewIrql);
00401 }
00402 
00403 #endif
00404 

Generated on Sat May 26 2012 04:15:49 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.