diff options
author | Matei Dibu <matdibu@protonmail.com> | 2022-08-02 00:48:59 +0300 |
---|---|---|
committer | Martin L Roth <gaumless@gmail.com> | 2022-10-22 16:40:42 +0000 |
commit | 516eff01e61155a681a4f684515ae7924b9bff0d (patch) | |
tree | 140a1c5cde9827f2e8c1ff07f1f14c964eac8d09 /src/arch | |
parent | 436f1c471a576d36101d7ef42e29d2c4e28950e6 (diff) |
arch/x86/include/arch: fix assembly clobber for 64bit
the "x86 PIC code ebx" workaround done previously
by commit 689e31d18b0f ("Make cpuid functions usable
when compiled with PIC") does not work for x86_64
(the upper dword of rbx is set to 0)
the GCC bug that needed the workaround was fixed
in version 5 (see GCC bug 54232)
Change-Id: Iff1dd72c7423a3b385a000457bcd065cf7ed6b95
Signed-off-by: Matei Dibu <matdibu@protonmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66345
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Elyes Haouas <ehaouas@noos.fr>
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/x86/include/arch/cpuid.h | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/src/arch/x86/include/arch/cpuid.h b/src/arch/x86/include/arch/cpuid.h index 27848a8688..70a5beb9b9 100644 --- a/src/arch/x86/include/arch/cpuid.h +++ b/src/arch/x86/include/arch/cpuid.h @@ -15,96 +15,80 @@ struct cpuid_result { /* * Generic CPUID function */ -static inline struct cpuid_result cpuid(int op) +static inline struct cpuid_result cpuid(const uint32_t eax) { struct cpuid_result result; asm volatile( - "mov %%ebx, %%edi;" "cpuid;" - "mov %%ebx, %%esi;" - "mov %%edi, %%ebx;" : "=a" (result.eax), - "=S" (result.ebx), + "=b" (result.ebx), "=c" (result.ecx), "=d" (result.edx) - : "0" (op) - : "edi"); + : "a" (eax)); return result; } /* * Generic Extended CPUID function */ -static inline struct cpuid_result cpuid_ext(int op, unsigned int ecx) +static inline struct cpuid_result cpuid_ext(const uint32_t eax, const uint32_t ecx) { struct cpuid_result result; asm volatile( - "mov %%ebx, %%edi;" "cpuid;" - "mov %%ebx, %%esi;" - "mov %%edi, %%ebx;" : "=a" (result.eax), - "=S" (result.ebx), + "=b" (result.ebx), "=c" (result.ecx), "=d" (result.edx) - : "0" (op), "2" (ecx) - : "edi"); + : "a" (eax), "c" (ecx)); return result; } /* * CPUID functions returning a single datum */ -static inline unsigned int cpuid_eax(unsigned int op) +static inline uint32_t cpuid_eax(uint32_t eax) { - unsigned int eax; - - __asm__("mov %%ebx, %%edi;" + asm volatile( "cpuid;" - "mov %%edi, %%ebx;" - : "=a" (eax) - : "0" (op) - : "ecx", "edx", "edi"); + : "+a" (eax) + :: "ebx", "ecx", "edx"); return eax; } -static inline unsigned int cpuid_ebx(unsigned int op) +static inline uint32_t cpuid_ebx(const uint32_t eax) { - unsigned int eax, ebx; + uint32_t ebx; - __asm__("mov %%ebx, %%edi;" + asm volatile( "cpuid;" - "mov %%ebx, %%esi;" - "mov %%edi, %%ebx;" - : "=a" (eax), "=S" (ebx) - : "0" (op) - : "ecx", "edx", "edi"); + : "=b" (ebx) + : "a" (eax) + : "ecx", "edx"); return ebx; } -static inline unsigned int cpuid_ecx(unsigned int op) +static inline uint32_t cpuid_ecx(const uint32_t eax) { - unsigned int eax, ecx; + uint32_t ecx; - __asm__("mov %%ebx, %%edi;" + asm volatile( "cpuid;" - "mov %%edi, %%ebx;" - : "=a" (eax), "=c" (ecx) - : "0" (op) - : "edx", "edi"); + : "=c" (ecx) + : "a" (eax) + : "ebx", "edx"); return ecx; } -static inline unsigned int cpuid_edx(unsigned int op) +static inline uint32_t cpuid_edx(const uint32_t eax) { - unsigned int eax, edx; + uint32_t edx; - __asm__("mov %%ebx, %%edi;" + asm volatile( "cpuid;" - "mov %%edi, %%ebx;" - : "=a" (eax), "=d" (edx) - : "0" (op) - : "ecx", "edi"); + : "=d" (edx) + : "a" (eax) + : "ebx", "ecx"); return edx; } |