[NTOS] Remove some hacks that are not needed anymore, since a real registry hive...
[reactos.git] / ntoskrnl / config / i386 / cmhardwr.c
index 5d967e1..b98c269 100644 (file)
@@ -230,11 +230,13 @@ VOID
 NTAPI
 CmpGetIntelBrandString(OUT PCHAR CpuString)
 {
-    ULONG BrandId, Ebx, Signature, Dummy;
-    
+    CPU_INFO CpuInfo;
+    ULONG BrandId, Signature;
+
     /* Get the Brand Id */
-    CPUID(0x00000001, &Signature, &Ebx, &Dummy, &Dummy);
-    BrandId = Ebx & 0xFF;
+    KiCpuId(&CpuInfo, 0x00000001);
+    Signature = CpuInfo.Eax;
+    BrandId = CpuInfo.Ebx & 0xFF;
 
     switch (BrandId)
     {
@@ -329,7 +331,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
     HANDLE KeyHandle, BiosHandle, SystemHandle, FpuHandle, SectionHandle;
     CONFIGURATION_COMPONENT_DATA ConfigData;
     CHAR Buffer[128];
-    ULONG VendorId, ExtendedId, Dummy;
+    CPU_INFO CpuInfo;
+    ULONG VendorId, ExtendedId;
     PKPRCB Prcb;
     USHORT IndexTable[MaximumType + 1] = {0};
     ANSI_STRING TempString;
@@ -379,7 +382,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                                NULL,
                                NULL);
     Status = NtOpenKey(&SystemHandle, KEY_READ | KEY_WRITE, &ObjectAttributes);
-    if (!NT_SUCCESS(Status)) return Status;
+    if (!NT_SUCCESS(Status))
+        return Status;
 
     /* Create the BIOS Information key */
     RtlInitUnicodeString(&KeyName,
@@ -397,13 +401,11 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                          NULL,
                          REG_OPTION_NON_VOLATILE,
                          &Disposition);
-    if (ExpInTextModeSetup)
+    if (!NT_SUCCESS(Status))
     {
-        if (!NT_SUCCESS(Status))
-            BiosHandle = NULL;
-    }
-    else if (!NT_SUCCESS(Status))
+        NtClose(SystemHandle);
         return Status;
+    }
 
     /* Create the CPU Key, and check if it already existed */
     RtlInitUnicodeString(&KeyName, L"CentralProcessor");
@@ -428,7 +430,11 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
         CmpConfigurationData = ExAllocatePoolWithTag(PagedPool,
                                                      CmpConfigurationAreaSize,
                                                      TAG_CM);
-        if (!CmpConfigurationData) return STATUS_INSUFFICIENT_RESOURCES;
+        if (!CmpConfigurationData)
+        {
+            // FIXME: Cleanup stuff!!
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
 
         /* Loop all CPUs */
         for (i = 0; i < KeNumberProcessors; i++)
@@ -437,7 +443,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
             Prcb = KiProcessorBlock[i];
 
             /* Setup the Configuration Entry for the Processor */
-            RtlZeroMemory(&ConfigData, sizeof (ConfigData));
+            RtlZeroMemory(&ConfigData, sizeof(ConfigData));
             ConfigData.ComponentEntry.Class = ProcessorClass;
             ConfigData.ComponentEntry.Type = CentralProcessor;
             ConfigData.ComponentEntry.Key = i;
@@ -474,7 +480,12 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                                                InterfaceTypeUndefined,
                                                0xFFFFFFFF,
                                                IndexTable);
-            if (!NT_SUCCESS(Status)) return(Status);
+            if (!NT_SUCCESS(Status))
+            {
+                NtClose(BiosHandle);
+                NtClose(SystemHandle);
+                return Status;
+            }
 
             /* Check if we have an FPU */
             if (KeI386NpxPresent)
@@ -502,8 +513,10 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                                                    IndexTable);
                 if (!NT_SUCCESS(Status))
                 {
-                    /* Failed, close the CPU handle and return */
+                    /* We failed, close all the opened handles and return */
                     NtClose(KeyHandle);
+                    NtClose(BiosHandle);
+                    NtClose(SystemHandle);
                     return Status;
                 }
 
@@ -521,7 +534,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                 else
                 {
                     /* Check if we have extended CPUID that supports name ID */
-                    CPUID(0x80000000, &ExtendedId, &Dummy, &Dummy, &Dummy);
+                    KiCpuId(&CpuInfo, 0x80000000);
+                    ExtendedId = CpuInfo.Eax;
                     if (ExtendedId >= 0x80000004)
                     {
                         /* Do all the CPUIDs required to get the full name */
@@ -529,11 +543,11 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                         for (ExtendedId = 2; ExtendedId <= 4; ExtendedId++)
                         {
                             /* Do the CPUID and save the name string */
-                            CPUID(0x80000000 | ExtendedId,
-                                  (PULONG)PartialString,
-                                  (PULONG)PartialString + 1,
-                                  (PULONG)PartialString + 2,
-                                  (PULONG)PartialString + 3);
+                            KiCpuId(&CpuInfo, 0x80000000 | ExtendedId);
+                            ((PULONG)PartialString)[0] = CpuInfo.Eax;
+                            ((PULONG)PartialString)[1] = CpuInfo.Ebx;
+                            ((PULONG)PartialString)[2] = CpuInfo.Ecx;
+                            ((PULONG)PartialString)[3] = CpuInfo.Edx;
 
                             /* Go to the next name string */
                             PartialString += 16;
@@ -544,7 +558,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                     }
                     else
                     {
-                        CPUID(0x00000000, &Dummy, &VendorId, &Dummy, &Dummy);
+                        KiCpuId(&CpuInfo, 0x00000000);
+                        VendorId = CpuInfo.Ebx;
                         PartialString = CpuString;
                         switch (VendorId)
                         {
@@ -667,7 +682,15 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
     Status = ZwOpenSection(&SectionHandle,
                            SECTION_ALL_ACCESS,
                            &ObjectAttributes);
-    if (!NT_SUCCESS(Status)) goto Quickie;
+    if (!NT_SUCCESS(Status))
+    {
+        /* We failed, close all the opened handles and return */
+        // NtClose(KeyHandle);
+        NtClose(BiosHandle);
+        NtClose(SystemHandle);
+        /* 'Quickie' closes KeyHandle */
+        goto Quickie;
+    }
 
     /* Map the first 1KB of memory to get the IVT */
     ViewSize = PAGE_SIZE;
@@ -934,7 +957,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
     if (BiosVersion) ExFreePoolWithTag(BiosVersion, TAG_CM);
 
 Quickie:
-    /* Close the procesor handle */
+    /* Close the processor handle */
     NtClose(KeyHandle);
     return STATUS_SUCCESS;
 }