From: Eric Farman <far...@linux.vnet.ibm.com>

Provide a routine to access the correct floating point register,
to simplify future expansion.

Suggested-by: David Hildenbrand <d...@linux.vnet.ibm.com>
Signed-off-by: Eric Farman <far...@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <d...@linux.vnet.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.h...@de.ibm.com>
---
 linux-user/signal.c      | 4 ++--
 target-s390x/arch_dump.c | 3 ++-
 target-s390x/cpu.h       | 5 +++++
 target-s390x/gdbstub.c   | 4 ++--
 target-s390x/helper.c    | 2 +-
 target-s390x/kvm.c       | 9 ++++++---
 target-s390x/translate.c | 2 +-
 7 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 5bb399e..1166f2f 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -4098,7 +4098,7 @@ static void save_sigregs(CPUS390XState *env, 
target_sigregs *sregs)
      */
     //save_fp_regs(&current->thread.fp_regs); FIXME
     for (i = 0; i < 16; i++) {
-        __put_user(env->fregs[i].ll, &sregs->fpregs.fprs[i]);
+        __put_user(get_freg(env, i)->ll, &sregs->fpregs.fprs[i]);
     }
 }
 
@@ -4239,7 +4239,7 @@ restore_sigregs(CPUS390XState *env, target_sigregs *sc)
         __get_user(env->aregs[i], &sc->regs.acrs[i]);
     }
     for (i = 0; i < 16; i++) {
-        __get_user(env->fregs[i].ll, &sc->fpregs.fprs[i]);
+        __get_user(get_freg(env, i)->ll, &sc->fpregs.fprs[i]);
     }
 
     return err;
diff --git a/target-s390x/arch_dump.c b/target-s390x/arch_dump.c
index a1554f5..36e8407 100644
--- a/target-s390x/arch_dump.c
+++ b/target-s390x/arch_dump.c
@@ -78,11 +78,12 @@ static void s390x_write_elf64_prstatus(Note *note, S390CPU 
*cpu)
 static void s390x_write_elf64_fpregset(Note *note, S390CPU *cpu)
 {
     int i;
+    CPUS390XState *cs = &cpu->env;
 
     note->hdr.n_type = cpu_to_be32(NT_FPREGSET);
     note->contents.fpregset.fpc = cpu_to_be32(cpu->env.fpc);
     for (i = 0; i <= 15; i++) {
-        note->contents.fpregset.fprs[i] = cpu_to_be64(cpu->env.fregs[i].ll);
+        note->contents.fpregset.fprs[i] = cpu_to_be64(get_freg(cs, i)->ll);
     }
 }
 
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index c557211..e968769 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -162,6 +162,11 @@ typedef struct CPUS390XState {
 
 } CPUS390XState;
 
+static inline CPU_DoubleU *get_freg(CPUS390XState *cs, int nr)
+{
+    return &cs->fregs[nr];
+}
+
 #include "cpu-qom.h"
 #include <sysemu/kvm.h>
 
diff --git a/target-s390x/gdbstub.c b/target-s390x/gdbstub.c
index 8945f02..40bdfe7 100644
--- a/target-s390x/gdbstub.c
+++ b/target-s390x/gdbstub.c
@@ -111,7 +111,7 @@ static int cpu_read_fp_reg(CPUS390XState *env, uint8_t 
*mem_buf, int n)
     case S390_FPC_REGNUM:
         return gdb_get_reg32(mem_buf, env->fpc);
     case S390_F0_REGNUM ... S390_F15_REGNUM:
-        return gdb_get_reg64(mem_buf, env->fregs[n - S390_F0_REGNUM].ll);
+        return gdb_get_reg64(mem_buf, get_freg(env, n - S390_F0_REGNUM)->ll);
     default:
         return 0;
     }
@@ -124,7 +124,7 @@ static int cpu_write_fp_reg(CPUS390XState *env, uint8_t 
*mem_buf, int n)
         env->fpc = ldl_p(mem_buf);
         return 4;
     case S390_F0_REGNUM ... S390_F15_REGNUM:
-        env->fregs[n - S390_F0_REGNUM].ll = ldtul_p(mem_buf);
+        get_freg(env, n - S390_F0_REGNUM)->ll = ldtul_p(mem_buf);
         return 8;
     default:
         return 0;
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index 041c9c7..6b47766 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -445,7 +445,7 @@ static void do_mchk_interrupt(CPUS390XState *env)
     lowcore = cpu_map_lowcore(env);
 
     for (i = 0; i < 16; i++) {
-        lowcore->floating_pt_save_area[i] = cpu_to_be64(env->fregs[i].ll);
+        lowcore->floating_pt_save_area[i] = cpu_to_be64(get_freg(env, i)->ll);
         lowcore->gpregs_save_area[i] = cpu_to_be64(env->regs[i]);
         lowcore->access_regs_save_area[i] = cpu_to_be32(env->aregs[i]);
         lowcore->cregs_save_area[i] = cpu_to_be64(env->cregs[i]);
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index ea18015..1a40a94 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -339,7 +339,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 
     /* Floating point */
     for (i = 0; i < 16; i++) {
-        fpu.fprs[i] = env->fregs[i].ll;
+        fpu.fprs[i] = get_freg(env, i)->ll;
     }
     fpu.fpc = env->fpc;
 
@@ -474,7 +474,7 @@ int kvm_arch_get_registers(CPUState *cs)
         return r;
     }
     for (i = 0; i < 16; i++) {
-        env->fregs[i].ll = fpu.fprs[i];
+        get_freg(env, i)->ll = fpu.fprs[i];
     }
     env->fpc = fpu.fpc;
 
@@ -1363,6 +1363,7 @@ static int kvm_s390_store_status(S390CPU *cpu, hwaddr 
addr, bool store_arch)
     static const uint8_t ar_id = 1;
     uint64_t ckc = cpu->env.ckc >> 8;
     void *mem;
+    int i;
     hwaddr len = SAVE_AREA_SIZE;
 
     mem = cpu_physical_memory_map(addr, &len, 1);
@@ -1377,7 +1378,9 @@ static int kvm_s390_store_status(S390CPU *cpu, hwaddr 
addr, bool store_arch)
     if (store_arch) {
         cpu_physical_memory_write(offsetof(LowCore, ar_access_id), &ar_id, 1);
     }
-    memcpy(mem, &cpu->env.fregs, 128);
+    for (i = 0; i < 16; ++i) {
+        *((uint64 *)mem + i) = get_freg(&cpu->env, i)->ll;
+    }
     memcpy(mem + 128, &cpu->env.regs, 128);
     memcpy(mem + 256, &cpu->env.psw, 16);
     memcpy(mem + 280, &cpu->env.psa, 4);
diff --git a/target-s390x/translate.c b/target-s390x/translate.c
index 80e3a54..96b43b3 100644
--- a/target-s390x/translate.c
+++ b/target-s390x/translate.c
@@ -113,7 +113,7 @@ void s390_cpu_dump_state(CPUState *cs, FILE *f, 
fprintf_function cpu_fprintf,
     }
 
     for (i = 0; i < 16; i++) {
-        cpu_fprintf(f, "F%02d=%016" PRIx64, i, env->fregs[i].ll);
+        cpu_fprintf(f, "F%02d=%016" PRIx64, i, get_freg(env, i)->ll);
         if ((i % 4) == 3) {
             cpu_fprintf(f, "\n");
         } else {
-- 
2.4.2


Reply via email to