diff options
| author | Tim Newsome <tim@sifive.com> | 2017-09-01 12:31:15 -0700 |
|---|---|---|
| committer | Tim Newsome <tim@sifive.com> | 2017-09-01 12:31:15 -0700 |
| commit | a7238f6f683705a92a3216562d91cfc8979c75ed (patch) | |
| tree | b05fb4b85558c595517fb23e08193baa8623c415 /debug/programs/init.c | |
| parent | 5acbf6414ddaa6552ead5099868897a161bd945f (diff) | |
| download | riscv-tests-a7238f6f683705a92a3216562d91cfc8979c75ed.zip riscv-tests-a7238f6f683705a92a3216562d91cfc8979c75ed.tar.gz riscv-tests-a7238f6f683705a92a3216562d91cfc8979c75ed.tar.bz2 | |
Add some infrastructure for multicore tests.
When compiling, define the number of harts. This means we only need to
allocate a lot of stack if there are a lot of harts.
Diffstat (limited to 'debug/programs/init.c')
| -rw-r--r-- | debug/programs/init.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/debug/programs/init.c b/debug/programs/init.c index a2b41b0..9933c23 100644 --- a/debug/programs/init.c +++ b/debug/programs/init.c @@ -1,7 +1,30 @@ +#include "init.h" +#include "encoding.h" + int main(void); +trap_handler_t trap_handler[NHARTS] = {0}; + +void set_trap_handler(trap_handler_t handler) +{ + unsigned hartid = csr_read(mhartid); + trap_handler[hartid] = handler; +} + +void enable_timer_interrupts() +{ + set_csr(mie, MIP_MTIP); + set_csr(mstatus, MSTATUS_MIE); +} + void handle_trap(unsigned int mcause, unsigned int mepc, unsigned int sp) { + unsigned hartid = csr_read(mhartid); + if (trap_handler[hartid]) { + trap_handler[hartid](hartid, mcause, mepc, sp); + return; + } + while (1) ; } |
