diff mbox series

[v2,1/8] linux-user/nios2: Hoist pc advance to the top of EXCP_TRAP

Message ID 20220325195250.386071-2-richard.henderson@linaro.org
State Superseded
Headers show
Series linux-user/nios2: Fix clone and sigreturn | expand

Commit Message

Richard Henderson March 25, 2022, 7:52 p.m. UTC
Note that this advance *should* be done by the translator, as
that's the pc value that's supposed to be generated by hardware.
However, that's a much larger change across sysemu as well.

In the meantime, produce the correct PC for any signals raised
by the trap instruction.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/nios2/cpu_loop.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Peter Maydell March 26, 2022, 12:50 p.m. UTC | #1
On Fri, 25 Mar 2022 at 19:52, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Note that this advance *should* be done by the translator, as
> that's the pc value that's supposed to be generated by hardware.
> However, that's a much larger change across sysemu as well.
>
> In the meantime, produce the correct PC for any signals raised
> by the trap instruction.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/nios2/cpu_loop.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
> index 1e93ef34e6..2768ae61dd 100644
> --- a/linux-user/nios2/cpu_loop.c
> +++ b/linux-user/nios2/cpu_loop.c
> @@ -40,6 +40,12 @@ void cpu_loop(CPUNios2State *env)
>              break;
>
>          case EXCP_TRAP:
> +            /*
> +             * TODO: This advance should be done in the translator, as
> +             * hardware produces an advanced pc as part of all exceptions.
> +             */
> +            env->regs[R_PC] += 4;
> +

You need to rewind again for the TRAP_BRKPT case, as the
kernel does fp->ea -= 4 in breakpoint_c().

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Richard Henderson March 26, 2022, 1:39 p.m. UTC | #2
On 3/26/22 06:50, Peter Maydell wrote:
> On Fri, 25 Mar 2022 at 19:52, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> Note that this advance *should* be done by the translator, as
>> that's the pc value that's supposed to be generated by hardware.
>> However, that's a much larger change across sysemu as well.
>>
>> In the meantime, produce the correct PC for any signals raised
>> by the trap instruction.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   linux-user/nios2/cpu_loop.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
>> index 1e93ef34e6..2768ae61dd 100644
>> --- a/linux-user/nios2/cpu_loop.c
>> +++ b/linux-user/nios2/cpu_loop.c
>> @@ -40,6 +40,12 @@ void cpu_loop(CPUNios2State *env)
>>               break;
>>
>>           case EXCP_TRAP:
>> +            /*
>> +             * TODO: This advance should be done in the translator, as
>> +             * hardware produces an advanced pc as part of all exceptions.
>> +             */
>> +            env->regs[R_PC] += 4;
>> +
> 
> You need to rewind again for the TRAP_BRKPT case, as the
> kernel does fp->ea -= 4 in breakpoint_c().

Yep, thanks.


r~
diff mbox series

Patch

diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c
index 1e93ef34e6..2768ae61dd 100644
--- a/linux-user/nios2/cpu_loop.c
+++ b/linux-user/nios2/cpu_loop.c
@@ -40,6 +40,12 @@  void cpu_loop(CPUNios2State *env)
             break;
 
         case EXCP_TRAP:
+            /*
+             * TODO: This advance should be done in the translator, as
+             * hardware produces an advanced pc as part of all exceptions.
+             */
+            env->regs[R_PC] += 4;
+
             switch (env->error_code) {
             case 0:
                 qemu_log_mask(CPU_LOG_INT, "\nSyscall\n");
@@ -56,7 +62,6 @@  void cpu_loop(CPUNios2State *env)
                 env->regs[2] = abs(ret);
                 /* Return value is 0..4096 */
                 env->regs[7] = ret > 0xfffff000u;
-                env->regs[R_PC] += 4;
                 break;
 
             case 1:
@@ -99,7 +104,6 @@  void cpu_loop(CPUNios2State *env)
                     o = env->regs[5];
                     n = env->regs[6];
                     env->regs[2] = qatomic_cmpxchg(h, o, n) - o;
-                    env->regs[R_PC] += 4;
                 }
                 break;
             }