X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=debug%2Fprograms%2Finterrupt.c;fp=debug%2Fprograms%2Finterrupt.c;h=c2dd5eccf268e2006db98f8a17c48cf8d0413a85;hb=6c2ad1c5c27f5e19e005541f7665a32814d32e0f;hp=0000000000000000000000000000000000000000;hpb=706b6476a2eb320a84fef39716a7c19a83b68a39;p=riscv-tests.git 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++; + } +}