x86/include/arch/cpuid.h: Fix inline assembly

In the cpuid helper functions eax is always written to
by the cpuid instruction, so add it to the output clobbered list.

This prevents GCC from generating code with undefined behaviour
when the function is inlined.

Test: Verified that the generated assembly is sane and runtime
      tests showed no "strange" behaviour when calling cpuid
      functions.

Change-Id: I5dc0bb620184a355716b9c8d4206d55554b41ab9
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78192
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
This commit is contained in:
Patrick Rudolph 2023-09-30 15:12:17 +02:00 committed by Felix Held
parent 4c7e97b26a
commit 699b1c4a66
1 changed files with 9 additions and 12 deletions

View File

@ -56,39 +56,36 @@ static inline uint32_t cpuid_eax(uint32_t eax)
return eax; return eax;
} }
static inline uint32_t cpuid_ebx(const uint32_t eax) static inline uint32_t cpuid_ebx(uint32_t eax)
{ {
uint32_t ebx; uint32_t ebx;
asm volatile( asm volatile(
"cpuid;" "cpuid;"
: "=b" (ebx) : "=b" (ebx), "+a" (eax)
: "a" (eax) :: "ecx", "edx");
: "ecx", "edx");
return ebx; return ebx;
} }
static inline uint32_t cpuid_ecx(const uint32_t eax) static inline uint32_t cpuid_ecx(uint32_t eax)
{ {
uint32_t ecx; uint32_t ecx;
asm volatile( asm volatile(
"cpuid;" "cpuid;"
: "=c" (ecx) : "=c" (ecx), "+a" (eax)
: "a" (eax) :: "ebx", "edx");
: "ebx", "edx");
return ecx; return ecx;
} }
static inline uint32_t cpuid_edx(const uint32_t eax) static inline uint32_t cpuid_edx(uint32_t eax)
{ {
uint32_t edx; uint32_t edx;
asm volatile( asm volatile(
"cpuid;" "cpuid;"
: "=d" (edx) : "=d" (edx), "+a" (eax)
: "a" (eax) :: "ebx", "ecx");
: "ebx", "ecx");
return edx; return edx;
} }