Skip to contentSkip to conversation

linux-user: ppc: mark as long long aligned

PATCH In review Alexander Graf 5 participants 7 messages Oct 1, 2012 – Oct 12, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 linux-user: ppc: mark as long long aligned

The PPC32 ABI dictates that long long (64bit) parameters are pass in odd/even register pairs. Because unlike ARM and MIPS we start at an odd register number, we can reuse the same aligning code that ARM and MIPS use.

---
 linux-user/syscall.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
linux-user/syscall.c +5 -1
index 1a38169..8cd56f2 100644
@@ -587,12 +587,16 @@ extern int setfsgid(int);
 extern int setgroups(int, gid_t *);
 
 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
-#ifdef TARGET_ARM 
+#ifdef TARGET_ARM
 static inline int regpairs_aligned(void *cpu_env) {
     return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
 }
 #elif defined(TARGET_MIPS)
 static inline int regpairs_aligned(void *cpu_env) { return 1; }
+#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
+/* PPC32 expects 64bit parameters to be passed on odd/even pairs of registers
+   which translates to the same as ARM/MIPS, because we start with r3 as arg1 */
+static inline int regpairs_aligned(void *cpu_env) { return 1; }
 #else
 static inline int regpairs_aligned(void *cpu_env) { return 0; }
 #endif
Signature · 1 line
1.6.0.2
#1 lore raw

PATCH 2/2 linux-user: register align p{read, write}64

pread64 and pwrite64 pass 64bit parameters which for some architectures need to be aligned to special argument pairs, creating a gap argument.

Handle this special case the same way we handle it in other places of the code.

---
 linux-user/syscall.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
linux-user/syscall.c +8 -0
index 8cd56f2..7992b1b 100644
@@ -7423,12 +7423,20 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef TARGET_NR_pread64
     case TARGET_NR_pread64:
+        if (regpairs_aligned(cpu_env)) {
+            arg4 = arg5;
+            arg5 = arg6;
+        }
         if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
             goto efault;
         ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_NR_pwrite64:
+        if (regpairs_aligned(cpu_env)) {
+            arg4 = arg5;
+            arg5 = arg6;
+        }
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
             goto efault;
         ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
Signature · 1 line
1.6.0.2
Tested-by on v1 2/2
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] linux-user: register align p{read, write}64

Quoted 37 lines · Alexander Graf

pread64 and pwrite64 pass 64bit parameters which for some architectures need to be aligned to special argument pairs, creating a gap argument.

Handle this special case the same way we handle it in other places of the code.

---
 linux-user/syscall.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
linux-user/syscall.c +8 -1
index 8cd56f2..7992b1b 100644
@@ -7423,12 +7423,20 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef TARGET_NR_pread64
     case TARGET_NR_pread64:
+        if (regpairs_aligned(cpu_env)) {
+            arg4 = arg5;
+            arg5 = arg6;
+        }
         if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
             goto efault;
         ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5)));
         unlock_user(p, arg2, ret);
         break;
     case TARGET_NR_pwrite64:
+        if (regpairs_aligned(cpu_env)) {
+            arg4 = arg5;
+            arg5 = arg6;
+        }
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
             goto efault;
         ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5)));
--
Quoted 3 lines

1.6.0.2

Reviewed-by on v1 2/2
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] linux-user: register align p{read, write}64

In reply to Alexander Graf
Quoted 7 lines · Alexander Graf

pread64 and pwrite64 pass 64bit parameters which for some architectures need to be aligned to special argument pairs, creating a gap argument.

Handle this special case the same way we handle it in other places of the code.

#4 lore raw
In reply to Alexander Graf

Am 30.09.2012 03:32, schrieb Alexander Graf:

Quoted 14 lines

The PPC32 ABI dictates that long long (64bit) parameters are pass in odd/even register pairs. Because unlike ARM and MIPS we start at an odd register number, we can reuse the same aligning code that ARM and MIPS use.

---
 linux-user/syscall.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
linux-user/syscall.c +0 -0
index 1a38169..8cd56f2 100644

linux-user/syscall.c extern int setfsgid(int); · line 590

Quoted 5 lines
linux-user/syscall.c +1 -1
@@ -587,12 +587,16 @@ extern int setfsgid(int);
 extern int setgroups(int, gid_t *);
 
 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
-#ifdef TARGET_ARM 
+#ifdef TARGET_ARM

For anyone wondering, this is dropping a whitespace at end of line. ;)

linux-user/syscall.c extern int setfsgid(int); · line 602

Quoted 12 lines
linux-user/syscall.c +4 -0
 static inline int regpairs_aligned(void *cpu_env) {
     return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
 }
 #elif defined(TARGET_MIPS)
 static inline int regpairs_aligned(void *cpu_env) { return 1; }
+#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
+/* PPC32 expects 64bit parameters to be passed on odd/even pairs of registers
+   which translates to the same as ARM/MIPS, because we start with r3 as arg1 */
+static inline int regpairs_aligned(void *cpu_env) { return 1; }
 #else
 static inline int regpairs_aligned(void *cpu_env) { return 0; }
 #endif

It is obvious that this function has been copied unmodified from mips, but shouldn't new code use bool and true, assuming that there is no magic performed on the return value? :)

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#5 lore raw
Quoted 17 lines · Andreas Färber

Am 30.09.2012 03:32, schrieb Alexander Graf:

Quoted 16 lines

The PPC32 ABI dictates that long long (64bit) parameters are pass in odd/even register pairs. Because unlike ARM and MIPS we start at an odd register number, we can reuse the same aligning code that ARM and MIPS use.

---
linux-user/syscall.c | 6 +++++-

1 files changed, 5 insertions(+), 1 deletions(-)
linux-user/syscall.c +0 -0
index 1a38169..8cd56f2 100644
@@ -587,12 +587,16 @@ extern int setfsgid(int);
 extern int setgroups(int, gid_t *);
 
Quoted 5 lines

linux-user/syscall.c extern int setfsgid(int); · line 590

Quoted 3 lines
linux-user/syscall.c +1 -1
 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
-#ifdef TARGET_ARM 
+#ifdef TARGET_ARM

For anyone wondering, this is dropping a whitespace at end of line. ;)

Yeah, my vi scripts marked it as red, which always makes me nervous :).

Quoted 17 lines

linux-user/syscall.c extern int setfsgid(int); · line 602

Quoted 13 lines
linux-user/syscall.c +4 -0
 static inline int regpairs_aligned(void *cpu_env) {
    return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
 }
 #elif defined(TARGET_MIPS)
 static inline int regpairs_aligned(void *cpu_env) { return 1; }
+#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
+/* PPC32 expects 64bit parameters to be passed on odd/even pairs of registers
+   which translates to the same as ARM/MIPS, because we start with r3 as arg1 */
+static inline int regpairs_aligned(void *cpu_env) { return 1; }
 #else
 static inline int regpairs_aligned(void *cpu_env) { return 0; }
 #endif

It is obvious that this function has been copied unmodified from mips, but shouldn't new code use bool and true, assuming that there is no magic performed on the return value? :)

The asm result should be the same, since they're all getting inlined, no? And it wouldn't tremendously increase readability either. So for now, I'd say either

a) send a separate cleanup patch

or

b) leave it as is :)

Alex

#6 lore raw
In reply to Alexander Graf
Quoted 17 lines · Alexander Graf

The PPC32 ABI dictates that long long (64bit) parameters are pass in odd/even register pairs. Because unlike ARM and MIPS we start at an odd register number, we can reuse the same aligning code that ARM and MIPS use.

---
 linux-user/syscall.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
linux-user/syscall.c +0 -0
index 1a38169..8cd56f2 100644
@@ -587,12 +587,16 @@ extern int setfsgid(int);
 extern int setgroups(int, gid_t *);
 
 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */

linux-user/syscall.c extern int setfsgid(int); · line 598

Quoted 10 lines
linux-user/syscall.c +4 -1
-#ifdef TARGET_ARM 
+#ifdef TARGET_ARM
 static inline int regpairs_aligned(void *cpu_env) {
     return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
 }
 #elif defined(TARGET_MIPS)
 static inline int regpairs_aligned(void *cpu_env) { return 1; }
+#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
+/* PPC32 expects 64bit parameters to be passed on odd/even pairs of registers
+   which translates to the same as ARM/MIPS, because we start with r3 as arg1 */

This is inaccurate, PPC32 doesn't expect anything, SysV ABI for PPC32, which linux uses, does. This is linux-user so SysV ABI is a given but still i'd reword it.

Quoted 5 lines
linux-user/syscall.c +1 -0
+static inline int regpairs_aligned(void *cpu_env) { return 1; }
 #else
 static inline int regpairs_aligned(void *cpu_env) { return 0; }
 #endif
Signature · 1 line
mailto:[email protected]