summaryrefslogtreecommitdiff
path: root/kernel/drivers/pit.c
blob: 1a05f03a773a6b51f3e127743ad930e08819b084 (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
#include <comus/asm.h>
#include <comus/drivers/pit.h>

#define CHAN_0 0x40
#define CHAN_1 0x41
#define CHAN_2 0x42
#define CMD 0x43

volatile uint64_t ticks = 0;

uint16_t pit_read_divider(void)
{
	uint16_t count = 0;
	cli();
	outb(CMD, 0); // clear bits
	count = inb(CHAN_0); // low byte
	count |= inb(CHAN_0) << 8; // highbyte
	sti();
	return count;
}

void pit_set_divider(uint16_t count)
{
	// FIXME: broken on -O0
	// cli();
	// outb(CHAN_0, count & 0xFF); // low byte
	// outb(CHAN_0, (count & 0xFF00) >> 8); // high byte
	// sti();
}