x86: cpu: Use native_cpuid() in cpuid_ext()
PATCH 1/2 x86: cpu: Use native_cpuid() in cpuid_ext()
cpuid_ext() saves and restores EBX with 32-bit moves, which clear the upper half of RBX in long mode. The assembly does not declare RBX as an output, so the compiler cannot account for this change.
Initialize the leaf and subleaf in cpuid_result and use native_cpuid(), which declares all four output registers and lets the compiler preserve RBX correctly. Keep the structure-returning interface for callers.
---
arch/x86/include/asm/cpu.h | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
arch/x86/include/asm/cpu.h +15 -20
@@ -89,26 +89,6 @@ static inline struct cpuid_result cpuid(int op)return result; } -/* -* Generic Extended CPUID function -*/ -static inline struct cpuid_result cpuid_ext (int op,unsigned ecx) -{ -struct cpuid_result result; - asmvolatile ( -"mov %%ebx, %%edi;" -"cpuid;" -"mov %%ebx, %%esi;" -"mov %%edi, %%ebx;" - :"=a" (result.eax), -"=S" (result.ebx), -"=c" (result.ecx), -"=d" (result.edx) - :"0" (op),"2" (ecx) - :"edi" ); -return result; -} -static inline void native_cpuid (unsigned int *eax,unsigned int *ebx,unsigned int *ecx,unsigned int *edx) {
@@ -122,6 +102,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx, : "memory"); } +/* +* Generic Extended CPUID function +*/ +static inline struct cpuid_result cpuid_ext (int op,unsigned int ecx) +{ +struct cpuid_result result = { + .eax = op, + .ecx = ecx, + }; + +native_cpuid (&result.eax, &result.ebx, &result.ecx, &result.edx); + +return result; +} +#define native_cpuid_reg (reg) \ static inline unsigned int cpuid_##reg(unsigned int op) \ { \
---
base-commit: 5e3b01c8466dbe45cd6a06299f8f4c7e8c1c2363
branch: cpuid
Signature · 1 line
2.53.0
PATCH 2/2 x86: cpu: Implement cpuid() through cpuid_ext()
cpuid() duplicates the old EBX save and restore sequence and leaves the ECX input unspecified. This is unsafe in long mode and makes queries of indexed CPUID leaves depend on the incoming ECX value.
Call cpuid_ext() with subleaf zero to reuse native_cpuid() and provide a deterministic default for indexed leaves. Keep the existing interface so callers do not need to manage individual register outputs.
---
arch/x86/include/asm/cpu.h | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)
arch/x86/include/asm/cpu.h +8 -20
@@ -69,26 +69,6 @@ struct cpuid_result {uint32_t edx; }; -/* -* Generic CPUID function -*/ -static inline struct cpuid_result cpuid (int op) -{ -struct cpuid_result result; - asmvolatile ( -"mov %%ebx, %%edi;" -"cpuid;" -"mov %%ebx, %%esi;" -"mov %%edi, %%ebx;" - :"=a" (result.eax), -"=S" (result.ebx), -"=c" (result.ecx), -"=d" (result.edx) - :"0" (op) - :"edi" ); -return result; -} -static inline void native_cpuid (unsigned int *eax,unsigned int *ebx,unsigned int *ecx,unsigned int *edx) {
@@ -117,6 +97,14 @@ static inline struct cpuid_result cpuid_ext(int op, unsigned int ecx)return result; } +/* +* Generic CPUID function with subleaf zero +*/ +static inline struct cpuid_result cpuid (int op) +{ +return cpuid_ext (op,0 ); +} +#define native_cpuid_reg (reg) \ static inline unsigned int cpuid_##reg(unsigned int op) \ { \
---
base-commit: 5e3b01c8466dbe45cd6a06299f8f4c7e8c1c2363
branch: cpuid
Signature · 1 line
2.53.0
Re: [PATCH 2/2] x86: cpu: Implement cpuid() through cpuid_ext()
Quoted 6 lines · Bin Meng
x86: cpu: Implement
cpuid()throughcpuid_ext()
cpuid()duplicates the old EBX save and restore sequence and leaves the ECX input unspecified. This is unsafe in long mode and makes queries of indexed CPUID leaves depend on the incoming ECX value.
Quoted 8 lines
Call
cpuid_ext()with subleaf zero to reusenative_cpuid()and provide a deterministic default for indexed leaves. Keep the existing interface so callers do not need to manage individual register outputs.Signed-off-by Bin Meng <[email protected]>
arch/x86/include/asm/cpu.h| 28 ++++++++--------------------1 file changed, 8 insertions(+), 20 deletions(-)
Re: [PATCH 2/2] x86: cpu: Implement cpuid() through cpuid_ext()
Quoted 12 lines · Simon Glass
Quoted 10 lines · Bin Meng
x86: cpu: Implement
cpuid()throughcpuid_ext()
cpuid()duplicates the old EBX save and restore sequence and leaves the ECX input unspecified. This is unsafe in long mode and makes queries of indexed CPUID leaves depend on the incoming ECX value.Call
cpuid_ext()with subleaf zero to reusenative_cpuid()and provide a deterministic default for indexed leaves. Keep the existing interface so callers do not need to manage individual register outputs.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Bin Meng <[email protected]>
arch/x86/include/asm/cpu.h| 28 ++++++++--------------------1 file changed, 8 insertions(+), 20 deletions(-)Reviewed-by Simon Glass <[email protected]>
applied to u-boot-x86, thanks!
Quoted 6 lines · Bin Meng
x86: cpu: Use
native_cpuid()incpuid_ext()
cpuid_ext()saves and restores EBX with 32-bit moves, which clear the upper half of RBX in long mode. The assembly does not declare RBX as an output, so the compiler cannot account for this change.
Quoted 8 lines
Initialize the leaf and subleaf in
cpuid_resultand usenative_cpuid(), which declares all four output registers and lets the compiler preserve RBX correctly. Keep the structure-returning interface for callers.Signed-off-by Bin Meng <[email protected]>
arch/x86/include/asm/cpu.h| 35 +++++++++++++++--------------------1 file changed, 15 insertions(+), 20 deletions(-)
Quoted 12 lines · Simon Glass
Quoted 10 lines · Bin Meng
x86: cpu: Use
native_cpuid()incpuid_ext()
cpuid_ext()saves and restores EBX with 32-bit moves, which clear the upper half of RBX in long mode. The assembly does not declare RBX as an output, so the compiler cannot account for this change.Initialize the leaf and subleaf in
cpuid_resultand usenative_cpuid(), which declares all four output registers and lets the compiler preserve RBX correctly. Keep the structure-returning interface for callers.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Bin Meng <[email protected]>
arch/x86/include/asm/cpu.h| 35 +++++++++++++++--------------------1 file changed, 15 insertions(+), 20 deletions(-)Reviewed-by Simon Glass <[email protected]>
applied to u-boot-x86, thanks!