Subversion Repositories Kolibri OS

Rev

Rev 8111 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8111 dunkaist 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
9715 Doczom 3
;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;;
8111 dunkaist 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
 
9715 Doczom 41
        mov     eax, [ebx + HPET_PERIOD]
8111 dunkaist 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
 
9715 Doczom 49
        mov     esi, [ebx + HPET_CFG]
8111 dunkaist 50
        and     esi, not HPET_CFG_ENABLE
9715 Doczom 51
        mov     [ebx + HPET_CFG], esi             ;stop main counter
8111 dunkaist 52
 
9715 Doczom 53
        lea     edx, [ebx + HPET_T0_CFG]
8111 dunkaist 54
@@:
55
        jcxz    @F
56
        mov     eax, [edx]
9715 Doczom 57
        and     eax, not (HPET_TN_ENABLE + HPET_TN_LEVEL + HPET_TN_FSB)
8111 dunkaist 58
        mov     [edx], eax
59
        add     edx, 0x20
60
        dec     ecx
61
        jmp     @B
62
@@:
9715 Doczom 63
        mov     [ebx + HPET_COUNTER], ecx         ;reset main counter
64
        mov     [ebx + HPET_COUNTER + 4], ecx
8111 dunkaist 65
 
66
        or      esi, HPET_CFG_ENABLE
9715 Doczom 67
        mov     [ebx + HPET_CFG], esi             ;and start again
8111 dunkaist 68
 
69
.done:
70
        rdtsc
71
        mov     [hpet_tsc_start], eax
9715 Doczom 72
        mov     [hpet_tsc_start + 4], edx
8111 dunkaist 73
 
74
        ret