diff mbox series

[06/17] ppc64: Clean register values in reginfo_init

Message ID 20240511115400.7587-7-richard.henderson@linaro.org
State New
Headers show
Series RISU misc updates | expand

Commit Message

Richard Henderson May 11, 2024, 11:53 a.m. UTC
Smash the stack and thread pointers to deadbeef, as is common
for the other architectures.  This allows us to drop these
special cases within reginfo_is_eq and reginfo_dump_mismatch.

Do not copy the unused special registers that are packed into gregs[].
Most of these are related to system instructions and thus are not
manipulable via the user-mode instructions targeted by RISU.  LNK and
CTR are not initialized by risugen, and since in general we cannot
test branches with risugen these can be ignored.  This leaves only
XER and CCR as the only special registers to be copied.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 risu_reginfo_ppc64.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

Comments

Peter Maydell May 21, 2024, 12:22 p.m. UTC | #1
On Sat, 11 May 2024 at 12:54, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Smash the stack and thread pointers to deadbeef, as is common
> for the other architectures.  This allows us to drop these
> special cases within reginfo_is_eq and reginfo_dump_mismatch.
>
> Do not copy the unused special registers that are packed into gregs[].
> Most of these are related to system instructions and thus are not
> manipulable via the user-mode instructions targeted by RISU.  LNK and
> CTR are not initialized by risugen, and since in general we cannot
> test branches with risugen these can be ignored.  This leaves only
> XER and CCR as the only special registers to be copied.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

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

thanks
-- PMM
diff mbox series

Patch

diff --git a/risu_reginfo_ppc64.c b/risu_reginfo_ppc64.c
index fc69805..67ea3ce 100644
--- a/risu_reginfo_ppc64.c
+++ b/risu_reginfo_ppc64.c
@@ -44,16 +44,16 @@  int reginfo_size(struct reginfo *ri)
 /* reginfo_init: initialize with a ucontext */
 void reginfo_init(struct reginfo *ri, ucontext_t *uc, void *siaddr)
 {
-    int i;
-
     memset(ri, 0, sizeof(*ri));
 
     ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.regs->nip);
     ri->nip = uc->uc_mcontext.regs->nip - image_start_address;
 
-    for (i = 0; i < NGREG; i++) {
-        ri->gregs[i] = uc->uc_mcontext.gp_regs[i];
-    }
+    memcpy(ri->gregs, uc->uc_mcontext.gp_regs, 32 * sizeof(ri->gregs[0]));
+    ri->gregs[1] = 0xdeadbeefdeadbeef;   /* sp */
+    ri->gregs[13] = 0xdeadbeefdeadbeef;  /* tp */
+    ri->gregs[XER] = uc->uc_mcontext.gp_regs[XER];
+    ri->gregs[CCR] = uc->uc_mcontext.gp_regs[CCR];
 
     memcpy(ri->fpregs, uc->uc_mcontext.fp_regs, 32 * sizeof(double));
     ri->fpscr = uc->uc_mcontext.fp_regs[32];
@@ -69,10 +69,6 @@  int reginfo_is_eq(struct reginfo *m, struct reginfo *a)
 {
     int i;
     for (i = 0; i < 32; i++) {
-        if (i == 1 || i == 13) {
-            continue;
-        }
-
         if (m->gregs[i] != a->gregs[i]) {
             return 0;
         }
@@ -150,9 +146,6 @@  void reginfo_dump_mismatch(struct reginfo *m, struct reginfo *a, FILE *f)
     int i;
 
     for (i = 0; i < 32; i++) {
-        if (i == 1 || i == 13) {
-            continue;
-        }
         if (m->gregs[i] != a->gregs[i]) {
             fprintf(f, "%*s%d: %016lx vs %016lx\n",
                     6 - (1 < 10 ? 1 : 2), "r", i,