2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/config/i386/cmhardwr.c
5 * PURPOSE: Configuration Manager - Hardware-Specific Code
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
15 /* GLOBALS *******************************************************************/
17 PCHAR CmpID1
= "80%u86-%c%x";
18 PCHAR CmpID2
= "x86 Family %u Model %u Stepping %u";
19 PCHAR CmpBiosStrings
[] =
24 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9",
25 "v 0", "v 1", "v 2", "v 3", "v 4", "v 5", "v 6", "v 7", "v 8", "v 9",
29 PCHAR CmpBiosBegin
, CmpBiosSearchStart
, CmpBiosSearchEnd
;
31 /* FUNCTIONS *****************************************************************/
35 CmpGetBiosDate(IN PCHAR BiosStart
,
40 CHAR LastDate
[11] = {0}, CurrentDate
[11];
43 /* Skip the signature and the magic, and loop the BIOS ROM */
45 pp
= BiosStart
+ BiosLength
- 5;
48 /* Check for xx/yy/zz which we assume to be a date */
57 /* Copy the string proper */
58 RtlMoveMemory(&CurrentDate
[5], p
- 2, 5);
60 /* Add a 0 if the month only has one digit */
61 if (!isdigit(CurrentDate
[5])) CurrentDate
[5] = '0';
63 /* Now copy the year */
64 CurrentDate
[2] = p
[4];
65 CurrentDate
[3] = p
[5];
66 CurrentDate
[4] = CurrentDate
[7] = CurrentDate
[10] = ANSI_NULL
;
68 /* If the date comes from the BIOS, check if it's a 4-digit year */
72 ((RtlEqualMemory(&p
[4], "19", 2)) ||
73 (RtlEqualMemory(&p
[4], "20", 2))))
75 /* Copy the year proper */
76 CurrentDate
[0] = p
[4];
77 CurrentDate
[1] = p
[5];
78 CurrentDate
[2] = p
[6];
79 CurrentDate
[3] = p
[7];
83 /* Otherwise, we'll just assume anything under 80 is 2000 */
84 if (strtoul(&CurrentDate
[2], NULL
, 10) < 80)
86 /* Hopefully your BIOS wasn't made in 1979 */
92 /* Anything over 80, was probably made in the 1900s... */
98 /* Add slashes where we previously had NULLs */
99 CurrentDate
[4] = CurrentDate
[7] = '/';
101 /* Check which date is newer */
102 if (memcmp(LastDate
, CurrentDate
, 10) < 0)
104 /* Found a newer date, select it */
105 RtlMoveMemory(LastDate
, CurrentDate
, 10);
113 /* Make sure we found a date */
116 /* Copy the year at the pp, and keep only the last two digits */
117 RtlMoveMemory(BiosDate
, &LastDate
[5], 5);
119 BiosDate
[6] = LastDate
[2];
120 BiosDate
[7] = LastDate
[3];
121 BiosDate
[8] = ANSI_NULL
;
125 /* No date found, return empty string */
126 BiosDate
[0] = ANSI_NULL
;
132 CmpGetBiosVersion(IN PCHAR BiosStart
,
134 IN PCHAR BiosVersion
)
140 /* Check if we were given intitial data for the search */
143 /* Save it for later use */
144 CmpBiosBegin
= BiosStart
;
145 CmpBiosSearchStart
= BiosStart
+ 1;
146 CmpBiosSearchEnd
= BiosStart
+ BiosLength
- 2;
149 /* Now loop the BIOS area */
152 /* Start an initial search looking for numbers and periods */
154 while (CmpBiosSearchStart
<= CmpBiosSearchEnd
)
156 /* Check if we have an "x.y" version string */
157 if ((*CmpBiosSearchStart
== '.') &&
158 (*(CmpBiosSearchStart
+ 1) >= '0') &&
159 (*(CmpBiosSearchStart
+ 1) <= '9') &&
160 (*(CmpBiosSearchStart
- 1) >= '0') &&
161 (*(CmpBiosSearchStart
- 1) <= '9'))
163 /* Start looking in this area for the actual BIOS Version */
164 pp
= CmpBiosSearchStart
;
170 CmpBiosSearchStart
++;
174 /* Break out if we're went past the BIOS area */
175 if (CmpBiosSearchStart
> CmpBiosSearchEnd
) return FALSE
;
177 /* Move to the next 2 bytes */
178 CmpBiosSearchStart
+= 2;
180 /* Null-terminate our scratch buffer and start the string here */
181 Buffer
[127] = ANSI_NULL
;
184 /* Go back one character since we're doing this backwards */
187 /* Loop the identifier we found as long as it's valid */
189 while ((i
++ < 127) &&
190 (pp
>= CmpBiosBegin
) &&
194 /* Copy the character */
198 /* Go past the last character since we went backwards */
201 /* Loop the strings we recognize */
202 for (i
= 0; CmpBiosStrings
[i
]; i
++)
204 /* Check if a match was found */
205 if (strstr(p
, CmpBiosStrings
[i
])) goto Match
;
210 /* Skip until we find a space */
211 for (; *pp
== ' '; pp
++);
213 /* Loop the final string */
217 /* Copy the character into the final string */
218 BiosVersion
[i
] = *pp
++;
219 } while ((++i
< 127) &&
220 (pp
<= (CmpBiosSearchEnd
+ 1)) &&
224 /* Null-terminate the version string */
225 BiosVersion
[i
] = ANSI_NULL
;
231 CmpGetIntelBrandString(OUT PCHAR CpuString
)
233 ULONG BrandId
, Ebx
, Signature
, Dummy
;
235 /* Get the Brand Id */
236 CPUID(0x00000001, &Signature
, &Ebx
, &Dummy
, &Dummy
);
237 BrandId
= Ebx
& 0xFF;
242 strcpy(CpuString
, "Intel(R) Celeron(R) processor");
246 strcpy(CpuString
, "Intel(R) Pentium(R) III processor");
249 if(Signature
== 0x000006B1)
250 strcpy(CpuString
, "Intel(R) Celeron(R) processor");
252 strcpy(CpuString
, "Intel(R) Pentium(R) III Xeon(R) processor");
255 strcpy(CpuString
, "Mobile Intel(R) Pentium(R) III Processor-M");
258 if(Signature
>= 0x00000F13)
259 strcpy(CpuString
, "Intel(R) Genuine Processor");
261 strcpy(CpuString
, "Intel(R) Pentium(R) 4 processor");
264 strcpy(CpuString
, "Intel(R) Pentium(R) 4 processor");
267 if(Signature
>= 0x00000F13)
268 strcpy(CpuString
, "Intel(R) Xeon(R) processor");
270 strcpy(CpuString
, "Intel(R) Xeon(R) processor MP");
273 strcpy(CpuString
, "Intel(R) Xeon(R) processor MP");
276 if(Signature
>= 0x00000F13)
277 strcpy(CpuString
, "Mobile Intel(R) Pentium(R) 4 processor-M");
279 strcpy(CpuString
, "Intel(R) Xeon(R) processor");
282 strcpy(CpuString
, "Intel(R) Celeron(R) M processor");
288 strcpy(CpuString
, "Mobile Intel(R) Celeron(R) processor");
292 strcpy(CpuString
, "Intel(R) Celeron(R) Processor");
295 strcpy(CpuString
, "Mobile Genuine Intel(R) Processor");
298 strcpy(CpuString
, "Intel(R) Pentium(R) M processor");
301 strcpy(CpuString
, "Unknown Intel processor");
307 CmpGetVendorString(IN PKPRCB Prcb
, OUT PCHAR CpuString
)
309 /* Check if we have a Vendor String */
310 if (Prcb
->VendorString
[0])
312 strcpy(CpuString
, Prcb
->VendorString
);
316 strcpy(CpuString
, "Unknown x86 processor");
322 CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
324 UNICODE_STRING KeyName
, ValueName
, Data
, SectionName
;
325 OBJECT_ATTRIBUTES ObjectAttributes
;
326 ULONG HavePae
, Length
, TotalLength
= 0, i
, Disposition
;
329 HANDLE KeyHandle
, BiosHandle
, SystemHandle
, FpuHandle
, SectionHandle
;
330 CONFIGURATION_COMPONENT_DATA ConfigData
;
332 ULONG VendorId
, ExtendedId
, Dummy
;
334 USHORT IndexTable
[MaximumType
+ 1] = {0};
335 ANSI_STRING TempString
;
336 PCHAR PartialString
= NULL
, BiosVersion
;
338 PVOID BaseAddress
= NULL
;
339 LARGE_INTEGER ViewBase
= {{0, 0}};
340 ULONG_PTR VideoRomBase
;
341 PCHAR CurrentVersion
;
342 extern UNICODE_STRING KeRosProcessorName
, KeRosBiosDate
, KeRosBiosVersion
;
343 extern UNICODE_STRING KeRosVideoBiosDate
, KeRosVideoBiosVersion
;
345 /* Open the SMSS Memory Management key */
346 RtlInitUnicodeString(&KeyName
,
347 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\"
348 L
"Control\\Session Manager\\Memory Management");
349 InitializeObjectAttributes(&ObjectAttributes
,
351 OBJ_CASE_INSENSITIVE
,
354 Status
= NtOpenKey(&KeyHandle
, KEY_READ
| KEY_WRITE
, &ObjectAttributes
);
355 if (NT_SUCCESS(Status
))
357 /* Detect if PAE is enabled */
358 HavePae
= SharedUserData
->ProcessorFeatures
[PF_PAE_ENABLED
];
361 RtlInitUnicodeString(&ValueName
, L
"PhysicalAddressExtension");
362 NtSetValueKey(KeyHandle
,
373 /* Open the hardware description key */
374 RtlInitUnicodeString(&KeyName
,
375 L
"\\Registry\\Machine\\Hardware\\Description\\System");
376 InitializeObjectAttributes(&ObjectAttributes
,
378 OBJ_CASE_INSENSITIVE
,
381 Status
= NtOpenKey(&SystemHandle
, KEY_READ
| KEY_WRITE
, &ObjectAttributes
);
382 if (!NT_SUCCESS(Status
)) return Status
;
384 /* Create the BIOS Information key */
385 RtlInitUnicodeString(&KeyName
,
386 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\"
387 L
"Control\\BIOSINFO");
388 InitializeObjectAttributes(&ObjectAttributes
,
390 OBJ_CASE_INSENSITIVE
,
393 Status
= NtCreateKey(&BiosHandle
,
398 REG_OPTION_NON_VOLATILE
,
400 if (ExpInTextModeSetup
)
402 if (!NT_SUCCESS(Status
))
405 else if (!NT_SUCCESS(Status
))
408 /* Create the CPU Key, and check if it already existed */
409 RtlInitUnicodeString(&KeyName
, L
"CentralProcessor");
410 InitializeObjectAttributes(&ObjectAttributes
,
412 OBJ_CASE_INSENSITIVE
,
415 Status
= NtCreateKey(&KeyHandle
,
416 KEY_READ
| KEY_WRITE
,
424 /* The key shouldn't already exist */
425 if (Disposition
== REG_CREATED_NEW_KEY
)
427 /* Allocate the configuration data for cmconfig.c */
428 CmpConfigurationData
= ExAllocatePoolWithTag(PagedPool
,
429 CmpConfigurationAreaSize
,
431 if (!CmpConfigurationData
) return STATUS_INSUFFICIENT_RESOURCES
;
434 for (i
= 0; i
< KeNumberProcessors
; i
++)
437 Prcb
= KiProcessorBlock
[i
];
439 /* Setup the Configuration Entry for the Processor */
440 RtlZeroMemory(&ConfigData
, sizeof (ConfigData
));
441 ConfigData
.ComponentEntry
.Class
= ProcessorClass
;
442 ConfigData
.ComponentEntry
.Type
= CentralProcessor
;
443 ConfigData
.ComponentEntry
.Key
= i
;
444 ConfigData
.ComponentEntry
.AffinityMask
= AFFINITY_MASK(i
);
445 ConfigData
.ComponentEntry
.Identifier
= Buffer
;
447 /* Check if the CPU doesn't support CPUID */
450 /* Build ID1-style string for older CPUs */
454 (Prcb
->CpuStep
>> 8) + 'A',
455 Prcb
->CpuStep
& 0xff);
459 /* Build ID2-style string for newer CPUs */
463 (Prcb
->CpuStep
>> 8),
464 Prcb
->CpuStep
& 0xff);
467 /* Save the ID string length now that we've created it */
468 ConfigData
.ComponentEntry
.IdentifierLength
= (ULONG
)strlen(Buffer
) + 1;
470 /* Initialize the registry configuration node for it */
471 Status
= CmpInitializeRegistryNode(&ConfigData
,
474 InterfaceTypeUndefined
,
477 if (!NT_SUCCESS(Status
)) return(Status
);
479 /* Check if we have an FPU */
480 if (KeI386NpxPresent
)
482 /* Setup the Configuration Entry for the FPU */
483 RtlZeroMemory(&ConfigData
, sizeof(ConfigData
));
484 ConfigData
.ComponentEntry
.Class
= ProcessorClass
;
485 ConfigData
.ComponentEntry
.Type
= FloatingPointProcessor
;
486 ConfigData
.ComponentEntry
.Key
= i
;
487 ConfigData
.ComponentEntry
.AffinityMask
= AFFINITY_MASK(i
);
488 ConfigData
.ComponentEntry
.Identifier
= Buffer
;
490 /* For 386 cpus, the CPU pp is the identifier */
491 if (Prcb
->CpuType
== 3) strcpy(Buffer
, "80387");
493 /* Save the ID string length now that we've created it */
494 ConfigData
.ComponentEntry
.IdentifierLength
= (ULONG
)strlen(Buffer
) + 1;
496 /* Initialize the registry configuration node for it */
497 Status
= CmpInitializeRegistryNode(&ConfigData
,
500 InterfaceTypeUndefined
,
503 if (!NT_SUCCESS(Status
))
505 /* Failed, close the CPU handle and return */
510 /* Close this new handle */
513 /* Stay on this CPU only */
514 KeSetSystemAffinityThread(Prcb
->SetMember
);
517 /* Uh oh, no CPUID! */
518 PartialString
= CpuString
;
519 CmpGetVendorString(Prcb
, PartialString
);
523 /* Check if we have extended CPUID that supports name ID */
524 CPUID(0x80000000, &ExtendedId
, &Dummy
, &Dummy
, &Dummy
);
525 if (ExtendedId
>= 0x80000004)
527 /* Do all the CPUIDs required to get the full name */
528 PartialString
= CpuString
;
529 for (ExtendedId
= 2; ExtendedId
<= 4; ExtendedId
++)
531 /* Do the CPUID and save the name string */
532 CPUID(0x80000000 | ExtendedId
,
533 (PULONG
)PartialString
,
534 (PULONG
)PartialString
+ 1,
535 (PULONG
)PartialString
+ 2,
536 (PULONG
)PartialString
+ 3);
538 /* Go to the next name string */
542 /* Null-terminate it */
543 CpuString
[47] = ANSI_NULL
;
547 CPUID(0x00000000, &Dummy
, &VendorId
, &Dummy
, &Dummy
);
548 PartialString
= CpuString
;
551 case 'uneG': /* Intel */
552 CmpGetIntelBrandString(PartialString
);
554 case 'htuA': /* AMD */
556 CmpGetVendorString(Prcb
, PartialString
);
559 CmpGetVendorString(Prcb
, PartialString
);
564 /* Go back to user affinity */
565 KeRevertToUserAffinityThread();
567 /* Check if we have a CPU Name */
570 /* Convert it to Unicode */
571 RtlInitAnsiString(&TempString
, CpuString
);
572 RtlAnsiStringToUnicodeString(&Data
, &TempString
, TRUE
);
574 /* Add it to the registry */
575 RtlInitUnicodeString(&ValueName
, L
"ProcessorNameString");
576 Status
= NtSetValueKey(KeyHandle
,
581 Data
.Length
+ sizeof(UNICODE_NULL
));
583 /* ROS: Save a copy for bugzilla reporting */
584 RtlCreateUnicodeString(&KeRosProcessorName
, Data
.Buffer
);
586 /* Free the temporary buffer */
587 RtlFreeUnicodeString(&Data
);
590 /* Check if we had a Vendor ID */
591 if (Prcb
->VendorString
[0])
593 /* Convert it to Unicode */
594 RtlInitAnsiString(&TempString
, Prcb
->VendorString
);
595 RtlAnsiStringToUnicodeString(&Data
, &TempString
, TRUE
);
597 /* Add it to the registry */
598 RtlInitUnicodeString(&ValueName
, L
"VendorIdentifier");
599 Status
= NtSetValueKey(KeyHandle
,
604 Data
.Length
+ sizeof(UNICODE_NULL
));
606 /* Free the temporary buffer */
607 RtlFreeUnicodeString(&Data
);
610 /* Check if we have features bits */
611 if (Prcb
->FeatureBits
)
613 /* Add them to the registry */
614 RtlInitUnicodeString(&ValueName
, L
"FeatureSet");
615 Status
= NtSetValueKey(KeyHandle
,
620 sizeof(Prcb
->FeatureBits
));
623 /* Check if we detected the CPU Speed */
626 /* Add it to the registry */
627 RtlInitUnicodeString(&ValueName
, L
"~MHz");
628 Status
= NtSetValueKey(KeyHandle
,
636 /* Check if we have an update signature */
637 if (Prcb
->UpdateSignature
.QuadPart
)
639 /* Add it to the registry */
640 RtlInitUnicodeString(&ValueName
, L
"Update Signature");
641 Status
= NtSetValueKey(KeyHandle
,
645 &Prcb
->UpdateSignature
,
646 sizeof(Prcb
->UpdateSignature
));
649 /* Close the processor handle */
652 /* FIXME: Detect CPU mismatches */
656 /* Free the configuration data */
657 ExFreePoolWithTag(CmpConfigurationData
, TAG_CM
);
660 /* Open physical memory */
661 RtlInitUnicodeString(&SectionName
, L
"\\Device\\PhysicalMemory");
662 InitializeObjectAttributes(&ObjectAttributes
,
664 OBJ_CASE_INSENSITIVE
,
667 Status
= ZwOpenSection(&SectionHandle
,
670 if (!NT_SUCCESS(Status
)) goto Quickie
;
672 /* Map the first 1KB of memory to get the IVT */
673 ViewSize
= PAGE_SIZE
;
674 Status
= ZwMapViewOfSection(SectionHandle
,
684 if (!NT_SUCCESS(Status
))
687 VideoRomBase
= 0xC0000;
691 /* Calculate the base address from the vector */
692 VideoRomBase
= (*((PULONG
)BaseAddress
+ 0x10) >> 12) & 0xFFFF0;
693 VideoRomBase
+= *((PULONG
)BaseAddress
+ 0x10) & 0xFFF0;
695 /* Now get to the actual ROM Start and make sure it's not invalid*/
696 VideoRomBase
&= 0xFFFF8000;
697 if (VideoRomBase
< 0xC0000) VideoRomBase
= 0xC0000;
699 /* And unmap the section */
700 ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress
);
703 /* Allocate BIOS Version pp Buffer */
704 BiosVersion
= ExAllocatePoolWithTag(PagedPool
, PAGE_SIZE
, TAG_CM
);
706 /* Setup settings to map the 64K BIOS ROM */
708 ViewSize
= 16 * PAGE_SIZE
;
709 ViewBase
.LowPart
= 0xF0000;
710 ViewBase
.HighPart
= 0;
713 Status
= ZwMapViewOfSection(SectionHandle
,
723 if (NT_SUCCESS(Status
))
725 /* Scan the ROM to get the BIOS Date */
726 if (CmpGetBiosDate(BaseAddress
, 16 * PAGE_SIZE
, Buffer
, TRUE
))
728 /* Convert it to Unicode */
729 RtlInitAnsiString(&TempString
, Buffer
);
730 RtlAnsiStringToUnicodeString(&Data
, &TempString
, TRUE
);
732 /* Write the date into the registry */
733 RtlInitUnicodeString(&ValueName
, L
"SystemBiosDate");
734 Status
= NtSetValueKey(SystemHandle
,
739 Data
.Length
+ sizeof(UNICODE_NULL
));
741 /* Free the string */
742 RtlFreeUnicodeString(&Data
);
746 /* Get the BIOS Date Identifier */
747 RtlCopyMemory(Buffer
, (PCHAR
)BaseAddress
+ (16 * PAGE_SIZE
- 11), 8);
748 Buffer
[8] = ANSI_NULL
;
750 /* Convert it to unicode */
751 RtlInitAnsiString(&TempString
, Buffer
);
752 Status
= RtlAnsiStringToUnicodeString(&Data
, &TempString
, TRUE
);
753 if (NT_SUCCESS(Status
))
755 /* Save it to the registry */
756 Status
= NtSetValueKey(BiosHandle
,
761 Data
.Length
+ sizeof(UNICODE_NULL
));
763 /* ROS: Save a copy for bugzilla reporting */
764 RtlCreateUnicodeString(&KeRosBiosDate
, Data
.Buffer
);
766 /* Free the string */
767 RtlFreeUnicodeString(&Data
);
770 /* Close the bios information handle */
775 /* Get the BIOS Version */
776 if (CmpGetBiosVersion(BaseAddress
, 16 * PAGE_SIZE
, Buffer
))
778 /* Start at the beginning of our buffer */
779 CurrentVersion
= BiosVersion
;
782 /* Convert to Unicode */
783 RtlInitAnsiString(&TempString
, Buffer
);
784 RtlAnsiStringToUnicodeString(&Data
, &TempString
, TRUE
);
786 /* Calculate the length of this string and copy it in */
787 Length
= Data
.Length
+ sizeof(UNICODE_NULL
);
788 RtlMoveMemory(CurrentVersion
, Data
.Buffer
, Length
);
790 /* Free the unicode string */
791 RtlFreeUnicodeString(&Data
);
793 /* Update the total length and see if we're out of space */
794 TotalLength
+= Length
;
795 if (TotalLength
+ 256 + sizeof(UNICODE_NULL
) > PAGE_SIZE
)
797 /* One more string would push us out, so stop here */
801 /* Go to the next string inside the multi-string buffer */
802 CurrentVersion
+= Length
;
804 /* Query the next BIOS Version */
805 } while (CmpGetBiosVersion(NULL
, 0, Buffer
));
807 /* Check if we found any strings at all */
810 /* Add the final null-terminator */
811 *(PWSTR
)CurrentVersion
= UNICODE_NULL
;
812 TotalLength
+= sizeof(UNICODE_NULL
);
814 /* Write the BIOS Version to the registry */
815 RtlInitUnicodeString(&ValueName
, L
"SystemBiosVersion");
816 Status
= NtSetValueKey(SystemHandle
,
823 /* ROS: Save a copy for bugzilla reporting */
824 RtlCreateUnicodeString(&KeRosBiosVersion
, (PWCH
)BiosVersion
);
828 /* Unmap the section */
829 ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress
);
832 /* Now prepare for Video BIOS Mapping of 32KB */
834 ViewSize
= 8 * PAGE_SIZE
;
835 ViewBase
.QuadPart
= VideoRomBase
;
838 Status
= ZwMapViewOfSection(SectionHandle
,
848 if (NT_SUCCESS(Status
))
850 /* Scan the ROM to get the BIOS Date */
851 if (CmpGetBiosDate(BaseAddress
, 8 * PAGE_SIZE
, Buffer
, FALSE
))
853 /* Convert it to Unicode */
854 RtlInitAnsiString(&TempString
, Buffer
);
855 RtlAnsiStringToUnicodeString(&Data
, &TempString
, TRUE
);
857 /* Write the date into the registry */
858 RtlInitUnicodeString(&ValueName
, L
"VideoBiosDate");
859 Status
= NtSetValueKey(SystemHandle
,
864 Data
.Length
+ sizeof(UNICODE_NULL
));
866 /* ROS: Save a copy for bugzilla reporting */
867 RtlCreateUnicodeString(&KeRosVideoBiosDate
, Data
.Buffer
);
869 /* Free the string */
870 RtlFreeUnicodeString(&Data
);
873 /* Get the Video BIOS Version */
874 if (CmpGetBiosVersion(BaseAddress
, 8 * PAGE_SIZE
, Buffer
))
876 /* Start at the beginning of our buffer */
877 CurrentVersion
= BiosVersion
;
880 /* Convert to Unicode */
881 RtlInitAnsiString(&TempString
, Buffer
);
882 RtlAnsiStringToUnicodeString(&Data
, &TempString
, TRUE
);
884 /* Calculate the length of this string and copy it in */
885 Length
= Data
.Length
+ sizeof(UNICODE_NULL
);
886 RtlMoveMemory(CurrentVersion
, Data
.Buffer
, Length
);
888 /* Free the unicode string */
889 RtlFreeUnicodeString(&Data
);
891 /* Update the total length and see if we're out of space */
892 TotalLength
+= Length
;
893 if (TotalLength
+ 256 + sizeof(UNICODE_NULL
) > PAGE_SIZE
)
895 /* One more string would push us out, so stop here */
899 /* Go to the next string inside the multi-string buffer */
900 CurrentVersion
+= Length
;
902 /* Query the next BIOS Version */
903 } while (CmpGetBiosVersion(NULL
, 0, Buffer
));
905 /* Check if we found any strings at all */
908 /* Add the final null-terminator */
909 *(PWSTR
)CurrentVersion
= UNICODE_NULL
;
910 TotalLength
+= sizeof(UNICODE_NULL
);
912 /* Write the BIOS Version to the registry */
913 RtlInitUnicodeString(&ValueName
, L
"VideoBiosVersion");
914 Status
= NtSetValueKey(SystemHandle
,
921 /* ROS: Save a copy for bugzilla reporting */
922 RtlCreateUnicodeString(&KeRosVideoBiosVersion
, (PWCH
)BiosVersion
);
926 /* Unmap the section */
927 ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress
);
930 /* Close the section */
931 ZwClose(SectionHandle
);
933 /* Free the BIOS version string buffer */
934 if (BiosVersion
) ExFreePoolWithTag(BiosVersion
, TAG_CM
);
937 /* Close the procesor handle */
939 return STATUS_SUCCESS
;