diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-07-16 18:56:01 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-07-16 18:56:01 -0700 |
commit | 553ccf230b4e9e0bc3c152ea7a2c479b6bbdade1 (patch) | |
tree | daee8198914dc8d317d2f88785d09235984c9866 /com32 | |
parent | 963a38fc45a50d555d61f4a4640b02d7c398b4f4 (diff) | |
download | syslinux-553ccf230b4e9e0bc3c152ea7a2c479b6bbdade1.tar.gz |
com32: move cpuid inlines to <sys/cpu.h>
<sys/cpu.h> already has most of the CPUID inlines, put them all there.
<cpuid.h> still have structures for the code that really should be
librarized at some point.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32')
-rw-r--r-- | com32/include/cpuid.h | 69 | ||||
-rw-r--r-- | com32/include/sys/cpu.h | 45 |
2 files changed, 41 insertions, 73 deletions
diff --git a/com32/include/cpuid.h b/com32/include/cpuid.h index 67c28fea..050cfedb 100644 --- a/com32/include/cpuid.h +++ b/com32/include/cpuid.h @@ -31,6 +31,7 @@ #include <stdbool.h> #include <stdint.h> #include <cpufeature.h> +#include <sys/cpu.h> #include <klibc/compiler.h> #define PAGE_SIZE 4096 @@ -191,74 +192,6 @@ struct cpu_dev { }; /* - * Generic CPUID function - * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx - * resulting in stale register contents being returned. - */ -static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) -{ - __asm__("cpuid" - : "=a" (*eax), - "=b" (*ebx), - "=c" (*ecx), - "=d" (*edx) - : "0" (op), "c"(0)); -} - -static inline __constfunc unsigned int cpuid_eax(unsigned int op) -{ - unsigned int eax; - - __asm__("cpuid" - : "=a" (eax) - : "0" (op) - : "bx", "cx", "dx"); - return eax; -} - -static inline __constfunc unsigned int cpuid_ecx(unsigned int op) -{ - unsigned int eax, ecx; - - __asm__("cpuid" - : "=a" (eax), "=c" (ecx) - : "0" (op) - : "bx", "dx" ); - return ecx; -} -static inline __constfunc unsigned int cpuid_edx(unsigned int op) -{ - unsigned int eax, edx; - - __asm__("cpuid" - : "=a" (eax), "=d" (edx) - : "0" (op) - : "bx", "cx"); - return edx; -} - -/* Standard macro to see if a specific flag is changeable */ -static inline __constfunc bool cpu_has_eflag(uint32_t flag) -{ - uint32_t f1, f2; - - asm("pushfl\n\t" - "pushfl\n\t" - "popl %0\n\t" - "movl %0,%1\n\t" - "xorl %2,%0\n\t" - "pushl %0\n\t" - "popfl\n\t" - "pushfl\n\t" - "popl %0\n\t" - "popfl\n\t" - : "=&r" (f1), "=&r" (f2) - : "ir" (flag)); - - return ((f1^f2) & flag) != 0; -} - -/* * Structure definitions for SMP machines following the * Intel Multiprocessing Specification 1.1 and 1.4. */ diff --git a/com32/include/sys/cpu.h b/com32/include/sys/cpu.h index 0a7b4652..7a23d514 100644 --- a/com32/include/sys/cpu.h +++ b/com32/include/sys/cpu.h @@ -1,7 +1,9 @@ #ifndef _CPU_H #define _CPU_H -#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <klibc/compiler.h> static inline uint64_t rdtsc(void) { @@ -17,28 +19,40 @@ static inline uint32_t rdtscl(void) return v; } -static inline uint32_t cpuid_eax(uint32_t level) +static inline void cpuid_count(uint32_t op, uint32_t cnt, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + asm("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) + : "a" (op), "c" (cnt)); +} +static inline void cpuid(uint32_t op, uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + return cpuid_count(op, 0, eax, ebx, ecx, edx); +} +static inline __constfunc uint32_t cpuid_eax(uint32_t level) { uint32_t v; asm("cpuid" : "=a" (v) : "a" (level) : "ebx", "ecx", "edx"); return v; } -static inline uint32_t cpuid_ebx(uint32_t level) +static inline __constfunc uint32_t cpuid_ebx(uint32_t level) { uint32_t v; asm("cpuid" : "=b" (v), "+a" (level) : : "ecx", "edx"); return v; } -static inline uint32_t cpuid_ecx(uint32_t level) +static inline __constfunc uint32_t cpuid_ecx(uint32_t level) { uint32_t v; asm("cpuid" : "=c" (v), "+a" (level) : : "ebx", "edx"); return v; } -static inline uint32_t cpuid_edx(uint32_t level) +static inline __constfunc uint32_t cpuid_edx(uint32_t level) { uint32_t v; @@ -46,6 +60,27 @@ static inline uint32_t cpuid_edx(uint32_t level) return v; } +/* Standard macro to see if a specific flag is changeable */ +static inline __constfunc bool cpu_has_eflag(uint32_t flag) +{ + uint32_t f1, f2; + + asm("pushfl\n\t" + "pushfl\n\t" + "popl %0\n\t" + "movl %0,%1\n\t" + "xorl %2,%0\n\t" + "pushl %0\n\t" + "popfl\n\t" + "pushfl\n\t" + "popl %0\n\t" + "popfl\n\t" + : "=&r" (f1), "=&r" (f2) + : "ir" (flag)); + + return ((f1^f2) & flag) != 0; +} + static inline uint64_t rdmsr(uint32_t msr) { uint64_t v; |