Hi Simon, On Fri, Nov 7, 2014 at 4:19 AM, Simon Glass <s...@chromium.org> wrote: > Add some functions to access cpuid from C in various useful ways. Also > add a function to get the stack pointer and another to halt the CPU. > > Signed-off-by: Simon Glass <s...@chromium.org> > --- > > arch/x86/include/asm/processor.h | 121 > +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 121 insertions(+) > > diff --git a/arch/x86/include/asm/processor.h > b/arch/x86/include/asm/processor.h > index bb3172f..30d7d48 100644 > --- a/arch/x86/include/asm/processor.h > +++ b/arch/x86/include/asm/processor.h > @@ -30,4 +30,125 @@ enum { > > #define X86_GDT_SIZE (X86_GDT_NUM_ENTRIES * X86_GDT_ENTRY_SIZE) > > +#ifndef __ASSEMBLY__ > + > +static inline __attribute__((always_inline)) void cpu_hlt(void) > +{ > + asm("hlt"); > +} > + > +struct cpuid_result { > + uint32_t eax; > + uint32_t ebx; > + uint32_t ecx; > + uint32_t edx; > +}; > + > +/* > + * Generic CPUID function > + */ > +static inline struct cpuid_result cpuid(int op) > +{ > + struct cpuid_result result; > + asm volatile( > + "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; > +} > + > +/* > + * Generic Extended CPUID function > + */ > +static inline struct cpuid_result cpuid_ext(int op, unsigned ecx) > +{ > + struct cpuid_result result; > + asm volatile( > + "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 ulong cpu_get_sp(void) > +{ > + ulong result; > + > + asm volatile( > + "mov %%esp, %%eax" > + : "=a" (result)); > + return result; > +} > + > +/* > + * CPUID functions returning a single datum > + */ > +static inline unsigned int cpuid_eax(unsigned int op) > +{ > + unsigned int eax; > + > + __asm__("mov %%ebx, %%edi;" > + "cpuid;" > + "mov %%edi, %%ebx;" > + : "=a" (eax) > + : "0" (op) > + : "ecx", "edx", "edi"); > + return eax; > +} > + > +static inline unsigned int cpuid_ebx(unsigned int op) > +{ > + unsigned int eax, ebx; > + > + __asm__("mov %%ebx, %%edi;" > + "cpuid;" > + "mov %%ebx, %%esi;" > + "mov %%edi, %%ebx;" > + : "=a" (eax), "=S" (ebx) > + : "0" (op) > + : "ecx", "edx", "edi"); > + return ebx; > +} > + > +static inline unsigned int cpuid_ecx(unsigned int op) > +{ > + unsigned int eax, ecx; > + > + __asm__("mov %%ebx, %%edi;" > + "cpuid;" > + "mov %%edi, %%ebx;" > + : "=a" (eax), "=c" (ecx) > + : "0" (op) > + : "edx", "edi"); > + return ecx; > +} > + > +static inline unsigned int cpuid_edx(unsigned int op) > +{ > + unsigned int eax, edx; > + > + __asm__("mov %%ebx, %%edi;" > + "cpuid;" > + "mov %%edi, %%ebx;" > + : "=a" (eax), "=d" (edx) > + : "0" (op) > + : "ecx", "edi"); > + return edx; > +} > +#endif /* __ASSEMBLY__ */ > + > #endif
My previous patch (http://patchwork.ozlabs.org/patch/406636/) introduced these cpuid_xxx functions already. Would you consider merging the two patches? Regards, Bin _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot