Rev 333 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
120 | giacomo | 1 | /* Project: OSLib |
2 | * Description: The OS Construction Kit |
||
3 | * Date: 1.6.2000 |
||
4 | * Idea by: Luca Abeni & Gerardo Lamastra |
||
5 | * |
||
6 | * OSLib is an SO project aimed at developing a common, easy-to-use |
||
7 | * low-level infrastructure for developing OS kernels and Embedded |
||
8 | * Applications; it partially derives from the HARTIK project but it |
||
9 | * currently is independently developed. |
||
10 | * |
||
11 | * OSLib is distributed under GPL License, and some of its code has |
||
12 | * been derived from the Linux kernel source; also some important |
||
13 | * ideas come from studying the DJGPP go32 extender. |
||
14 | * |
||
15 | * We acknowledge the Linux Community, Free Software Foundation, |
||
16 | * D.J. Delorie and all the other developers who believe in the |
||
17 | * freedom of software and ideas. |
||
18 | * |
||
19 | * For legalese, check out the included GPL license. |
||
20 | */ |
||
21 | |||
22 | /* Advanced Timer |
||
23 | * Date: 8.4.2003 |
||
24 | * Author: Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
25 | * |
||
26 | */ |
||
27 | |||
28 | #ifndef __ADVTIMER_H__ |
||
29 | #define __ADVTIMER_H__ |
||
30 | |||
31 | #include <ll/i386/defs.h> |
||
32 | BEGIN_DEF |
||
33 | |||
305 | giacomo | 34 | #include <ll/sys/ll/time.h> |
35 | |||
120 | giacomo | 36 | /* TSC */ |
37 | |||
38 | #define rdtsc(low,high) \ |
||
239 | giacomo | 39 | __asm__ __volatile__("xorl %%eax,%%eax\n\t" \ |
242 | giacomo | 40 | "cpuid\n\t" \ |
41 | "rdtsc\n\t" \ |
||
336 | giacomo | 42 | : "=a" (low), "=d" (high) \ |
239 | giacomo | 43 | :: "ebx", "ecx") |
120 | giacomo | 44 | |
45 | #define rdtscll(val) \ |
||
239 | giacomo | 46 | __asm__ __volatile__("xorl %%eax,%%eax\n\t" \ |
242 | giacomo | 47 | "cpuid\n\t" \ |
48 | "rdtsc\n\t" \ |
||
49 | : "=A" (val) \ |
||
239 | giacomo | 50 | :: "ebx","ecx") |
120 | giacomo | 51 | |
330 | giacomo | 52 | #ifdef __O1000__ |
53 | #define ll_read_timespec ll_read_timespec_1000 |
||
54 | #else |
||
55 | #ifdef __02000__ |
||
56 | #define ll_read_timespec ll_read_timespec_2000 |
||
57 | #else |
||
58 | #ifdef __O4000__ |
||
59 | #define ll_read_timespec ll_read_timespec_4000 |
||
60 | #else |
||
336 | giacomo | 61 | #define ll_read_timespec ll_read_timespec_8000 |
330 | giacomo | 62 | #endif |
63 | #endif |
||
64 | #endif |
||
65 | |||
66 | //Low level time read function: Optimized for CPU < 1 GHz |
||
67 | extern __inline__ void ll_read_timespec_1000(struct timespec *tspec) |
||
68 | { |
||
69 | extern unsigned int clk_opt_1,clk_opt_2; |
||
70 | extern unsigned long long *ptr_init_tsc; |
||
71 | |||
72 | if (clk_opt_1 == 0) { |
||
73 | NULL_TIMESPEC(tspec); |
||
74 | return; |
||
75 | } |
||
76 | |||
336 | giacomo | 77 | __asm__("rdtsc\n\t" |
330 | giacomo | 78 | "subl (%%edi),%%eax\n\t" |
79 | "sbbl 4(%%edi),%%edx\n\t" |
||
80 | "divl %%ebx\n\t" |
||
81 | "movl %%eax,%%ebx\n\t" |
||
82 | "xorl %%eax,%%eax\n\t" |
||
83 | "divl %%ecx\n\t" |
||
84 | : "=a" (tspec->tv_nsec), "=b" (tspec->tv_sec) |
||
85 | : "D" (ptr_init_tsc) , "b" (clk_opt_1), "c" (clk_opt_2) |
||
86 | : "edx" ); |
||
87 | |||
88 | } |
||
89 | |||
90 | //Low level time read function: Optimized for CPU < 2 GHz |
||
91 | extern __inline__ void ll_read_timespec_2000(struct timespec *tspec) |
||
92 | { |
||
93 | extern unsigned int clk_opt_1,clk_opt_3; |
||
94 | extern unsigned long long *ptr_init_tsc; |
||
95 | |||
96 | if (clk_opt_1 == 0) { |
||
97 | NULL_TIMESPEC(tspec); |
||
98 | return; |
||
99 | } |
||
100 | |||
336 | giacomo | 101 | __asm__("rdtsc\n\t" |
330 | giacomo | 102 | "subl (%%edi),%%eax\n\t" |
103 | "sbbl 4(%%edi),%%edx\n\t" |
||
104 | "divl %%ebx\n\t" |
||
105 | "movl %%eax,%%ebx\n\t" |
||
336 | giacomo | 106 | "xorl %%eax,%%eax\n\t" |
107 | "shrdl $1,%%edx,%%eax\n\t" |
||
330 | giacomo | 108 | "shrl %%edx\n\t" |
109 | "divl %%ecx\n\t" |
||
110 | : "=a" (tspec->tv_nsec), "=b" (tspec->tv_sec) |
||
111 | : "D" (ptr_init_tsc) , "b" (clk_opt_1), "c" (clk_opt_3) |
||
112 | : "edx" ); |
||
113 | |||
114 | } |
||
115 | |||
116 | //Low level time read function: Optimized for CPU < 4 GHz |
||
117 | extern __inline__ void ll_read_timespec_4000(struct timespec *tspec) |
||
118 | { |
||
119 | extern unsigned int clk_opt_1,clk_opt_4; |
||
120 | extern unsigned long long *ptr_init_tsc; |
||
121 | |||
122 | if (clk_opt_1 == 0) { |
||
123 | NULL_TIMESPEC(tspec); |
||
124 | return; |
||
125 | } |
||
126 | |||
336 | giacomo | 127 | __asm__("rdtsc\n\t" |
330 | giacomo | 128 | "subl (%%edi),%%eax\n\t" |
129 | "sbbl 4(%%edi),%%edx\n\t" |
||
130 | "divl %%ebx\n\t" |
||
131 | "movl %%eax,%%ebx\n\t" |
||
336 | giacomo | 132 | "xorl %%eax,%%eax\n\t" |
133 | "shrdl $2,%%edx,%%eax\n\t" |
||
134 | "shrl $2,%%edx\n\t" |
||
330 | giacomo | 135 | "divl %%ecx\n\t" |
136 | : "=a" (tspec->tv_nsec), "=b" (tspec->tv_sec) |
||
137 | : "D" (ptr_init_tsc) , "b" (clk_opt_1), "c" (clk_opt_4) |
||
138 | : "edx" ); |
||
139 | |||
140 | } |
||
141 | |||
305 | giacomo | 142 | //Low level time read function |
336 | giacomo | 143 | extern __inline__ void ll_read_timespec_8000(struct timespec *tspec) |
305 | giacomo | 144 | { |
336 | giacomo | 145 | extern unsigned int clk_opt_0,clk_opt_5; |
305 | giacomo | 146 | extern unsigned long long *ptr_init_tsc; |
147 | |||
336 | giacomo | 148 | if (clk_opt_0 == 0) { |
305 | giacomo | 149 | NULL_TIMESPEC(tspec); |
150 | return; |
||
151 | } |
||
336 | giacomo | 152 | |
153 | __asm__("rdtsc\n\t" |
||
305 | giacomo | 154 | "subl (%%edi),%%eax\n\t" |
336 | giacomo | 155 | "sbbl 4(%%edi),%%edx\n\t" |
156 | "shrdl $1,%%edx,%%eax\n\t" |
||
157 | "shrl %%edx\n\t" |
||
158 | "divl %%ebx\n\t" |
||
159 | "movl %%eax,%%ebx\n\t" |
||
160 | "xorl %%eax,%%eax\n\t" |
||
161 | "shrdl $2,%%edx,%%eax\n\t" |
||
162 | "shrl $2,%%edx\n\t" |
||
163 | "divl %%ecx\n\t" |
||
164 | : "=b" (tspec->tv_sec), "=a" (tspec->tv_nsec) |
||
165 | : "D" (ptr_init_tsc), "b" (clk_opt_0), "c" (clk_opt_5) |
||
166 | : "edx"); |
||
305 | giacomo | 167 | |
168 | } |
||
169 | |||
299 | giacomo | 170 | #define rdmsr(msr,val1,val2) \ |
171 | __asm__ __volatile__("rdmsr" \ |
||
172 | : "=a" (val1), "=d" (val2) \ |
||
173 | : "c" (msr)) |
||
174 | |||
175 | #define wrmsr(msr,val1,val2) \ |
||
176 | __asm__ __volatile__("wrmsr" \ |
||
177 | : /* no outputs */ \ |
||
178 | : "c" (msr), "a" (val1), "d" (val2)) |
||
179 | |||
120 | giacomo | 180 | /* RTC */ |
181 | |||
182 | #define RTC_PORT(x) (0x70 + (x)) |
||
183 | |||
184 | #define CMOS_READ(addr,val) \ |
||
185 | { \ |
||
186 | outp(RTC_PORT(0),(addr)); \ |
||
187 | val = inp(RTC_PORT(1)); \ |
||
188 | } |
||
189 | |||
190 | #define CMOS_WRITE(addr,val) \ |
||
191 | { \ |
||
192 | outp(RTC_PORT(0),(addr)); \ |
||
193 | outp(RTC_PORT(1),(val)); \ |
||
194 | } |
||
195 | |||
196 | #define RTC_IRQ 8 |
||
197 | |||
131 | giacomo | 198 | void ll_init_advtimer(void); |
301 | giacomo | 199 | void ll_restore_adv(void); |
131 | giacomo | 200 | |
120 | giacomo | 201 | END_DEF |
202 | #endif |