From: Zhangjin Wu <falcon@tinylab.org> 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 10/11] tools/nolibc: riscv: shrink _start with _start_c Date: Thu, 29 Jun 2023 03:04:12 +0800 [thread overview] Message-ID: <4a6e7245c3aa07eb20fd6c6aa43bc663e480e0c5.1687976753.git.falcon@tinylab.org> (raw) In-Reply-To: <cover.1687976753.git.falcon@tinylab.org> Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu <falcon@tinylab.org> --- tools/include/nolibc/arch-riscv.h | 42 ++++--------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index 7f4abcc15206..ec0f9c597d0b 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -9,18 +9,6 @@ #include "compiler.h" -#if __riscv_xlen == 64 -#define PTRLOG "3" -#define SZREG "8" -#define REG_L "ld" -#define REG_S "sd" -#elif __riscv_xlen == 32 -#define PTRLOG "2" -#define SZREG "4" -#define REG_L "lw" -#define REG_S "sw" -#endif - /* Syscalls for RISCV : * - stack is 16-byte aligned * - syscall number is passed in a7 @@ -153,40 +141,20 @@ _arg1; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void) { __asm__ volatile ( ".option push\n" ".option norelax\n" - "lla gp, __global_pointer$\n" + "lla gp, __global_pointer$\n" ".option pop\n" #ifdef _NOLIBC_STACKPROTECTOR - "call __stack_chk_init\n" /* initialize stack protector */ + "call __stack_chk_init\n" /* initialize stack protector */ #endif - REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack */ - "add a1, sp, "SZREG"\n" /* argv (a1) = sp */ - "slli a2, a0, "PTRLOG"\n" /* envp (a2) = SZREG*argc ... */ - "add a2, a2, "SZREG"\n" /* + SZREG (skip null) */ - "add a2,a2,a1\n" /* + argv */ - - "add a3, a2, zero\n" /* iterate a3 over envp to find auxv (after NULL) */ - "0:\n" /* do { */ - REG_L" a4, 0(a3)\n" /* a4 = *a3; */ - "add a3, a3, "SZREG"\n" /* a3 += sizeof(void*); */ - "bne a4, zero, 0b\n" /* } while (a4); */ - "lui a4, %hi(_auxv)\n" /* a4 = &_auxv (high bits) */ - REG_S" a3, %lo(_auxv)(a4)\n" /* store a3 into _auxv */ - - "lui a3, %hi(environ)\n" /* a3 = &environ (high bits) */ - REG_S" a2,%lo(environ)(a3)\n"/* store envp(a2) into environ */ - "andi sp,a1,-16\n" /* sp must be 16-byte aligned */ - "call main\n" /* main() returns the status code, we'll exit with it. */ - "li a7, 93\n" /* NR_exit == 93 */ - "ecall\n" + "mv a0, sp\n" /* save stack pointer to a0, as arg1 of _start_c*/ + "andi sp, a0, -16\n" /* sp must be 16-byte aligned */ + "call _start_c\n" /* transfer to c runtime */ ); __builtin_unreachable(); } -- 2.25.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Zhangjin Wu <falcon@tinylab.org> 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 10/11] tools/nolibc: riscv: shrink _start with _start_c Date: Thu, 29 Jun 2023 03:04:12 +0800 [thread overview] Message-ID: <4a6e7245c3aa07eb20fd6c6aa43bc663e480e0c5.1687976753.git.falcon@tinylab.org> (raw) In-Reply-To: <cover.1687976753.git.falcon@tinylab.org> Let's move most of the _start operations to _start_c(). Signed-off-by: Zhangjin Wu <falcon@tinylab.org> --- tools/include/nolibc/arch-riscv.h | 42 ++++--------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h index 7f4abcc15206..ec0f9c597d0b 100644 --- a/tools/include/nolibc/arch-riscv.h +++ b/tools/include/nolibc/arch-riscv.h @@ -9,18 +9,6 @@ #include "compiler.h" -#if __riscv_xlen == 64 -#define PTRLOG "3" -#define SZREG "8" -#define REG_L "ld" -#define REG_S "sd" -#elif __riscv_xlen == 32 -#define PTRLOG "2" -#define SZREG "4" -#define REG_L "lw" -#define REG_S "sw" -#endif - /* Syscalls for RISCV : * - stack is 16-byte aligned * - syscall number is passed in a7 @@ -153,40 +141,20 @@ _arg1; \ }) -char **environ __attribute__((weak)); -const unsigned long *_auxv __attribute__((weak)); - /* startup code */ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) __no_stack_protector _start(void) { __asm__ volatile ( ".option push\n" ".option norelax\n" - "lla gp, __global_pointer$\n" + "lla gp, __global_pointer$\n" ".option pop\n" #ifdef _NOLIBC_STACKPROTECTOR - "call __stack_chk_init\n" /* initialize stack protector */ + "call __stack_chk_init\n" /* initialize stack protector */ #endif - REG_L" a0, 0(sp)\n" /* argc (a0) was in the stack */ - "add a1, sp, "SZREG"\n" /* argv (a1) = sp */ - "slli a2, a0, "PTRLOG"\n" /* envp (a2) = SZREG*argc ... */ - "add a2, a2, "SZREG"\n" /* + SZREG (skip null) */ - "add a2,a2,a1\n" /* + argv */ - - "add a3, a2, zero\n" /* iterate a3 over envp to find auxv (after NULL) */ - "0:\n" /* do { */ - REG_L" a4, 0(a3)\n" /* a4 = *a3; */ - "add a3, a3, "SZREG"\n" /* a3 += sizeof(void*); */ - "bne a4, zero, 0b\n" /* } while (a4); */ - "lui a4, %hi(_auxv)\n" /* a4 = &_auxv (high bits) */ - REG_S" a3, %lo(_auxv)(a4)\n" /* store a3 into _auxv */ - - "lui a3, %hi(environ)\n" /* a3 = &environ (high bits) */ - REG_S" a2,%lo(environ)(a3)\n"/* store envp(a2) into environ */ - "andi sp,a1,-16\n" /* sp must be 16-byte aligned */ - "call main\n" /* main() returns the status code, we'll exit with it. */ - "li a7, 93\n" /* NR_exit == 93 */ - "ecall\n" + "mv a0, sp\n" /* save stack pointer to a0, as arg1 of _start_c*/ + "andi sp, a0, -16\n" /* sp must be 16-byte aligned */ + "call _start_c\n" /* transfer to c runtime */ ); __builtin_unreachable(); } -- 2.25.1
next prev parent reply other threads:[~2023-06-28 19:05 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-28 18:50 [PATCH v1 00/11] tools/nolibc: shrink arch support Zhangjin Wu 2023-06-28 18:50 ` Zhangjin Wu 2023-06-28 18:51 ` [PATCH v1 01/11] tools/nolibc: remove old arch specific stat support Zhangjin Wu 2023-06-28 18:51 ` Zhangjin Wu 2023-06-28 18:53 ` [PATCH v1 02/11] tools/nolibc: add new crt.h with _start_c Zhangjin Wu 2023-06-28 18:53 ` Zhangjin Wu 2023-06-28 18:54 ` [PATCH v1 03/11] tools/nolibc: include crt.h before arch.h Zhangjin Wu 2023-06-28 18:54 ` Zhangjin Wu 2023-07-02 18:57 ` Thomas Weißschuh 2023-07-02 18:57 ` Thomas Weißschuh 2023-07-03 9:58 ` Zhangjin Wu 2023-07-03 9:58 ` Zhangjin Wu 2023-07-03 10:11 ` Thomas Weißschuh 2023-07-03 10:11 ` Thomas Weißschuh 2023-07-03 14:55 ` Zhangjin Wu 2023-07-03 14:55 ` Zhangjin Wu 2023-06-28 18:55 ` [PATCH v1 04/11] tools/nolibc: arm: shrink _start with _start_c Zhangjin Wu 2023-06-28 18:55 ` Zhangjin Wu 2023-06-28 18:57 ` [PATCH v1 05/11] tools/nolibc: aarch64: " Zhangjin Wu 2023-06-28 18:57 ` Zhangjin Wu 2023-06-28 18:58 ` [PATCH v1 06/11] tools/nolibc: i386: " Zhangjin Wu 2023-06-28 18:58 ` Zhangjin Wu 2023-06-28 18:59 ` [PATCH v1 07/11] tools/nolibc: x86_64: " Zhangjin Wu 2023-06-28 18:59 ` Zhangjin Wu 2023-06-28 19:01 ` [PATCH v1 08/11] tools/nolibc: mips: " Zhangjin Wu 2023-06-28 19:01 ` Zhangjin Wu 2023-06-28 19:02 ` [PATCH v1 09/11] tools/nolibc: loongarch: " Zhangjin Wu 2023-06-28 19:02 ` Zhangjin Wu 2023-06-28 19:04 ` Zhangjin Wu [this message] 2023-06-28 19:04 ` [PATCH v1 10/11] tools/nolibc: riscv: " Zhangjin Wu 2023-06-28 19:06 ` [PATCH v1 11/11] tools/nolibc: s390: " Zhangjin Wu 2023-06-28 19:06 ` Zhangjin Wu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=4a6e7245c3aa07eb20fd6c6aa43bc663e480e0c5.1687976753.git.falcon@tinylab.org \ --to=falcon@tinylab.org \ --cc=arnd@arndb.de \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-kselftest@vger.kernel.org \ --cc=linux-riscv@lists.infradead.org \ --cc=thomas@t-8ch.de \ --cc=w@1wt.eu \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.