public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.org, Willy Tarreau <w@1wt.eu>
Subject: [PATCH v2 02/22] tools/nolibc: enable support for thumb1 mode for ARM
Date: Tue, 10 Jan 2023 08:24:14 +0100	[thread overview]
Message-ID: <20230110072434.3863-3-w@1wt.eu> (raw)
In-Reply-To: <20230110072434.3863-1-w@1wt.eu>

Passing -mthumb to the kernel.org arm toolchain failed to build because it
defaults to armv5 hence thumb1, which has a fairly limited instruction set
compared to thumb2 enabled with armv7 that is much more complete. It's not
very difficult to adjust the instructions to also build on thumb1, it only
adds a total of 3 instructions, so it's worth doing it at least to ease use
by casual testers. It was verified that the adjusted code now builds and
works fine for armv5, thumb1, armv7 and thumb2, as long as frame pointers
are not used.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 tools/include/nolibc/arch-arm.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-arm.h
index 875b21975137..e4ba77b0310f 100644
--- a/tools/include/nolibc/arch-arm.h
+++ b/tools/include/nolibc/arch-arm.h
@@ -180,10 +180,16 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"))) _start(void)
 	__asm__ volatile (
 		"pop {%r0}\n"                 // argc was in the stack
 		"mov %r1, %sp\n"              // argv = sp
-		"add %r2, %r1, %r0, lsl #2\n" // envp = argv + 4*argc ...
-		"add %r2, %r2, $4\n"          //        ... + 4
-		"and %r3, %r1, $-8\n"         // AAPCS : sp must be 8-byte aligned in the
-		"mov %sp, %r3\n"              //         callee, an bl doesn't push (lr=pc)
+
+		"add %r2, %r0, $1\n"          // envp = (argc + 1) ...
+		"lsl %r2, %r2, $2\n"          //        * 4        ...
+		"add %r2, %r2, %r1\n"         //        + argv
+
+		"mov %r3, $8\n"               // AAPCS : sp must be 8-byte aligned in the
+		"neg %r3, %r3\n"              //         callee, and bl doesn't push (lr=pc)
+		"and %r3, %r3, %r1\n"         // so we do sp = r1(=sp) & r3(=-8);
+		"mov %sp, %r3\n"              //
+
 		"bl main\n"                   // main() returns the status code, we'll exit with it.
 		"movs r7, $1\n"               // NR_exit == 1
 		"svc $0x00\n"
-- 
2.17.5


  parent reply	other threads:[~2023-01-10  7:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10  7:24 [PATCH v2 00/22] nolibc: usability improvements (errno, environ, auxv) Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 01/22] tools/nolibc: make compiler and assembler agree on the section around _start Willy Tarreau
2023-01-10  7:24 ` Willy Tarreau [this message]
2023-01-10  7:24 ` [PATCH v2 03/22] tools/nolibc: support thumb mode with frame pointers on ARM Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 04/22] tools/nolibc: remove local definitions of O_* flags for open/fcntl Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 05/22] tools/nolibc: make errno a weak symbol instead of a static one Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 06/22] tools/nolibc: export environ as a weak symbol on x86_64 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 07/22] tools/nolibc: export environ as a weak symbol on i386 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 08/22] tools/nolibc: export environ as a weak symbol on arm64 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 09/22] tools/nolibc: export environ as a weak symbol on arm Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 10/22] tools/nolibc: export environ as a weak symbol on mips Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 11/22] tools/nolibc: export environ as a weak symbol on riscv Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 12/22] tools/nolibc: export environ as a weak symbol on s390 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 13/22] tools/nolibc: add auxiliary vector retrieval for i386 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 14/22] tools/nolibc: add auxiliary vector retrieval for x86_64 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 15/22] tools/nolibc: add auxiliary vector retrieval for arm64 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 16/22] tools/nolibc: add auxiliary vector retrieval for arm Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 17/22] tools/nolibc: add auxiliary vector retrieval for riscv Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 18/22] tools/nolibc: add auxiliary vector retrieval for mips Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 19/22] tools/nolibc: add auxiliary vector retrieval for s390 Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 20/22] nolibc/stdlib: Implement `getauxval(3)` function Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 21/22] nolibc/sys: Implement `getpagesize(2)` function Willy Tarreau
2023-01-10  7:24 ` [PATCH v2 22/22] selftests/nolibc: Add `getpagesize(2)` selftest Willy Tarreau
2023-01-10 22:21 ` [PATCH v2 00/22] nolibc: usability improvements (errno, environ, auxv) Paul E. McKenney

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=20230110072434.3863-3-w@1wt.eu \
    --to=w@1wt.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox