- Renamed cpu header files
[coreboot.git] / src / include / cpu / p6 / msr.h
1 #ifndef CPU_P6_MSR_H
2 #define CPU_P6_MSR_H
3
4
5 #ifdef __ROMCC__
6
7 typedef __builtin_msr_t msr_t;
8
9 static msr_t rdmsr(unsigned long index)
10 {
11         return __builtin_rdmsr(index);
12 }
13
14 static void wrmsr(unsigned long index, msr_t msr)
15 {
16         __builtin_wrmsr(index, msr.lo, msr.hi);
17 }
18
19
20 struct tsc_struct {
21         unsigned lo;
22         unsigned hi;
23 };
24 typedef struct tsc_struct tsc_t;
25
26 static tsc_t rdtsc(void)
27 {
28         tsc_t res;
29         asm ("rdtsc"
30                 : "=a" (res.lo), "=d"(res.hi) /* outputs */
31                 : /* inputs */
32                 : /* Clobbers */
33                 );
34         return res;
35 }
36 #endif
37
38 #ifdef __GNUC__
39
40 typedef struct msr_struct 
41 {
42         unsigned lo;
43         unsigned hi;
44 } msr_t;
45
46 static inline msr_t rdmsr(unsigned index)
47 {
48         msr_t result;
49         __asm__ __volatile__ (
50                 "rdmsr"
51                 : "=a" (result.lo), "=d" (result.hi)
52                 : "c" (index)
53                 );
54         return result;
55 }
56
57 static inline void wrmsr(unsigned index, msr_t msr)
58 {
59         __asm__ __volatile__ (
60                 "wrmsr"
61                 : /* No outputs */
62                 : "c" (index), "a" (msr.lo), "d" (msr.hi)
63                 );
64 }
65
66 typedef struct tsc_struct 
67 {
68         unsigned lo;
69         unsigned hi;
70 } tsc_t;
71
72 static inline tsc_t rdtsc(void)
73 {
74         tsc_t result;
75         __asm__ __volatile__(
76                 "rdtsc"
77                 : "=a"  (result.lo), "=d" (result.hi)
78                 );
79         return result;
80 }
81
82 typedef struct pmc_struct 
83 {
84         unsigned lo;
85         unsigned hi;
86 } pmc_t; 
87
88 static inline pmc_t rdpmc(unsigned counter)
89 {
90         pmc_t result;
91         __asm__ __volatile__(
92                 "rdpmc"
93                 : "=a" (result.lo), "=d" (result.hi)
94                 : "c" (counter)
95                 );
96         return result;
97 }
98
99 #endif
100
101 #endif /* CPU_P6_MSR_H */