From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Shuah Khan <shuah@kernel.org>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mips@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] tools/nolibc: add support for N64 and N32 ABIs
Date: Sun, 16 Feb 2025 10:49:38 +0100 [thread overview]
Message-ID: <20250216094938.GB2192@1wt.eu> (raw)
In-Reply-To: <20250212-nolibc-mips-n32-v1-1-6892e58d1321@weissschuh.net>
On Wed, Feb 12, 2025 at 07:49:53PM +0100, Thomas Weißschuh wrote:
> +#if defined(_ABIO32)
> +
> #define _NOLIBC_SYSCALL_CLOBBERLIST \
> "memory", "cc", "at", "v1", "hi", "lo", \
> "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9"
> +#define _NOLIBC_SYSCALL_STACK_RESERVE "addiu $sp, $sp, -32\n"
> +#define _NOLIBC_SYSCALL_STACK_UNRESERVE "addiu $sp, $sp, 32\n"
> +
> +#elif defined(_ABIN32) || defined(_ABI64)
> +
> +/* binutils, GCC and clang disagree about register aliases, use numbers instead. */
Is this often encountered despite this ? I guess it can cause portability
issues :-/
> +#if defined(_ABIO32)
> +
> #define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
> ({ \
> register long _num __asm__ ("v0") = (num); \
(...)
> @@ -178,6 +201,50 @@
> _arg4 ? -_num : _num; \
> })
>
> +#else
> +
Here you should indicate which ABI is covered by this #else, because one
has to go up to previous definitions to figure it's _ABIN32 and _ABI64.
> +#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
> +({ \
> + register long _num __asm__ ("v0") = (num); \
> + register long _arg1 __asm__ ("$4") = (long)(arg1); \
> + register long _arg2 __asm__ ("$5") = (long)(arg2); \
> + register long _arg3 __asm__ ("$6") = (long)(arg3); \
> + register long _arg4 __asm__ ("$7") = (long)(arg4); \
> + register long _arg5 __asm__ ("$8") = (long)(arg5); \
(...)
> @@ -190,13 +257,33 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __
> "1:\n"
> ".cpload $ra\n"
> "move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
> +
> +#if defined(_ABIO32)
> "addiu $sp, $sp, -4\n" /* space for .cprestore to store $gp */
> ".cprestore 0\n"
> "li $t0, -8\n"
> "and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */
> "addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */
> - "lui $t9, %hi(_start_c)\n" /* ABI requires current function address in $t9 */
> +#else
So same here. I think you should do it for all #else since you're generally
grouping 2 ABIs vs one between a #if and a #else and it's not trivial to
figure what a #else covers, like below.
> + "daddiu $sp, $sp, -8\n" /* space for .cprestore to store $gp */
> + ".cpsetup $ra, 0, 1b\n"
> + "li $t0, -16\n"
> + "and $sp, $sp, $t0\n" /* $sp must be 16-byte aligned */
> +#endif
> +
> + /* ABI requires current function address in $t9 */
> +#if defined(_ABIO32) || defined(_ABIN32)
> + "lui $t9, %hi(_start_c)\n"
> "ori $t9, %lo(_start_c)\n"
> +#else
This one indeed covers only _ABI64
> + "lui $t9, %highest(_start_c)\n"
> + "ori $t9, %higher(_start_c)\n"
> + "dsll $t9, 0x10\n"
> + "ori $t9, %hi(_start_c)\n"
> + "dsll $t9, 0x10\n"
> + "ori $t9, %lo(_start_c)\n"
> +#endif
With the tiny details above, this looks fine. It's great that syscall
numbers didn't change so that you can cover an extra arch with only a
few ifdefs. I have not tested but I guess you did :-) So that's OK for
me:
Acked-by: Willy Tarreau <w@1wt.eu>
Thanks!
Willy
next prev parent reply other threads:[~2025-02-16 9:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 18:49 [PATCH] tools/nolibc: add support for N64 and N32 ABIs Thomas Weißschuh
2025-02-16 9:49 ` Willy Tarreau [this message]
2025-02-17 21:26 ` Thomas Weißschuh
2025-02-16 15:41 ` Maciej W. Rozycki
2025-02-17 21:41 ` Thomas Weißschuh
2025-02-17 23:23 ` Maciej W. Rozycki
2025-02-18 4:52 ` Willy Tarreau
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=20250216094938.GB2192@1wt.eu \
--to=w@1wt.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=llvm@lists.linux.dev \
--cc=shuah@kernel.org \
--cc=tsbogend@alpha.franken.de \
/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