Rev 301 | 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" \ |
||
42 | "movl %%eax,%%esi\n\t" \ |
||
43 | "movl %%edx,%%edi\n\t" \ |
||
44 | "xorl %%eax,%%eax\n\t" \ |
||
45 | "cpuid" \ |
||
46 | : "=S" (low), "=D" (high) \ |
||
239 | giacomo | 47 | :: "ebx", "ecx") |
120 | giacomo | 48 | |
49 | #define rdtscll(val) \ |
||
239 | giacomo | 50 | __asm__ __volatile__("xorl %%eax,%%eax\n\t" \ |
242 | giacomo | 51 | "cpuid\n\t" \ |
52 | "rdtsc\n\t" \ |
||
53 | "pushl %%eax\n\t" \ |
||
54 | "pushl %%edx\n\t" \ |
||
55 | "xorl %%eax,%%eax\n\t" \ |
||
56 | "cpuid\n\t" \ |
||
57 | "popl %%edx\n\t" \ |
||
58 | "popl %%eax\n\t" \ |
||
59 | : "=A" (val) \ |
||
239 | giacomo | 60 | :: "ebx","ecx") |
120 | giacomo | 61 | |
305 | giacomo | 62 | //Low level time read function |
63 | extern __inline__ void ll_read_timespec(struct timespec *tspec) |
||
64 | { |
||
65 | extern unsigned int clk_per_msec; |
||
66 | extern unsigned long long *ptr_init_nsec; |
||
67 | extern unsigned long long *ptr_init_tsc; |
||
68 | |||
69 | if (clk_per_msec == 0) { |
||
70 | NULL_TIMESPEC(tspec); |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | __asm__("xorl %%eax,%%eax\n\t" |
||
75 | "cpuid\n\t" |
||
76 | "rdtsc\n\t" |
||
77 | "pushl %%eax\n\t" |
||
78 | "pushl %%edx\n\t" |
||
79 | "xorl %%eax,%%eax\n\t" |
||
80 | "cpuid\n\t" |
||
81 | "popl %%edx\n\t" |
||
82 | "popl %%eax\n\t" |
||
83 | "movl %4,%%ebx\n\t" |
||
84 | "subl (%%edi),%%eax\n\t" |
||
85 | "sbbl 4(%%edi),%%edx\n\t" |
||
86 | "movl %%edx,%%ecx\n\t" |
||
87 | "movl $1000000,%%edi\n\t" |
||
88 | "mull %%edi\n\t" |
||
89 | "pushl %%eax\n\t" |
||
90 | "movl %%ecx,%%eax\n\t" |
||
91 | "movl %%edx,%%ecx\n\t" |
||
92 | "mull %%edi\n\t" |
||
93 | "addl %%ecx,%%eax\n\t" |
||
94 | "adcl $0,%%edx\n\t" |
||
95 | "divl %%ebx\n\t" |
||
96 | "movl %%eax,%%ecx\n\t" |
||
97 | "popl %%eax\n\t" |
||
98 | "divl %%ebx\n\t" |
||
99 | "movl %%ecx,%%edx\n\t" |
||
100 | "addl (%%esi),%%eax\n\t" |
||
101 | "adcl 4(%%esi),%%edx\n\t" |
||
102 | "movl $1000000000,%%edi\n\t" |
||
103 | "divl %%edi\n\t" |
||
104 | : "=a" (tspec->tv_sec), "=d" (tspec->tv_nsec) |
||
105 | : "D" (ptr_init_tsc), "S" (ptr_init_nsec), "m" (clk_per_msec) |
||
106 | : "ebx", "ecx"); |
||
107 | |||
108 | } |
||
109 | |||
299 | giacomo | 110 | #define rdmsr(msr,val1,val2) \ |
111 | __asm__ __volatile__("rdmsr" \ |
||
112 | : "=a" (val1), "=d" (val2) \ |
||
113 | : "c" (msr)) |
||
114 | |||
115 | #define wrmsr(msr,val1,val2) \ |
||
116 | __asm__ __volatile__("wrmsr" \ |
||
117 | : /* no outputs */ \ |
||
118 | : "c" (msr), "a" (val1), "d" (val2)) |
||
119 | |||
120 | giacomo | 120 | /* RTC */ |
121 | |||
122 | #define RTC_PORT(x) (0x70 + (x)) |
||
123 | |||
124 | #define CMOS_READ(addr,val) \ |
||
125 | { \ |
||
126 | outp(RTC_PORT(0),(addr)); \ |
||
127 | val = inp(RTC_PORT(1)); \ |
||
128 | } |
||
129 | |||
130 | #define CMOS_WRITE(addr,val) \ |
||
131 | { \ |
||
132 | outp(RTC_PORT(0),(addr)); \ |
||
133 | outp(RTC_PORT(1),(val)); \ |
||
134 | } |
||
135 | |||
136 | #define RTC_IRQ 8 |
||
137 | |||
131 | giacomo | 138 | void ll_init_advtimer(void); |
301 | giacomo | 139 | void ll_restore_adv(void); |
131 | giacomo | 140 | |
120 | giacomo | 141 | END_DEF |
142 | #endif |