On Thu, 17 Mar 2022 at 05:53, Richard Henderson
<richard.henderson@linaro.org> wrote:
Create an array of masks which detail the writable and readonly
bits for each control register. Apply them when writing to
control registers, including the write to status during eret.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
@@ -34,6 +34,15 @@ void helper_raise_exception(CPUNios2State *env, uint32_t
index)
#ifndef CONFIG_USER_ONLY
void helper_eret(CPUNios2State *env, uint32_t new_status, uint32_t new_pc)
{
+ Nios2CPU *cpu = env_archcpu(env);
+
+ /*
+ * Both estatus and bstatus have no constraints on write;
+ * do not allow reserved fields in status to be set.
+ */
+ new_status &= (cpu->cr_state[CR_STATUS].writable |
+ cpu->cr_state[CR_STATUS].readonly);
+
env->ctrl[CR_STATUS] = new_status;
Isn't this allowing the guest to write to readonly bits ?