From c57a80f358ff150e5ac88a0affbf5c11a388a43b Mon Sep 17 00:00:00 2001 From: Luke Wren Date: Mon, 6 Dec 2021 07:47:20 +0000 Subject: [PATCH] Add AMO + timer testcase --- test/sim/amo_timer_irq/Makefile | 5 +++ test/sim/amo_timer_irq/amo_timer_irq.gtkw | 46 +++++++++++++++++++++++ test/sim/amo_timer_irq/main.c | 45 ++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 test/sim/amo_timer_irq/Makefile create mode 100644 test/sim/amo_timer_irq/amo_timer_irq.gtkw create mode 100644 test/sim/amo_timer_irq/main.c diff --git a/test/sim/amo_timer_irq/Makefile b/test/sim/amo_timer_irq/Makefile new file mode 100644 index 0000000..e950845 --- /dev/null +++ b/test/sim/amo_timer_irq/Makefile @@ -0,0 +1,5 @@ +SRCS := ../common/init.S main.c +APP := amo_timer_irq +CCFLAGS = -march=rv32imac -Os + +include ../common/src_only_app.mk diff --git a/test/sim/amo_timer_irq/amo_timer_irq.gtkw b/test/sim/amo_timer_irq/amo_timer_irq.gtkw new file mode 100644 index 0000000..648884f --- /dev/null +++ b/test/sim/amo_timer_irq/amo_timer_irq.gtkw @@ -0,0 +1,46 @@ +[*] +[*] GTKWave Analyzer v3.3.103 (w)1999-2019 BSI +[*] Sat Dec 4 23:25:19 2021 +[*] +[dumpfile] "amo_timer_irq_run.vcd" +[dumpfile_mtime] "Sat Dec 4 23:21:36 2021" +[dumpfile_size] 6246687 +[savefile] "/home/luke/proj/hazard3/test/sim/amo_smoke/amo_smoke.gtkw" +[timestart] 420 +[size] 1975 1095 +[pos] -1 -1 +*-3.000000 458 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +[treeopen] core. +[sst_width] 233 +[signals_width] 246 +[sst_expanded] 1 +[sst_vpaned_height] 317 +@22 +core.d_pc[31:0] +@28 +core.mw_local_exclusive_reserved +core.m_stall +core.x_stall +core.x_stall_on_amo +@200 +- +@22 +d_haddr[31:0] +@28 +d_htrans[1:0] +d_hsize[2:0] +@29 +d_hexcl +@28 +d_hwrite +d_hready +@22 +d_hwdata[31:0] +d_hrdata[31:0] +@200 +- +@22 +core.x_rs2_bypass[31:0] +core.xm_store_data[31:0] +[pattern_trace] 1 +[pattern_trace] 0 diff --git a/test/sim/amo_timer_irq/main.c b/test/sim/amo_timer_irq/main.c new file mode 100644 index 0000000..4534e3b --- /dev/null +++ b/test/sim/amo_timer_irq/main.c @@ -0,0 +1,45 @@ +#include "tb_cxxrtl_io.h" +#include + +// Serve timer IRQs in the background whilst performing AMOs in a loop in the +// foreground. + +#define IRQ_INTERVAL 201 +#define N_AMOS 1000 + +#define test_assert(cond, ...) if (!(cond)) {tb_printf(__VA_ARGS__); return -1;} + +volatile uint32_t amo_count, irq_count; + +void __attribute__((interrupt)) isr_machine_timer() { + mm_timer->mtimecmp = mm_timer->mtimecmp + IRQ_INTERVAL; + ++irq_count; +} + +int main() { + amo_count = 0; + irq_count = 0; + + asm volatile ("csrw mie, %0" : : "r" (0x80)); + mm_timer->mtime = 0; + // Will take first timer interrupt immediately: + asm volatile ("csrsi mstatus, 0x8"); + + for (uint32_t i = 0; i < N_AMOS; i = i + 1) { + uint32_t fetch; + asm volatile ( + "amoadd.w %0, %1, (%2)" + : "=r" (fetch) + : "r" (1), "r" (&amo_count) + ); + test_assert(fetch == i, "Bad fetch, expected %u, got %u\n", i, fetch); + } + + asm volatile ("csrci mstatus, 0x8"); + uint32_t current_time = mm_timer->mtime; + tb_printf("At time %u, received %u IRQs\n", current_time, irq_count); + test_assert(current_time / IRQ_INTERVAL + 1 == irq_count, "Bad IRQ count\n"); + test_assert(amo_count == N_AMOS, "Bad final AMO count %u\n", N_AMOS); + + return 0; +}