[PATCH v5 11/48] target/nios2: Do not zero the general registers on reset

Richard Henderson posted 48 patches 3 years, 11 months ago
Maintainers: Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, Laurent Vivier <laurent@vivier.eu>
There is a newer version of this series
[PATCH v5 11/48] target/nios2: Do not zero the general registers on reset
Posted by Richard Henderson 3 years, 11 months ago
The bulk of the general register set is undefined on reset.

The zero register is for the most part special-cased in translate,
but the slot is still exposed to gdbstub and nios2_cpu_dump_state,
so continue to make sure that's zeroed.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/nios2/cpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
index 182ddcc18f..97bdc0a61b 100644
--- a/target/nios2/cpu.c
+++ b/target/nios2/cpu.c
@@ -53,16 +53,16 @@ static void nios2_cpu_reset(DeviceState *dev)
 
     ncc->parent_reset(dev);
 
-    memset(env->regs, 0, sizeof(env->regs));
     memset(env->ctrl, 0, sizeof(env->ctrl));
-    env->pc = cpu->reset_addr;
-
 #if defined(CONFIG_USER_ONLY)
     /* Start in user mode with interrupts enabled. */
     env->ctrl[CR_STATUS] = CR_STATUS_U | CR_STATUS_PIE;
 #else
     env->ctrl[CR_STATUS] = 0;
 #endif
+
+    env->regs[R_ZERO] = 0;
+    env->pc = cpu->reset_addr;
 }
 
 #ifndef CONFIG_USER_ONLY
-- 
2.25.1
Re: [PATCH v5 11/48] target/nios2: Do not zero the general registers on reset
Posted by Peter Maydell 3 years, 11 months ago
On Thu, 10 Mar 2022 at 11:27, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The bulk of the general register set is undefined on reset.

They might be architecturally undefined, but for QEMU's
purposes we want the state of the CPU on reset to be
identical to the state it is in when QEMU is first started.

thanks
-- PMM
Re: [PATCH v5 11/48] target/nios2: Do not zero the general registers on reset
Posted by Richard Henderson 3 years, 11 months ago
On 3/10/22 04:21, Peter Maydell wrote:
> On Thu, 10 Mar 2022 at 11:27, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> The bulk of the general register set is undefined on reset.
> 
> They might be architecturally undefined, but for QEMU's
> purposes we want the state of the CPU on reset to be
> identical to the state it is in when QEMU is first started.

Ok, I've dropped this.

The intent had been to remove a user/sysemu difference when we get to introducing shadow 
regs, but it isn't that big of a deal.


r~