BMOSP/kernel/arch/arch.c

47 lines
816 B
C
Raw Permalink Normal View History

2023-10-21 21:23:51 +03:00
/**
* arch.c
* Инициализация архитектуры
*
* Настройка архитектурнозависимых функций
*
*/
2023-10-21 21:23:51 +03:00
#include <arch.h>
2023-10-29 16:12:00 +03:00
static uint64_t kernel_start_ticks = 0;
static uint64_t kernel_ticks = 0;
uint64_t rdtsc( ) {
unsigned int lo, hi;
asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
return ((uint64_t)hi << 32) | lo;
}
uint64_t arch_get_tick( ) {
if (kernel_start_ticks == 0) {
kernel_start_ticks = rdtsc( );
return 0;
}
kernel_ticks = rdtsc( ) - kernel_start_ticks;
return kernel_ticks;
}
uint64_t arch_get_tick_b( ) {
uint64_t tick = arch_get_tick( ) + 1;
return tick / 1000000;
}
uint64_t arch_get_tick_l( ) {
uint64_t tick = arch_get_tick( ) + 1;
return tick % 1000000;
}
void arch_init( ) {
gdt_init( );
idt_init( );
2023-10-21 21:23:51 +03:00
cpu_init( );
}