mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-19 01:25:05 -04:00
Basic frequency calculation
This commit is contained in:
parent
2d7ac44dc6
commit
8866ca95d2
@ -250,25 +250,33 @@ sysinfo_command:
|
||||
|
||||
; rbx = max_frequency
|
||||
|
||||
mov eax, 0x06
|
||||
cpuid
|
||||
and ecx, 1b
|
||||
test ecx, ecx
|
||||
je .last
|
||||
|
||||
call goto_next_line
|
||||
|
||||
mov r8, sysinfo_current_frequency
|
||||
mov r9, sysinfo_current_frequency_length
|
||||
call print_normal
|
||||
|
||||
; read MPERF
|
||||
mov rcx, 0xe7
|
||||
rdmsr
|
||||
rdtscp
|
||||
shl rdx, 32
|
||||
or rax, rdx
|
||||
mov rcx, rax ; cycles start
|
||||
|
||||
; read APERF
|
||||
mov rcx, 0xe8
|
||||
rdmsr
|
||||
mov r8, 100
|
||||
call wait_ms ; wait 100ms
|
||||
|
||||
rdtscp
|
||||
shl rdx, 32
|
||||
or rax, rdx ; cycles end
|
||||
|
||||
sub rax, rcx ; cycles
|
||||
imul rax, 10
|
||||
|
||||
xor rdx, rdx
|
||||
mov rcx, 1000000
|
||||
div rcx
|
||||
|
||||
mov r8, rax
|
||||
call print_int_normal
|
||||
|
||||
.last:
|
||||
|
||||
|
@ -20,6 +20,9 @@ install_timer:
|
||||
|
||||
irq_timer_handler:
|
||||
push rax
|
||||
push rbx
|
||||
push rcx
|
||||
push rdx
|
||||
|
||||
mov rax, [timer_ticks]
|
||||
inc rax
|
||||
@ -37,7 +40,39 @@ irq_timer_handler:
|
||||
|
||||
.end:
|
||||
|
||||
pop r8
|
||||
pop rdx
|
||||
pop rcx
|
||||
pop rbx
|
||||
pop rax
|
||||
|
||||
ret
|
||||
|
||||
; in r8: milliseconds to wait
|
||||
wait_ms:
|
||||
push r9
|
||||
push r10
|
||||
|
||||
mov r9, [timer_ticks]
|
||||
add r9, r8
|
||||
|
||||
.start:
|
||||
cli
|
||||
mov r10, [timer_ticks]
|
||||
cmp r10, r9
|
||||
je .done
|
||||
sti
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
jmp .start
|
||||
|
||||
.done:
|
||||
|
||||
pop r10
|
||||
pop r9
|
||||
|
||||
ret
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user