From: Willy Tarreau <w@1wt.eu>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Michal Simek <monstr@monstr.eu>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] tools/nolibc: add support for microblaze
Date: Sat, 5 Dec 2026 15:38:05 +0100 [thread overview]
Message-ID: <axQhzZSXOjL7E03F@1wt.eu> (raw)
In-Reply-To: <20261202-nolibc-microblaze-v1-2-795490036c34@weissschuh.net>
Hi Thomas!
On Wed, Dec 02, 2026 at 06:20:32PM +0100, Thomas Weißschuh wrote:
> Add support for microblaze to nolibc.
>
> QEMU system tests are skipped by default, as there is no clean way to
> signal the shutdown to QEMU. CONFIG_MB_POWER_OFF_THROUGH_UNALIGNED_PC
> works but generates coredumps and ugly output.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> tools/include/nolibc/Makefile | 1 +
> tools/include/nolibc/arch-microblaze.h | 156 +++++++++++++++++++++++++
> tools/include/nolibc/arch.h | 2 +
> tools/testing/selftests/nolibc/Makefile.nolibc | 7 ++
> tools/testing/selftests/nolibc/run-tests.sh | 3 +-
> 5 files changed, 168 insertions(+), 1 deletion(-)
>
> diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
> index 0880be0f6ef5..fe2e7f5cbae4 100644
> --- a/tools/include/nolibc/Makefile
> +++ b/tools/include/nolibc/Makefile
> @@ -24,6 +24,7 @@ architectures := \
> hexagon \
> loongarch \
> m68k \
> + microblaze \
> mips \
> openrisc \
> parisc \
> diff --git a/tools/include/nolibc/arch-microblaze.h b/tools/include/nolibc/arch-microblaze.h
> new file mode 100644
> index 000000000000..54f96ba1b007
> --- /dev/null
> +++ b/tools/include/nolibc/arch-microblaze.h
> @@ -0,0 +1,156 @@
> +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
> +/*
> + * Microblaze specific definitions for NOLIBC
> + * Copyright (C) 2026 Thomas Weißschuh <linux@weissschuh.net>
> + */
> +
> +#ifndef _NOLIBC_ARCH_MICROBLAZE_H
> +#define _NOLIBC_ARCH_MICROBLAZE_H
> +
> +#include "compiler.h"
> +#include "crt.h"
> +
> +/*
> + * Syscalls for Microblaze:
> + * - syscall number is passed in r12
> + * - arguments are in r5, r6, r7, r8, r9, r10
> + * - the system call is performed by calling brki r14,8
> + * - syscall return value is in r3
> + */
> +
> +#define __nolibc_syscall0(num) \
> +({ \
> + register long _num __asm__ ("r12") = (num); \
> + register long _ret __asm__ ("r3"); \
> + \
> + __asm__ volatile ( \
> + "brki r14,8\n" \
> + : "=r"(_ret) \
> + : "r"(_num) \
> + : "r4", "memory" \
> + ); \
> + _ret; \
> +})
> +
> +#define __nolibc_syscall1(num, arg1) \
> +({ \
> + register long _num __asm__ ("r12") = (num); \
> + register long _ret __asm__ ("r3"); \
> + register long _arg1 __asm__ ("r5") = (long)(arg1); \
> + \
> + __asm__ volatile ( \
> + "brki r14,8\n" \
> + : "=r"(_ret) \
> + : "r"(_num), "r"(_arg1) \
> + : "r4", "memory" \
> + ); \
> + _ret; \
> +})
> +
> +#define __nolibc_syscall2(num, arg1, arg2) \
> +({ \
> + register long _num __asm__ ("r12") = (num); \
> + register long _ret __asm__ ("r3"); \
> + register long _arg1 __asm__ ("r5") = (long)(arg1); \
> + register long _arg2 __asm__ ("r6") = (long)(arg2); \
> + \
> + __asm__ volatile ( \
> + "brki r14,8\n" \
> + : "=r"(_ret) \
> + : "r"(_num), "r"(_arg1), "r"(_arg2) \
> + : "r4", "memory" \
> + ); \
> + _ret; \
> +})
> +
> +#define __nolibc_syscall3(num, arg1, arg2, arg3) \
> +({ \
> + register long _num __asm__ ("r12") = (num); \
> + register long _ret __asm__ ("r3"); \
> + register long _arg1 __asm__ ("r5") = (long)(arg1); \
> + register long _arg2 __asm__ ("r6") = (long)(arg2); \
> + register long _arg3 __asm__ ("r7") = (long)(arg3); \
> + \
> + __asm__ volatile ( \
> + "brki r14,8\n" \
> + : "=r"(_ret) \
> + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3) \
> + : "r4", "memory" \
> + ); \
> + _ret; \
> +})
> +
> +#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4) \
> +({ \
> + register long _num __asm__ ("r12") = (num); \
> + register long _ret __asm__ ("r3"); \
> + register long _arg1 __asm__ ("r5") = (long)(arg1); \
> + register long _arg2 __asm__ ("r6") = (long)(arg2); \
> + register long _arg3 __asm__ ("r7") = (long)(arg3); \
> + register long _arg4 __asm__ ("r8") = (long)(arg4); \
> + \
> + __asm__ volatile ( \
> + "brki r14,8\n" \
> + : "=r"(_ret) \
> + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4) \
> + : "r4", "memory" \
> + ); \
> + _ret; \
> +})
> +
> +#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5) \
> +({ \
> + register long _num __asm__ ("r12") = (num); \
> + register long _ret __asm__ ("r3"); \
> + register long _arg1 __asm__ ("r5") = (long)(arg1); \
> + register long _arg2 __asm__ ("r6") = (long)(arg2); \
> + register long _arg3 __asm__ ("r7") = (long)(arg3); \
> + register long _arg4 __asm__ ("r8") = (long)(arg4); \
> + register long _arg5 __asm__ ("r9") = (long)(arg5); \
> + \
> + __asm__ volatile ( \
> + "brki r14,8\n" \
> + : "=r"(_ret) \
> + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
> + "r"(_arg5) \
> + : "r4", "memory" \
> + ); \
> + _ret; \
> +})
> +
> +#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
> +({ \
> + register long _num __asm__ ("r12") = (num); \
> + register long _ret __asm__ ("r3"); \
> + register long _arg1 __asm__ ("r5") = (long)(arg1); \
> + register long _arg2 __asm__ ("r6") = (long)(arg2); \
> + register long _arg3 __asm__ ("r7") = (long)(arg3); \
> + register long _arg4 __asm__ ("r8") = (long)(arg4); \
> + register long _arg5 __asm__ ("r9") = (long)(arg5); \
> + register long _arg6 __asm__ ("r10") = (long)(arg6); \
> + \
> + __asm__ volatile ( \
> + "brki r14,8\n" \
> + : "=r"(_ret) \
> + : "r"(_num), "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), \
> + "r"(_arg5), "r"(_arg6) \
> + : "r4", "memory" \
> + ); \
> + _ret; \
> +})
> +
> +#ifndef NOLIBC_NO_RUNTIME
> +/* startup code */
> +void __attribute__((weak,noreturn))
> +__nolibc_entrypoint __nolibc_no_stack_protector
> +_start(void)
> +{
> + __asm__ volatile (
> + "addi r5, r1, 0\n" /* save stack pointer to r5, as arg1 of _start_c */
> + "bri _start_c\n" /* transfer to c runtime */
> + );
> + __nolibc_entrypoint_epilogue();
> +}
> +#endif /* NOLIBC_NO_RUNTIME */
> +
> +#endif /* _NOLIBC_ARCH_MICROBLAZE_H */
> diff --git a/tools/include/nolibc/arch.h b/tools/include/nolibc/arch.h
> index 79ed5900f2a7..de8cfac5113b 100644
> --- a/tools/include/nolibc/arch.h
> +++ b/tools/include/nolibc/arch.h
> @@ -36,6 +36,8 @@
> #include "arch-alpha.h"
> #elif defined(__hexagon__)
> #include "arch-hexagon.h"
> +#elif defined(__microblaze__)
> +#include "arch-microblaze.h"
> #else
> #error Unsupported Architecture
> #endif
> diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing/selftests/nolibc/Makefile.nolibc
> index 529244356280..1f903057444a 100644
> --- a/tools/testing/selftests/nolibc/Makefile.nolibc
> +++ b/tools/testing/selftests/nolibc/Makefile.nolibc
> @@ -84,6 +84,7 @@ IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi
> IMAGE_sparc32 = arch/sparc/boot/image
> IMAGE_sparc64 = arch/sparc/boot/image
> IMAGE_sh4 = arch/sh/boot/zImage
> +IMAGE_microblaze = arch/microblaze/boot/linux.bin
> IMAGE = $(objtree)/$(or $(IMAGE_$(XARCH)),vmlinux)
> IMAGE_NAME = $(notdir $(IMAGE))
>
> @@ -105,6 +106,7 @@ DEFCONFIG_sparc64 = sparc64_defconfig
> DEFCONFIG_m68k = virt_defconfig
> DEFCONFIG_sh4 = rts7751r2dplus_defconfig
> DEFCONFIG_openrisc = virt_defconfig
> +DEFCONFIG_microblaze = defconfig petalogix-ml605.config
> DEFCONFIG = $(or $(DEFCONFIG_$(XARCH)),defconfig)
>
> EXTRACONFIG_x32 = -e CONFIG_X86_X32_ABI
> @@ -115,6 +117,8 @@ EXTRACONFIG_m68k = -e CONFIG_BLK_DEV_INITRD
> EXTRACONFIG_sh4 = -e CONFIG_BLK_DEV_INITRD -e CONFIG_CMDLINE_FROM_BOOTLOADER
> EXTRACONFIG_alpha = -e CONFIG_BLK_DEV_INITRD
> EXTRACONFIG_parisc64 = -d CONFIG_COMPAT
> +EXTRACONFIG_microblaze= -e CONFIG_BLK_DEV_INITRD -e CONFIG_NAMESPACES -d CONFIG_CMDLINE_BOOL \
> + -e CONFIG_MB_POWER_OFF_THROUGH_UNALIGNED_PC
> EXTRACONFIG = $(EXTRACONFIG_$(XARCH))
>
> # optional tests to run (default = all)
> @@ -142,6 +146,7 @@ QEMU_ARCH = $(or $(QEMU_ARCH_$(XARCH)),$(XARCH))
> QEMU_ARCH_USER_ppc64le = ppc64le
> QEMU_ARCH_USER_mipsn32le = mipsn32el
> QEMU_ARCH_USER_mipsn32be = mipsn32
> +QEMU_ARCH_USER_microblaze = microblazeel
> QEMU_ARCH_USER = $(or $(QEMU_ARCH_USER_$(XARCH)),$(QEMU_ARCH))
>
> QEMU_BIOS_DIR = /usr/share/edk2/
> @@ -180,6 +185,7 @@ QEMU_ARGS_openrisc = -M virt -m 512M -append "console=ttyS0 panic=-1 $(TEST:%=
> QEMU_ARGS_parisc32 = -M B160L -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
> QEMU_ARGS_parisc64 = -M C3700 -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
> QEMU_ARGS_alpha = -M clipper -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
> +QEMU_ARGS_microblaze = -M petalogix-ml605 -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
> QEMU_ARGS = -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
>
> # OUTPUT is only set when run from the main makefile, otherwise
> @@ -213,6 +219,7 @@ CFLAGS_sparc32 = $(call cc-option,-m32) -mcpu=v8
> CFLAGS_sh4 = -ml -m4
> # github.com/llvm/llvm-project/issues/216765
> CFLAGS_hexagon = -fno-sanitize=undefined
> +CFLAGS_microblaze = -mlittle-endian -mno-xl-soft-mul -mno-xl-soft-div -mxl-multiply-high
> ifeq ($(origin XARCH),command line)
> CFLAGS_XARCH = $(CFLAGS_$(XARCH))
> endif
> diff --git a/tools/testing/selftests/nolibc/run-tests.sh b/tools/testing/selftests/nolibc/run-tests.sh
> index cc91b8656b20..30dc022b20b7 100755
> --- a/tools/testing/selftests/nolibc/run-tests.sh
> +++ b/tools/testing/selftests/nolibc/run-tests.sh
> @@ -32,6 +32,7 @@ all_archs=(
> parisc32 parisc64
> alpha
> hexagon
> + microblaze
> )
> archs="${all_archs[@]}"
>
> @@ -221,7 +222,7 @@ test_arch() {
> echo "Unsupported configuration"
> return
> fi
> - if [ -z "$llvm" -o "$test_mode" = "system" ] && [ "$arch" = "hexagon" ]; then
> + if [ -z "$llvm" -o "$test_mode" = "system" ] && [ "$arch" = "hexagon" -o "$arch" = "microblaze" ]; then
> echo "Unsupported configuration"
> return
> fi
While I don't have any opinion on the microblaze-specific details, from
a nolibc perspective, this look good!
Acked-by: Willy Tarreau <w@1wt.eu>
Thanks!
Willy
prev parent reply other threads:[~2026-12-05 14:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 17:20 [PATCH 0/2] " Thomas Weißschuh
2026-12-02 17:20 ` [PATCH 1/2] microblaze: Add a PetaLogix ML605 configuration snippet Thomas Weißschuh
2026-12-02 17:20 ` [PATCH 2/2] tools/nolibc: add support for microblaze Thomas Weißschuh
2026-12-05 14:38 ` Willy Tarreau [this message]
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=axQhzZSXOjL7E03F@1wt.eu \
--to=w@1wt.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=monstr@monstr.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®