kernel: Make delay_ms use HPET when available.

I got a laptop that has timer on channel 1 of PIT that doesn't tick.

git-svn-id: svn://kolibrios.org@8139 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2020-11-05 19:53:54 +00:00
parent e923e0d4db
commit dd55ceaa16

View File

@ -556,7 +556,6 @@ high_code:
mov eax, [hpet_base] mov eax, [hpet_base]
test eax, eax test eax, eax
jz @F jz @F
mov eax, [hpet_base]
stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR
mov [hpet_base], eax mov [hpet_base], eax
mov eax, [eax+HPET_ID] mov eax, [eax+HPET_ID]
@ -3931,9 +3930,33 @@ endg
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
align 4 align 4
delay_ms: ; delay in 1/1000 sec delay_ms: ; delay in 1/1000 sec
push eax pushad
push ecx
cmp [hpet_base], 0
jz .no_hpet
mov eax, esi
mov edx, 10_000_000 ; cs to ns
mul edx
mov ebx, edx
mov ecx, eax
push ecx
call get_clock_ns
pop ecx
mov edi, edx
mov esi, eax
.wait:
push ecx
call get_clock_ns
pop ecx
sub eax, esi
sbb edx, edi
sub eax, ecx
sbb edx, ebx
jc .wait
jmp .done
.no_hpet:
mov ecx, esi mov ecx, esi
; <CPU clock fix by Sergey Kuzmin aka Wildwest> ; <CPU clock fix by Sergey Kuzmin aka Wildwest>
imul ecx, 33941 imul ecx, 33941
@ -3944,19 +3967,18 @@ delay_ms: ; delay in 1/1000 sec
and al, 0x10 and al, 0x10
mov ah, al mov ah, al
cld cld
;--------------------------------------
align 4 .cnt1:
cnt1:
in al, 0x61 in al, 0x61
and al, 0x10 and al, 0x10
cmp al, ah cmp al, ah
jz cnt1 jz .cnt1
mov ah, al mov ah, al
loop cnt1 loop .cnt1
pop ecx .done:
pop eax popad
ret ret
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
align 4 align 4