Subversion Repositories Kolibri OS

Rev

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

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