fix O_RDWR bug.
[mit-jos.git] / kern / kclock.c
blobe5310ce145078d50f1e920f90dba9ccc44f7c05f
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>
16 unsigned
17 mc146818_read(unsigned reg)
19 outb(IO_RTC, reg);
20 return inb(IO_RTC+1);
23 void
24 mc146818_write(unsigned reg, unsigned datum)
26 outb(IO_RTC, reg);
27 outb(IO_RTC+1, datum);
30 void
31 kclock_init(void)
33 /* initialize 8253 clock to interrupt 100 times/sec */
34 outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
35 outb(IO_TIMER1, TIMER_DIV(100) % 256);
36 outb(IO_TIMER1, TIMER_DIV(100) / 256);
37 cprintf(" Setup timer interrupts via 8259A\n");
38 irq_setmask_8259A(irq_mask_8259A & ~(1<<0));
39 cprintf(" unmasked timer interrupt\n");