L4Re Operating System Framework
Interface and Usage Documentation
•All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12
13#ifndef __L4_UTIL_CPU_H
14#define __L4_UTIL_CPU_H
15
16#include <l4/sys/compiler.h>
17
19
32
39L4_INLINE unsigned int l4util_cpu_capabilities(void);
40
47
51L4_INLINE void
52l4util_cpu_cpuid(unsigned long mode,
53 unsigned long *eax, unsigned long *ebx,
54 unsigned long *ecx, unsigned long *edx);
55
57static inline void
58l4util_cpu_pause(void)
59{
60 __asm__ __volatile__ ("rep; nop");
61}
62
63L4_INLINE int
65{
66 unsigned long eax;
67
68 asm volatile("pushl %%ebx \t\n"
69 "pushfl \t\n"
70 "popl %%eax \t\n" /* get eflags */
71 "movl %%eax, %%ebx \t\n" /* save it */
72 "xorl $0x200000, %%eax \t\n" /* toggle ID bit */
73 "pushl %%eax \t\n"
74 "popfl \t\n" /* set again */
75 "pushfl \t\n"
76 "popl %%eax \t\n" /* get it again */
77 "xorl %%ebx, %%eax \t\n"
78 "pushl %%ebx \t\n"
79 "popfl \t\n" /* restore saved flags */
80 "popl %%ebx \t\n"
81 : "=a" (eax)
82 : /* no input */
83 );
84
85 return eax & 0x200000;
86}
87
88L4_INLINE void
89l4util_cpu_cpuid(unsigned long mode,
90 unsigned long *eax, unsigned long *ebx,
91 unsigned long *ecx, unsigned long *edx)
92{
93 asm volatile("pushl %%ebx \t\n"
94 "cpuid \t\n"
95 "mov %%ebx, %%esi \t\n"
96 "popl %%ebx \t\n"
97 : "=a" (*eax),
98 "=S" (*ebx),
99 "=c" (*ecx),
100 "=d" (*edx)
101 : "a" (mode));
102}
103
104L4_INLINE unsigned int
106{
107 unsigned long dummy, capability;
108
109 /* get CPU capabilities */
110 l4util_cpu_cpuid(1, &dummy, &dummy, &dummy, &capability);
111
112 return capability;
113}
114
115L4_INLINE unsigned int
117{
119 return 0; /* CPU has not cpuid instruction */
120
122}
123
125
126#endif
127
L4 compiler related defines.
#define __END_DECLS
End section with C types and functions.
Definition compiler.h:167
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define __BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:164
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
unsigned int l4util_cpu_capabilities_nocheck(void)
Returns the CPU capabilities.
Definition cpu.h:84
unsigned int l4util_cpu_capabilities(void)
Returns the CPU capabilities if the "cpuid" instruction is available.
Definition cpu.h:95
int l4util_cpu_has_cpuid(void)
Check whether the CPU supports the "cpuid" instruction.
Definition cpu.h:64