db3405
From: Greg Kurz <gkurz@linux.vnet.ibm.com>
db3405
Date: Fri, 15 Jan 2016 16:00:31 +0100
db3405
Subject: [PATCH] target-ppc: gdbstub: introduce avr_need_swap()
db3405
db3405
This helper will be used to support Altivec registers in little-endian guests.
db3405
This patch does not change functionnality.
db3405
db3405
Note: I had to put the helper some lines away from the gdb_*_avr_reg()
db3405
routines to get a more readable patch.
db3405
db3405
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
db3405
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
db3405
(cherry picked from commit 87601e2d5c22d9c1fef0e09978d377f46336c1db)
db3405
---
db3405
 target-ppc/translate_init.c | 37 +++++++++++++++++++++++--------------
db3405
 1 file changed, 23 insertions(+), 14 deletions(-)
db3405
db3405
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
db3405
index 51fa03c..c1d2db6 100644
db3405
--- a/target-ppc/translate_init.c
db3405
+++ b/target-ppc/translate_init.c
db3405
@@ -8754,6 +8754,15 @@ static void dump_ppc_insns (CPUPPCState *env)
db3405
 }
db3405
 #endif
db3405
 
db3405
+static bool avr_need_swap(CPUPPCState *env)
db3405
+{
db3405
+#ifdef HOST_WORDS_BIGENDIAN
db3405
+    return false;
db3405
+#else
db3405
+    return true;
db3405
+#endif
db3405
+}
db3405
+
db3405
 static int gdb_get_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
db3405
 {
db3405
     if (n < 32) {
db3405
@@ -8787,13 +8796,13 @@ static int gdb_set_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
db3405
 static int gdb_get_avr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
db3405
 {
db3405
     if (n < 32) {
db3405
-#ifdef HOST_WORDS_BIGENDIAN
db3405
-        stq_p(mem_buf, env->avr[n].u64[0]);
db3405
-        stq_p(mem_buf+8, env->avr[n].u64[1]);
db3405
-#else
db3405
-        stq_p(mem_buf, env->avr[n].u64[1]);
db3405
-        stq_p(mem_buf+8, env->avr[n].u64[0]);
db3405
-#endif
db3405
+        if (!avr_need_swap(env)) {
db3405
+            stq_p(mem_buf, env->avr[n].u64[0]);
db3405
+            stq_p(mem_buf+8, env->avr[n].u64[1]);
db3405
+        } else {
db3405
+            stq_p(mem_buf, env->avr[n].u64[1]);
db3405
+            stq_p(mem_buf+8, env->avr[n].u64[0]);
db3405
+        }
db3405
         return 16;
db3405
     }
db3405
     if (n == 32) {
db3405
@@ -8810,13 +8819,13 @@ static int gdb_get_avr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
db3405
 static int gdb_set_avr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
db3405
 {
db3405
     if (n < 32) {
db3405
-#ifdef HOST_WORDS_BIGENDIAN
db3405
-        env->avr[n].u64[0] = ldq_p(mem_buf);
db3405
-        env->avr[n].u64[1] = ldq_p(mem_buf+8);
db3405
-#else
db3405
-        env->avr[n].u64[1] = ldq_p(mem_buf);
db3405
-        env->avr[n].u64[0] = ldq_p(mem_buf+8);
db3405
-#endif
db3405
+        if (!avr_need_swap(env)) {
db3405
+            env->avr[n].u64[0] = ldq_p(mem_buf);
db3405
+            env->avr[n].u64[1] = ldq_p(mem_buf+8);
db3405
+        } else {
db3405
+            env->avr[n].u64[1] = ldq_p(mem_buf);
db3405
+            env->avr[n].u64[0] = ldq_p(mem_buf+8);
db3405
+        }
db3405
         return 16;
db3405
     }
db3405
     if (n == 32) {