All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Willy Tarreau <w@1wt.eu>, Daniel Palmer <daniel@thingy.jp>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/7] tools/nolibc: handle 64-bit system call arguments on MIPS N32
Date: Sat, 18 Apr 2026 17:32:44 +0100	[thread overview]
Message-ID: <20260418173244.0f9c970a@pumpkin> (raw)
In-Reply-To: <e0c9710e-67b5-49c8-a496-d6b7f30563e7@weissschuh.net>

On Sat, 18 Apr 2026 13:54:55 +0200
Thomas Weißschuh <linux@weissschuh.net> wrote:

> Hey David,
> 
> Apr 18, 2026 13:14:46 David Laight <david.laight.linux@gmail.com>:
> 
> > On Sat, 18 Apr 2026 12:20:00 +0200
> > Thomas Weißschuh <linux@weissschuh.net> wrote:
> >  
> >> The N32 system call ABI expects 64-bit values directly in registers.
> >> This does not work on nolibc currently, as a 'long' is only 32 bits
> >> wide. Switch the system call wrappers to use 'long long' instead which
> >> can handle 64-bit values on N32. As on N64 'long' and 'long long' are
> >> the same, this does not change the behavior there.
> >>
> >> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> >> ---
> >> tools/include/nolibc/arch-mips.h | 94 +++++++++++++++++++++-------------------
> >> 1 file changed, 49 insertions(+), 45 deletions(-)
> >>
> >> diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h
> >> index bb9d580ea1b1..557ef34d9df8 100644
> >> --- a/tools/include/nolibc/arch-mips.h
> >> +++ b/tools/include/nolibc/arch-mips.h
> >> @@ -55,6 +55,8 @@
> >> #define _NOLIBC_SYSCALL_STACK_RESERVE "addiu $sp, $sp, -32\n"
> >> #define _NOLIBC_SYSCALL_STACK_UNRESERVE "addiu $sp, $sp, 32\n"
> >>
> >> +#define _NOLIBC_SYSCALL_REG register long
> >> +
> >> #else /* _ABIN32 || _ABI64 */
> >>
> >> /* binutils, GCC and clang disagree about register aliases, use numbers instead. */
> >> @@ -66,12 +68,14 @@
> >> #define _NOLIBC_SYSCALL_STACK_RESERVE
> >> #define _NOLIBC_SYSCALL_STACK_UNRESERVE
> >>
> >> +#define _NOLIBC_SYSCALL_REG register long long
> >> +
> >> #endif /* _ABIO32 */  
> >
> > Since you need to use a #define, did you think about:
> > #define _NOLIBC_SYSCALL_REG(var, reg) register long long var __asm__ (reg)
> > to shorten the lines and the repetitive pattern.  
> 
> I didn't think of this.
> Personally I am fine with both variants.
> The parameterized macro is a bit weird
> is it breaks the normal syntax.
> Let's wait what Willy thinks.

Actually you could take it one stage further:
#define _NOLIBC_SYSCALL_REG(reg) register long long _##reg __asm__ (#reg)
So you'd have:
	_NOLIBC_SYSCALL_REG(a0) = (cast)(arg1);
I'd then use "+r" (_v0), "+r" (_a3).

For the variables that get pushed use the [name] syntax to avoid counting,
they also don't need (well shouldn't need) a local variable - the cast
can be included on the asm line. Giving:
	"sw %[arg5], 16($sp)\n"
	...
	[arg5]"r"((long)(arg5), ...
(Does look like those are all 32bit only, so the (long) cast is correct.)

	David

> 
> >> #define __nolibc_syscall0(num)                                                \
> >> ({                                                                            \
> >> -   register long _num __asm__ ("v0") = (num);                            \
> >> -   register long _arg4 __asm__ ("a3");                                   \
> >> +   _NOLIBC_SYSCALL_REG _num __asm__ ("v0")  = (num);                     \
> >> +   _NOLIBC_SYSCALL_REG _arg4 __asm__ ("a3");                             \  
> >
> >     __NOLIBC_SYSCALL_REG(_num, "v0") = (num);
> >     __NOLIBC_SYSCALL_REG(_arg4, "a3");
> >
> > ...
> >
> >     David  
> 
> 


  reply	other threads:[~2026-04-18 16:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-18 10:19 [PATCH 0/7] tools/nolibc: large file support Thomas Weißschuh
2026-04-18 10:19 ` [PATCH 1/7] tools/nolibc: also handle _llseek system call Thomas Weißschuh
2026-04-18 11:23   ` David Laight
2026-04-18 11:56     ` Thomas Weißschuh
2026-04-18 16:03       ` David Laight
2026-04-19 15:22         ` Willy Tarreau
2026-04-19 15:38           ` Thomas Weißschuh
2026-04-19 16:10             ` Willy Tarreau
2026-04-18 10:19 ` [PATCH 2/7] tools/nolibc: add __nolibc_arg_to_reg() Thomas Weißschuh
2026-04-18 10:19 ` [PATCH 3/7] tools/nolibc: cast pointers returned from system calls through integers Thomas Weißschuh
2026-04-18 10:19 ` [PATCH 4/7] tools/nolibc: handle 64-bit system call arguments on x32 Thomas Weißschuh
2026-04-18 10:20 ` [PATCH 5/7] tools/nolibc: handle 64-bit system call arguments on MIPS N32 Thomas Weißschuh
2026-04-18 11:14   ` David Laight
2026-04-18 11:54     ` Thomas Weißschuh
2026-04-18 16:32       ` David Laight [this message]
2026-04-19 15:30       ` Willy Tarreau
2026-04-19 21:35         ` David Laight
2026-04-20 15:58           ` Thomas Weißschuh
2026-04-18 10:20 ` [PATCH 6/7] tools/nolibc: open files with O_LARGEFILE Thomas Weißschuh
2026-04-18 10:20 ` [PATCH 7/7] selftests/nolibc: test large file support Thomas Weißschuh
2026-04-18 14:01 ` [PATCH 0/7] tools/nolibc: " Daniel Palmer
2026-04-19 15:31 ` 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=20260418173244.0f9c970a@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=daniel@thingy.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --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: link
Be 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.