summaryrefslogtreecommitdiff
path: root/start.c
diff options
context:
space:
mode:
Diffstat (limited to 'start.c')
-rw-r--r--start.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/start.c b/start.c
index b7af38a..8743955 100644
--- a/start.c
+++ b/start.c
@@ -8,6 +8,19 @@ void main();
// entry.S uses this as the initial stack.
__attribute__ ((aligned (16))) char stack0[4096];
+// assembly code in kernelvec for machine-mode timer interrupt.
+extern void machinevec();
+
+// scratch area for timer interrupt.
+uint64 mscratch0[8];
+
+__attribute__ ((aligned (16)))
+void
+xyzzy()
+{
+ uartputc('I');
+}
+
// entry.S jumps here in machine mode on stack0.
void
mstart()
@@ -28,7 +41,16 @@ mstart()
// delegate all interrupts and exceptions to supervisor mode.
w_medeleg(0xffff);
w_mideleg(0xffff);
-
+
+ // set up to receive timer interrupts in machine mode.
+ *(uint64*)CLINT_MTIMECMP0 = *(uint64*)CLINT_MTIME + 10000;
+ mscratch0[4] = CLINT_MTIMECMP0;
+ mscratch0[5] = 10000000;
+ w_mscratch((uint64)mscratch0);
+ w_mtvec((uint64)machinevec);
+ w_mstatus(r_mstatus() | MSTATUS_MIE);
+ w_mie(r_mie() | MIE_MTIE);
+
// jump to main in supervisor mode.
asm("mret");
}