diff --git a/kernel/trunk/init.inc b/kernel/trunk/init.inc index a60e1eb0b8..3b9af4672c 100644 --- a/kernel/trunk/init.inc +++ b/kernel/trunk/init.inc @@ -439,7 +439,7 @@ acpi_hpet_base rd 1 hpet_base rd 1 hpet_period rd 1 hpet_timers rd 1 - +hpet_tsc_start rd 2 cpu_count rd 1 smpt rd 16 endg @@ -613,7 +613,7 @@ align 4 init_hpet: mov ebx, [hpet_base-OS_BASE] test ebx, ebx - jz @F + jz .done mov eax, [ebx] and ah, 0x1F @@ -649,7 +649,12 @@ init_hpet: or esi, HPET_CFG_ENABLE mov [ebx+HPET_CFG], esi ;and start again -@@: + +.done: + rdtsc + mov [hpet_tsc_start-OS_BASE], eax + mov [hpet_tsc_start+4-OS_BASE], edx + ret diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 854a734a94..7b08d1a42c 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -701,19 +701,11 @@ setvideomode: mov eax, [hpet_base] test eax, eax jz @F - DEBUGF 1, "K : HPET base %x\n", eax - mov eax, [hpet_period] - DEBUGF 1, "K : HPET period %d\n", eax - mov eax, [hpet_timers] - DEBUGF 1, "K : HPET timers %d\n", eax - mov eax, [hpet_base] stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR mov [hpet_base], eax - mov eax, [eax] DEBUGF 1, "K : HPET caps %x\n", eax - @@: ; SET UP OS TASK @@ -1041,7 +1033,31 @@ include "detect/vortex86.inc" ; Vortex86 SoC detection code mov esi, boot_cpufreq call boot_log - cli ;FIXME check IF + cli + mov ebx, [hpet_base] + test ebx, ebx + jz @F + mov ebx, [ebx+0xF0] + + rdtsc + mov ecx, 1000 + sub eax, [hpet_tsc_start] + sbb edx, [hpet_tsc_start+4] + shld edx, eax, 10 + shl eax, 10 + mov esi, eax + mov eax, edx + mul ecx + xchg eax, esi + mul ecx + adc edx, esi + div ebx + mul ecx + div [hpet_period] + mul ecx + DEBUGF 1, "K : cpu frequency %u Hz\n", eax + jmp .next +@@: rdtsc mov ecx, eax mov esi, 250 ; wait 1/4 a second @@ -1053,6 +1069,7 @@ include "detect/vortex86.inc" ; Vortex86 SoC detection code xor edx, edx shld edx, eax, 2 shl eax, 2 +.next: mov dword [cpu_freq], eax mov dword [cpu_freq+4], edx mov ebx, 1000000