]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/nolibc: add support for Alpha
authorThomas Weißschuh <linux@weissschuh.net>
Tue, 21 Jul 2026 22:07:05 +0000 (00:07 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Sun, 2 Aug 2026 07:30:55 +0000 (09:30 +0200)
A straightforward new architecture.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Tested-by: Michael Cree <mcree@orcon.net.nz>
Link: https://patch.msgid.link/20260722-nolibc-alpha-v2-1-4970e48eb7bf@weissschuh.net
tools/include/nolibc/Makefile
tools/include/nolibc/arch-alpha.h [new file with mode: 0644]
tools/include/nolibc/arch.h
tools/testing/selftests/nolibc/Makefile.nolibc
tools/testing/selftests/nolibc/nolibc-test.c
tools/testing/selftests/nolibc/run-tests.sh

index 00fd2e566d755956118b9767acae952827a1173e..6d213d372bf835a93b7a983a49493bd52c7256f0 100644 (file)
@@ -17,7 +17,7 @@ endif
 # it defaults to this nolibc directory.
 OUTPUT ?= $(CURDIR)/
 
-architectures := arm arm64 loongarch m68k mips openrisc parisc powerpc riscv s390 sh sparc x86
+architectures := alpha arm arm64 loongarch m68k mips openrisc parisc powerpc riscv s390 sh sparc x86
 arch_files := arch.h $(addsuffix .h, $(addprefix arch-, $(architectures)))
 all_files := \
                alloca.h \
diff --git a/tools/include/nolibc/arch-alpha.h b/tools/include/nolibc/arch-alpha.h
new file mode 100644 (file)
index 0000000..04ff8a9
--- /dev/null
@@ -0,0 +1,159 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * Alpha specific definitions for NOLIBC
+ * Copyright (C) 2025 Thomas Weißschuh <linux@weissschuh.net>
+ */
+
+#ifndef _NOLIBC_ARCH_ALPHA_H
+#define _NOLIBC_ARCH_ALPHA_H
+
+#include "compiler.h"
+#include "crt.h"
+
+/*
+ * Syscalls for Alpha:
+ *   - registers are 64-bit
+ *   - syscall number is passed in $0/v0
+ *   - the system call is performed by calling callsys
+ *   - syscall return comes in $0/v0, error flag in $19/a3
+ *   - arguments are passed in $16/a0 to $21/a5
+ *   - GCC does not support symbol register names
+ */
+
+#define _NOLIBC_SYSCALL_CLOBBERLIST \
+       "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
+       "$22", "$23", "$24", "$25", "$27", "$28", "memory", "cc"
+
+#define __nolibc_syscall0(num)                                                \
+({                                                                            \
+       register long _num __asm__ ("$0") = (num);                            \
+       register long _err __asm__ ("$19");                                   \
+                                                                              \
+       __asm__ volatile (                                                    \
+               "callsys"                                                     \
+               : "+r"(_num), "=r"(_err)                                      \
+               :                                                             \
+               : _NOLIBC_SYSCALL_CLOBBERLIST,                                \
+                 "$16", "$17", "$18", "$20", "$21"                           \
+       );                                                                    \
+       _err ? -_num : _num;                                                  \
+})
+
+#define __nolibc_syscall1(num, arg1)                                          \
+({                                                                            \
+       register long _num __asm__ ("$0") = (num);                            \
+       register long _err __asm__ ("$19");                                   \
+       register long _arg1 __asm__ ("$16") = (long)(arg1);                   \
+                                                                              \
+       __asm__ volatile (                                                    \
+               "callsys"                                                     \
+               : "+r"(_num), "=r"(_err)                                      \
+               : "r"(_arg1)                                                  \
+               : _NOLIBC_SYSCALL_CLOBBERLIST, "$17", "$18", "$20", "$21"     \
+       );                                                                    \
+       _err ? -_num : _num;                                                  \
+})
+
+#define __nolibc_syscall2(num, arg1, arg2)                                    \
+({                                                                            \
+       register long _num __asm__ ("$0") = (num);                            \
+       register long _err __asm__ ("$19");                                   \
+       register long _arg1 __asm__ ("$16") = (long)(arg1);                   \
+       register long _arg2 __asm__ ("$17") = (long)(arg2);                   \
+                                                                              \
+       __asm__ volatile (                                                    \
+               "callsys"                                                     \
+               : "+r"(_num), "=r"(_err)                                      \
+               : "r"(_arg1), "r"(_arg2)                                      \
+               : _NOLIBC_SYSCALL_CLOBBERLIST, "$18", "$20", "$21"            \
+       );                                                                    \
+       _err ? -_num : _num;                                                  \
+})
+
+#define __nolibc_syscall3(num, arg1, arg2, arg3)                              \
+({                                                                            \
+       register long _num __asm__ ("$0") = (num);                            \
+       register long _err __asm__ ("$19");                                   \
+       register long _arg1 __asm__ ("$16") = (long)(arg1);                   \
+       register long _arg2 __asm__ ("$17") = (long)(arg2);                   \
+       register long _arg3 __asm__ ("$18") = (long)(arg3);                   \
+                                                                              \
+       __asm__ volatile (                                                    \
+               "callsys"                                                     \
+               : "+r"(_num), "=r"(_err)                                      \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3)                          \
+               : _NOLIBC_SYSCALL_CLOBBERLIST, "$20", "$21"                   \
+       );                                                                    \
+       _err ? -_num : _num;                                                  \
+})
+
+#define __nolibc_syscall4(num, arg1, arg2, arg3, arg4)                        \
+({                                                                            \
+       register long _num __asm__ ("$0") = (num);                            \
+       register long _arg1 __asm__ ("$16") = (long)(arg1);                   \
+       register long _arg2 __asm__ ("$17") = (long)(arg2);                   \
+       register long _arg3 __asm__ ("$18") = (long)(arg3);                   \
+       register long _arg4 __asm__ ("$19") = (long)(arg4);                   \
+                                                                              \
+       __asm__ volatile (                                                    \
+               "callsys"                                                     \
+               : "+r"(_num), "+r"(_arg4)                                     \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3)                          \
+               : _NOLIBC_SYSCALL_CLOBBERLIST, "$20", "$21"                   \
+       );                                                                    \
+       _arg4 ? -_num : _num;                                                 \
+})
+
+#define __nolibc_syscall5(num, arg1, arg2, arg3, arg4, arg5)                  \
+({                                                                            \
+       register long _num __asm__ ("$0") = (num);                            \
+       register long _arg1 __asm__ ("$16") = (long)(arg1);                   \
+       register long _arg2 __asm__ ("$17") = (long)(arg2);                   \
+       register long _arg3 __asm__ ("$18") = (long)(arg3);                   \
+       register long _arg4 __asm__ ("$19") = (long)(arg4);                   \
+       register long _arg5 __asm__ ("$20") = (long)(arg5);                   \
+                                                                              \
+       __asm__ volatile (                                                    \
+               "callsys"                                                     \
+               : "+r"(_num), "+r"(_arg4)                                     \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg5)              \
+               : _NOLIBC_SYSCALL_CLOBBERLIST, "$21"                          \
+       );                                                                    \
+       _arg4 ? -_num : _num;                                                 \
+})
+
+#define __nolibc_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6)            \
+({                                                                            \
+       register long _num __asm__ ("$0") = (num);                            \
+       register long _arg1 __asm__ ("$16") = (long)(arg1);                   \
+       register long _arg2 __asm__ ("$17") = (long)(arg2);                   \
+       register long _arg3 __asm__ ("$18") = (long)(arg3);                   \
+       register long _arg4 __asm__ ("$19") = (long)(arg4);                   \
+       register long _arg5 __asm__ ("$20") = (long)(arg5);                   \
+       register long _arg6 __asm__ ("$21") = (long)(arg6);                   \
+                                                                              \
+       __asm__ volatile (                                                    \
+               "callsys"                                                     \
+               : "+r"(_num), "+r"(_arg4)                                     \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg5),             \
+                 "r"(_arg6)                                                  \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _arg4 ? -_num : _num;                                                 \
+})
+
+/* startup code */
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __nolibc_no_stack_protector
+_start(void)
+{
+       __asm__ volatile (
+               "br $gp, 0f\n"               /* setup $gp, so that 'lda' works                */
+               "0: ldgp $gp, 0($gp)\n"
+               "lda $27, _start_c\n"        /* setup current function address for _start_c   */
+               "mov $sp, $16\n"             /* save argc pointer to $16, as arg1 of _start_c */
+               "br  _start_c\n"             /* transfer to c runtime                         */
+       );
+       __nolibc_entrypoint_epilogue();
+}
+
+#endif /* _NOLIBC_ARCH_ALPHA_H */
index b69d9c5ec5c6a7421c69bd7798b21cc8f57ad78c..06cc2dbe7a33055a342cf9ade604bc4f025a90e2 100644 (file)
@@ -32,6 +32,8 @@
 #include "arch-openrisc.h"
 #elif defined(__hppa__)
 #include "arch-parisc.h"
+#elif defined(__alpha__)
+#include "arch-alpha.h"
 #else
 #error Unsupported Architecture
 #endif
index 06f881e2e90c307a3183d163d49467104cd8e651..f70c8dfca01869d5f4d8328916c5d0e6a7f102e8 100644 (file)
@@ -112,6 +112,7 @@ EXTRACONFIG_armthumb  = -e CONFIG_NAMESPACES
 EXTRACONFIG_sparc32   = -e CONFIG_TMPFS
 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           = $(EXTRACONFIG_$(XARCH))
 
 # optional tests to run (default = all)
@@ -174,6 +175,7 @@ QEMU_ARGS_m68k       = -M virt -append "console=ttyGF0,115200 panic=-1 $(TEST:%=
 QEMU_ARGS_sh4        = -M r2d -serial file:/dev/stdout -append "console=ttySC1,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
 QEMU_ARGS_openrisc   = -M virt -m 512M -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
 QEMU_ARGS_parisc32   = -M B160L -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
+QEMU_ARGS_alpha      = -M clipper -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
index 996e8d13508e2eb874cd3d4c3e066c59b8f1e151..ed860b0a15a1e56c59eb54e3e2c9f986526ffd9f 100644 (file)
@@ -756,6 +756,10 @@ int run_startup(int min, int max)
        /* checking NULL for argv/argv0, environ and _auxv is not enough, let's compare with sbrk(0) or &end */
        extern char end;
        char *brk = sbrk(0) != (void *)-1 ? sbrk(0) : &end;
+#if defined(__alpha__)
+       /* the ordering above does not work on an alpha kernel due to STACK_TOP != TASK_SIZE */
+       brk = NULL;
+#endif
        /* differ from nolibc, both glibc and musl have no global _auxv */
        const unsigned long *test_auxv = (void *)-1;
 #ifdef NOLIBC
index 6460e25001de834246a33e61430660af5b40241b..dc0b1649c6419e0fb507312dc03772c107632165 100755 (executable)
@@ -30,6 +30,7 @@ all_archs=(
        m68k
        sh4
        parisc32
+       alpha
 )
 archs="${all_archs[@]}"
 
@@ -193,7 +194,7 @@ test_arch() {
                        exit 1
        esac
        printf '%-15s' "$arch:"
-       if [ "$arch" = "m68k" -o "$arch" = "sh4" -o "$arch" = "openrisc" -o "$arch" = "parisc32" ] && [ "$llvm" = "1" ]; then
+       if [ "$arch" = "m68k" -o "$arch" = "sh4" -o "$arch" = "openrisc" -o "$arch" = "parisc32" -o "$arch" = "alpha" ] && [ "$llvm" = "1" ]; then
                echo "Unsupported configuration"
                return
        fi