Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp838129rwb; Wed, 28 Sep 2022 09:41:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wGJiJjD8TY/ygX0JxADhzV2cuRVbK1mY6/tgERyoYasGb9boTxOGum31GHCmdUrSYiU/z X-Received: by 2002:a17:90b:17cd:b0:205:d3bb:2706 with SMTP id me13-20020a17090b17cd00b00205d3bb2706mr11803103pjb.232.1664383268689; Wed, 28 Sep 2022 09:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664383268; cv=none; d=google.com; s=arc-20160816; b=yeR+aGUiOMhNVXeTAy2ttb8fnfm+4JXKbHe13jJlwrH9xD/Fww8GpLacGev5zEwmnl jX/IP7lc6vb4Sx7s0ILhSniHTt1oTvcpxNb2svdek8H3K23qRHesBZatLO44IDXnxS+k 0qXbp0aku6eZje9MxuJL90f29sp1pnrnWwtwHw7rb/8CBaFVuA8CaiYEYSM809qlkx7n 4D+OjTKHAJtReOIhHpCfviXpWwwXeC6dGAVmY+qumqHMl0KmgLaUH4hQz4u3U+sn8pg9 5rq6ZQaFSjDpUGXcMJb9u4OUVm69ZoPtnn8/WUF+/ElEVhs/c/feLOpPIMnmYfylP2M6 VyRw== 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=akRLUjoI+JTAjIutBI20dqjfFb+qZV/be2yA9ZQQPUk=; b=QJiWzjQ5/k1Zc88HRrniyObsMAZtBE6a3AFB3I87Xrmhcy9/H8Lm2HHXxCtX1k7Lr2 MbSI57IyDMigAcG8QLoH5j39bQsf1p4RNRVqTc1OT5fVCvSy4tKHU8DoEbXslXVdLJ1I 9UGimmMSGRjwmE9UUjQNIZHcNDSSl3+QULZDSuh7Oy/+jABD97z3b/IddRFRa1ddIcpk U7jrDhl8zPBcvdmxZlfkFke3dde3TPttaXlTtpksDcyuWYdEUHt+otq+wLGTpxU4YXUn eNTrBHV7HSNI9afSD4xb0h6dgZS3zoIb5QG3kZKb9CmFJChNinTPXma70xMSA/NNdQM8 1VbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U0eXGiUa; 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 w28-20020aa7955c000000b0051bbbc5f0aasi3045283pfq.261.2022.09.28.09.40.56; Wed, 28 Sep 2022 09:41:08 -0700 (PDT) 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=U0eXGiUa; 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 S234486AbiI1QaX (ORCPT + 99 others); Wed, 28 Sep 2022 12:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234508AbiI1Q3x (ORCPT ); Wed, 28 Sep 2022 12:29:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDA1420BE5 for ; Wed, 28 Sep 2022 09:29:49 -0700 (PDT) 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 E0546B8216E for ; Wed, 28 Sep 2022 16:29:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F829C43141; Wed, 28 Sep 2022 16:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664382585; bh=fdpi10kQlRazyTr+SlOn77cvFkgoSevjT+ijKpXJ/sA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0eXGiUahBnc1trC2eUbTTEwU5CEKFe9nfnL69aZSqjDFhV5csBJpIPA3O/lJHOGz 6ueK5LQQWpAxqL5F6PTiirlV2lRUsZ+JsvJ+Nj4sfinwpH+ygi+nu6yF/Mje9NKdrf aSlYNx4/TRcIwBg4ii4b2wa9SnsEXV0iihHfqQB+hTbbqXx5g+nWVTx2KGS20FGpc9 G65p5G/+hBO6kLnoKsHeYTG0UZX2IuWwjazSyocGMF9GRvc+nnRucazD481qZfTpcS R+T8Z14mSVtgsbmOZjGJPg1R4Tl/IfO2Sevq0ecqYGjs7nlblOjRKzAE1MQp/B1jlB BBqYmLiwhZvlA== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 4/4] riscv: entry: consolidate general regs saving into save_gp Date: Thu, 29 Sep 2022 00:20:07 +0800 Message-Id: <20220928162007.3791-5-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220928162007.3791-1-jszhang@kernel.org> References: <20220928162007.3791-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 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 Consolidate the saving/restoring GPs(except ra, sp and tp) into save_gp/restore_gp macro. No functional change intended. Signed-off-by: Jisheng Zhang --- arch/riscv/include/asm/asm.h | 65 +++++++++++++++++++++++++ arch/riscv/kernel/entry.S | 87 ++-------------------------------- arch/riscv/kernel/mcount-dyn.S | 58 +---------------------- 3 files changed, 70 insertions(+), 140 deletions(-) diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h index 1b471ff73178..2f3b49536e9d 100644 --- a/arch/riscv/include/asm/asm.h +++ b/arch/riscv/include/asm/asm.h @@ -68,6 +68,7 @@ #endif #ifdef __ASSEMBLY__ +#include /* Common assembly source macros */ @@ -80,6 +81,70 @@ .endr .endm + /* save all GPs except ra, sp and tp */ + .macro save_gp + REG_S x3, PT_GP(sp) + REG_S x5, PT_T0(sp) + REG_S x6, PT_T1(sp) + REG_S x7, PT_T2(sp) + REG_S x8, PT_S0(sp) + REG_S x9, PT_S1(sp) + REG_S x10, PT_A0(sp) + REG_S x11, PT_A1(sp) + REG_S x12, PT_A2(sp) + REG_S x13, PT_A3(sp) + REG_S x14, PT_A4(sp) + REG_S x15, PT_A5(sp) + REG_S x16, PT_A6(sp) + REG_S x17, PT_A7(sp) + REG_S x18, PT_S2(sp) + REG_S x19, PT_S3(sp) + REG_S x20, PT_S4(sp) + REG_S x21, PT_S5(sp) + REG_S x22, PT_S6(sp) + REG_S x23, PT_S7(sp) + REG_S x24, PT_S8(sp) + REG_S x25, PT_S9(sp) + REG_S x26, PT_S10(sp) + REG_S x27, PT_S11(sp) + REG_S x28, PT_T3(sp) + REG_S x29, PT_T4(sp) + REG_S x30, PT_T5(sp) + REG_S x31, PT_T6(sp) + .endm + + /* restore all GPs except ra, sp and tp */ + .macro restore_gp + REG_L x3, PT_GP(sp) + REG_L x5, PT_T0(sp) + REG_L x6, PT_T1(sp) + REG_L x7, PT_T2(sp) + REG_L x8, PT_S0(sp) + REG_L x9, PT_S1(sp) + REG_L x10, PT_A0(sp) + REG_L x11, PT_A1(sp) + REG_L x12, PT_A2(sp) + REG_L x13, PT_A3(sp) + REG_L x14, PT_A4(sp) + REG_L x15, PT_A5(sp) + REG_L x16, PT_A6(sp) + REG_L x17, PT_A7(sp) + REG_L x18, PT_S2(sp) + REG_L x19, PT_S3(sp) + REG_L x20, PT_S4(sp) + REG_L x21, PT_S5(sp) + REG_L x22, PT_S6(sp) + REG_L x23, PT_S7(sp) + REG_L x24, PT_S8(sp) + REG_L x25, PT_S9(sp) + REG_L x26, PT_S10(sp) + REG_L x27, PT_S11(sp) + REG_L x28, PT_T3(sp) + REG_L x29, PT_T4(sp) + REG_L x30, PT_T5(sp) + REG_L x31, PT_T6(sp) + .endm + #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_ASM_H */ diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 5a6171a90d81..a90f17ed2822 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -40,34 +40,7 @@ _save_context: REG_L sp, TASK_TI_KERNEL_SP(tp) addi sp, sp, -(PT_SIZE_ON_STACK) REG_S x1, PT_RA(sp) - REG_S x3, PT_GP(sp) - REG_S x5, PT_T0(sp) - REG_S x6, PT_T1(sp) - REG_S x7, PT_T2(sp) - REG_S x8, PT_S0(sp) - REG_S x9, PT_S1(sp) - REG_S x10, PT_A0(sp) - REG_S x11, PT_A1(sp) - REG_S x12, PT_A2(sp) - REG_S x13, PT_A3(sp) - REG_S x14, PT_A4(sp) - REG_S x15, PT_A5(sp) - REG_S x16, PT_A6(sp) - REG_S x17, PT_A7(sp) - REG_S x18, PT_S2(sp) - REG_S x19, PT_S3(sp) - REG_S x20, PT_S4(sp) - REG_S x21, PT_S5(sp) - REG_S x22, PT_S6(sp) - REG_S x23, PT_S7(sp) - REG_S x24, PT_S8(sp) - REG_S x25, PT_S9(sp) - REG_S x26, PT_S10(sp) - REG_S x27, PT_S11(sp) - REG_S x28, PT_T3(sp) - REG_S x29, PT_T4(sp) - REG_S x30, PT_T5(sp) - REG_S x31, PT_T6(sp) + save_gp /* * Disable user-mode memory access as it should only be set in the @@ -182,35 +155,8 @@ ENTRY(ret_from_exception) csrw CSR_STATUS, a0 REG_L x1, PT_RA(sp) - REG_L x3, PT_GP(sp) REG_L x4, PT_TP(sp) - REG_L x5, PT_T0(sp) - REG_L x6, PT_T1(sp) - REG_L x7, PT_T2(sp) - REG_L x8, PT_S0(sp) - REG_L x9, PT_S1(sp) - REG_L x10, PT_A0(sp) - REG_L x11, PT_A1(sp) - REG_L x12, PT_A2(sp) - REG_L x13, PT_A3(sp) - REG_L x14, PT_A4(sp) - REG_L x15, PT_A5(sp) - REG_L x16, PT_A6(sp) - REG_L x17, PT_A7(sp) - REG_L x18, PT_S2(sp) - REG_L x19, PT_S3(sp) - REG_L x20, PT_S4(sp) - REG_L x21, PT_S5(sp) - REG_L x22, PT_S6(sp) - REG_L x23, PT_S7(sp) - REG_L x24, PT_S8(sp) - REG_L x25, PT_S9(sp) - REG_L x26, PT_S10(sp) - REG_L x27, PT_S11(sp) - REG_L x28, PT_T3(sp) - REG_L x29, PT_T4(sp) - REG_L x30, PT_T5(sp) - REG_L x31, PT_T6(sp) + restore_gp REG_L x2, PT_SP(sp) @@ -237,34 +183,7 @@ ENTRY(handle_kernel_stack_overflow) //save context to overflow stack REG_S x1, PT_RA(sp) - REG_S x3, PT_GP(sp) - REG_S x5, PT_T0(sp) - REG_S x6, PT_T1(sp) - REG_S x7, PT_T2(sp) - REG_S x8, PT_S0(sp) - REG_S x9, PT_S1(sp) - REG_S x10, PT_A0(sp) - REG_S x11, PT_A1(sp) - REG_S x12, PT_A2(sp) - REG_S x13, PT_A3(sp) - REG_S x14, PT_A4(sp) - REG_S x15, PT_A5(sp) - REG_S x16, PT_A6(sp) - REG_S x17, PT_A7(sp) - REG_S x18, PT_S2(sp) - REG_S x19, PT_S3(sp) - REG_S x20, PT_S4(sp) - REG_S x21, PT_S5(sp) - REG_S x22, PT_S6(sp) - REG_S x23, PT_S7(sp) - REG_S x24, PT_S8(sp) - REG_S x25, PT_S9(sp) - REG_S x26, PT_S10(sp) - REG_S x27, PT_S11(sp) - REG_S x28, PT_T3(sp) - REG_S x29, PT_T4(sp) - REG_S x30, PT_T5(sp) - REG_S x31, PT_T6(sp) + save_gp REG_L s0, TASK_TI_KERNEL_SP(tp) csrr s1, CSR_STATUS diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index d171eca623b6..1b4b0aecf4f5 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -68,35 +68,8 @@ REG_L x1, PT_EPC(sp) REG_S x2, PT_SP(sp) - REG_S x3, PT_GP(sp) REG_S x4, PT_TP(sp) - REG_S x5, PT_T0(sp) - REG_S x6, PT_T1(sp) - REG_S x7, PT_T2(sp) - REG_S x8, PT_S0(sp) - REG_S x9, PT_S1(sp) - REG_S x10, PT_A0(sp) - REG_S x11, PT_A1(sp) - REG_S x12, PT_A2(sp) - REG_S x13, PT_A3(sp) - REG_S x14, PT_A4(sp) - REG_S x15, PT_A5(sp) - REG_S x16, PT_A6(sp) - REG_S x17, PT_A7(sp) - REG_S x18, PT_S2(sp) - REG_S x19, PT_S3(sp) - REG_S x20, PT_S4(sp) - REG_S x21, PT_S5(sp) - REG_S x22, PT_S6(sp) - REG_S x23, PT_S7(sp) - REG_S x24, PT_S8(sp) - REG_S x25, PT_S9(sp) - REG_S x26, PT_S10(sp) - REG_S x27, PT_S11(sp) - REG_S x28, PT_T3(sp) - REG_S x29, PT_T4(sp) - REG_S x30, PT_T5(sp) - REG_S x31, PT_T6(sp) + save_gp .endm .macro RESTORE_ALL @@ -106,35 +79,8 @@ addi sp, sp, -PT_SIZE_ON_STACK REG_L x1, PT_EPC(sp) REG_L x2, PT_SP(sp) - REG_L x3, PT_GP(sp) REG_L x4, PT_TP(sp) - REG_L x5, PT_T0(sp) - REG_L x6, PT_T1(sp) - REG_L x7, PT_T2(sp) - REG_L x8, PT_S0(sp) - REG_L x9, PT_S1(sp) - REG_L x10, PT_A0(sp) - REG_L x11, PT_A1(sp) - REG_L x12, PT_A2(sp) - REG_L x13, PT_A3(sp) - REG_L x14, PT_A4(sp) - REG_L x15, PT_A5(sp) - REG_L x16, PT_A6(sp) - REG_L x17, PT_A7(sp) - REG_L x18, PT_S2(sp) - REG_L x19, PT_S3(sp) - REG_L x20, PT_S4(sp) - REG_L x21, PT_S5(sp) - REG_L x22, PT_S6(sp) - REG_L x23, PT_S7(sp) - REG_L x24, PT_S8(sp) - REG_L x25, PT_S9(sp) - REG_L x26, PT_S10(sp) - REG_L x27, PT_S11(sp) - REG_L x28, PT_T3(sp) - REG_L x29, PT_T4(sp) - REG_L x30, PT_T5(sp) - REG_L x31, PT_T6(sp) + restore_gp addi sp, sp, PT_SIZE_ON_STACK addi sp, sp, SZREG -- 2.34.1