From patchwork Wed May 23 00:15:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 918661 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="ITF6ypQN"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rDJ23PNHz9s02 for ; Wed, 23 May 2018 10:42:42 +1000 (AEST) Received: from localhost ([::1]:58616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLHrU-0001DS-78 for incoming@patchwork.ozlabs.org; Tue, 22 May 2018 20:42:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLHUA-0000gT-7b for qemu-devel@nongnu.org; Tue, 22 May 2018 20:18:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLHU7-0001X1-Fm for qemu-devel@nongnu.org; Tue, 22 May 2018 20:18:34 -0400 Received: from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]:44835) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fLHU7-0001Vy-4s for qemu-devel@nongnu.org; Tue, 22 May 2018 20:18:31 -0400 Received: by mail-pf0-x236.google.com with SMTP id q22-v6so9550341pff.11 for ; Tue, 22 May 2018 17:18:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8FIjaO8xQRxbLc4V6sL21mhrYl0BnXc1jSL7tJrd6As=; b=ITF6ypQN9u3jFAniNJibOy6jvYJ8AzTFEmhD1SqNJXHe8b7pLcSVaJR3n588sgDa0t Dn1ZwxuQgbji9Y2C9RvSmgrU7PIqW2PM+wmLptYxHYCyQNLziseRPGfd3GIKKGYSagyq bxQKN8JcCP9+5PAlP6QnPnuZv7V/hY11fyf/qtekeRYb3ZuYi3cff+gMB+m567Pc1Fec Qucywyl1EfrFFzfg8JfEeA/8PKivC9GS0zmADR/kQ4pNMdIeq7YHiLwJUt+pHlJz7P76 ezPYXGRe6c5aUEntYbh5kEWDwtYi89pGMEjQ9E8Nj4xrk6oDPl5VGl0xRV4bSh7lKXms Tz1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8FIjaO8xQRxbLc4V6sL21mhrYl0BnXc1jSL7tJrd6As=; b=B1V/on81eC0n8LSnTfZh7oTJRFm7rLbP9gv7HIzIJZ3XnplU2ayHXimbbT2vJvWgcm /JC4EW/cwcIPyNtBpq0Em2DcF79aVSGqN1rpxJb2+GxDIBJzi/qISzxNj+WG+ULsHF95 /GfSzsR6XnHqZh8qU5t9zvGk6oSlzNo5Xbcp2XYK1KMckm9i0uXu6gIkc6Hw6oRp5BHq Sqj8YR3ayJnHgWI4Nh+JTEqmREdbVe79jLoGYKwkR3A5h0aRJs0BHjzKLYrJKmNCHpBr oQT/Sa+GfCGC4gJPKzmEVd3a7isbj2cURGyX4lKZnjWSqrAQZj7Uc8gMW7Jpp3rpiN5A iKtQ== X-Gm-Message-State: ALKqPwfnLcOYAHkzH42XA4o+TwyuWHGazIQwnd+wh2k02QvueKP2n/uZ cz4tSxfVzqISukgJOOt31YKFdiBXiEo= X-Google-Smtp-Source: AB8JxZoDm4XgXvPrrnTUoPLSS4kwypc86RM3Z+z+tuBHAUSYi8FuMEPOYT1wlal6XiLA7FKILgkf5Q== X-Received: by 2002:a65:654a:: with SMTP id a10-v6mr475861pgw.107.1527034710170; Tue, 22 May 2018 17:18:30 -0700 (PDT) Received: from localhost.localdomain (122-58-167-22-fibre.bb.spark.co.nz. [122.58.167.22]) by smtp.gmail.com with ESMTPSA id j1-v6sm28935626pfh.95.2018.05.22.17.18.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 May 2018 17:18:29 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Wed, 23 May 2018 12:15:15 +1200 Message-Id: <1527034517-7851-29-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1527034517-7851-1-git-send-email-mjc@sifive.com> References: <1527034517-7851-1-git-send-email-mjc@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::236 Subject: [Qemu-devel] [PATCH v1 28/30] RISC-V: linux-user support for RVE ABI X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , Kito Cheng , Michael Clark , Alistair Francis , patches@groups.riscv.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Kito Cheng This change checks elf_flags for EF_RISCV_RVE and if present uses the RVE linux syscall ABI which uses t0 for the syscall number instead of a7. Warn and exit if a non-RVE ABI binary is run on a cpu with the RVE extension as it is incompatible. Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Alistair Francis Co-authored-by: Kito Cheng Co-authored-by: Michael Clark Signed-off-by: Michael Clark --- linux-user/riscv/cpu_loop.c | 14 +++++++++++++- target/riscv/cpu.h | 4 ++++ target/riscv/cpu_user.h | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index f137d39d7e82..5f6a941c6c19 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "elf.h" void cpu_loop(CPURISCVState *env) { @@ -53,7 +54,8 @@ void cpu_loop(CPURISCVState *env) ret = 0; } else { ret = do_syscall(env, - env->gpr[xA7], + env->gpr[(env->elf_flags & EF_RISCV_RVE) + ? xT0 : xA7], env->gpr[xA0], env->gpr[xA1], env->gpr[xA2], @@ -113,6 +115,16 @@ void cpu_loop(CPURISCVState *env) void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { + CPUState *cpu = ENV_GET_CPU(env); + TaskState *ts = cpu->opaque; + struct image_info *info = ts->info; + env->pc = regs->sepc; env->gpr[xSP] = regs->sp; + env->elf_flags = info->elf_flags; + + if ((env->misa & RVE) && !(env->elf_flags & EF_RISCV_RVE)) { + fprintf(stderr, "Incompatible ELF: RVE cpu requires RVE ABI binary\n"); + exit(EXIT_FAILURE); + } } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 830a9d476dce..0823461ae9f2 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -123,6 +123,10 @@ struct CPURISCVState { uint32_t features; +#ifdef CONFIG_USER_ONLY + uint32_t elf_flags; +#endif + #ifndef CONFIG_USER_ONLY target_ulong priv; target_ulong resetvec; diff --git a/target/riscv/cpu_user.h b/target/riscv/cpu_user.h index c2199610abff..52d380aa98c2 100644 --- a/target/riscv/cpu_user.h +++ b/target/riscv/cpu_user.h @@ -10,4 +10,5 @@ #define xA4 14 #define xA5 15 #define xA6 16 -#define xA7 17 /* syscall number goes here */ +#define xA7 17 /* syscall number for RVI ABI */ +#define xT0 5 /* syscall number for RVE ABI */