From patchwork Sat May 10 09:16:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?RG91ZyBLd2FuICjpl5zmjK/lvrcp?= X-Patchwork-Id: 347610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 678451400A4 for ; Sat, 10 May 2014 19:17:25 +1000 (EST) Received: from localhost ([::1]:56600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wj3PH-0003Bg-6M for incoming@patchwork.ozlabs.org; Sat, 10 May 2014 05:17:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wj3Oj-00028B-V4 for qemu-devel@nongnu.org; Sat, 10 May 2014 05:16:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wj3Oj-0005bg-1B for qemu-devel@nongnu.org; Sat, 10 May 2014 05:16:49 -0400 Received: from mail-qc0-x249.google.com ([2607:f8b0:400d:c01::249]:56088) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wj3Oi-0005bI-RL for qemu-devel@nongnu.org; Sat, 10 May 2014 05:16:48 -0400 Received: by mail-qc0-f201.google.com with SMTP id l6so744699qcy.2 for ; Sat, 10 May 2014 02:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y6dvcJmJak7lybcO2IsV2L3XO5lhedTMzXO32E/iDOc=; b=TPtodMW8JUvkZHKzKcHzfUgv5QwZoQtBEvdFL0yDsp65LsSAPGkRh0FiLBYr6u/NtU ErLfCkG2Jq53peNwt9V2mFvt8kF8CaGCyrSyNbGKIzr560R2iHUlWp1poRrPsU5raEfs CACETsXXTAFaKFZY7xEfuVrm0a0qchnH7i3bBgsL8VpwIsQKVlJUSw9kxciGi9H4RtUS syP6QQ4eWZd8tlVWE0L3B6LZzacgCW56tcK6X778ZkmZln2OAw0U+HYJ8O1f8/NIrvWn YL2b2tMLIFg1WPcxuBHtH/1yGrk8j+M13GR6QNXcRc/U1xi6EUhgw1cAlN+lwDgsV7kg DVuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Y6dvcJmJak7lybcO2IsV2L3XO5lhedTMzXO32E/iDOc=; b=ar+KWNOpcAH3P2drgiM2nv4X051KCoaGJbaNM3sDJuEPHFJvgSkA1Z+3ASGxobWB3I v83JtLz2LxnYnghZG/E4259lyalLJhPDMsJ/xHFtFO3U69sWyfMo4BnhfemLSnvM+vFW ojW2bnW4Rt5OSoBXgHbG7vovTQagWq9BudTslRuaxctWDd5fIOHr0jdUYpwL08smTxzz hIZfgIt5yPJT3CeDuCkyGWtRshkv0Uzt/iGLo4Cw9gMrmISUo6Xsx68b16/ylbZuh8fd QvUcB3M28cFqqBkwYK7GAo0tO9LebPDfZ/BR6smjSPA6KNC83uGTrMjX+zP4G7o1Zjdj zmzw== X-Gm-Message-State: ALoCoQmAG5MkxN63aamCg284KmH+bIdA9foiFZ7SmAh+IWjIqByO6z30cT5LXceZ1mczCq2KYl+P X-Received: by 10.58.161.175 with SMTP id xt15mr7972328veb.19.1399713407929; Sat, 10 May 2014 02:16:47 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id y50si330850yhk.4.2014.05.10.02.16.47 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 May 2014 02:16:47 -0700 (PDT) Received: from atree.mtv.corp.google.com (atree.mtv.corp.google.com [172.17.128.10]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id C28AE5A41E5; Sat, 10 May 2014 02:16:47 -0700 (PDT) Received: by atree.mtv.corp.google.com (Postfix, from userid 51281) id 1EAC6120169; Sat, 10 May 2014 02:16:46 -0700 (PDT) From: Doug Kwan To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Date: Sat, 10 May 2014 02:16:38 -0700 Message-Id: <1399713400-8619-2-git-send-email-dougkwan@google.com> X-Mailer: git-send-email 1.9.1.423.g4596e3a In-Reply-To: <1399713400-8619-1-git-send-email-dougkwan@google.com> References: <1399713400-8619-1-git-send-email-dougkwan@google.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c01::249 Cc: riku.voipio@iki.fi, Doug Kwan , agraf@suse.de Subject: [Qemu-devel] [PATCH v2 1/3] linux-user: Support little-endian PPC64 in user mode. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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;