diff options
author | Tim Newsome <tim@sifive.com> | 2017-09-12 18:48:44 -0700 |
---|---|---|
committer | Tim Newsome <tim@sifive.com> | 2017-09-14 12:32:59 -0700 |
commit | 6c2ad1c5c27f5e19e005541f7665a32814d32e0f (patch) | |
tree | bebb1df50e44a8d0d87c235eba10e7f6332f1d36 /debug/programs | |
parent | 706b6476a2eb320a84fef39716a7c19a83b68a39 (diff) | |
download | riscv-tests-6c2ad1c5c27f5e19e005541f7665a32814d32e0f.zip riscv-tests-6c2ad1c5c27f5e19e005541f7665a32814d32e0f.tar.gz riscv-tests-6c2ad1c5c27f5e19e005541f7665a32814d32e0f.tar.bz2 |
Test debugging code with interrupts.
Diffstat (limited to 'debug/programs')
-rwxr-xr-x | debug/programs/entry.S | 4 | ||||
-rw-r--r-- | debug/programs/init.c | 2 | ||||
-rw-r--r-- | debug/programs/interrupt.c | 32 |
3 files changed, 34 insertions, 4 deletions
diff --git a/debug/programs/entry.S b/debug/programs/entry.S index a2ea955..97b62a3 100755 --- a/debug/programs/entry.S +++ b/debug/programs/entry.S @@ -1,8 +1,6 @@ #include "encoding.h" -// Enough stack to store every register in case a trap handler is executed, -// plus 33 more values. -#define STACK_SIZE (64 * XLEN / 8) +#define STACK_SIZE (74 * XLEN / 8) #if XLEN == 64 # define LREG ld diff --git a/debug/programs/init.c b/debug/programs/init.c index 9933c23..8b047de 100644 --- a/debug/programs/init.c +++ b/debug/programs/init.c @@ -17,7 +17,7 @@ void enable_timer_interrupts() set_csr(mstatus, MSTATUS_MIE); } -void handle_trap(unsigned int mcause, unsigned int mepc, unsigned int sp) +void handle_trap(unsigned int mcause, void *mepc, void *sp) { unsigned hartid = csr_read(mhartid); if (trap_handler[hartid]) { diff --git a/debug/programs/interrupt.c b/debug/programs/interrupt.c new file mode 100644 index 0000000..c2dd5ec --- /dev/null +++ b/debug/programs/interrupt.c @@ -0,0 +1,32 @@ +#include "init.h" +#include "encoding.h" + +static volatile unsigned interrupt_count; +static volatile unsigned local; + +static unsigned delta = 0x100; +void *increment_count(unsigned hartid, unsigned mcause, void *mepc, void *sp) +{ + interrupt_count++; + // There is no guarantee that the interrupt is cleared immediately when + // MTIMECMP is written, so stick around here until that happens. + while (csr_read(mip) & MIP_MTIP) { + MTIMECMP[hartid] = MTIME + delta; + } + return mepc; +} + +int main() +{ + interrupt_count = 0; + local = 0; + unsigned hartid = csr_read(mhartid); + + set_trap_handler(increment_count); + MTIMECMP[hartid] = MTIME - 1; + enable_timer_interrupts(); + + while (1) { + local++; + } +} |