From patchwork Wed Jun 28 19:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 114021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9147224vqr; Wed, 28 Jun 2023 12:08:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lRCdEBGUq/cqu5Lt7KYp0D9GMoTnbMu1e3+a75Gt6fCFCd4M+vpBzzij6JQOfLEcIe7G1 X-Received: by 2002:a17:906:73cc:b0:98d:b10f:f3cd with SMTP id n12-20020a17090673cc00b0098db10ff3cdmr9220404ejl.7.1687979304878; Wed, 28 Jun 2023 12:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979304; cv=none; d=google.com; s=arc-20160816; b=sqyDaAjyrXEd4pkmSvz4VVGUQBN8y4paUYhty6Q1b1OI1F1WVyuFb8l9vwGoLrNr4W hQMVYXKmrb50tLoVlEmTxUUA7x2Ng/yr32B+NXGoOOVxQowCe7YklWGuuWcaqRSL6dHN Ew7NvKnJy+X14ogVfXLS0wwoBIUkj5ErISUMvz3yna41I01DJ8wZDHhRE+EW4JSnXRTJ ltTKl6rSg4HB8xW+rkiiW3uf+KbQQ+PaKC8RfBTtWCiT9hT2SyB8aa8C2DC9gdQ1Uwl3 Mk0qCsnFhvq2VtJ1Eyj2woSwdFEbNguVXGfFuEpXgsANhjN3IMWmaPMpXwQbBeApuho+ lzkw== 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=W7UNnnFVdIc/TKqQz36OlyYto66FhsQ0NfyOu0f+7CI=; fh=jGpRxxGHkcGZyN2ZnaDwhUy8S6joixew3DGGT1L/CuQ=; b=SqDIpS/ORMCFgsSvNfGBQdJNdSBH2x4J6/CKq0Ei5g4dl9GcxqHc/K2f6ZGnj9j2oV IxwL9Cs4OaHDn9kDtYbhXnLifv5N5NczPxDrgbCmgzRQiBVeUoliQ4UOMOK2EKusjCrT l8fiTfZbZHrCPpoUFvocWTeGWNm7WetBRzbtTNF+BYIeustSG2D0aKU5YW50WdJLyq1a 1FD7MC6rJgeZb9PBujhFRdMkyWKxnAT9smwafrUd2maUm1TXWOWbzILL7hjL5p5nZumY p7rrlp+R4rcz/03v53p2BT0uzEKZBJpzMTrNgbNRZ6NbUXGffTGaKczEIngXKgSR1lbc nXEA== 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 lr26-20020a170906fb9a00b0099207b3bc48si2713077ejb.224.2023.06.28.12.07.56; Wed, 28 Jun 2023 12:08:24 -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 S231637AbjF1TD6 (ORCPT + 99 others); Wed, 28 Jun 2023 15:03:58 -0400 Received: from bg4.exmail.qq.com ([43.155.65.254]:6174 "EHLO bg4.exmail.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbjF1TDR (ORCPT ); Wed, 28 Jun 2023 15:03:17 -0400 X-QQ-mid: bizesmtp85t1687978987tlvjj2iy Received: from linux-lab-host.localdomain ( [116.30.129.193]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 29 Jun 2023 03:03:06 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 30t4+KEGo2kqMzIzajseusyLF7DGV3trcgVIZWDyeuDiPdn9oiQdoe9C6XJAD vRYykuFZb8aw+newmuj0ZpRZbq0olfDeXM0x7P3WWiHkTf+RxIC6e0va5PbFtdi31S7emfy BgWC8COyFGZmilAgD/mTUgkxKuUbRPK1ZBCcw4yTh1Um5vGJptGF1X/y/y+2bxUYydm8Hys 1rxzCBDgc9rUTPxmLdlt6TDy2B+4s0BQEA8E5kMilhmEU4iFzpsThdNQUe5tOB8Uogv5JB5 EOAMYtW4/Jp5C/kEwJY4Ll8PZad+UsXQW1qxIjYDjIZ3FxqazztHdJGRH78+TnxowJqO00q e7IYl+PYRC4K9WgitssfviOC/U+GsgbUhQD8FLxCWtM9SHztqs= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2025772407350311878 From: Zhangjin Wu To: thomas@t-8ch.de, w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v1 09/11] tools/nolibc: loongarch: shrink _start with _start_c Date: Thu, 29 Jun 2023 03:02:29 +0800 Message-Id: <3304844b9d5c02416d08aaffd2f009941b38163c.1687976753.git.falcon@tinylab.org> 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:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769974587261044312?= X-GMAIL-MSGID: =?utf-8?q?1769974587261044312?= Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-loongarch.h | 42 +++------------------------ 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h index fbb4844f7993..f5cac2e81a13 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -145,26 +145,9 @@ _arg1; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - #if __loongarch_grlen == 32 -#define LONGLOG "2" -#define SZREG "4" -#define REG_L "ld.w" -#define LONG_S "st.w" -#define LONG_ADD "add.w" -#define LONG_ADDI "addi.w" -#define LONG_SLL "slli.w" #define LONG_BSTRINS "bstrins.w" #else /* __loongarch_grlen == 64 */ -#define LONGLOG "3" -#define SZREG "8" -#define REG_L "ld.d" -#define LONG_S "st.d" -#define LONG_ADD "add.d" -#define LONG_ADDI "addi.d" -#define LONG_SLL "slli.d" #define LONG_BSTRINS "bstrins.d" #endif @@ -173,28 +156,11 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_pr { __asm__ volatile ( #ifdef _NOLIBC_STACKPROTECTOR - "bl __stack_chk_init\n" /* initialize stack protector */ + "bl __stack_chk_init\n" /* initialize stack protector */ #endif - REG_L " $a0, $sp, 0\n" /* argc (a0) was in the stack */ - LONG_ADDI " $a1, $sp, "SZREG"\n" /* argv (a1) = sp + SZREG */ - LONG_SLL " $a2, $a0, "LONGLOG"\n" /* envp (a2) = SZREG*argc ... */ - LONG_ADDI " $a2, $a2, "SZREG"\n" /* + SZREG (skip null) */ - LONG_ADD " $a2, $a2, $a1\n" /* + argv */ - - "move $a3, $a2\n" /* iterate a3 over envp to find auxv (after NULL) */ - "0:\n" /* do { */ - REG_L " $a4, $a3, 0\n" /* a4 = *a3; */ - LONG_ADDI " $a3, $a3, "SZREG"\n" /* a3 += sizeof(void*); */ - "bne $a4, $zero, 0b\n" /* } while (a4); */ - "la.pcrel $a4, _auxv\n" /* a4 = &_auxv */ - LONG_S " $a3, $a4, 0\n" /* store a3 into _auxv */ - - "la.pcrel $a3, environ\n" /* a3 = &environ */ - LONG_S " $a2, $a3, 0\n" /* store envp(a2) into environ */ - LONG_BSTRINS " $sp, $zero, 3, 0\n" /* sp must be 16-byte aligned */ - "bl main\n" /* main() returns the status code, we'll exit with it. */ - "li.w $a7, 93\n" /* NR_exit == 93 */ - "syscall 0\n" + "move $a0, $sp\n" /* save stack pointer to a0, as arg1 of _start_c*/ + LONG_BSTRINS " $sp, $zero, 3, 0\n" /* sp must be 16-byte aligned */ + "bl _start_c\n" /* transfer to c runtime */ ); __builtin_unreachable(); }