From: bxing Date: Sat, 10 Jun 2006 09:37:12 +0000 (+0000) Subject: 1. Added AsmCpuidEx() to BaseLib X-Git-Tag: edk2-stable201903~25280 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=dee4740abe5925ff25e452c1a705a36f8fb3b4b9 1. Added AsmCpuidEx() to BaseLib 2. Added DecimalToBcd8() and BcdToDecimal8() to String.c git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@465 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index e042ccb712..a63bc1bc3e 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -638,6 +638,45 @@ AsciiStrnCat ( IN UINTN Length ); +/** + Converts an 8-bit value to an 8-bit BCD value. + + Converts the 8-bit value specified by Value to BCD. The BCD value is + returned. + + If Value >= 100, then ASSERT(). + + @param Value The 8-bit value to convert to BCD. Range 0..99. + + @return The BCD value + +**/ +UINT8 +EFIAPI +DecimalToBcd8 ( + IN UINT8 Value + ); + +/** + Converts an 8-bit BCD value to an 8-bit value. + + Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit + value is returned. + + If Value >= 0xA0, then ASSERT(). + If (Value & 0x0F) >= 0x0A, then ASSERT(). + + @param Value The 8-bit BCD value to convert to an 8-bit value. + + @return The 8-bit value is returned. + +**/ +UINT8 +EFIAPI +BcdToDecimal8 ( + IN UINT8 Value + ); + // // LIST_ENTRY definition // @@ -2994,6 +3033,49 @@ AsmCpuid ( OUT UINT32 *Edx OPTIONAL ); +/** + Retrieves CPUID information using an extended leaf identifier. + + Executes the CPUID instruction with EAX set to the value specified by Index + and ECX set to the value specified by SubIndex. This function always returns + Index. This function is only available on IA-32 and x64. + + If Eax is not NULL, then the value of EAX after CPUID is returned in Eax. + If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx. + If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx. + If Edx is not NULL, then the value of EDX after CPUID is returned in Edx. + + @param Index The 32-bit value to load into EAX prior to invoking the + CPUID instruction. + @param SubIndex The 32-bit value to load into ECX prior to invoking the + CPUID instruction. + @param Eax Pointer to the 32-bit EAX value returned by the CPUID + instruction. This is an optional parameter that may be + NULL. + @param Ebx Pointer to the 32-bit EBX value returned by the CPUID + instruction. This is an optional parameter that may be + NULL. + @param Ecx Pointer to the 32-bit ECX value returned by the CPUID + instruction. This is an optional parameter that may be + NULL. + @param Edx Pointer to the 32-bit EDX value returned by the CPUID + instruction. This is an optional parameter that may be + NULL. + + @return Index + +**/ +UINT32 +EFIAPI +AsmCpuidEx ( + IN UINT32 Index, + IN UINT32 SubIndex, + OUT UINT32 *Eax, OPTIONAL + OUT UINT32 *Ebx, OPTIONAL + OUT UINT32 *Ecx, OPTIONAL + OUT UINT32 *Edx OPTIONAL + ); + /** Returns the lower 32-bits of a Machine Specific Register(MSR). diff --git a/MdePkg/Library/BaseLib/BaseLib.msa b/MdePkg/Library/BaseLib/BaseLib.msa index 5fc8430422..0d07e79af4 100644 --- a/MdePkg/Library/BaseLib/BaseLib.msa +++ b/MdePkg/Library/BaseLib/BaseLib.msa @@ -94,6 +94,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Ia32/SetJump.asm Ia32/LongJump.asm Ia32/CpuId.asm + Ia32/CpuIdEx.asm Ia32/ReadEflags.asm Ia32/ReadMsr64.asm Ia32/WriteMsr32.asm diff --git a/MdePkg/Library/BaseLib/Ia32/CpuIdEx.asm b/MdePkg/Library/BaseLib/Ia32/CpuIdEx.asm new file mode 100644 index 0000000000..cdebec2114 --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/CpuIdEx.asm @@ -0,0 +1,68 @@ +;------------------------------------------------------------------------------ +; +; Copyright (c) 2006, Intel Corporation +; All rights reserved. This program and the accompanying materials +; are licensed and made available under the terms and conditions of the BSD License +; which accompanies this distribution. The full text of the license may be found at +; http://opensource.org/licenses/bsd-license.php +; +; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +; +; Module Name: +; +; CpuIdEx.Asm +; +; Abstract: +; +; AsmCpuidEx function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .686 + .model flat,C + .code + +;------------------------------------------------------------------------------ +; UINT32 +; EFIAPI +; AsmCpuidEx ( +; IN UINT32 RegisterInEax, +; IN UINT32 RegisterInEcx, +; OUT UINT32 *RegisterOutEax OPTIONAL, +; OUT UINT32 *RegisterOutEbx OPTIONAL, +; OUT UINT32 *RegisterOutEcx OPTIONAL, +; OUT UINT32 *RegisterOutEdx OPTIONAL +; ) +;------------------------------------------------------------------------------ +AsmCpuidEx PROC USES ebx + push ebp + mov ebp, esp + mov eax, [ebp + 12] + mov ecx, [ebp + 16] + cpuid + push ecx + mov ecx, [ebp + 20] + jecxz @F + mov [ecx], eax +@@: + mov ecx, [ebp + 24] + jecxz @F + mov [ecx], ebx +@@: + mov ecx, [ebp + 28] + jecxz @F + pop [ecx] +@@: + mov edx, [ebp + 32] + jecxz @F + mov [ecx], edx +@@: + mov eax, [ebp + 12] + leave + ret +AsmCpuidEx ENDP + + END diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c index 6ef2c3b2d3..0483fc712e 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -796,3 +796,51 @@ AsciiStrnCat ( ASSERT (AsciiStrSize (Destination) != 0); return Destination; } + +/** + Converts an 8-bit value to an 8-bit BCD value. + + Converts the 8-bit value specified by Value to BCD. The BCD value is + returned. + + If Value >= 100, then ASSERT(). + + @param Value The 8-bit value to convert to BCD. Range 0..99. + + @return The BCD value + +**/ +UINT8 +EFIAPI +DecimalToBcd8 ( + IN UINT8 Value + ) +{ + ASSERT (Value < 100); + return ((Value / 10) << 4) | (Value % 10); +} + +/** + Converts an 8-bit BCD value to an 8-bit value. + + Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit + value is returned. + + If Value >= 0xA0, then ASSERT(). + If (Value & 0x0F) >= 0x0A, then ASSERT(). + + @param Value The 8-bit BCD value to convert to an 8-bit value. + + @return The 8-bit value is returned. + +**/ +UINT8 +EFIAPI +BcdToDecimal8 ( + IN UINT8 Value + ) +{ + ASSERT (Value < 0xa0); + ASSERT ((Value & 0xf) < 0xa); + return (Value >> 4) * 10 + (Value & 0xf); +} diff --git a/MdePkg/Library/BaseLib/X64/CpuIdEx.asm b/MdePkg/Library/BaseLib/X64/CpuIdEx.asm index ec5729fbaa..450cf543f7 100644 --- a/MdePkg/Library/BaseLib/X64/CpuIdEx.asm +++ b/MdePkg/Library/BaseLib/X64/CpuIdEx.asm @@ -11,11 +11,11 @@ ; ; Module Name: ; -; CpuId.Asm +; CpuIdEx.Asm ; ; Abstract: ; -; AsmCpuid function +; AsmCpuidEx function ; ; Notes: ; @@ -26,7 +26,7 @@ ;------------------------------------------------------------------------------ ; UINT32 ; EFIAPI -; AsmCpuid ( +; AsmCpuidEx ( ; IN UINT32 RegisterInEax, ; IN UINT32 RegisterInEcx, ; OUT UINT32 *RegisterOutEax OPTIONAL,