[NTOS] Remove some hacks that are not needed anymore, since a real registry hive...
[reactos.git] / ntoskrnl / config / i386 / cmhardwr.c
index cb8d7e8..b98c269 100644 (file)
@@ -226,6 +226,99 @@ Match:
     return TRUE;
 }
 
+VOID
+NTAPI
+CmpGetIntelBrandString(OUT PCHAR CpuString)
+{
+    CPU_INFO CpuInfo;
+    ULONG BrandId, Signature;
+
+    /* Get the Brand Id */
+    KiCpuId(&CpuInfo, 0x00000001);
+    Signature = CpuInfo.Eax;
+    BrandId = CpuInfo.Ebx & 0xFF;
+
+    switch (BrandId)
+    {
+        case 0x01:
+            strcpy(CpuString, "Intel(R) Celeron(R) processor");
+            break;
+        case 0x02:
+        case 0x04:
+            strcpy(CpuString, "Intel(R) Pentium(R) III processor");
+            break;
+        case 0x03:
+            if(Signature == 0x000006B1)
+                strcpy(CpuString, "Intel(R) Celeron(R) processor");
+            else
+                strcpy(CpuString, "Intel(R) Pentium(R) III Xeon(R) processor");
+            break;
+        case 0x06:
+            strcpy(CpuString, "Mobile Intel(R) Pentium(R) III Processor-M");
+            break;
+        case 0x08:
+            if(Signature >= 0x00000F13)
+                strcpy(CpuString, "Intel(R) Genuine Processor");
+            else
+                strcpy(CpuString, "Intel(R) Pentium(R) 4 processor");
+            break;
+        case 0x09:
+            strcpy(CpuString, "Intel(R) Pentium(R) 4 processor");
+            break;
+        case 0x0B:
+            if(Signature >= 0x00000F13)
+                strcpy(CpuString, "Intel(R) Xeon(R) processor");
+            else
+                strcpy(CpuString, "Intel(R) Xeon(R) processor MP");
+            break;
+        case 0x0C:
+            strcpy(CpuString, "Intel(R) Xeon(R) processor MP");
+            break;
+        case 0x0E:
+            if(Signature >= 0x00000F13)
+                strcpy(CpuString, "Mobile Intel(R) Pentium(R) 4 processor-M");
+            else
+                strcpy(CpuString, "Intel(R) Xeon(R) processor");
+            break;
+        case 0x12:
+            strcpy(CpuString, "Intel(R) Celeron(R) M processor");
+            break;
+        case 0x07:
+        case 0x0F:
+        case 0x13:
+        case 0x17:
+            strcpy(CpuString, "Mobile Intel(R) Celeron(R) processor");
+            break;
+        case 0x0A:
+        case 0x14:
+            strcpy(CpuString, "Intel(R) Celeron(R) Processor");
+            break;
+        case 0x15:
+            strcpy(CpuString, "Mobile Genuine Intel(R) Processor");
+            break;
+        case 0x16:
+            strcpy(CpuString, "Intel(R) Pentium(R) M processor");
+            break;
+        default:
+            strcpy(CpuString, "Unknown Intel processor");
+    }
+}
+
+VOID
+NTAPI
+CmpGetVendorString(IN PKPRCB Prcb, OUT PCHAR CpuString)
+{
+    /* Check if we have a Vendor String */
+    if (Prcb->VendorString[0])
+    {
+        strcpy(CpuString, Prcb->VendorString);
+    }
+    else
+    {
+        strcpy(CpuString, "Unknown x86 processor");
+    }
+}
+
 NTSTATUS
 NTAPI
 CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
@@ -238,7 +331,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
     HANDLE KeyHandle, BiosHandle, SystemHandle, FpuHandle, SectionHandle;
     CONFIGURATION_COMPONENT_DATA ConfigData;
     CHAR Buffer[128];
-    ULONG ExtendedId, Dummy;
+    CPU_INFO CpuInfo;
+    ULONG VendorId, ExtendedId;
     PKPRCB Prcb;
     USHORT IndexTable[MaximumType + 1] = {0};
     ANSI_STRING TempString;
@@ -288,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,
@@ -306,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");
@@ -337,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++)
@@ -346,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;
@@ -383,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)
@@ -411,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;
                 }
 
@@ -424,11 +528,14 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                 if (!Prcb->CpuID)
                 {
                     /* Uh oh, no CPUID! */
+                    PartialString = CpuString;
+                    CmpGetVendorString(Prcb, PartialString);
                 }
                 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 */
@@ -436,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;
@@ -449,6 +556,24 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
                         /* Null-terminate it */
                         CpuString[47] = ANSI_NULL;
                     }
+                    else
+                    {
+                        KiCpuId(&CpuInfo, 0x00000000);
+                        VendorId = CpuInfo.Ebx;
+                        PartialString = CpuString;
+                        switch (VendorId)
+                        {
+                            case 'uneG': /* Intel */
+                                CmpGetIntelBrandString(PartialString);
+                                break;
+                            case 'htuA': /* AMD */
+                                /* FIXME */
+                                CmpGetVendorString(Prcb, PartialString);
+                                break;
+                            default:
+                                CmpGetVendorString(Prcb, PartialString);
+                        }
+                    }
                 }
 
                 /* Go back to user affinity */
@@ -557,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;
@@ -824,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;
 }