[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <45f8e3a6bef02996cdd97b672b3e350a9a90b626.1688828139.git.falcon@tinylab.org>
Date: Sat, 8 Jul 2023 23:32:09 +0800
From: Zhangjin Wu <falcon@...ylab.org>
To: w@....eu
Cc: falcon@...ylab.org, arnd@...db.de, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, thomas@...ch.de
Subject: [PATCH v2 06/12] tools/nolibc: aarch64/crt.h: shrink _start with _start_c
move most of the _start operations to _start_c().
Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
---
tools/include/nolibc/aarch64/crt.h | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)
diff --git a/tools/include/nolibc/aarch64/crt.h b/tools/include/nolibc/aarch64/crt.h
index 6c81d81cf31f..4e04c421ab63 100644
--- a/tools/include/nolibc/aarch64/crt.h
+++ b/tools/include/nolibc/aarch64/crt.h
@@ -12,26 +12,13 @@ void __attribute__((weak, noreturn, optimize("omit-frame-pointer"))) __no_stack_
{
__asm__ volatile (
#ifdef _NOLIBC_STACKPROTECTOR
- "bl __stack_chk_init\n" /* initialize stack protector */
+ "bl __stack_chk_init\n" /* initialize stack protector */
#endif
- "ldr x0, [sp]\n" /* argc (x0) was in the stack */
- "add x1, sp, 8\n" /* argv (x1) = sp */
- "lsl x2, x0, 3\n" /* envp (x2) = 8*argc ... */
- "add x2, x2, 8\n" /* + 8 (skip null) */
- "add x2, x2, x1\n" /* + argv */
- "adrp x3, environ\n" /* x3 = &environ (high bits) */
- "str x2, [x3, #:lo12:environ]\n" /* store envp into environ */
- "mov x4, x2\n" /* search for auxv (follows NULL after last env) */
- "0:\n"
- "ldr x5, [x4], 8\n" /* x5 = *x4; x4 += 8 */
- "cbnz x5, 0b\n" /* and stop at NULL after last env */
- "adrp x3, _auxv\n" /* x3 = &_auxv (high bits) */
- "str x4, [x3, #:lo12:_auxv]\n" /* store x4 into _auxv */
- "and sp, x1, -16\n" /* sp must be 16-byte aligned in the callee */
- "bl main\n" /* main() returns the status code, we'll exit with it. */
- "mov x8, 93\n" /* NR_exit == 93 */
- "svc #0\n"
+ "mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
+ "and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */
+ "bl _start_c\n" /* transfer to c runtime */
);
__builtin_unreachable();
+
}
#endif /* _NOLIBC_AARCH64_CRT_H */
--
2.25.1
Powered by blists - more mailing lists