From 0c7383ce047721ddbf3144c0b5e17015c1557ce4 Mon Sep 17 00:00:00 2001 From: Denis Drakhnya Date: Sun, 13 Dec 2020 20:58:32 +0200 Subject: [PATCH] target: e2k: Clear registers in new allocated range of window. --- target/e2k/helper.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/target/e2k/helper.c b/target/e2k/helper.c index 6c6d84c6ff..5f0c637829 100644 --- a/target/e2k/helper.c +++ b/target/e2k/helper.c @@ -165,7 +165,14 @@ static inline void do_call(CPUE2KState *env, int wbs, target_ulong pc_next) void helper_setwd(CPUE2KState *env, uint32_t lts) { - env->wd.size = extract32(lts, 5, 7) * 2; + int old_size = env->wd.size, size = extract32(lts, 5, 7) * 2; + + if (size < env->wd.psize) { + helper_raise_exception(env, E2K_EXCP_ILLOPN); + return; + } + + env->wd.size = size; env->wd.fx = extract32(lts, 4, 1) == 0; if (env->version >= 3) { @@ -175,6 +182,17 @@ void helper_setwd(CPUE2KState *env, uint32_t lts) } ps_spill(env, false, PS_FORCE_FX); + + if (old_size < size) { + unsigned int i, offset; + + offset = env->wd.base + old_size + E2K_NR_COUNT; + for (i = 0; i < size - old_size; i++) { + unsigned int idx = (offset + i) % E2K_NR_COUNT; + env->regs[idx] = 0; + env->tags[idx] = E2K_TAG_NON_NUMBER64; + } + } } uint64_t helper_prep_return(CPUE2KState *env, int ipd)