From patchwork Tue Jul 18 21:11:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 122231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2017780vqt; Tue, 18 Jul 2023 14:24:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlHoU165v536RqaE1m1MW/ampItVS7yvZWLvPBff5HyJfOKIDBrjyHNJK7X7HAVah9Ge1s9I X-Received: by 2002:a17:902:748c:b0:1b6:c139:9b23 with SMTP id h12-20020a170902748c00b001b6c1399b23mr905129pll.26.1689715466214; Tue, 18 Jul 2023 14:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689715466; cv=none; d=google.com; s=arc-20160816; b=XojPV6wODLubxWXH5B9Mc3lIu8wz+9hC8bAiJrSzWZSDuNE3k7tDbPJd2/rKfY0gYR fVm4lMVj08NkqQIdQISiRiiGMGlZM5eO2Lv6YyolXZb0fGvfaKT/+GnTxE6uVdgzuDF9 i8ltvHoGdGE8c/IKZHJXABSa1ipNwBsiL5WfQuV483QBc2oScvs52F1YYJTdHtivwNIS 1bN4BKjf/PB7UFE8k9x1J7y/RxPcXQVqUzSSOfgLMn6+a14+RsX8J02/6L5LSHvW6Ili dCaUjWwZRTQ6fO7TyTq3TfcnctMF7YFLkxUiRG5KNKIQOH9HEjFfpmK7VsQ7uCXXxEU6 YScg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=MD5Qv/gJ8YF/7/wcYhBv0O9VXHeFePApjjWnS/CEA98=; fh=LUnDCxFG3oyWlcYTkiNww5x4+0V5pkm51/GfDl61ZDU=; b=AtIBcVd5pgvL80xT5eHHFMFEI06BtygdSk/Zn776sutUEoB1BR3Gf1s9p5Lozb1wcH Lv2/7Lptv9rV2bxBY46Ztlq2s2Ft84TBKaKEYMHTL3I99jHv/5Cq7Lmt7UgMHlJlCBUs tsf1fBRoBhy8GU3kUf/LS6eBWu1aRg46RuGgkmNs0hnPMREEMIY2tPI0Bimurx5Eo9yb GWjLFs61mv2fOY/1uSPrCyM2pnOsai40s6fQiIJ5oxX96yJFHzJ1uM0om1virtPSMxv7 1S77lByp1gvMHcJx0WXg+LzK+jqyYzViL04x1JCKczHNwBF2xEfICf8nvlL4F6SvBRQr zt6A== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a1709028a8d00b001b8c6890595si2052402plo.310.2023.07.18.14.24.12; Tue, 18 Jul 2023 14:24:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbjGRVMZ (ORCPT + 99 others); Tue, 18 Jul 2023 17:12:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbjGRVMT (ORCPT ); Tue, 18 Jul 2023 17:12:19 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E7821FEE; Tue, 18 Jul 2023 14:12:05 -0700 (PDT) X-QQ-mid: bizesmtp67t1689714716ty3d409i Received: from linux-lab-host.localdomain ( [119.123.130.39]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 19 Jul 2023 05:11:55 +0800 (CST) X-QQ-SSF: 01200000000000D0X000000A0000000 X-QQ-FEAT: znfcQSa1hKbIWy9/nudIS6dweUsnw6YVkjkrjXVuU+TODYlb+AgCL6pXkl2Fl tSsRaDf72WXJcU3KEzH9E4XSY2yEuk3T/diWm8Ne5HqGX0DrjpE477mcQpG4G5DFd9ODAOv uaikbHrw6qk530JkQ8AXJcHgiIds6d+3aJefPFODPpZsURPJhdgFwh0jQjZ/vmKkYggOmvg aszaovcQXFBHNKeguR9bBylNG6atlyI7bfvZaKxSTY+3RBNZwLkFtoz5htQh0d6mbj20RuF K+5rrb2HGie6OTmRGi4ibC/KnE/f91NZCFgxKvguB/uEmc1BehQ7DhvhA7zqSZvkzSXxWHD 9PT7i9S5yx9Zpsyo+xynEYrc3KrTZZkfVU5bd7OV511CmwkmBLBB7D8q7X6YQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11373982133652074623 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 2/8] tools/nolibc: add support for powerpc64 Date: Wed, 19 Jul 2023 05:11:54 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771795084347679342 X-GMAIL-MSGID: 1771795084347679342 This follows the 64-bit PowerPC ABI [1], refers to the slides: "A new ABI for little-endian PowerPC64 Design & Implementation" [2] and the musl code in arch/powerpc64/crt_arch.h. Firstly, stdu and clrrdi are used instead of stwu and clrrwi for powerpc64. Second, the stack frame size is increased to 32 bytes for powerpc64, 32 bytes is the minimal stack frame size supported described in [2]. Besides, the TOC pointer (GOT pointer) must be saved to r2. This works on both little endian and big endian 64-bit PowerPC. [1]: https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.pdf [2]: https://www.llvm.org/devmtg/2014-04/PDFs/Talks/Euro-LLVM-2014-Weigand.pdf Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-powerpc.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arch-powerpc.h index 100ec0f412dc..7b28ebcfcc23 100644 --- a/tools/include/nolibc/arch-powerpc.h +++ b/tools/include/nolibc/arch-powerpc.h @@ -143,6 +143,19 @@ /* startup code */ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void) { +#ifdef __powerpc64__ + /* On 64-bit PowerPC, save TOC/GOT pointer to r2 */ + extern char TOC __asm__ (".TOC."); + register volatile long r2 __asm__ ("r2") = (void *)&TOC - (void *)_start; + + __asm__ volatile ( + "mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */ + "clrrdi 1, 1, 4\n" /* align the stack to 16 bytes */ + "li 0, 0\n" /* zero the frame pointer */ + "stdu 1, -32(1)\n" /* the initial stack frame */ + "bl _start_c\n" /* transfer to c runtime */ + ); +#else __asm__ volatile ( "mr 3, 1\n" /* save stack pointer to r3, as arg1 of _start_c */ "clrrwi 1, 1, 4\n" /* align the stack to 16 bytes */ @@ -150,6 +163,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_ "stwu 1, -16(1)\n" /* the initial stack frame */ "bl _start_c\n" /* transfer to c runtime */ ); +#endif __builtin_unreachable(); }