Skip to contentSkip to conversation

Adding new user mode target ppc64el-linux-user

PATCH Superseded Doug Kwan 6 participants 33 messages May 8, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Doug Kwan

author
#0 lore raw

cover Adding new user mode target ppc64el-linux-user

Hi

This is a series of 3 patches to add a new target for little-endian PPC64 linux user mode. This first patch is for loading PPC64 ELFv2 binaries. The second patch is the biggest and it contains changes to set up the LE environment and handle byteswapping appropriately. The third patch contains the necessary configuration changes for the new target.

This is tested briefly by running big-endian and little-endian Linux binaries in user mode. I also booted the QEMU ppc linux test image though it is 32-bit only.

-Doug

Doug Kwan (3):
linux-user: Handle ELFv2 PPC64 binaries in user mode.
PPC: Allow little-endian user mode.
configure: Add new target ppc64el-linux-user

 configure                              |  6 +++++
 default-configs/ppc64el-linux-user.mak |  1 +
 include/elf.h                          |  5 ++++
 linux-user/elfload.c                   | 17 +++++++++++--
 target-ppc/mem_helper.c                | 16 ++++++++++--
 target-ppc/translate.c                 | 45 ++++++++++++++++++++++------------
 target-ppc/translate_init.c            |  9 +++++++
 7 files changed, 80 insertions(+), 19 deletions(-)
 create mode 100644 default-configs/ppc64el-linux-user.mak
Signature · 1 line
1.9.1.423.g4596e3a
author
#1 lore raw

PATCH 1/3 linux-user: Handle ELFv2 PPC64 binaries in user mode.

Look at ELF header to determin ABI version on PPC64. This is required for executing the first instruction correctly.

---
 include/elf.h        |  5 +++++
 linux-user/elfload.c | 17 +++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)
include/elf.h +5 -0
index 1599ab2..b39f5db 100644
@@ -561,6 +561,11 @@ typedef struct {
 #define SHF_ALPHA_GPREL		0x10000000
 
 
+/* PowerPC specific definitions.  */
+
+/* Processor specific flags for the ELF header e_flags field.  */
+#define EF_PPC64_ABI		3
+
 /* PowerPC relocations defined by the ABIs */
 #define R_PPC_NONE		0
 #define R_PPC_ADDR32		1	/* 32bit absolute address */
linux-user/elfload.c +15 -2
index 995f999..b96d64a 100644
@@ -777,12 +777,18 @@ static uint32_t get_elf_hwcap(void)
         NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
     } while (0)
 
+static inline uint32_t get_ppc64_abi(struct image_info *infop);
+
 static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
 {
     _regs->gpr[1] = infop->start_stack;
 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-    _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
-    infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    if (get_ppc64_abi(infop) < 2) {
+      _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
+      infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    } else {
+      _regs->gpr[12] = infop->entry;  /* r12 set to global entry address */
+    }
 #endif
     _regs->nip = infop->entry;
 }
@@ -1152,6 +1158,13 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #include "elf.h"
 
+#ifdef TARGET_PPC
+static inline uint32_t get_ppc64_abi(struct image_info *infop)
+{
+  return infop->elf_flags & EF_PPC64_ABI;
+}
+#endif
+
 struct exec
 {
     unsigned int a_info;   /* Use macros N_MAGIC, etc for access */
Signature · 1 line
1.9.1.423.g4596e3a
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] linux-user: Handle ELFv2 PPC64 binaries in user mode.

Quoted 14 lines · Doug Kwan

Look at ELF header to determin ABI version on PPC64. This is required for executing the first instruction correctly.

---
  include/elf.h        |  5 +++++
  linux-user/elfload.c | 17 +++++++++++++++--
  2 files changed, 20 insertions(+), 2 deletions(-)
include/elf.h +0 -0
index 1599ab2..b39f5db 100644

include/elf.h typedef struct { · line 567

Quoted 7 lines
include/elf.h +4 -0
@@ -561,6 +561,11 @@ typedef struct {
  #define SHF_ALPHA_GPREL		0x10000000
 
 
+/* PowerPC specific definitions.  */
+
+/* Processor specific flags for the ELF header e_flags field.  */
+#define EF_PPC64_ABI		3

Please write bitmasks in hex.

Quoted 15 lines
include/elf.h +1 -0
+
  /* PowerPC relocations defined by the ABIs */
  #define R_PPC_NONE		0
  #define R_PPC_ADDR32		1	/* 32bit absolute address */
linux-user/elfload.c +2 -0
index 995f999..b96d64a 100644
@@ -777,12 +777,18 @@ static uint32_t get_elf_hwcap(void)
          NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
      } while (0)
 
+static inline uint32_t get_ppc64_abi(struct image_info *infop);
+
  static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)

linux-user/elfload.c static uint32_t get_elf_hwcap(void) · line 790

Quoted 10 lines
linux-user/elfload.c +5 -2
  {
      _regs->gpr[1] = infop->start_stack;
  #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-    _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
-    infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    if (get_ppc64_abi(infop) < 2) {
+      _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
+      infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    } else {
+      _regs->gpr[12] = infop->entry;  /* r12 set to global entry address */

Uli, is this correct? Also, why don't w need to adjust for the load_bias with ELFv2 anymore?

Quoted 5 lines
linux-user/elfload.c +1 -0
+    }
  #endif
      _regs->nip = infop->entry;
  }

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, struct image_info *i · line 1166

Quoted 9 lines
linux-user/elfload.c +6 -0
@@ -1152,6 +1158,13 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
  #include "elf.h"
 
+#ifdef TARGET_PPC
+static inline uint32_t get_ppc64_abi(struct image_info *infop)
+{
+  return infop->elf_flags & EF_PPC64_ABI;
+}
+#endif

I'm not sure this is more readable than doing it inline ... :).

Alex

#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] linux-user: Handle ELFv2 PPC64 binaries in user mode.

Hi

On Thu, May 8, 2014 at 1:36 AM, Alexander Graf <[email protected]> wrote:
3

Quoted 3 lines

Please write bitmasks in hex.

Will fix.

Quoted 22 lines

+

Quoted 21 lines
  /* PowerPC relocations defined by the ABIs */
  #define R_PPC_NONE            0
  #define R_PPC_ADDR32          1       /* 32bit absolute address */
linux-user/elfload.c +3 -2
index 995f999..b96d64a 100644
@@ -777,12 +777,18 @@ static uint32_t get_elf_hwcap(void)
          NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
      } while (0)
  +static inline uint32_t get_ppc64_abi(struct image_info *infop);
+
  static inline void init_thread(struct target_pt_regs *_regs, struct
 image_info *infop)
  {
      _regs->gpr[1] = infop->start_stack;
  #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-    _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
-    infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    if (get_ppc64_abi(infop) < 2) {
+      _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
Quoted 8 lines

linux-user/elfload.c static uint32_t get_elf_hwcap(void) · line 792

Quoted 5 lines
linux-user/elfload.c +3 -0
+      infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    } else {
+      _regs->gpr[12] = infop->entry;  /* r12 set to global entry address
 */
 

Uli, is this correct? Also, why don't w need to adjust for the load_bias with ELFv2 anymore?

No. This is a bug. It was not caught by testing because load_bias is 0 I guess.

Quoted 18 lines

+ }

linux-user/elfload.c static inline void init_thread(struct target_pt_regs *regs, struct image_info *i · line 1166

Quoted 13 lines
linux-user/elfload.c +0 -0
  #endif
      _regs->nip = infop->entry;
  }
@@ -1152,6 +1158,13 @@ static inline void init_thread(struct

target_pt_regs *regs, struct image_info *i

    #include "elf.h"

+#ifdef TARGET_PPC

linux-user/elfload.c +5 -0
+static inline uint32_t get_ppc64_abi(struct image_info *infop)
+{
+  return infop->elf_flags & EF_PPC64_ABI;
+}
+#endif

I'm not sure this is more readable than doing it inline ... :).

This is done so because the elf header is not yet included before the callee. To eliminate this I need to move the include before ppc's init_thread. Is that okay?

Thanks for the comments.

-Doug

#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] linux-user: Handle ELFv2 PPC64 binaries in user mode.

Quoted 64 lines · Doug Kwan (關振德)

Hi

On Thu, May 8, 2014 at 1:36 AM, Alexander Graf <[email protected] <mailto:[email protected]>> wrote: 3

Please write bitmasks in hex.

Will fix.

        +
          /* PowerPC relocations defined by the ABIs */
          #define R_PPC_NONE            0
          #define R_PPC_ADDR32          1       /* 32bit absolute
        address */
        diff --git a/linux-user/elfload.c b/linux-user/elfload.c
        index 995f999..b96d64a 100644
        --- a/linux-user/elfload.c
        +++ b/linux-user/elfload.c
        @@ -777,12 +777,18 @@ static uint32_t get_elf_hwcap(void)
                  NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);    \
              } while (0)
          +static inline uint32_t get_ppc64_abi(struct image_info *infop);
        +
          static inline void init_thread(struct target_pt_regs *_regs,
        struct image_info *infop)
          {
              _regs->gpr[1] = infop->start_stack;
          #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
        -    _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
        -    infop->entry = ldq_raw(infop->entry) + infop->load_bias;
        +    if (get_ppc64_abi(infop) < 2) {
        +      _regs->gpr[2] = ldq_raw(infop->entry + 8) +
        infop->load_bias;
        +      infop->entry = ldq_raw(infop->entry) + infop->load_bias;
        +    } else {
        +      _regs->gpr[12] = infop->entry;  /* r12 set to global
        entry address */


    Uli, is this correct? Also, why don't w need to adjust for the
    load_bias with ELFv2 anymore?

No. This is a bug. It was not caught by testing because load_bias is 0 I guess.

        +    }
          #endif
              _regs->nip = infop->entry;
          }
        @@ -1152,6 +1158,13 @@ static inline void init_thread(struct
        target_pt_regs *regs, struct image_info *i
            #include "elf.h"
          +#ifdef TARGET_PPC
        +static inline uint32_t get_ppc64_abi(struct image_info *infop)
        +{
        +  return infop->elf_flags & EF_PPC64_ABI;
        +}
        +#endif


    I'm not sure this is more readable than doing it inline ... :).
Quoted 1 line

This is done so because the elf header is not yet included before the callee. To eliminate this I need to move the include before ppc's init_thread. Is that okay?

Ah, I see. I don't have strong feelings either way. Riku, what would you prefer?

Alex

#5 lore raw

Re: [Qemu-devel] [PATCH 1/3] linux-user: Handle ELFv2 PPC64 binaries in user mode.

In reply to Doug Kwan (關振德)

Doug Kwan (關振德) <[email protected]> wrote on 08.05.2014 10:43:14:

Quoted 7 lines · Alexander Graf
Quoted 7 lines

-    _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
-    infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    if (get_ppc64_abi(infop) < 2) {
+      _regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_bias;
+      infop->entry = ldq_raw(infop->entry) + infop->load_bias;
+    } else {
+      _regs->gpr[12] = infop->entry;  /* r12 set to global entry

address */

Quoted 6 lines
Quoted 3 lines

Uli, is this correct? Also, why don't w need to adjust for the load_bias with ELFv2 anymore?

No.  This is a bug.  It was not caught by testing because load_bias is 0 I guess.

Actually, it looks correct to me. The value of infop->entry itself was presumably already adjusted for the load bias by common code.

However, on ELFv1, that value points to the descriptor, but the values we *load* from that descriptor *also* need to be adjusted by the load bias, since the image has not yet been relocated at this stage.

With ELFv2, the (already adjusted) infop->entry value points directly to the code, so no further adjustment is required.

Bye,
Ulrich

author
#6 lore raw

PATCH 2/3 PPC: Allow little-endian user mode.

In reply to Doug Kwan

This all running PPC64 little-endian in user mode if target is configured that way. In PPC64 LE user mode we set MSR.LE during initialization. Byteswapping logic is reversed also when QEMU is running in that mode.

---
 target-ppc/mem_helper.c     | 16 ++++++++++++++--
 target-ppc/translate.c      | 45 ++++++++++++++++++++++++++++++---------------
 target-ppc/translate_init.c |  9 +++++++++
 3 files changed, 53 insertions(+), 17 deletions(-)
target-ppc/mem_helper.c +14 -2
index f35ed03..7bacdab 100644
@@ -202,6 +202,14 @@ target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg,
 #define LO_IDX 0
 #endif
 
+static inline bool element_needs_byteswap(CPUPPCState *env) {
+#if defined(TARGET_WORDS_BIGENDIAN)
+  return msr_le;
+#else
+  return !msr_le;
+#endif
+}
+
 #define LVE(name, access, swap, element)                        \
     void helper_##name(CPUPPCState *env, ppc_avr_t *r,          \
                        target_ulong addr)                       \
@@ -210,9 +218,11 @@ target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg,
         int adjust = HI_IDX*(n_elems - 1);                      \
         int sh = sizeof(r->element[0]) >> 1;                    \
         int index = (addr & 0xf) >> sh;                         \
-                                                                \
         if (msr_le) {                                           \
             index = n_elems - index - 1;                        \
+        }                                                       \
+                                                                \
+        if (element_needs_byteswap(env)) {                      \
             r->element[LO_IDX ? index : (adjust - index)] =     \
                 swap(access(env, addr));                        \
         } else {                                                \
@@ -235,9 +245,11 @@ LVE(lvewx, cpu_ldl_data, bswap32, u32)
         int adjust = HI_IDX * (n_elems - 1);                            \
         int sh = sizeof(r->element[0]) >> 1;                            \
         int index = (addr & 0xf) >> sh;                                 \
-                                                                        \
         if (msr_le) {                                                   \
             index = n_elems - index - 1;                                \
+        }                                                               \
+                                                                        \
+        if (element_needs_byteswap(env)) {                              \
             access(env, addr, swap(r->element[LO_IDX ? index :          \
                                               (adjust - index)]));      \
         } else {                                                        \
target-ppc/translate.c +30 -15

145 lines not on this page · raw message

target-ppc/translate_init.c +9 -0
index 4d94015..84381ae 100644
@@ -8418,6 +8418,9 @@ static void ppc_cpu_reset(CPUState *s)
     msr |= (target_ulong)1 << MSR_VR; /* Allow altivec usage */
     msr |= (target_ulong)1 << MSR_SPE; /* Allow SPE usage */
     msr |= (target_ulong)1 << MSR_PR;
+#if !defined(TARGET_WORDS_BIGENDIAN)
+    msr |= (target_ulong)1 << MSR_LE; /* Little-endian user mode */
+#endif
 #endif
 
 #if defined(TARGET_PPC64)
@@ -8461,6 +8464,12 @@ static void ppc_cpu_reset(CPUState *s)
 
     /* Flush all TLBs */
     tlb_flush(s, 1);
+
+#if defined(CONFIG_USER_ONLY) && !defined(TARGET_WORDS_BIGENDIAN)
+    if (!msr_le) {
+        cpu_abort(CPU(cpu), "Cannot set QEMU to little-endian user mode\n");
+    }
+#endif
 }
 
 static void ppc_cpu_initfn(Object *obj)
Signature · 1 line
1.9.1.423.g4596e3a
#7 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

Quoted 5 lines · Doug Kwan

This all running PPC64 little-endian in user mode if target is configured that way. In PPC64 LE user mode we set MSR.LE during initialization. Byteswapping logic is reversed also when QEMU is running in that mode.

I can't say I'm a huge fan of this patch. It allows for really tricky subtile mistakes to happen. Can't we leave the target mode configured on big endian?

Alex

#8 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

If we leave the target mode as big-endian, we need to teach the elfloader to handle binary of reversed endianness. I have looked into that possibility as well but find the current approach easier.

Quoted 17 lines · Alexander Graf
Quoted 6 lines · Doug Kwan

This all running PPC64 little-endian in user mode if target is configured that way. In PPC64 LE user mode we set MSR.LE during initialization. Byteswapping logic is reversed also when QEMU is running in that mode.

I can't say I'm a huge fan of this patch. It allows for really tricky subtile mistakes to happen. Can't we leave the target mode configured on big endian?

Alex

#9 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

Quoted 1 line · Doug Kwan (關振德)

If we leave the target mode as big-endian, we need to teach the elfloader to handle binary of reversed endianness. I have looked into that possibility as well but find the current approach easier.

Please don't top post.

Ok, so if we really want to change the code to be able to handle !TARGET_WORDS_BIGENDIAN the whole notion of s->le_mode becomes flawed. Instead, it should get renamed into needs_swab or needs_byteswap or something along those lines. Then we can set it accordingly based on msr_le and target configuration.

For the mem_helper.c changes, could you please explain why you have to treat msr_le and needs_byteswap separately?

Thanks,

Alex

#10 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

There are a few places where we do 128-bit loads/store. We need to swap the high/low halves and also do byteswap for each half. Byteswap of each half is handled differently depending on TARGET_WORDS_BIGENDIAN but the swapping of high/low halves is always controlled by msr.le. Would our intention be clearer if defined another function swap_high_low_64_bits() instead of msr.le?

It's 2am in California. I need to go off-line. I will continue tomorrow. Thanks

-Doug

Quoted 24 lines · Alexander Graf
Quoted 4 lines · Doug Kwan (關振德)

If we leave the target mode as big-endian, we need to teach the elfloader to handle binary of reversed endianness. I have looked into that possibility as well but find the current approach easier.

Please don't top post.

Ok, so if we really want to change the code to be able to handle !TARGET_WORDS_BIGENDIAN the whole notion of s->le_mode becomes flawed. Instead, it should get renamed into needs_swab or needs_byteswap or something along those lines. Then we can set it accordingly based on msr_le and target configuration.

For the mem_helper.c changes, could you please explain why you have to treat msr_le and needs_byteswap separately?

Thanks,

Alex

#11 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

Quoted 1 line · Doug Kwan (關振德)

There are a few places where we do 128-bit loads/store. We need to swap the high/low halves and also do byteswap for each half. Byteswap of each half is handled differently depending on TARGET_WORDS_BIGENDIAN but the swapping of high/low halves is always controlled by msr.le. Would our intention be clearer if defined another function swap_high_low_64_bits() instead of msr.le?

This is my last warning about top posting. One more top post and I will ignore any future email from you.

The explanation makes a lot of sense. This probably just deserves a quick comment in the code so that nobody stumbles over this when he looks at it :).

Alex

#12 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

Quoted 13 lines · Alexander Graf
Quoted 7 lines · Doug Kwan (關振德)

There are a few places where we do 128-bit loads/store. We need to swap the high/low halves and also do byteswap for each half. Byteswap of each half is handled differently depending on TARGET_WORDS_BIGENDIAN but the swapping of high/low halves is always controlled by msr.le. Would our intention be clearer if defined another function swap_high_low_64_bits() instead of msr.le?

This is my last warning about top posting. One more top post and I will ignore any future email from you.

Quoted 8 lines

The explanation makes a lot of sense. This probably just deserves a quick comment in the code so that nobody stumbles over this when he looks at it :).

Alex

I'm terribly sorry about the mail format. I did not realize what "top-posting" was until I do a quick search just now. It does not help that Gmail does top-posting by default. I just noticed that I may have missed the multi-word load store. I will write a small test case tomorrow morning to check that they are okay.

Thanks

-Doug

#13 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

In reply to Alexander Graf
Quoted 6 lines · Alexander Graf
Quoted 5 lines · Doug Kwan

This all running PPC64 little-endian in user mode if target is configured that way. In PPC64 LE user mode we set MSR.LE during initialization. Byteswapping logic is reversed also when QEMU is running in that mode.

Quoted 6 lines
Quoted 1 line

I can't say I'm a huge fan of this patch. It allows for really tricky subtile mistakes to happen. Can't we leave the target mode configured on big endian?

Unfortunately not if you care about linux-user mode:
linux-user mode uses the target-endian setting to figure out if it needs to do swapping of data in all the syscall interfaces.

If you're going to overhaul how PPC deals with endian dependent loads/stores, I suspect you'll end up with a cleaner result if you convert to the new "specify endian setting as part of the memory operation" TCG ops:
So for instance rather than having:

    tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
    if (unlikely(ctx->le_mode)) {
        tcg_gen_bswap16_tl(arg1, arg1);
    }

it would be better to do

    TCGMemOp op = MO_UW | (ctx->le_mode ? MO_LE : MO_BE);
    tcg_gen_qemu_ld_i32(arg1, arg2, ctx->mem_idx, op);

This will work regardless of the TARGET_WORD_BIGENDIAN setting, since we directly ask TCG to do an LE or BE access, rather than doing a target-endian access and then swapping. (It's also more efficient if you're in little-endian mode on a little endian host since it won't swap at all rather than swapping twice.)

thanks
-- PMM

#14 lore raw

Re: [Qemu-devel] [PATCH 2/3] PPC: Allow little-endian user mode.

Quoted 31 lines · Peter Maydell
Quoted 10 lines · Alexander Graf
Quoted 5 lines · Doug Kwan

This all running PPC64 little-endian in user mode if target is configured that way. In PPC64 LE user mode we set MSR.LE during initialization. Byteswapping logic is reversed also when QEMU is running in that mode.

I can't say I'm a huge fan of this patch. It allows for really tricky subtile mistakes to happen. Can't we leave the target mode configured on big endian?

Unfortunately not if you care about linux-user mode:
linux-user mode uses the target-endian setting to figure out if it needs to do swapping of data in all the syscall interfaces.

If you're going to overhaul how PPC deals with endian dependent loads/stores, I suspect you'll end up with a cleaner result if you convert to the new "specify endian setting as part of the memory operation" TCG ops:
So for instance rather than having:

     tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
     if (unlikely(ctx->le_mode)) {
         tcg_gen_bswap16_tl(arg1, arg1);
     }

it would be better to do

     TCGMemOp op = MO_UW | (ctx->le_mode ? MO_LE : MO_BE);
     tcg_gen_qemu_ld_i32(arg1, arg2, ctx->mem_idx, op);
Quoted 6 lines

This will work regardless of the TARGET_WORD_BIGENDIAN setting, since we directly ask TCG to do an LE or BE access, rather than doing a target-endian access and then swapping. (It's also more efficient if you're in little-endian mode on a little endian host since it won't swap at all rather than swapping twice.)

Good point. We could store the "default TCGMemOp mask" in ctx and then only add the width per operation.

Alex

author
#15 lore raw

PATCH 3/3 configure: Add new target ppc64el-linux-user

In reply to Doug Kwan

Add a new user mode target for little-endian PPC64.

---
 configure                              | 6 ++++++
 default-configs/ppc64el-linux-user.mak | 1 +
 2 files changed, 7 insertions(+)
 create mode 100644 default-configs/ppc64el-linux-user.mak
configure +6 -0
index ac2fa15..ce44044 100755
@@ -4917,6 +4917,12 @@ case "$target_name" in
     echo "TARGET_ABI32=y" >> $config_target_mak
     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
   ;;
+  ppc64el)
+    TARGET_ARCH=ppc64
+    TARGET_BASE_ARCH=ppc
+    TARGET_ABI_DIR=ppc
+    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
+  ;;
   sh4|sh4eb)
     TARGET_ARCH=sh4
     bflt="yes"
default-configs/ppc64el-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..6948225
@@ -0,0 +1 @@
+# Default configuration for ppc64el-linux-user
Signature · 1 line
1.9.1.423.g4596e3a
#16 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 14 lines · Doug Kwan

Add a new user mode target for little-endian PPC64.

---
  configure                              | 6 ++++++
  default-configs/ppc64el-linux-user.mak | 1 +
  2 files changed, 7 insertions(+)

create mode 100644 default-configs/ppc64el-linux-user.mak

configure +0 -0
index ac2fa15..ce44044 100755

configure case "$target_name" in · line 4924

Quoted 8 lines
configure +5 -0
@@ -4917,6 +4917,12 @@ case "$target_name" in
      echo "TARGET_ABI32=y" >> $config_target_mak
      gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
    ;;
+  ppc64el)
+    TARGET_ARCH=ppc64
+    TARGET_BASE_ARCH=ppc
+    TARGET_ABI_DIR=ppc
+    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"

I can't see the part where this switches the ABI definition to be little endian? I'm sure that magic is hidden somewhere, mind to guide me to it?

Alex

#17 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

All the magic happens in the patch 2/3.

Quoted 35 lines · Alexander Graf
Quoted 23 lines · Doug Kwan

Add a new user mode target for little-endian PPC64.

---
  configure                              | 6 ++++++
  default-configs/ppc64el-linux-user.mak | 1 +
  2 files changed, 7 insertions(+)

create mode 100644 default-configs/ppc64el-linux-user.mak

configure +0 -0
index ac2fa15..ce44044 100755
@@ -4917,6 +4917,12 @@ case "$target_name" in
      echo "TARGET_ABI32=y" >> $config_target_mak
      gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml

power-spe.xml"

    ;;
configure +5 -0
+  ppc64el)
+    TARGET_ARCH=ppc64
+    TARGET_BASE_ARCH=ppc
+    TARGET_ABI_DIR=ppc
+    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml
Quoted 2 lines

power-spe.xml"

I can't see the part where this switches the ABI definition to be little endian? I'm sure that magic is hidden somewhere, mind to guide me to it?

Alex

#18 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 1 line · Doug Kwan (關振德)

All the magic happens in the patch 2/3.

Please don't top post.

I still fail to see where you tell the build system that ppc64le-linux-user should not have TARGET_WORDS_BIGENDIAN set.

Alex

#19 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Sorry about missing the question. TARGET_WORDS_BIGENDIAN is not set because of this (around line 4805 in configure):

case "$target_name" in
armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)

target_bigendian=yes

The configure script recognizes a list of big-endian target. ppc64le is not one of those.

Quoted 14 lines · Alexander Graf
Quoted 2 lines · Doug Kwan (關振德)

All the magic happens in the patch 2/3.

Please don't top post.

I still fail to see where you tell the build system that ppc64le-linux-user should not have TARGET_WORDS_BIGENDIAN set.

Alex

#20 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

In reply to Doug Kwan

Am 08.05.2014 10:26, schrieb Doug Kwan:

Quoted 14 lines

Add a new user mode target for little-endian PPC64.

---
 configure                              | 6 ++++++
 default-configs/ppc64el-linux-user.mak | 1 +
 2 files changed, 7 insertions(+)
 create mode 100644 default-configs/ppc64el-linux-user.mak
configure +0 -0
index ac2fa15..ce44044 100755

configure case "$target_name" in · line 4920

Quoted 4 lines
configure +1 -0
@@ -4917,6 +4917,12 @@ case "$target_name" in
     echo "TARGET_ABI32=y" >> $config_target_mak
     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
   ;;
+  ppc64el)

In SUSE's build system and everywhere I read people talking about it, including your 2/3, it's called ppc64le. Why did you choose ppc64el?

Regards,
Andreas

Quoted 16 lines
configure +5 -0
+    TARGET_ARCH=ppc64
+    TARGET_BASE_ARCH=ppc
+    TARGET_ABI_DIR=ppc
+    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
+  ;;
   sh4|sh4eb)
     TARGET_ARCH=sh4
     bflt="yes"
default-configs/ppc64el-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..6948225
@@ -0,0 +1 @@
+# Default configuration for ppc64el-linux-user
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
#21 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 10 lines · Andreas Färber

Am 08.05.2014 10:26, schrieb Doug Kwan:

Quoted 9 lines

Add a new user mode target for little-endian PPC64.

---
 configure                              | 6 ++++++
 default-configs/ppc64el-linux-user.mak | 1 +
 2 files changed, 7 insertions(+)
 create mode 100644 default-configs/ppc64el-linux-user.mak
Quoted 12 lines

configure case "$target_name" in · line 4920

Quoted 9 lines
configure +1 -0
index ac2fa15..ce44044 100755
@@ -4917,6 +4917,12 @@ case "$target_name" in
     echo "TARGET_ABI32=y" >> $config_target_mak
     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
   ;;
+  ppc64el)

In SUSE's build system and everywhere I read people talking about it, including your 2/3, it's called ppc64le. Why did you choose ppc64el?

In general we should follow what the kernel does, ie the output of 'uname -m' (which hopefully coincides with the gcc triplet name). What is that for this case?

thanks
-- PMM

#22 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 22 lines · Peter Maydell
Quoted 10 lines · Andreas Färber

Am 08.05.2014 10:26, schrieb Doug Kwan:

Quoted 9 lines

Add a new user mode target for little-endian PPC64.

---
  configure                              | 6 ++++++
  default-configs/ppc64el-linux-user.mak | 1 +
  2 files changed, 7 insertions(+)

create mode 100644 default-configs/ppc64el-linux-user.mak

Quoted 11 lines

configure case "$target_name" in · line 4920

Quoted 9 lines
configure +1 -0
index ac2fa15..ce44044 100755
@@ -4917,6 +4917,12 @@ case "$target_name" in
      echo "TARGET_ABI32=y" >> $config_target_mak
      gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
    ;;
+  ppc64el)

In SUSE's build system and everywhere I read people talking about it, including your 2/3, it's called ppc64le. Why did you choose ppc64el?

Quoted 3 lines

In general we should follow what the kernel does, ie the output of 'uname -m' (which hopefully coincides with the gcc triplet name). What is that for this case?

$ uname -a
Linux shiraz-1 3.15.0-rc4-2-default+ #22 SMP Wed May 7 22:57:22 CEST 2014 ppc64le ppc64le ppc64le GNU/Linux

Thanks a lot for the catch. Just because Debian has it all backwards we don't have to as well ;).

Alex

#23 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

In reply to Peter Maydell
Quoted 25 lines · Peter Maydell
Quoted 10 lines · Andreas Färber

Am 08.05.2014 10:26, schrieb Doug Kwan:

Quoted 9 lines

Add a new user mode target for little-endian PPC64.

---
 configure                              | 6 ++++++
 default-configs/ppc64el-linux-user.mak | 1 +
 2 files changed, 7 insertions(+)
 create mode 100644 default-configs/ppc64el-linux-user.mak
Quoted 7 lines

configure case "$target_name" in · line 4918

Quoted 7 lines
configure +0 -0
index ac2fa15..ce44044 100755
@@ -4917,6 +4917,12 @@ case "$target_name" in
     echo "TARGET_ABI32=y" >> $config_target_mak
     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml

power-spe.xml"

Quoted 5 lines

configure case "$target_name" in · line 4920

Quoted 2 lines
configure +1 -0
   ;;
+  ppc64el)

In SUSE's build system and everywhere I read people talking about it, including your 2/3, it's called ppc64le. Why did you choose ppc64el?

Quoted 7 lines

In general we should follow what the kernel does, ie the output of 'uname -m' (which hopefully coincides with the gcc triplet name). What is that for this case?

thanks
-- PMM

I am aware of the 'le' vs 'el' issue. However, I saw that all bi-endian targets have 'el' or 'eb' suffixes (e.g. mipsel-linux-user). So I thought qemu follows the Debian convention. I will fix that.

Thanks.

#24 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

In reply to Doug Kwan
Quoted 33 lines · Doug Kwan

Add a new user mode target for little-endian PPC64.

---
 configure                              | 6 ++++++
 default-configs/ppc64el-linux-user.mak | 1 +
 2 files changed, 7 insertions(+)
 create mode 100644 default-configs/ppc64el-linux-user.mak
configure +6 -0
index ac2fa15..ce44044 100755
@@ -4917,6 +4917,12 @@ case "$target_name" in
     echo "TARGET_ABI32=y" >> $config_target_mak
     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
   ;;
+  ppc64el)
+    TARGET_ARCH=ppc64
+    TARGET_BASE_ARCH=ppc
+    TARGET_ABI_DIR=ppc
+    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
+  ;;
   sh4|sh4eb)
     TARGET_ARCH=sh4
     bflt="yes"
default-configs/ppc64el-linux-user.mak new file +0 -0
new file mode 100644
index 0000000..6948225

default-configs/ppc64el-linux-user.mak line 1

Quoted 1 line
default-configs/ppc64el-linux-user.mak new file +1 -0
@@ -0,0 +1 @@
+# Default configuration for ppc64el-linux-user

We have TCG targets for PowerPC that are bi-endian. It would be much nicer to have to split user mode by endianness. If the user loads a BE ELF, then run in BE mode .... a LE ELF, then run in LE mode.

I know there is much hand waving in that statement ... but maybe we can do better? ("we" includes "me" in that statement ... since I offered to Doug to help out with this).

#25 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 45 lines · Tom Musta
Quoted 14 lines · Doug Kwan

Add a new user mode target for little-endian PPC64.

---
 configure                              | 6 ++++++
 default-configs/ppc64el-linux-user.mak | 1 +
 2 files changed, 7 insertions(+)
 create mode 100644 default-configs/ppc64el-linux-user.mak
configure +0 -0
index ac2fa15..ce44044 100755

configure case "$target_name" in · line 4918

Quoted 2 lines
configure +0 -0
@@ -4917,6 +4917,12 @@ case "$target_name" in
     echo "TARGET_ABI32=y" >> $config_target_mak
     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml

power-spe.xml"

configure case "$target_name" in

Quoted 6 lines
configure +5 -0
   ;;
+  ppc64el)
+    TARGET_ARCH=ppc64
+    TARGET_BASE_ARCH=ppc
+    TARGET_ABI_DIR=ppc
+    gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml

power-spe.xml"

Review

Quoted 5 lines
configure +1 -0
+  ;;
   sh4|sh4eb)
     TARGET_ARCH=sh4
     bflt="yes"
(quoted diff) +0 -0

b/default-configs/ppc64el-linux-user.mak

default-configs/ppc64el-linux-user.mak line 1

Quoted 7 lines

new file mode 100644
index 0000000..6948225

default-configs/ppc64el-linux-user.mak new file +1 -0
@@ -0,0 +1 @@
+# Default configuration for ppc64el-linux-user

We have TCG targets for PowerPC that are bi-endian. It would be much nicer to have to split
user mode by endianness. If the user loads a BE ELF, then run in BE mode .... a LE ELF,
then run in LE mode.

Quoted 7 lines

I know there is much hand waving in that statement ... but maybe we can do better? ("we" includes
"me" in that statement ... since I offered to Doug to help out with this).

To do this, we need to fix the elf load. I believe it currently only loads

binary the endianness of the same endianness of the configure target. It will be a more general change that will benefit other bi-endian architecture. Would you help me out in that?

-Doug

#26 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 7 lines · Doug Kwan (關振德)
Quoted 6 lines · Tom Musta

We have TCG targets for PowerPC that are bi-endian. It would be much nicer to have to split
user mode by endianness. If the user loads a BE ELF, then run in BE mode .... a LE ELF,
then run in LE mode.

Quoted 5 lines
Quoted 3 lines

I know there is much hand waving in that statement ... but maybe we can do better? ("we" includes
"me" in that statement ... since I offered to Doug to help out with this).

To do this, we need to fix the elf load.

That is far from the only thing that would need changing. I really don't recommend trying to do something different from the norm here.

Isn't LE PPC a different ABI anyway? (ELFv2).

thanks
-- PMM

#27 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 18 lines · Peter Maydell
Quoted 2 lines · Doug Kwan (關振德)
Quoted 1 line · Tom Musta

We have TCG targets for PowerPC that are bi-endian. It would be much

nicer

Quoted 2 lines
Quoted 2 lines

to have to split
user mode by endianness. If the user loads a BE ELF, then run in BE

mode

Quoted 4 lines
Quoted 4 lines

.... a LE ELF,
then run in LE mode.

I know there is much hand waving in that statement ... but maybe we can

do

Quoted 2 lines
Quoted 2 lines

better? ("we" includes
"me" in that statement ... since I offered to Doug to help out with

this).

Quoted 1 line

To do this, we need to fix the elf load.

Quoted 9 lines

That is far from the only thing that would need changing. I really don't recommend trying to do something different from the norm here.

Isn't LE PPC a different ABI anyway? (ELFv2).

thanks
-- PMM

What else needs to be fixed? I suspect that the user-mode linux kernel interface may also need some work but it worked well enough in practice for us to build glibc and run gcc testsuite. Yes ELFv2 is a different ABI but it is not complete different from the old one. A notable change is the removal of function descriptor. That affect how the user mode start the first instruction and that is addressed in this set of patches. It would also affect signal handling but user-mode signals do not work at all on PPC64 anyway and the parts that would be affected looks unimplemented.

#28 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 1 line · Doug Kwan (關振德)

What else needs to be fixed?

git grep ENDIAN linux-user is probably a good start on a list.

Quoted 3 lines

I suspect that the user-mode linux kernel interface may also need some work but it worked well enough in practice for us to build glibc and run gcc testsuite.

The gcc testsuite is really not very much of a workout. I recommend getting a chroot environment working and then trying the LTP testsuite:
http://wiki.qemu.org/Testing/LTP

Quoted 6 lines

Yes ELFv2 is a different ABI but it is not complete different from the old one. A notable change is the
removal of function descriptor. That affect how the user mode start the first instruction and that is addressed in this set of patches. It would also affect signal handling but user-mode signals do not work at all on PPC64 anyway and the parts that would be affected looks unimplemented.

Yes, but we need to actually implement signal handling at some point, so we don't want to end up having to totally redo the base support of ppc64le at that point.

The general approach linux-user takes is "one kernel ABI to one QEMU binary". Maybe we could change that, but would there be any benefit to it? I can't really see one.

thanks
-- PMM

#29 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 25 lines · Peter Maydell
Quoted 1 line · Doug Kwan (關振德)

What else needs to be fixed?

git grep ENDIAN linux-user is probably a good start on a list.

Quoted 3 lines

I suspect that the user-mode linux kernel interface may also need some work but it worked well enough in practice for us to build glibc and run gcc testsuite.

The gcc testsuite is really not very much of a workout. I recommend getting a chroot environment working and then trying the LTP testsuite:
http://wiki.qemu.org/Testing/LTP

Quoted 6 lines

Yes ELFv2 is a different ABI but it is not complete different from the old one. A notable change is the
removal of function descriptor. That affect how the user mode start the first instruction and that is addressed in this set of patches. It would also affect signal handling but user-mode signals do not work at all on PPC64 anyway and the parts that would be affected looks unimplemented.

Yes, but we need to actually implement signal handling at some point, so we don't want to end up having to totally redo the base support of ppc64le at that point.

Quoted 8 lines

The general approach linux-user takes is "one kernel ABI to one QEMU binary". Maybe we could change that, but would there be any benefit to it? I can't really see one.

thanks
-- PMM

May I ask what you would suggest to support ppc64le then? For signal handling, we can check the ELF header to see if we use a function descriptor or an entry for a signal handler when this is implemented for ppc64 in the future. I don't understand the "redoing the base support" bit.

#30 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 11 lines · Doug Kwan (關振德)
Quoted 4 lines · Peter Maydell

The general approach linux-user takes is "one kernel ABI to one QEMU binary". Maybe we could change that, but would there be any benefit to it? I can't really see one.

May I ask what you would suggest to support ppc64le then? For signal handling, we can check the ELF header to see if we use a function descriptor or an entry for a signal handler when this is implemented for ppc64 in the future. I don't understand the "redoing the base support" bit.

Do it the same way we support everything else that can deal with two endianness settings -- handle the other TARGET_ENDIAN case in the translator. This is pretty straightforward with the new TCGMemOp TCG ops.

thanks
-- PMM

#31 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

In reply to Peter Maydell
Quoted 14 lines · Peter Maydell
Quoted 7 lines · Doug Kwan (關振德)
Quoted 6 lines · Tom Musta

We have TCG targets for PowerPC that are bi-endian. It would be much nicer to have to split
user mode by endianness. If the user loads a BE ELF, then run in BE mode .... a LE ELF,
then run in LE mode.

Quoted 5 lines
Quoted 3 lines

I know there is much hand waving in that statement ... but maybe we can do better? ("we" includes
"me" in that statement ... since I offered to Doug to help out with this).

To do this, we need to fix the elf load.

Quoted 9 lines

That is far from the only thing that would need changing. I really don't recommend trying to do something different from the norm here.

Isn't LE PPC a different ABI anyway? (ELFv2).

thanks
-- PMM

It is true that the new LE distros are basing on ELFv2. But ELFv2 ABI is not limited to LE. I chatted with Uli on this very topic and he confirmed that endianness is specified in the e_ident field of the header.

I believe we have thoroughly demonstrated that the (softmmu) TCG code works correctly in both settings of MSR[LE], without making compile time decisions. It doesn't seem like we are that far off ... maybe I don't see the problem yet.

#32 lore raw

Re: [Qemu-devel] [PATCH 3/3] configure: Add new target ppc64el-linux-user

Quoted 4 lines · Tom Musta

I believe we have thoroughly demonstrated that the (softmmu) TCG code works correctly in both settings of MSR[LE], without making compile time decisions. It doesn't seem like we are that far off ... maybe I don't see the problem yet.

Yes, softmmu can and should all work in one TARGET_ENDIAN setting (which corresponds to "endianness of CPU bus", more or less). But linux-user isn't softmmu.

thanks
-- PMM