From patchwork Thu Mar 29 13:13:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10315421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3AEAD6055B for ; Thu, 29 Mar 2018 13:14:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EB5D2A362 for ; Thu, 29 Mar 2018 13:14:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22E542A364; Thu, 29 Mar 2018 13:14:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D9A62A362 for ; Thu, 29 Mar 2018 13:14:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8aos6c1kliPhblZmengIrlrTvpzMVBtikmcyvID7vvM=; b=Hh+GPAKN6OXbKe2dxqhQtlime5 tzXLmYpsp/Evd6S0Io2VFy+nOph7QE9AnZ0eVoyWeXkGScWYyWjA2QyEvp+1/5mjpDOb4L5AAP/Aw e6fitViqS15/wJt+MZhmA1c8zaB+q56m7eH3uMxqkazYUH+YNSsk4mW9SqpLewATe+AkjJj4UWu+W YONDO+O2aystF44Id3KAzRahSviXe3TSonvs80X1K1GQFS5/DMbDERInJf2uWnkdJ5sKtIiiiP966 gIps62SrE/gDeUShUTJUTwhUUs6Pdu+539T0yslcoHkBqdhK8Kh5J2OMT2kgKsUxhSTb3KXm/yvMz a5uU5CSA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1XNk-00031Y-Jz; Thu, 29 Mar 2018 13:14:20 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1XNE-0002j5-60 for linux-arm-kernel@lists.infradead.org; Thu, 29 Mar 2018 13:13:50 +0000 Received: by mail-wm0-x244.google.com with SMTP id a20so30239727wmd.1 for ; Thu, 29 Mar 2018 06:13:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MT/c9Y1SIVE8cUAlOt/b/M9ujlcKiyGRPcZUKbGrrT8=; b=iEDlcIaXKPtD4l/ivTAXub7ntgafwjjF+triW4Ho/GkR4GTqSNtKp1/XYXWOjXlYoj VlQYC9/00Q1zKdKrZ+u7i8jY5RFMLBMCKsb32gtKPANnP0wZDynsWkwq5GQAyxK0Cdd8 f54zVAWx0WHMe8LiqvSsfY9zIH33xzK1GSJSQ= 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=MT/c9Y1SIVE8cUAlOt/b/M9ujlcKiyGRPcZUKbGrrT8=; b=r+nJ6TYEcNqZwUryzoVBz/e2oQiJ2Wd+Q1GtpK7dPebza8NWNOI+MpJcqFNX/TAAHY trd/buTsNjzOq6XXgV4/FaEV9ctT9L1oVJpIN+R5tYOcFDaroqx4shY0hqmp70/b9ZeO t2wo9KRPKhY0rd2LVoeuyeQA1AxYjMjTidjM1cnvlWRDfrudmLr4I4+oulW5qUyoMHD9 0H2Ag22VdcDhVu8b1kIDySTnjCLnr3JJNxur8ATtn4q3lLZl7ar3aTVmr+Pu1g9hqfQp 3U9r8Q/8/zcD1fk/DXw8dKWV7rXj2ZWbe/hJWs2O1VeDTYvthiZpC3AyCofDceM1oUPw kOLg== X-Gm-Message-State: AElRT7ESSAbRr5xsxAj6PMxqZjVNmOeJwc+vqDAXMUrd6uPTcNQgYOSD PTZSEs+FkY+XIUYkszZuAi3Xv63TnVQ= X-Google-Smtp-Source: AIpwx4/UyXbdZNgwnx8AHP22IXU4Bw6ECDyEdxk7zoMMOH8nE4DI664RTLedT5IerhcchLkGadqZ0w== X-Received: by 10.28.175.141 with SMTP id y135mr5853534wme.23.1522329217791; Thu, 29 Mar 2018 06:13:37 -0700 (PDT) Received: from localhost.localdomain (187.14.136.77.rev.sfr.net. [77.136.14.187]) by smtp.gmail.com with ESMTPSA id l131sm4166526wmb.36.2018.03.29.06.13.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 06:13:37 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH resend v2 1/2] arm64: assembler: add utility macros to push/pop stack frames Date: Thu, 29 Mar 2018 15:13:22 +0200 Message-Id: <20180329131323.15881-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180329131323.15881-1-ard.biesheuvel@linaro.org> References: <20180329131323.15881-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180329_061348_229010_E1419A0B X-CRM114-Status: GOOD ( 14.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: will.deacon@arm.com, dave.martin@arm.com, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We are going to add code to all the NEON crypto routines that will turn them into non-leaf functions, so we need to manage the stack frames. To make this less tedious and error prone, add some macros that take the number of callee saved registers to preserve and the extra size to allocate in the stack frame (for locals) and emit the ldp/stp sequences. Signed-off-by: Ard Biesheuvel Reviewed-by: Dave Martin --- arch/arm64/include/asm/assembler.h | 63 ++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 053d83e8db6f..fe2ff3efe1f0 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -565,4 +565,67 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU #endif .endm + /* + * frame_push - Push @regcount callee saved registers to the stack, + * starting at x19, as well as x29/x30, and set x29 to + * the new value of sp. Add @extra bytes of stack space + * for locals. + */ + .macro frame_push, regcount:req, extra + __frame st, \regcount, \extra + .endm + + /* + * frame_pop - Pop the callee saved registers from the stack that were + * pushed in the most recent call to frame_push, as well + * as x29/x30 and any extra stack space that may have been + * allocated. + */ + .macro frame_pop + __frame ld + .endm + + .macro __frame_regs, reg1, reg2, op, num + .if .Lframe_regcount == \num + \op\()r \reg1, [sp, #(\num + 1) * 8] + .elseif .Lframe_regcount > \num + \op\()p \reg1, \reg2, [sp, #(\num + 1) * 8] + .endif + .endm + + .macro __frame, op, regcount, extra=0 + .ifc \op, st + .if (\regcount) < 0 || (\regcount) > 10 + .error "regcount should be in the range [0 ... 10]" + .endif + .if ((\extra) % 16) != 0 + .error "extra should be a multiple of 16 bytes" + .endif + .ifdef .Lframe_regcount + .if .Lframe_regcount != -1 + .error "frame_push/frame_pop may not be nested" + .endif + .endif + .set .Lframe_regcount, \regcount + .set .Lframe_extra, \extra + .set .Lframe_local_offset, ((\regcount + 3) / 2) * 16 + stp x29, x30, [sp, #-.Lframe_local_offset - .Lframe_extra]! + mov x29, sp + .endif + + __frame_regs x19, x20, \op, 1 + __frame_regs x21, x22, \op, 3 + __frame_regs x23, x24, \op, 5 + __frame_regs x25, x26, \op, 7 + __frame_regs x27, x28, \op, 9 + + .ifc \op, ld + .if .Lframe_regcount == -1 + .error "frame_push/frame_pop may not be nested" + .endif + ldp x29, x30, [sp], #.Lframe_local_offset + .Lframe_extra + .set .Lframe_regcount, -1 + .endif + .endm + #endif /* __ASM_ASSEMBLER_H */