From 2de873c9bb7c633bbc84a76b67adff8a374af932 Mon Sep 17 00:00:00 2001 From: Greg Chadwick Date: Wed, 13 Sep 2023 13:42:47 +0100 Subject: [PATCH] Add icache_enable function to simple_system_common.h --- .../simple_system/common/simple_system_common.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/sw/simple_system/common/simple_system_common.h b/examples/sw/simple_system/common/simple_system_common.h index 949df9dbc0..e0caf6d4cd 100644 --- a/examples/sw/simple_system/common/simple_system_common.h +++ b/examples/sw/simple_system/common/simple_system_common.h @@ -95,4 +95,21 @@ void timer_disable(void); */ uint64_t get_elapsed_time(void); +/** + * Enables/disables the instruction cache. This has no effect on Ibex + * configurations that do not have an instruction cache and in particular is + * safe to execute on those configurations. + * + * @param enable if non-zero enables, otherwise disables + */ +static inline void icache_enable(int enable) { + if (enable) { + // Set icache enable bit in CPUCTRLSTS + asm volatile("csrs 0x7c0, 1"); + } else { + // Clear icache enable bit in CPUCTRLSTS + asm volatile("csrc 0x7c0, 1"); + } +} + #endif