From patchwork Wed Jul 12 09:24:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 119020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1025690vqm; Wed, 12 Jul 2023 02:35:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlFrqdKd0XwEK+WSDzMU5fUoo4OSL4GNx+J5dr0yzgcHiZGMKh0xwMRwUJH30/r1rezpySDI X-Received: by 2002:a05:6a00:22c7:b0:67f:830f:b809 with SMTP id f7-20020a056a0022c700b0067f830fb809mr2105801pfj.3.1689154554576; Wed, 12 Jul 2023 02:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689154554; cv=none; d=google.com; s=arc-20160816; b=PttcY/wnHo0EBcul1IkZpNjSC3WROHSApZ27meZ/SrMT7idx1p/FhZZzQ8kEqgwNn2 DKpCGkjzMVdUp3E2fbLGQDaG4539R1J7Pz/3uyiagJJyVzf7vjs3b+SQ33S/WQnH1yPR VfaQ37c/RiLn6U3kDHypPSo5l6fcSJD+OH/LlVN3BewX3oRe8QqS/z1IcfaxkNeyIfTX dW62Qxo1z281MuXAqf7QVRXMP+KFQgKFT81BeJRlR9Fe6+GHXGYdtcVXp5FTTfotLnvR UQIzYIpRxQGX8qpWUA6Kbtr4McXU5+1rtejKn9M+7a0pjazzsI1vpa0/RFASuRuK2Gc3 ywLA== 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=kFPQVgN8PsnbcREpkCqGZoqolJD3mtGhwi9rakRiV38=; fh=kgRNfNE6xRCHBUX3iUlrLhv5pQPglsdZFzOkxo2Fhpc=; b=YLb6BZCjC6i7kdwG24fHWPptbV5PdWnt+mny4R2M8gNtGazfeXelOflpYCv5J8J/hU GqOqjIV1W/c872KAsorKgHBBgd+gY4OJl10+gSk6gjH5Q8GN3ZfYZOq2Sf0jIJdW7WUJ qK193NbW3TvUxwRQillk/9CPSmpFaJNgOnspDaM3yETJd9kRVJEihWnVqnuiy9jWjSpd w7fvaSmqAzIj/lO/o3dbeBTjGxUojK0+jDMSSRL8PQswPoLCgjk4Cft8zhxXWkt5RsFX 3asCJKvIwuAcwGanJgzpQ/Hd9oYk+5QOtwspt7IMpQ1KFtAql22pjB2VuMRN+glYeb3F MmWg== 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 fe10-20020a056a002f0a00b006778c5e02afsi2855661pfb.362.2023.07.12.02.35.41; Wed, 12 Jul 2023 02:35:54 -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 S232324AbjGLJYr (ORCPT + 99 others); Wed, 12 Jul 2023 05:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbjGLJYm (ORCPT ); Wed, 12 Jul 2023 05:24:42 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 508741995; Wed, 12 Jul 2023 02:24:21 -0700 (PDT) X-QQ-mid: bizesmtp74t1689153852t7x4q3lf Received: from linux-lab-host.localdomain ( [116.30.126.249]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Jul 2023 17:24:11 +0800 (CST) X-QQ-SSF: 01200000000000D0W000000A0000000 X-QQ-FEAT: 7jw2iSiCazrYV30tqA3rE/xk9YB446MUEUfOtIQC4wAExzPRDbLzHgqE9b1Zm I2p1W+qGWca7sApfHy5SvhFkO0VunsETK7Kh6N1KjRgGEML/roQB+/F3p2X5KQi+yZ6I6pn VDhAESpTzlhYjfrbcCTKuk4qQFv7NakQVLs4DfRuKxJh94TpZ7f/Kfze+ix2Xvs3jwywbGh f86pV5ZP07NUwLipz5WQ1YsOO/PAZ0TTVe3dRXV30dTX+lpkzmsAHxwlV9K+XTzy7sTPCSm wqpSMKNNifEA6EKAOzW318c5AIxixFcA2fUwQcFlp16BhrNTYFL+oUyy85nhbLZ/4ptyTw9 hPYb/Sy2GUraSshYqx8VlvVnSuSoesUATEcQTFy1SUGVO/JwtkBoFZJkkUM5A== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 17383144857410459709 From: Zhangjin Wu To: w@1wt.eu Cc: falcon@tinylab.org, arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, thomas@t-8ch.de Subject: [PATCH v3 08/11] tools/nolibc: loongarch: shrink _start with _start_c Date: Wed, 12 Jul 2023 17:24:10 +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 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: 1771206926443615049 X-GMAIL-MSGID: 1771206926443615049 move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu --- tools/include/nolibc/arch-loongarch.h | 43 ++++----------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/tools/include/nolibc/arch-loongarch.h b/tools/include/nolibc/arch-loongarch.h index 8aa7724fe38e..9db70d6f2c31 100644 --- a/tools/include/nolibc/arch-loongarch.h +++ b/tools/include/nolibc/arch-loongarch.h @@ -8,6 +8,7 @@ #define _NOLIBC_ARCH_LOONGARCH_H #include "compiler.h" +#include "crt.h" /* Syscalls for LoongArch : * - stack is 16-byte aligned @@ -143,26 +144,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 @@ -171,28 +155,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(); }