Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8111 | dunkaist | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | $Revision$ |
||
9 | |||
10 | HPET_ID = 0x0000 |
||
11 | HPET_PERIOD = 0x0004 |
||
12 | HPET_CFG_ENABLE = 0x0001 |
||
13 | HPET_CFG = 0x0010 |
||
14 | HPET_COUNTER = 0x00f0 |
||
15 | HPET_T0_CFG = 0x0100 |
||
16 | |||
17 | HPET_TN_LEVEL = 0x0002 |
||
18 | HPET_TN_ENABLE = 0x0004 |
||
19 | HPET_TN_FSB = 0x4000 |
||
20 | |||
21 | uglobal |
||
22 | hpet_base rd 1 |
||
23 | hpet_period rd 1 |
||
24 | hpet_timers rd 1 |
||
25 | hpet_tsc_start rd 2 |
||
26 | endg |
||
27 | |||
28 | align 4 |
||
29 | init_hpet: |
||
30 | mov ebx, [hpet_base] |
||
31 | test ebx, ebx |
||
32 | jz .done |
||
33 | |||
34 | mov eax, [ebx] |
||
35 | and ah, 0x1F |
||
36 | inc ah |
||
37 | movzx eax, ah |
||
38 | mov [hpet_timers], eax |
||
39 | mov ecx, eax |
||
40 | |||
41 | mov eax, [ebx+HPET_PERIOD] |
||
42 | xor edx, edx |
||
43 | shld edx, eax, 10 |
||
44 | shl eax, 10 |
||
45 | mov esi, 1000000 |
||
46 | div esi |
||
47 | mov [hpet_period], eax |
||
48 | |||
49 | mov esi, [ebx+HPET_CFG] |
||
50 | and esi, not HPET_CFG_ENABLE |
||
51 | mov [ebx+HPET_CFG], esi ;stop main counter |
||
52 | |||
53 | lea edx, [ebx+HPET_T0_CFG] |
||
54 | @@: |
||
55 | jcxz @F |
||
56 | mov eax, [edx] |
||
57 | and eax, not (HPET_TN_ENABLE+HPET_TN_LEVEL+HPET_TN_FSB) |
||
58 | mov [edx], eax |
||
59 | add edx, 0x20 |
||
60 | dec ecx |
||
61 | jmp @B |
||
62 | @@: |
||
63 | mov [ebx+HPET_COUNTER], ecx ;reset main counter |
||
64 | mov [ebx+HPET_COUNTER+4], ecx |
||
65 | |||
66 | or esi, HPET_CFG_ENABLE |
||
67 | mov [ebx+HPET_CFG], esi ;and start again |
||
68 | |||
69 | .done: |
||
70 | rdtsc |
||
71 | mov [hpet_tsc_start], eax |
||
72 | mov [hpet_tsc_start+4], edx |
||
73 | |||
74 | ret |