2020301918-os/kern/time.c
2022-10-19 21:37:15 +08:00

36 lines
628 B
C

#include "type.h"
#include "time.h"
#include "x86.h"
static size_t timecounter;
/*
* 时间戳加一
*/
void
timecounter_inc()
{
timecounter++;
}
/*
* 获取内核当前的时间戳
*/
size_t
clock()
{
return timecounter;
}
void
change_8253Counter0(int hertz) {
outb(TIMER_MODEREG, TIMER_MODE);
outb(TIMER0, (u8)(TIMER_FREQ / hertz));
outb(TIMER0, (u8)((TIMER_FREQ / hertz) >> 8));
/*
8253's counter is 2bytes long
port 0x43 be the Mode Control Register
Orange book writes 00_11_010_0 into this reg, which means
SelectCounter0 | RW low byte first and then high byte | rate generator mode | binary counter
*/
}