mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Willy Tarreau <w@1wt.eu>
Cc: Shuah Khan <shuah@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	 Andreas Larsson <andreas@gaisler.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	 sparclinux@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: Add support for SPARC
Date: Mon, 17 Mar 2025 18:52:57 +0100	[thread overview]
Message-ID: <dacaa712-08a8-4fd6-ad47-2226040f02aa@t-8ch.de> (raw)
In-Reply-To: <20250317073746.GB5114@1wt.eu>

On 2025-03-17 08:37:46+0100, Willy Tarreau wrote:
> On Sun, Mar 16, 2025 at 02:55:02PM +0100, Thomas Weißschuh wrote:
> > Add support for 32bit and 64bit SPARC to nolibc.
> 
> Oh nice!
> 
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> > This is only tested on QEMU.
> > Any tests on real hardware would be very welcome.
> 
> I still have a working U60 here, but under solaris. Such machines are
> not trivial to boot on alternate OSes (and when you find a working
> image usually it's based on an old kernel).

An old kernel should be perfectly fine, no?

> But I've run it under
> Linux 20 years ago, so I know it was supported. I may give it a try
> when I find a moment, but let's not wait for this!

Thanks!

> A few comments below:
> 
> > diff --git a/tools/include/nolibc/arch-sparc.h b/tools/include/nolibc/arch-sparc.h
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..cb5543eca87bb4d52cfba4c0668e35cbbf6dd124
> > --- /dev/null
> > +++ b/tools/include/nolibc/arch-sparc.h
> > @@ -0,0 +1,191 @@
> > +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
> > +/*
> > + * SPARC (32bit and 64bit) specific definitions for NOLIBC
> > + * Copyright (C) 2025 Thomas Weißschuh <linux@weissschuh.net>
> > + */
> > +
> > +#ifndef _NOLIBC_ARCH_SPARC_H
> > +#define _NOLIBC_ARCH_SPARC_H
> > +
> > +#include <linux/unistd.h>
> > +
> > +#include "compiler.h"
> > +#include "crt.h"
> > +
> > +/*
> > + * Syscalls for SPARC:
> > + *   - registers are native word size
> > + *   - syscall number is passed in g1
> > + *   - arguments are in o0-o5
> > + *   - the system call is performed by calling a trap instruction
> > + *   - syscall return value is in 0a
>                                      ^^
> What is "0a" here ? I suspect a typo and you meant "o0".

Correct, will fix.

> > +/* startup code */
> > +void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
> > +{
> > +	__asm__ volatile (
> > +		/*
> > +		 * Save stack pointer to o0, as arg1 of _start_c.
> > +		 * Account for window save area and stack bias.
> > +		 */
> > +#ifdef __arch64__
> > +		"add %sp, 128 + 2047, %o0\n"
> 
> It's really unclear where this magical 2047 comes from, I think it must
> be explained in the comment above so that someone disagreeing with it
> later can figure whether it's right or wrong.

128 is the context window and 2047 is the stack bias.
I'll try to make it clearer.

> 
> > +#else
> > +		"add %sp, 64, %o0\n"
> > +#endif
> 
> Also, I could be wrong, but from my old memories of playing with the
> stack on SPARC long ago, I seem to remember that the stack is growing
> down. Thus I find these "add" suspicious or at least confusing. You
> mention "window save area and stack bias" above, I'm not sure what it
> refers to, but if we can safely erase parts of the stack because too
> much was preserved, maybe some more explanation about the initial and
> target layouts is deserved here.

There is a graphic in the psABI [0] under "Process Stack and Registers".
I'll write something based on that.

> > +		"b,a _start_c\n"     /* transfer to c runtime */
> 
> OK great, the delayed slot is covered! (that type of thing can work
> by pure luck in one test and fail in another one depending on what
> bytes follow the jump).

Yeah, it brings memories to the work on MIPS support.

> Thanks!
> 
> Acked-by: Willy Tarreau <w@1wt.eu>

Thanks!

[0] https://uclibc.org/docs/psABI-sparc.pdf

  reply	other threads:[~2025-03-17 17:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-16 13:55 Thomas Weißschuh
2025-03-17  7:37 ` Willy Tarreau
2025-03-17 17:52   ` Thomas Weißschuh [this message]
2025-03-17 18:14     ` Willy Tarreau
2025-03-18  1:57       ` Chris Torek
2025-03-18  4:10         ` 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=dacaa712-08a8-4fd6-ad47-2226040f02aa@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=andreas@gaisler.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=sparclinux@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®