qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Doug Kwan <dougkwan@google.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: riku.voipio@iki.fi, Doug Kwan <dougkwan@google.com>, agraf@suse.de
Subject: [Qemu-devel] [PATCH v2 1/3] linux-user: Support little-endian PPC64 in user mode.
Date: Sat, 10 May 2014 02:16:38 -0700	[thread overview]
Message-ID: <1399713400-8619-2-git-send-email-dougkwan@google.com> (raw)
In-Reply-To: <1399713400-8619-1-git-send-email-dougkwan@google.com>

Look at ELF header to determin ABI version on PPC64.  This is required
for executing the first instruction correctly.  Also print correct machine
name in uname() system call.

Signed-off-by: Doug Kwan <dougkwan@google.com>
---
 include/elf.h        |  5 +++++
 linux-user/elfload.c | 17 +++++++++++++++--
 linux-user/uname.c   |  6 ++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/include/elf.h b/include/elf.h
index 1599ab2..f9f1675 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -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		0x3
+
 /* 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 */
+    }
 #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 */
diff --git a/linux-user/uname.c b/linux-user/uname.c
index f5d4c66..cb1f9a3 100644
--- a/linux-user/uname.c
+++ b/linux-user/uname.c
@@ -65,6 +65,12 @@ const char *cpu_to_uname_machine(void *cpu_env)
         return "i586";
     }
     return "i686";
+#elif defined(TARGET_PPC64)
+#ifdef TARGET_WORDS_BIGENDIAN
+    return UNAME_MACHINE;
+#else
+    return UNAME_MACHINE "le";
+#endif
 #else
     /* default is #define-d in each arch/ subdir */
     return UNAME_MACHINE;
-- 
1.9.1.423.g4596e3a

  reply	other threads:[~2014-05-10  9:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-10  9:16 [Qemu-devel] [PATCH v2 0/3] Adding new user mode target ppc64le-linux-user Doug Kwan
2014-05-10  9:16 ` Doug Kwan [this message]
2014-05-10  9:55   ` [Qemu-devel] [PATCH v2 1/3] linux-user: Support little-endian PPC64 in user mode Peter Maydell
2014-05-10 10:02   ` Peter Maydell
2014-05-10  9:16 ` [Qemu-devel] [PATCH v2 2/3] PPC: Allow little-endian " Doug Kwan
2014-05-10 10:13   ` Peter Maydell
2014-05-13  7:05   ` Alexander Graf
2014-05-13  7:30     ` Doug Kwan (關振德)
2014-05-13  7:32       ` Alexander Graf
2014-05-10  9:16 ` [Qemu-devel] [PATCH v2 3/3] Add a new user mode target for little-endian PPC64 Doug Kwan
2014-05-10 10:00   ` Peter Maydell
2014-05-12 13:05   ` Tom Musta
2014-05-13  6:45     ` Doug Kwan (關振德)
2014-05-13  7:06 ` [Qemu-devel] [PATCH v2 0/3] Adding new user mode target ppc64le-linux-user Alexander Graf
2014-05-13 12:08   ` [Qemu-devel] [Qemu-ppc] " Tom Musta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399713400-8619-2-git-send-email-dougkwan@google.com \
    --to=dougkwan@google.com \
    --cc=agraf@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).