Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
/*
* (c) 2004-2009 Author(s)
* economic rights: Technische Universität Dresden (Germany)
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#ifndef __L4_UTIL_CPU_H
#define __L4_UTIL_CPU_H
#include <l4/sys/compiler.h>
L4_BEGIN_DECLS
L4_INLINE int l4util_cpu_has_cpuid(void);
L4_INLINE unsigned int l4util_cpu_capabilities(void);
L4_INLINE unsigned int l4util_cpu_capabilities_nocheck(void);
L4_INLINE void
l4util_cpu_cpuid(unsigned long mode,
unsigned long *eax, unsigned long *ebx,
unsigned long *ecx, unsigned long *edx);
static inline void
l4util_cpu_pause(void)
{
__asm__ __volatile__ ("rep; nop");
}
L4_INLINE int
l4util_cpu_has_cpuid(void)
{
return 1;
}
L4_INLINE void
l4util_cpu_cpuid(unsigned long mode,
unsigned long *eax, unsigned long *ebx,
unsigned long *ecx, unsigned long *edx)
{
asm volatile("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "a" (mode)
);
}
L4_INLINE unsigned int
l4util_cpu_capabilities_nocheck(void)
{
unsigned long dummy, capability;
/* get CPU capabilities */
l4util_cpu_cpuid(1, &dummy, &dummy, &dummy, &capability);
return capability;
}
L4_INLINE unsigned int
l4util_cpu_capabilities(void)
{
if (!l4util_cpu_has_cpuid())
return 0; /* CPU has not cpuid instruction */
return l4util_cpu_capabilities_nocheck();
}
L4_END_DECLS
#endif
compiler.h
L4 compiler related defines.
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
L4_BEGIN_DECLS
#define L4_BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:165
L4_END_DECLS
#define L4_END_DECLS
End section with C types and functions.
Definition compiler.h:166
l4util_cpu_cpuid
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:70
l4util_cpu_capabilities_nocheck
unsigned int l4util_cpu_capabilities_nocheck(void)
Returns the CPU capabilities.
Definition cpu.h:84
l4util_cpu_capabilities
unsigned int l4util_cpu_capabilities(void)
Returns the CPU capabilities if the "cpuid" instruction is available.
Definition cpu.h:95
l4util_cpu_has_cpuid
int l4util_cpu_has_cpuid(void)
Check whether the CPU supports the "cpuid" instruction.
Definition cpu.h:64