[07/13] linux-user/sparc: Use WREG constants in sparc/signal.c

Message ID 20190519201953.20161-8-richard.henderson@linaro.org
State New
Headers show
Series
  • linux-user: path, clone, sparc, shmat fixes
Related show

Commit Message

Richard Henderson May 19, 2019, 8:19 p.m.
Remove the incorrectly defined UREG constants.

Maddeningly, in some cases we used the correct constant getting
the env register wrong, and in other cases we used the incorrect
constant getting the env register right.

In the case of getcontext/setcontext, we are aided by the fact
that the "other" constant, e.g. SPARC_MC_O0, is correct.  So we
can easily guess that the WREG_* constant on the other side
should also be O0.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/sparc/signal.c | 96 +++++++++++++--------------------------
 1 file changed, 32 insertions(+), 64 deletions(-)

-- 
2.17.1

Comments

Laurent Vivier June 13, 2019, 9:31 p.m. | #1
Le 19/05/2019 à 22:19, Richard Henderson a écrit :
> Remove the incorrectly defined UREG constants.

> 

> Maddeningly, in some cases we used the correct constant getting

> the env register wrong, and in other cases we used the incorrect

> constant getting the env register right.

> 

> In the case of getcontext/setcontext, we are aided by the fact

> that the "other" constant, e.g. SPARC_MC_O0, is correct.  So we

> can easily guess that the WREG_* constant on the other side

> should also be O0.


For readability, I'd like you split this patch in two:
- one with no behavior change, only with s/UREG_/WREG_/
- one using the correct constants

Thanks,
Laurent

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>  linux-user/sparc/signal.c | 96 +++++++++++++--------------------------

>  1 file changed, 32 insertions(+), 64 deletions(-)

> 

> diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c

> index ead169fbaa..243f237528 100644

> --- a/linux-user/sparc/signal.c

> +++ b/linux-user/sparc/signal.c

> @@ -104,20 +104,6 @@ struct target_rt_signal_frame {

>      qemu_siginfo_fpu_t  fpu_state;

>  };

>  

> -#define UREG_O0        16

> -#define UREG_O6        22

> -#define UREG_I0        0

> -#define UREG_I1        1

> -#define UREG_I2        2

> -#define UREG_I3        3

> -#define UREG_I4        4

> -#define UREG_I5        5

> -#define UREG_I6        6

> -#define UREG_I7        7

> -#define UREG_L0        8

> -#define UREG_FP        UREG_I6

> -#define UREG_SP        UREG_O6

> -

>  static inline abi_ulong get_sigframe(struct target_sigaction *sa, 

>                                       CPUSPARCState *env,

>                                       unsigned long framesize)

> @@ -159,30 +145,12 @@ setup___siginfo(__siginfo_t *si, CPUSPARCState *env, abi_ulong mask)

>          __put_user(env->gregs[i], &si->si_regs.u_regs[i]);

>      }

>      for (i=0; i < 8; i++) {

> -        __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);

> +        __put_user(env->regwptr[WREG_O0 + i], &si->si_regs.u_regs[i+8]);

>      }

>      __put_user(mask, &si->si_mask);

>      return err;

>  }

>  

> -#if 0

> -static int

> -setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/

> -                 CPUSPARCState *env, unsigned long mask)

> -{

> -    int err = 0;

> -

> -    __put_user(mask, &sc->sigc_mask);

> -    __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);

> -    __put_user(env->pc, &sc->sigc_pc);

> -    __put_user(env->npc, &sc->sigc_npc);

> -    __put_user(env->psr, &sc->sigc_psr);

> -    __put_user(env->gregs[1], &sc->sigc_g1);

> -    __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);

> -

> -    return err;

> -}

> -#endif

>  #define NF_ALIGNEDSZ  (((sizeof(struct target_signal_frame) + 7) & (~7)))

>  

>  void setup_frame(int sig, struct target_sigaction *ka,

> @@ -221,20 +189,20 @@ void setup_frame(int sig, struct target_sigaction *ka,

>      }

>  

>      for (i = 0; i < 8; i++) {

> -        __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]);

> +        __put_user(env->regwptr[i + WREG_L0], &sf->ss.locals[i]);

>      }

>      for (i = 0; i < 8; i++) {

> -        __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]);

> +        __put_user(env->regwptr[i + WREG_I0], &sf->ss.ins[i]);

>      }

>      if (err)

>          goto sigsegv;

>  

>      /* 3. signal handler back-trampoline and parameters */

> -    env->regwptr[UREG_FP] = sf_addr;

> -    env->regwptr[UREG_I0] = sig;

> -    env->regwptr[UREG_I1] = sf_addr +

> +    env->regwptr[WREG_FP] = sf_addr;

> +    env->regwptr[WREG_I0] = sig;

> +    env->regwptr[WREG_I1] = sf_addr +

>              offsetof(struct target_signal_frame, info);

> -    env->regwptr[UREG_I2] = sf_addr +

> +    env->regwptr[WREG_I2] = sf_addr +

>              offsetof(struct target_signal_frame, info);

>  

>      /* 4. signal handler */

> @@ -242,11 +210,11 @@ void setup_frame(int sig, struct target_sigaction *ka,

>      env->npc = (env->pc + 4);

>      /* 5. return to kernel instructions */

>      if (ka->ka_restorer) {

> -        env->regwptr[UREG_I7] = ka->ka_restorer;

> +        env->regwptr[WREG_I7] = ka->ka_restorer;

>      } else {

>          uint32_t val32;

>  

> -        env->regwptr[UREG_I7] = sf_addr +

> +        env->regwptr[WREG_I7] = sf_addr +

>                  offsetof(struct target_signal_frame, insns) - 2 * 4;

>  

>          /* mov __NR_sigreturn, %g1 */

> @@ -284,7 +252,7 @@ long do_sigreturn(CPUSPARCState *env)

>      sigset_t host_set;

>      int i;

>  

> -    sf_addr = env->regwptr[UREG_FP];

> +    sf_addr = env->regwptr[WREG_SP];

>      trace_user_do_sigreturn(env, sf_addr);

>      if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) {

>          goto segv_and_exit;

> @@ -316,7 +284,7 @@ long do_sigreturn(CPUSPARCState *env)

>          __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]);

>      }

>      for (i=0; i < 8; i++) {

> -        __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);

> +        __get_user(env->regwptr[i + WREG_O0], &sf->info.si_regs.u_regs[i+8]);

>      }

>  

>      /* FIXME: implement FPU save/restore:

> @@ -433,7 +401,7 @@ void sparc64_set_context(CPUSPARCState *env)

>      abi_ulong fp, i7, w_addr;

>      unsigned int i;

>  

> -    ucp_addr = env->regwptr[UREG_I0];

> +    ucp_addr = env->regwptr[WREG_O0];

>      if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) {

>          goto do_sigsegv;

>      }

> @@ -443,7 +411,7 @@ void sparc64_set_context(CPUSPARCState *env)

>      if ((pc | npc) & 3) {

>          goto do_sigsegv;

>      }

> -    if (env->regwptr[UREG_I1]) {

> +    if (env->regwptr[WREG_O1]) {

>          target_sigset_t target_set;

>          sigset_t set;

>  

> @@ -474,19 +442,19 @@ void sparc64_set_context(CPUSPARCState *env)

>      __get_user(env->gregs[5], (&(*grp)[SPARC_MC_G5]));

>      __get_user(env->gregs[6], (&(*grp)[SPARC_MC_G6]));

>      __get_user(env->gregs[7], (&(*grp)[SPARC_MC_G7]));

> -    __get_user(env->regwptr[UREG_I0], (&(*grp)[SPARC_MC_O0]));

> -    __get_user(env->regwptr[UREG_I1], (&(*grp)[SPARC_MC_O1]));

> -    __get_user(env->regwptr[UREG_I2], (&(*grp)[SPARC_MC_O2]));

> -    __get_user(env->regwptr[UREG_I3], (&(*grp)[SPARC_MC_O3]));

> -    __get_user(env->regwptr[UREG_I4], (&(*grp)[SPARC_MC_O4]));

> -    __get_user(env->regwptr[UREG_I5], (&(*grp)[SPARC_MC_O5]));

> -    __get_user(env->regwptr[UREG_I6], (&(*grp)[SPARC_MC_O6]));

> -    __get_user(env->regwptr[UREG_I7], (&(*grp)[SPARC_MC_O7]));

> +    __get_user(env->regwptr[WREG_O0], (&(*grp)[SPARC_MC_O0]));

> +    __get_user(env->regwptr[WREG_O1], (&(*grp)[SPARC_MC_O1]));

> +    __get_user(env->regwptr[WREG_O2], (&(*grp)[SPARC_MC_O2]));

> +    __get_user(env->regwptr[WREG_O3], (&(*grp)[SPARC_MC_O3]));

> +    __get_user(env->regwptr[WREG_O4], (&(*grp)[SPARC_MC_O4]));

> +    __get_user(env->regwptr[WREG_O5], (&(*grp)[SPARC_MC_O5]));

> +    __get_user(env->regwptr[WREG_O6], (&(*grp)[SPARC_MC_O6]));

> +    __get_user(env->regwptr[WREG_O7], (&(*grp)[SPARC_MC_O7]));

>  

>      __get_user(fp, &(ucp->tuc_mcontext.mc_fp));

>      __get_user(i7, &(ucp->tuc_mcontext.mc_i7));

>  

> -    w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];

> +    w_addr = TARGET_STACK_BIAS + env->regwptr[WREG_FP];

>      if (put_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),

>                   abi_ulong) != 0) {

>          goto do_sigsegv;

> @@ -534,7 +502,7 @@ void sparc64_get_context(CPUSPARCState *env)

>      target_sigset_t target_set;

>      sigset_t set;

>  

> -    ucp_addr = env->regwptr[UREG_I0];

> +    ucp_addr = env->regwptr[WREG_O0];

>      if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) {

>          goto do_sigsegv;

>      }

> @@ -580,16 +548,16 @@ void sparc64_get_context(CPUSPARCState *env)

>      __put_user(env->gregs[5], &((*grp)[SPARC_MC_G5]));

>      __put_user(env->gregs[6], &((*grp)[SPARC_MC_G6]));

>      __put_user(env->gregs[7], &((*grp)[SPARC_MC_G7]));

> -    __put_user(env->regwptr[UREG_I0], &((*grp)[SPARC_MC_O0]));

> -    __put_user(env->regwptr[UREG_I1], &((*grp)[SPARC_MC_O1]));

> -    __put_user(env->regwptr[UREG_I2], &((*grp)[SPARC_MC_O2]));

> -    __put_user(env->regwptr[UREG_I3], &((*grp)[SPARC_MC_O3]));

> -    __put_user(env->regwptr[UREG_I4], &((*grp)[SPARC_MC_O4]));

> -    __put_user(env->regwptr[UREG_I5], &((*grp)[SPARC_MC_O5]));

> -    __put_user(env->regwptr[UREG_I6], &((*grp)[SPARC_MC_O6]));

> -    __put_user(env->regwptr[UREG_I7], &((*grp)[SPARC_MC_O7]));

> +    __put_user(env->regwptr[WREG_O0], &((*grp)[SPARC_MC_O0]));

> +    __put_user(env->regwptr[WREG_O1], &((*grp)[SPARC_MC_O1]));

> +    __put_user(env->regwptr[WREG_O2], &((*grp)[SPARC_MC_O2]));

> +    __put_user(env->regwptr[WREG_O3], &((*grp)[SPARC_MC_O3]));

> +    __put_user(env->regwptr[WREG_O4], &((*grp)[SPARC_MC_O4]));

> +    __put_user(env->regwptr[WREG_O5], &((*grp)[SPARC_MC_O5]));

> +    __put_user(env->regwptr[WREG_O6], &((*grp)[SPARC_MC_O6]));

> +    __put_user(env->regwptr[WREG_O7], &((*grp)[SPARC_MC_O7]));

>  

> -    w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];

> +    w_addr = TARGET_STACK_BIAS + env->regwptr[WREG_FP];

>      fp = i7 = 0;

>      if (get_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),

>                   abi_ulong) != 0) {

>

Patch

diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index ead169fbaa..243f237528 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -104,20 +104,6 @@  struct target_rt_signal_frame {
     qemu_siginfo_fpu_t  fpu_state;
 };
 
-#define UREG_O0        16
-#define UREG_O6        22
-#define UREG_I0        0
-#define UREG_I1        1
-#define UREG_I2        2
-#define UREG_I3        3
-#define UREG_I4        4
-#define UREG_I5        5
-#define UREG_I6        6
-#define UREG_I7        7
-#define UREG_L0        8
-#define UREG_FP        UREG_I6
-#define UREG_SP        UREG_O6
-
 static inline abi_ulong get_sigframe(struct target_sigaction *sa, 
                                      CPUSPARCState *env,
                                      unsigned long framesize)
@@ -159,30 +145,12 @@  setup___siginfo(__siginfo_t *si, CPUSPARCState *env, abi_ulong mask)
         __put_user(env->gregs[i], &si->si_regs.u_regs[i]);
     }
     for (i=0; i < 8; i++) {
-        __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);
+        __put_user(env->regwptr[WREG_O0 + i], &si->si_regs.u_regs[i+8]);
     }
     __put_user(mask, &si->si_mask);
     return err;
 }
 
-#if 0
-static int
-setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
-                 CPUSPARCState *env, unsigned long mask)
-{
-    int err = 0;
-
-    __put_user(mask, &sc->sigc_mask);
-    __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);
-    __put_user(env->pc, &sc->sigc_pc);
-    __put_user(env->npc, &sc->sigc_npc);
-    __put_user(env->psr, &sc->sigc_psr);
-    __put_user(env->gregs[1], &sc->sigc_g1);
-    __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);
-
-    return err;
-}
-#endif
 #define NF_ALIGNEDSZ  (((sizeof(struct target_signal_frame) + 7) & (~7)))
 
 void setup_frame(int sig, struct target_sigaction *ka,
@@ -221,20 +189,20 @@  void setup_frame(int sig, struct target_sigaction *ka,
     }
 
     for (i = 0; i < 8; i++) {
-        __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]);
+        __put_user(env->regwptr[i + WREG_L0], &sf->ss.locals[i]);
     }
     for (i = 0; i < 8; i++) {
-        __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]);
+        __put_user(env->regwptr[i + WREG_I0], &sf->ss.ins[i]);
     }
     if (err)
         goto sigsegv;
 
     /* 3. signal handler back-trampoline and parameters */
-    env->regwptr[UREG_FP] = sf_addr;
-    env->regwptr[UREG_I0] = sig;
-    env->regwptr[UREG_I1] = sf_addr +
+    env->regwptr[WREG_FP] = sf_addr;
+    env->regwptr[WREG_I0] = sig;
+    env->regwptr[WREG_I1] = sf_addr +
             offsetof(struct target_signal_frame, info);
-    env->regwptr[UREG_I2] = sf_addr +
+    env->regwptr[WREG_I2] = sf_addr +
             offsetof(struct target_signal_frame, info);
 
     /* 4. signal handler */
@@ -242,11 +210,11 @@  void setup_frame(int sig, struct target_sigaction *ka,
     env->npc = (env->pc + 4);
     /* 5. return to kernel instructions */
     if (ka->ka_restorer) {
-        env->regwptr[UREG_I7] = ka->ka_restorer;
+        env->regwptr[WREG_I7] = ka->ka_restorer;
     } else {
         uint32_t val32;
 
-        env->regwptr[UREG_I7] = sf_addr +
+        env->regwptr[WREG_I7] = sf_addr +
                 offsetof(struct target_signal_frame, insns) - 2 * 4;
 
         /* mov __NR_sigreturn, %g1 */
@@ -284,7 +252,7 @@  long do_sigreturn(CPUSPARCState *env)
     sigset_t host_set;
     int i;
 
-    sf_addr = env->regwptr[UREG_FP];
+    sf_addr = env->regwptr[WREG_SP];
     trace_user_do_sigreturn(env, sf_addr);
     if (!lock_user_struct(VERIFY_READ, sf, sf_addr, 1)) {
         goto segv_and_exit;
@@ -316,7 +284,7 @@  long do_sigreturn(CPUSPARCState *env)
         __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]);
     }
     for (i=0; i < 8; i++) {
-        __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);
+        __get_user(env->regwptr[i + WREG_O0], &sf->info.si_regs.u_regs[i+8]);
     }
 
     /* FIXME: implement FPU save/restore:
@@ -433,7 +401,7 @@  void sparc64_set_context(CPUSPARCState *env)
     abi_ulong fp, i7, w_addr;
     unsigned int i;
 
-    ucp_addr = env->regwptr[UREG_I0];
+    ucp_addr = env->regwptr[WREG_O0];
     if (!lock_user_struct(VERIFY_READ, ucp, ucp_addr, 1)) {
         goto do_sigsegv;
     }
@@ -443,7 +411,7 @@  void sparc64_set_context(CPUSPARCState *env)
     if ((pc | npc) & 3) {
         goto do_sigsegv;
     }
-    if (env->regwptr[UREG_I1]) {
+    if (env->regwptr[WREG_O1]) {
         target_sigset_t target_set;
         sigset_t set;
 
@@ -474,19 +442,19 @@  void sparc64_set_context(CPUSPARCState *env)
     __get_user(env->gregs[5], (&(*grp)[SPARC_MC_G5]));
     __get_user(env->gregs[6], (&(*grp)[SPARC_MC_G6]));
     __get_user(env->gregs[7], (&(*grp)[SPARC_MC_G7]));
-    __get_user(env->regwptr[UREG_I0], (&(*grp)[SPARC_MC_O0]));
-    __get_user(env->regwptr[UREG_I1], (&(*grp)[SPARC_MC_O1]));
-    __get_user(env->regwptr[UREG_I2], (&(*grp)[SPARC_MC_O2]));
-    __get_user(env->regwptr[UREG_I3], (&(*grp)[SPARC_MC_O3]));
-    __get_user(env->regwptr[UREG_I4], (&(*grp)[SPARC_MC_O4]));
-    __get_user(env->regwptr[UREG_I5], (&(*grp)[SPARC_MC_O5]));
-    __get_user(env->regwptr[UREG_I6], (&(*grp)[SPARC_MC_O6]));
-    __get_user(env->regwptr[UREG_I7], (&(*grp)[SPARC_MC_O7]));
+    __get_user(env->regwptr[WREG_O0], (&(*grp)[SPARC_MC_O0]));
+    __get_user(env->regwptr[WREG_O1], (&(*grp)[SPARC_MC_O1]));
+    __get_user(env->regwptr[WREG_O2], (&(*grp)[SPARC_MC_O2]));
+    __get_user(env->regwptr[WREG_O3], (&(*grp)[SPARC_MC_O3]));
+    __get_user(env->regwptr[WREG_O4], (&(*grp)[SPARC_MC_O4]));
+    __get_user(env->regwptr[WREG_O5], (&(*grp)[SPARC_MC_O5]));
+    __get_user(env->regwptr[WREG_O6], (&(*grp)[SPARC_MC_O6]));
+    __get_user(env->regwptr[WREG_O7], (&(*grp)[SPARC_MC_O7]));
 
     __get_user(fp, &(ucp->tuc_mcontext.mc_fp));
     __get_user(i7, &(ucp->tuc_mcontext.mc_i7));
 
-    w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
+    w_addr = TARGET_STACK_BIAS + env->regwptr[WREG_FP];
     if (put_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
                  abi_ulong) != 0) {
         goto do_sigsegv;
@@ -534,7 +502,7 @@  void sparc64_get_context(CPUSPARCState *env)
     target_sigset_t target_set;
     sigset_t set;
 
-    ucp_addr = env->regwptr[UREG_I0];
+    ucp_addr = env->regwptr[WREG_O0];
     if (!lock_user_struct(VERIFY_WRITE, ucp, ucp_addr, 0)) {
         goto do_sigsegv;
     }
@@ -580,16 +548,16 @@  void sparc64_get_context(CPUSPARCState *env)
     __put_user(env->gregs[5], &((*grp)[SPARC_MC_G5]));
     __put_user(env->gregs[6], &((*grp)[SPARC_MC_G6]));
     __put_user(env->gregs[7], &((*grp)[SPARC_MC_G7]));
-    __put_user(env->regwptr[UREG_I0], &((*grp)[SPARC_MC_O0]));
-    __put_user(env->regwptr[UREG_I1], &((*grp)[SPARC_MC_O1]));
-    __put_user(env->regwptr[UREG_I2], &((*grp)[SPARC_MC_O2]));
-    __put_user(env->regwptr[UREG_I3], &((*grp)[SPARC_MC_O3]));
-    __put_user(env->regwptr[UREG_I4], &((*grp)[SPARC_MC_O4]));
-    __put_user(env->regwptr[UREG_I5], &((*grp)[SPARC_MC_O5]));
-    __put_user(env->regwptr[UREG_I6], &((*grp)[SPARC_MC_O6]));
-    __put_user(env->regwptr[UREG_I7], &((*grp)[SPARC_MC_O7]));
+    __put_user(env->regwptr[WREG_O0], &((*grp)[SPARC_MC_O0]));
+    __put_user(env->regwptr[WREG_O1], &((*grp)[SPARC_MC_O1]));
+    __put_user(env->regwptr[WREG_O2], &((*grp)[SPARC_MC_O2]));
+    __put_user(env->regwptr[WREG_O3], &((*grp)[SPARC_MC_O3]));
+    __put_user(env->regwptr[WREG_O4], &((*grp)[SPARC_MC_O4]));
+    __put_user(env->regwptr[WREG_O5], &((*grp)[SPARC_MC_O5]));
+    __put_user(env->regwptr[WREG_O6], &((*grp)[SPARC_MC_O6]));
+    __put_user(env->regwptr[WREG_O7], &((*grp)[SPARC_MC_O7]));
 
-    w_addr = TARGET_STACK_BIAS+env->regwptr[UREG_I6];
+    w_addr = TARGET_STACK_BIAS + env->regwptr[WREG_FP];
     fp = i7 = 0;
     if (get_user(fp, w_addr + offsetof(struct target_reg_window, ins[6]),
                  abi_ulong) != 0) {