From a82772594e1807632b3650bff111108f250de3b7 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 4 Jun 2019 14:20:37 -0400 Subject: timer interrupts -> supervisor software interrupt --- start.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'start.c') 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"); } -- cgit v1.2.3