summaryrefslogtreecommitdiff
path: root/stage3/clock.c
blob: 372d3da5a9b9d4ccc9c1f0ba5efa18b6dc193d71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "clock.h"
#include "pic.h"
#include "font.h"
#include "io.h"
#include "thread.h"
#include "heap.h"
#include "halt.h"

u64 monoclock_rtc_time = 0;

void clock_init()
{
	outb(0x70, 0x8B);
	char prev = inb(0x71);
	outb(0x70, 0x8B);
	outb(0x71, prev | 0x40);
	unmask_irq(8);
}

u64 clock_monotonic_coarse() {
	return monoclock_rtc_time;
}

u64 clock_monotonic()
{
	return monoclock_rtc_time; // TODO: high resolution clock
}

u64 clock_cycles()
{
	u64 lo,hi;
	asm volatile("rdtsc\n\t": "=a" (lo), "=d" (hi));
	return lo | hi << 32;
}