[PATCH 2/2] tools/nolibc: add support for microblaze
From: Thomas Weißschuh
Date: Wed Dec 02 2026 - 12:21:18 EST
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@xxxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxxx>
+ */
+
+#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
--
2.56.1