From 7eb18debb71f6d222d18e78f4dc564f2a27ebf25 Mon Sep 17 00:00:00 2001 From: Brennan Ashton Date: Sun, 28 Jun 2020 22:47:50 -0700 Subject: [PATCH] Allow mpie bit to be writeable in mstatus This bit is currently not r/w but this means that it is not possible to change the mstatus mie state from within an exception handler. The mie bit is always set to its previous state when mret is called. This is an issue with an RTOS where ecall may be called from a new task creation which is in a critial section. This mean that interrupts including the system tick will not be triggered. This functionality was tested with the code in this GitHub gist https://gist.github.com/btashton/4aa7ed42bc81ff4716821636997d9df9 Signed-off-by: Brennan Ashton --- rtl/serv_csr.v | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rtl/serv_csr.v b/rtl/serv_csr.v index 897e2728..dc6bcaac 100644 --- a/rtl/serv_csr.v +++ b/rtl/serv_csr.v @@ -71,11 +71,14 @@ module serv_csr always @(posedge i_clk) begin /* Note: To save resources mstatus_mpie (mstatus bit 7) is not - readable or writable from sw + readable from sw */ if (i_mstatus_en & i_cnt3) mstatus_mie <= csr_in; + if (i_mstatus_en & i_cnt7) + mstatus_mpie <= csr_in; + if (i_mie_en & i_cnt7) mie_mtie <= csr_in;