Skip to contentSkip to conversation

PPC/GDB: handle read and write of fpscr

PATCH Superseded Fabien Chouteau 4 participants 10 messages Mar 19, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPC/GDB: handle read and write of fpscr

Although the support of this register may be uncomplete, there are no reason to prevent the debugger from reading or writing it.

---
 gdbstub.c                   |    3 ++-
 target-ppc/translate_init.c |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
gdbstub.c +2 -1
index e414ad9..d23d9c5 100644
@@ -781,7 +781,8 @@ static int cpu_gdb_write_register(CPUPPCState *env, uint8_t *mem_buf, int n)
             /* fpscr */
             if (gdb_has_xml)
                 return 0;
-            return 4;
+            env->fpscr = ldtul_p(mem_buf);
+            return sizeof(target_ulong);
         }
     }
     return 0;
target-ppc/translate_init.c +1 -1
index 09ad4ba..a5d2cc3 100644
@@ -7693,7 +7693,7 @@ static int gdb_set_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
         return 8;
     }
     if (n == 32) {
-        /* FPSCR not implemented  */
+        env->fpscr = ldl_p(mem_buf);
         return 4;
     }
     return 0;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 14 lines · Fabien Chouteau

Although the support of this register may be uncomplete, there are no reason to prevent the debugger from reading or writing it.

---

gdbstub.c                   |    3 ++-
target-ppc/translate_init.c |    2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
gdbstub.c +0 -0
index e414ad9..d23d9c5 100644

gdbstub.c static int cpu_gdb_write_register(CPUPPCState *env, uint8_t *mem_buf, int n) · line 784

Quoted 5 lines
gdbstub.c +1 -1
@@ -781,7 +781,8 @@ static int cpu_gdb_write_register(CPUPPCState *env, uint8_t *mem_buf, int n)
            /* fpscr */
            if (gdb_has_xml)
                return 0;
-            return 4;
+            env->fpscr = ldtul_p(mem_buf);

Check out helper_store_fpscr() in target-ppc/fpu_helper.c. Storing fpscr has a bunch of side effects that won't happen when you just set the env variable. I'd prefer not to enable users to set fpscr when we can't guarantee that the updated values are actually used.

Can't you just call the helper function here?

Alex

Quoted 20 lines
gdbstub.c +1 -0
+            return sizeof(target_ulong);
        }
    }
    return 0;
target-ppc/translate_init.c +1 -1
index 09ad4ba..a5d2cc3 100644
@@ -7693,7 +7693,7 @@ static int gdb_set_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
        return 8;
    }
    if (n == 32) {
-        /* FPSCR not implemented  */
+        env->fpscr = ldl_p(mem_buf);
        return 4;
    }
    return 0;
Signature · 1 line
1.7.9.5
#2 lore raw
Quoted 3 lines · Alexander Graf

Check out helper_store_fpscr() in target-ppc/fpu_helper.c. Storing fpscr has a bunch of side effects that won't happen when you just set the env variable.

Speaking of which, am I missing something, or does the code in machine.c do nothing to ensure that we call set_float_rounding_mode to set the fpu/ emulation code up with the right rounding mode when loading CPU state on incoming migration?

thanks
-- PMM

#3 lore raw
Quoted 9 lines · Peter Maydell
Quoted 3 lines · Alexander Graf

Check out helper_store_fpscr() in target-ppc/fpu_helper.c. Storing fpscr has a bunch of side effects that won't happen when you just set the env variable.

Speaking of which, am I missing something, or does the code in machine.c do nothing to ensure that we call set_float_rounding_mode to set the fpu/ emulation code up with the right rounding mode when loading CPU state on incoming migration?

I very much doubt anyone tests migration with TCG :)

Alex

#4 lore raw
In reply to Alexander Graf
Quoted 25 lines · Alexander Graf
Quoted 14 lines · Fabien Chouteau

Although the support of this register may be uncomplete, there are no reason to prevent the debugger from reading or writing it.

---

gdbstub.c                   |    3 ++-
target-ppc/translate_init.c |    2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
gdbstub.c +0 -0
index e414ad9..d23d9c5 100644

gdbstub.c static int cpu_gdb_write_register(CPUPPCState *env, uint8_t *mem_buf, int n) · line 784

Quoted 5 lines
gdbstub.c +1 -1
@@ -781,7 +781,8 @@ static int cpu_gdb_write_register(CPUPPCState *env, uint8_t *mem_buf, int n)
            /* fpscr */
            if (gdb_has_xml)
                return 0;
-            return 4;
+            env->fpscr = ldtul_p(mem_buf);

Check out helper_store_fpscr() in target-ppc/fpu_helper.c. Storing fpscr has a bunch of side effects that won't happen when you just set the env variable. I'd prefer not to enable users to set fpscr when we can't guarantee that the updated values are actually used.

Quoted 2 lines

Can't you just call the helper function here?

I can if I include helper.h, unfortunately this file is named helpers.h (note the 's') for m68k so I wont be able to include it for all platforms.

Either I put an include in the middle of the source (in a #if defined (TARGET_PPC) section), I don't know if this is allowed in Qemu:

@@ -691,6 +695,8 @@ static int cpu_gdb_write_register(CPUX86State *env, uint8_t *mem_buf, int n)

#elif defined (TARGET_PPC)

+#include "helper.h"
+
/* Old gdb always expects FP registers. Newer (xml-aware) gdb only
expects whatever the target description contains. Due to a historical mishap the FP registers appear in between core integer

or I just add a new PPC section after the others includes:

@@ -42,6 +42,10 @@
#include "sysemu/kvm.h"
#include "qemu/bitops.h"

+#if defined (TARGET_PPC)
+#include "helper.h"
+#endif
+
#ifndef TARGET_CPU_MEMORY_RW_DEBUG
static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
uint8_t *buf, int len, int is_write)

Signature · 1 line
Fabien Chouteau
#5 lore raw
Quoted 3 lines · Fabien Chouteau

I can if I include helper.h, unfortunately this file is named helpers.h (note the 's') for m68k so I wont be able to include it for all platforms.

The way we do this on ARM for cpsr_read is:
* cpsr_read() is defined in target-arm/cpu.h
* gdbstub.c calls cpsr_read()
* HELPER(cpsr_read) is mostly a wrapper calling cpsr_read()
* helper.h declares HELPER(cpsr_read) as usual

I'm not sure you want to include helper.h.

(m68k should have helpers.h renamed to bring it into line with everything else, though.)

-- PMM

#6 lore raw
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Fabien Chouteau

I can if I include helper.h, unfortunately this file is named helpers.h (note the 's') for m68k so I wont be able to include it for all platforms.

Quoted 8 lines

The way we do this on ARM for cpsr_read is:
* cpsr_read() is defined in target-arm/cpu.h
* gdbstub.c calls cpsr_read()
* HELPER(cpsr_read) is mostly a wrapper calling cpsr_read()
* helper.h declares HELPER(cpsr_read) as usual

I'm not sure you want to include helper.h.

Cleaner solution indeed. I'll do the opposite, store_fpscr calls helper_store_fpscr.

Thanks,

Signature · 1 line
Fabien Chouteau
#7 lore raw
Quoted 7 lines · Fabien Chouteau
Quoted 6 lines · Peter Maydell

The way we do this on ARM for cpsr_read is:
* cpsr_read() is defined in target-arm/cpu.h
* gdbstub.c calls cpsr_read()
* HELPER(cpsr_read) is mostly a wrapper calling cpsr_read()
* helper.h declares HELPER(cpsr_read) as usual

Quoted 5 lines
Quoted 2 lines

I'm not sure you want to include helper.h.

Cleaner solution indeed. I'll do the opposite, store_fpscr calls helper_store_fpscr.

I think that way round is kind of backwards personally (HELPER functions are for TCG generated code to call) but it doesn't make much difference really.

-- PMM

#8 lore raw
In reply to Fabien Chouteau
Quoted 1 line · Fabien Chouteau

Cleaner solution indeed. I'll do the opposite, store_fpscr calls helper_store_fpscr.

The declarations won't be in the right places for that to work right.

Canonically, cpu_store_fpscr should be declared in cpu.h, have the leading "cpu_" prefix, and then helper_store_fpscr is declared (via macro) in helper.h and its definition should call the cpu.h function.

r~

#9 lore raw
Quoted 8 lines · Richard Henderson
Quoted 1 line · Fabien Chouteau

Cleaner solution indeed. I'll do the opposite, store_fpscr calls helper_store_fpscr.

The declarations won't be in the right places for that to work right.

Canonically, cpu_store_fpscr should be declared in cpu.h, have the leading "cpu_" prefix, and then helper_store_fpscr is declared (via macro) in helper.h and its definition should call the cpu.h function.

Heh :) Fabien did a clever workaround that one in his v2. Mind to check whether it's ok for you?

Alex