L4Re - L4 Runtime Environment
cpu.h
Go to the documentation of this file.
1 
7 /*
8  * (c) 2004-2009 Author(s)
9  * economic rights: Technische Universit├Ąt Dresden (Germany)
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU Lesser General Public License 2.1.
12  * Please see the COPYING-LGPL-2.1 file for details.
13  */
14 
15 #ifndef __L4_UTIL_CPU_H
16 #define __L4_UTIL_CPU_H
17 
18 #include <l4/sys/compiler.h>
19 
21 
27 
33 L4_INLINE int l4util_cpu_has_cpuid(void);
34 
41 L4_INLINE unsigned int l4util_cpu_capabilities(void);
42 
48 L4_INLINE unsigned int l4util_cpu_capabilities_nocheck(void);
49 
53 L4_INLINE void
54 l4util_cpu_cpuid(unsigned long mode,
55  unsigned long *eax, unsigned long *ebx,
56  unsigned long *ecx, unsigned long *edx);
57 
59 static inline void
60 l4util_cpu_pause(void)
61 {
62  __asm__ __volatile__ ("rep; nop");
63 }
64 
65 L4_INLINE int
67 {
68  return 1;
69 }
70 
71 L4_INLINE void
72 l4util_cpu_cpuid(unsigned long mode,
73  unsigned long *eax, unsigned long *ebx,
74  unsigned long *ecx, unsigned long *edx)
75 {
76  asm volatile("cpuid"
77  : "=a" (*eax),
78  "=b" (*ebx),
79  "=c" (*ecx),
80  "=d" (*edx)
81  : "a" (mode)
82  );
83 }
84 
85 L4_INLINE unsigned int
87 {
88  unsigned long dummy, capability;
89 
90  /* get CPU capabilities */
91  l4util_cpu_cpuid(1, &dummy, &dummy, &dummy, &capability);
92 
93  return capability;
94 }
95 
96 L4_INLINE unsigned int
98 {
99  if (!l4util_cpu_has_cpuid())
100  return 0; /* CPU has not cpuid instruction */
101 
103 }
104 
106 
107 #endif
108 
void l4util_cpu_cpuid(unsigned long mode, unsigned long *eax, unsigned long *ebx, unsigned long *ecx, unsigned long *edx)
Generic CPUID access function.
Definition: cpu.h:72
#define EXTERN_C_END
End section with C types and functions.
Definition: compiler.h:187
unsigned int l4util_cpu_capabilities(void)
Returns the CPU capabilities if the "cpuid" instruction is available.
Definition: cpu.h:97
L4 compiler related defines.
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition: compiler.h:186
unsigned int l4util_cpu_capabilities_nocheck(void)
Returns the CPU capabilities.
Definition: cpu.h:86
int l4util_cpu_has_cpuid(void)
Check whether the CPU supports the "cpuid" instruction.
Definition: cpu.h:66