aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/drivers/timer.c')
-rw-r--r--kernel/drivers/timer.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c
index 2a7ca2a..294df84 100644
--- a/kernel/drivers/timer.c
+++ b/kernel/drivers/timer.c
@@ -3,7 +3,10 @@
#include <cpu.h>
#include <def.h>
#include <interrupts.h>
+#include <io.h>
+#include <mem.h>
#include <proc.h>
+#include <rtc.h>
#include <timer.h>
static u32 timer_ticks = 0;
@@ -42,15 +45,6 @@ void timer_wait(u32 ticks)
}
}
-// Install timer handler into IRQ0
-CLEAR void timer_install(void)
-{
- /* hpet_install(10000); // TODO: Find optimal femtosecond period */
- /* if (!hpet) */
- timer_phase(1000);
- irq_install_handler(0, timer_handler);
-}
-
CLEAR void scheduler_enable(void)
{
call_scheduler = 1;
@@ -62,3 +56,26 @@ CLEAR void scheduler_disable(void)
call_scheduler = 0;
irq_install_handler(0, timer_handler);
}
+
+static res timer_read(void *buf, u32 offset, u32 count)
+{
+ UNUSED(offset);
+
+ u32 stamp = rtc_stamp();
+ memcpy_user(buf, &stamp, MIN(count, sizeof(stamp)));
+
+ return MIN(count, sizeof(stamp));
+}
+
+// Install timer handler into IRQ0
+CLEAR void timer_install(void)
+{
+ /* hpet_install(10000); // TODO: Find optimal femtosecond period */
+ /* if (!hpet) */
+ timer_phase(1000);
+ irq_install_handler(0, timer_handler);
+
+ struct io_dev *dev = zalloc(sizeof(*dev));
+ dev->read = timer_read;
+ io_add(IO_TIMER, dev);
+}