Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2040909pxm; Sun, 27 Feb 2022 09:35:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwg6cIMZD6ShALiBfi/jHERNfmNnYkFQhPHnYlz4zVoRNxKV8d9SD7dD7Cb+6LiM0lcCbaX X-Received: by 2002:a17:902:a38a:b0:14f:c714:47d3 with SMTP id x10-20020a170902a38a00b0014fc71447d3mr16914580pla.124.1645983348559; Sun, 27 Feb 2022 09:35:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645983348; cv=none; d=google.com; s=arc-20160816; b=X8byqWRacUh/EMf7E+7+ZlIBvk8fi9wXz1zTM9MlCimL0PoGRJ2ttbL02ftD7fnoPv GW0dKkn4G8yQcBrRwmsU0S4/H7e7TfSf+6TJSMiDg/ajZx/jVlY8UEuZyWH/S0oGXc2J 2MXScDhEOPvyJW8GAbv2k0ufP190SDZC2xXNlPeTOQYZbg63Ic00z3kxvmLVuqRZYey4 o726Q4vMPM77tyZoqmao0QwyEVrNE52NtXT1GtfBV1z8kv68Fdga+PaXAZkjZUH+9UKA Nug7Q4VVehhzDgZ5ueIYBlCRDIi3TGNK9fAkEvv6n+9V5oj2QmfuDkzP20ZJT1fiMlus AXCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SVAXV/NSS/91zP4C46PpFH8bUNwtSc2rZ4Z4ymlHaxk=; b=RWl1D0ocqcZQfmGrwECZLPl5nFyD23B/JMvR1WkyD1JuLoyMlllWtieOMggy9GKemW 0Y2CEoimlI7qmh+CNI+XUKIrU5rKnq3Szoa9RjE6G3bxoTPOMsTlAxJtVa8MsWUU9Mpz 8BSvcd6tt0mv/Jk3pFCCZJQ6/UNudhstRlVs01ry6RmHCfAieUGEo7AMrFR7XxlLIwYy h8C6v+Zdn5wbljueycUddHtSgvws7PYDBAd35vn6hYYhVqsK0csn7EIZ66Jft234t2qb Yeuyxg900kUygiAZnVCnP7gDOaMKIbYWoS9xsHuz4fxARcPKIExyWDUAK9zLnNDD25ny F4Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZvZXl49n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m14-20020a17090a5a4e00b001bc8d7b15e7si7419379pji.166.2022.02.27.09.35.32; Sun, 27 Feb 2022 09:35:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZvZXl49n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231785AbiB0Qay (ORCPT + 99 others); Sun, 27 Feb 2022 11:30:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231659AbiB0Qa1 (ORCPT ); Sun, 27 Feb 2022 11:30:27 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D2CA6D1AD; Sun, 27 Feb 2022 08:29:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 49242B80CDE; Sun, 27 Feb 2022 16:29:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F38F0C340F3; Sun, 27 Feb 2022 16:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645979387; bh=xSsGAqDW7zdtYbNeY2i44zp7niNjPBksfq3s+NrQNOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZvZXl49n73m4W5xPaD3EkK7i4O1ucKTaFnNqC8zIIBuRfwSTQQvtpMvxTC//SH7fS SXET3eAXZtC5fiAo66Q5nOHuRx6mC25HDcDNFtHGec0R184gigJy+50fxYAHqri/5w X+9t07U77CVGebg/3/i92oZhYDDSoqyKBQCOdlBBQbhfgthIbnilVxotEc5jRQy/K6 +e9jvWeSVW4WCz8AFT0Ow28wz5WOuy2/JKTS/qE26uJJZXTX9ZLeg4usrMLZRU8K4f bQCCLUGRtkHGU6lqWqIN1U1wXywVMZ5X1NQMRoBN4Pn+T3YlFSPt4btZVMaKeNYVty sN6r6Y40clqxQ== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, arnd@arndb.de, anup@brainfault.org, gregkh@linuxfoundation.org, liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org, wangjunqiang@iscas.ac.cn, hch@lst.de Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-csky@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-parisc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, Guo Ren Subject: [PATCH V7 09/20] riscv: compat: Add basic compat data type implementation Date: Mon, 28 Feb 2022 00:28:20 +0800 Message-Id: <20220227162831.674483-10-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220227162831.674483-1-guoren@kernel.org> References: <20220227162831.674483-1-guoren@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guo Ren Implement riscv asm/compat.h for struct compat_xxx, is_compat_task, compat_user_regset, regset convert. The rv64 compat.h has inherited most of the structs from the generic one. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Cc: Arnd Bergmann Cc: Palmer Dabbelt --- arch/riscv/include/asm/compat.h | 129 +++++++++++++++++++++++++++ arch/riscv/include/asm/thread_info.h | 1 + 2 files changed, 130 insertions(+) create mode 100644 arch/riscv/include/asm/compat.h diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compat.h new file mode 100644 index 000000000000..2ac955b51148 --- /dev/null +++ b/arch/riscv/include/asm/compat.h @@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_COMPAT_H +#define __ASM_COMPAT_H + +#define COMPAT_UTS_MACHINE "riscv\0\0" + +/* + * Architecture specific compatibility types + */ +#include +#include +#include +#include + +static inline int is_compat_task(void) +{ + return test_thread_flag(TIF_32BIT); +} + +struct compat_user_regs_struct { + compat_ulong_t pc; + compat_ulong_t ra; + compat_ulong_t sp; + compat_ulong_t gp; + compat_ulong_t tp; + compat_ulong_t t0; + compat_ulong_t t1; + compat_ulong_t t2; + compat_ulong_t s0; + compat_ulong_t s1; + compat_ulong_t a0; + compat_ulong_t a1; + compat_ulong_t a2; + compat_ulong_t a3; + compat_ulong_t a4; + compat_ulong_t a5; + compat_ulong_t a6; + compat_ulong_t a7; + compat_ulong_t s2; + compat_ulong_t s3; + compat_ulong_t s4; + compat_ulong_t s5; + compat_ulong_t s6; + compat_ulong_t s7; + compat_ulong_t s8; + compat_ulong_t s9; + compat_ulong_t s10; + compat_ulong_t s11; + compat_ulong_t t3; + compat_ulong_t t4; + compat_ulong_t t5; + compat_ulong_t t6; +}; + +static inline void regs_to_cregs(struct compat_user_regs_struct *cregs, + struct pt_regs *regs) +{ + cregs->pc = (compat_ulong_t) regs->epc; + cregs->ra = (compat_ulong_t) regs->ra; + cregs->sp = (compat_ulong_t) regs->sp; + cregs->gp = (compat_ulong_t) regs->gp; + cregs->tp = (compat_ulong_t) regs->tp; + cregs->t0 = (compat_ulong_t) regs->t0; + cregs->t1 = (compat_ulong_t) regs->t1; + cregs->t2 = (compat_ulong_t) regs->t2; + cregs->s0 = (compat_ulong_t) regs->s0; + cregs->s1 = (compat_ulong_t) regs->s1; + cregs->a0 = (compat_ulong_t) regs->a0; + cregs->a1 = (compat_ulong_t) regs->a1; + cregs->a2 = (compat_ulong_t) regs->a2; + cregs->a3 = (compat_ulong_t) regs->a3; + cregs->a4 = (compat_ulong_t) regs->a4; + cregs->a5 = (compat_ulong_t) regs->a5; + cregs->a6 = (compat_ulong_t) regs->a6; + cregs->a7 = (compat_ulong_t) regs->a7; + cregs->s2 = (compat_ulong_t) regs->s2; + cregs->s3 = (compat_ulong_t) regs->s3; + cregs->s4 = (compat_ulong_t) regs->s4; + cregs->s5 = (compat_ulong_t) regs->s5; + cregs->s6 = (compat_ulong_t) regs->s6; + cregs->s7 = (compat_ulong_t) regs->s7; + cregs->s8 = (compat_ulong_t) regs->s8; + cregs->s9 = (compat_ulong_t) regs->s9; + cregs->s10 = (compat_ulong_t) regs->s10; + cregs->s11 = (compat_ulong_t) regs->s11; + cregs->t3 = (compat_ulong_t) regs->t3; + cregs->t4 = (compat_ulong_t) regs->t4; + cregs->t5 = (compat_ulong_t) regs->t5; + cregs->t6 = (compat_ulong_t) regs->t6; +}; + +static inline void cregs_to_regs(struct compat_user_regs_struct *cregs, + struct pt_regs *regs) +{ + regs->epc = (unsigned long) cregs->pc; + regs->ra = (unsigned long) cregs->ra; + regs->sp = (unsigned long) cregs->sp; + regs->gp = (unsigned long) cregs->gp; + regs->tp = (unsigned long) cregs->tp; + regs->t0 = (unsigned long) cregs->t0; + regs->t1 = (unsigned long) cregs->t1; + regs->t2 = (unsigned long) cregs->t2; + regs->s0 = (unsigned long) cregs->s0; + regs->s1 = (unsigned long) cregs->s1; + regs->a0 = (unsigned long) cregs->a0; + regs->a1 = (unsigned long) cregs->a1; + regs->a2 = (unsigned long) cregs->a2; + regs->a3 = (unsigned long) cregs->a3; + regs->a4 = (unsigned long) cregs->a4; + regs->a5 = (unsigned long) cregs->a5; + regs->a6 = (unsigned long) cregs->a6; + regs->a7 = (unsigned long) cregs->a7; + regs->s2 = (unsigned long) cregs->s2; + regs->s3 = (unsigned long) cregs->s3; + regs->s4 = (unsigned long) cregs->s4; + regs->s5 = (unsigned long) cregs->s5; + regs->s6 = (unsigned long) cregs->s6; + regs->s7 = (unsigned long) cregs->s7; + regs->s8 = (unsigned long) cregs->s8; + regs->s9 = (unsigned long) cregs->s9; + regs->s10 = (unsigned long) cregs->s10; + regs->s11 = (unsigned long) cregs->s11; + regs->t3 = (unsigned long) cregs->t3; + regs->t4 = (unsigned long) cregs->t4; + regs->t5 = (unsigned long) cregs->t5; + regs->t6 = (unsigned long) cregs->t6; +}; + +#endif /* __ASM_COMPAT_H */ diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h index 60da0dcacf14..e1ad5131944b 100644 --- a/arch/riscv/include/asm/thread_info.h +++ b/arch/riscv/include/asm/thread_info.h @@ -91,6 +91,7 @@ struct thread_info { #define TIF_SECCOMP 8 /* syscall secure computing */ #define TIF_NOTIFY_SIGNAL 9 /* signal notifications exist */ #define TIF_UPROBE 10 /* uprobe breakpoint or singlestep */ +#define TIF_32BIT 11 /* compat-mode 32bit process */ #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) -- 2.25.1