mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
timekeeper: initial implementation
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef _TIMEKEEPER_H_INCLUDE
|
||||||
|
#define _TIMEKEEPER_H_INCLUDE
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
struct timespec arch_timekeeper_gettime();
|
||||||
|
struct timespec arch_timekeeper_gettimefromboot();
|
||||||
|
|
||||||
|
void arch_timekeeper_init();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <arch/smp.h>
|
#include <arch/smp.h>
|
||||||
#include <kernel/timer.h>
|
#include <kernel/timer.h>
|
||||||
#include <kernel/keyboard.h>
|
#include <kernel/keyboard.h>
|
||||||
|
#include <arch/timekeeper.h>
|
||||||
|
|
||||||
void kmain(){
|
void kmain(){
|
||||||
|
|
||||||
@@ -31,7 +32,6 @@ void kmain(){
|
|||||||
|
|
||||||
pmm_init();
|
pmm_init();
|
||||||
|
|
||||||
|
|
||||||
arch_mmu_init();
|
arch_mmu_init();
|
||||||
|
|
||||||
vmm_init();
|
vmm_init();
|
||||||
@@ -48,6 +48,8 @@ void kmain(){
|
|||||||
|
|
||||||
hpet_init();
|
hpet_init();
|
||||||
|
|
||||||
|
arch_timekeeper_init();
|
||||||
|
|
||||||
timer_init();
|
timer_init();
|
||||||
|
|
||||||
vfs_init();
|
vfs_init();
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#include <arch/timekeeper.h>
|
||||||
|
#include <limine.h>
|
||||||
|
#include <arch/panic.h>
|
||||||
|
#include <arch/hpet.h>
|
||||||
|
|
||||||
|
static time_t bootunixtime;
|
||||||
|
static time_t timerticksperus;
|
||||||
|
static time_t timerusatboot;
|
||||||
|
|
||||||
|
static volatile struct limine_boot_time_request lim_boottime = {
|
||||||
|
.id = LIMINE_BOOT_TIME_REQUEST,
|
||||||
|
.revision = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct timespec arch_timekeeper_gettimefromboot(){
|
||||||
|
struct timespec time;
|
||||||
|
|
||||||
|
time_t timercurrentus = hpet_get_counter() / timerticksperus - timerusatboot;
|
||||||
|
|
||||||
|
time.tv_sec = timercurrentus / US_IN_SECS;
|
||||||
|
time.tv_nsec = (timercurrentus % US_IN_SECS) * NS_IN_US;
|
||||||
|
|
||||||
|
return time;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timespec arch_timekeeper_gettime(){
|
||||||
|
struct timespec time;
|
||||||
|
struct timespec timefromboot = arch_timekeeper_gettimefromboot();
|
||||||
|
time.tv_sec = bootunixtime + timefromboot.tv_sec;
|
||||||
|
time.tv_nsec = timefromboot.tv_nsec;
|
||||||
|
|
||||||
|
return time;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void arch_timekeeper_init(){
|
||||||
|
|
||||||
|
if(!lim_boottime.response)
|
||||||
|
_panic("No limine boot time response\n", 0);
|
||||||
|
|
||||||
|
bootunixtime = lim_boottime.response->boot_time;
|
||||||
|
|
||||||
|
timerticksperus = hpet_get_ticksperus();
|
||||||
|
|
||||||
|
timerusatboot = hpet_get_counter() / timerticksperus;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user