* same with xv6
[mascara-docs.git] / i386 / ucla / src / lab4 / kern / kclock.c
blob4aa8474825426e563fcce1874187a472b8c8c0cf
1 /* See COPYRIGHT for copyright information. */
3 /* Support for two time-related hardware gadgets: 1) the run time
4 * clock with its NVRAM access functions; 2) the 8253 timer, which
5 * generates interrupts on IRQ 0.
6 */
8 #include <inc/x86.h>
9 #include <inc/stdio.h>
10 #include <inc/isareg.h>
11 #include <inc/timerreg.h>
13 #include <kern/kclock.h>
14 #include <kern/picirq.h>
17 unsigned
18 mc146818_read(unsigned reg)
20 outb(IO_RTC, reg);
21 return inb(IO_RTC+1);
24 void
25 mc146818_write(unsigned reg, unsigned datum)
27 outb(IO_RTC, reg);
28 outb(IO_RTC+1, datum);
32 void
33 kclock_init(void)
35 /* initialize 8253 clock to interrupt 100 times/sec */
36 outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
37 outb(IO_TIMER1, TIMER_DIV(100) % 256);
38 outb(IO_TIMER1, TIMER_DIV(100) / 256);
39 cprintf(" Setup timer interrupts via 8259A\n");
40 irq_setmask_8259A(irq_mask_8259A & ~(1<<0));
41 cprintf(" unmasked timer interrupt\n");