Subversion Repositories shark

Rev

Rev 120 | Rev 194 | Go to most recent revision | 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
 
34
/* TSC */
35
 
36
#define rdtsc(low,high) \
37
     __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
38
 
39
#define rdtscll(val) \
40
     __asm__ __volatile__("rdtsc" : "=A" (val))
41
 
42
/* RTC */
43
 
44
#define RTC_PORT(x)     (0x70 + (x))
45
 
46
#define CMOS_READ(addr,val)     \
47
{                               \
48
outp(RTC_PORT(0),(addr));       \
49
val = inp(RTC_PORT(1));         \
50
}
51
 
52
#define CMOS_WRITE(addr,val)    \
53
{                               \
54
outp(RTC_PORT(0),(addr));       \
55
outp(RTC_PORT(1),(val));        \
56
}
57
 
58
#define RTC_IRQ 8
59
 
131 giacomo 60
extern signed long long clk_per_msec;
61
 
62
extern __inline__ void UNSIGNED_TSC2NSEC(unsigned long long tsc, unsigned long long *n)
63
{
64
 
65
        unsigned long nl,nh;
66
 
67
        nl = *n & 0xFFFFFFFF;
68
        nh = *n >> 32;
69
 
70
        __asm__("mull %%ecx\n\t"
71
                "movl %%eax,%%esi\n\t"
72
                "movl %%edx,%%edi\n\t"
73
                "xorl %%edx,%%edx\n\t"
74
                "movl %6,%%eax\n\t"
75
                "mull %%ecx\n\t"
76
                "addl %%edi,%%eax\n\t"
77
                "adcl $0,%%edx\n\t"
78
                "movl %5,%%ecx\n\t"
79
                "divl %%ecx\n\t"
80
                "xchgl %%eax,%%esi\n\t"
81
                "divl %%ecx\n\t"
82
                : "=a" (nl), "=S" (nh)
83
                : "c" (1000000), "a" ((unsigned long)(tsc & 0xFFFFFFFF)), "d" (0),
84
                  "m" ((unsigned long)(clk_per_msec)), "m" ((unsigned long)(tsc >> 32)),
85
                  "S" (0), "D" (0));
86
 
87
        *n = nh;
88
        *n <<= 32;
89
        *n |= nl;
90
 
91
}
92
 
93
void ll_init_advtimer(void);
94
void ll_restore_CMOS(void);
95
 
120 giacomo 96
END_DEF
97
#endif