]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tools/nolibc: Add m68k support
authorDaniel Palmer <daniel@0x0f.com>
Sat, 26 Apr 2025 22:47:38 +0000 (07:47 +0900)
committerThomas Weißschuh <linux@weissschuh.net>
Wed, 21 May 2025 13:31:54 +0000 (15:31 +0200)
Add nolibc support for m68k. Should be helpful for nommu where
linking libc can bloat even hello world to the point where you get
an OOM just trying to load it.

Signed-off-by: Daniel Palmer <daniel@thingy.jp>
Link: https://lore.kernel.org/r/20250426224738.284874-1-daniel@0x0f.com
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/include/nolibc/arch-m68k.h [new file with mode: 0644]
tools/include/nolibc/arch.h
tools/testing/selftests/nolibc/Makefile
tools/testing/selftests/nolibc/run-tests.sh

diff --git a/tools/include/nolibc/arch-m68k.h b/tools/include/nolibc/arch-m68k.h
new file mode 100644 (file)
index 0000000..6dac184
--- /dev/null
@@ -0,0 +1,141 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * m68k specific definitions for NOLIBC
+ * Copyright (C) 2025 Daniel Palmer<daniel@thingy.jp>
+ *
+ * Roughly based on one or more of the other arch files.
+ *
+ */
+
+#ifndef _NOLIBC_ARCH_M68K_H
+#define _NOLIBC_ARCH_M68K_H
+
+#include "compiler.h"
+#include "crt.h"
+
+#define _NOLIBC_SYSCALL_CLOBBERLIST "memory"
+
+#define my_syscall0(num)                                                      \
+({                                                                            \
+       register long _num __asm__ ("d0") = (num);                            \
+                                                                             \
+       __asm__ volatile (                                                    \
+               "trap #0\n"                                                   \
+               : "+r"(_num)                                                  \
+               : "r"(_num)                                                   \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _num;                                                                 \
+})
+
+#define my_syscall1(num, arg1)                                                \
+({                                                                            \
+       register long _num __asm__ ("d0") = (num);                            \
+       register long _arg1 __asm__ ("d1") = (long)(arg1);                    \
+                                                                             \
+       __asm__ volatile (                                                    \
+               "trap #0\n"                                                   \
+               : "+r"(_num)                                                  \
+               : "r"(_arg1)                                                  \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _num;                                                                 \
+})
+
+#define my_syscall2(num, arg1, arg2)                                          \
+({                                                                            \
+       register long _num __asm__ ("d0") = (num);                            \
+       register long _arg1 __asm__ ("d1") = (long)(arg1);                    \
+       register long _arg2 __asm__ ("d2") = (long)(arg2);                    \
+                                                                             \
+       __asm__ volatile (                                                    \
+               "trap #0\n"                                                   \
+               : "+r"(_num)                                                  \
+               : "r"(_arg1), "r"(_arg2)                                      \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _num;                                                                 \
+})
+
+#define my_syscall3(num, arg1, arg2, arg3)                                    \
+({                                                                            \
+       register long _num __asm__ ("d0")  = (num);                           \
+       register long _arg1 __asm__ ("d1") = (long)(arg1);                    \
+       register long _arg2 __asm__ ("d2") = (long)(arg2);                    \
+       register long _arg3 __asm__ ("d3") = (long)(arg3);                    \
+                                                                             \
+       __asm__ volatile (                                                    \
+               "trap #0\n"                                                   \
+               : "+r"(_num)                                                  \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3)                          \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _num;                                                                 \
+})
+
+#define my_syscall4(num, arg1, arg2, arg3, arg4)                              \
+({                                                                            \
+       register long _num __asm__ ("d0") = (num);                            \
+       register long _arg1 __asm__ ("d1") = (long)(arg1);                    \
+       register long _arg2 __asm__ ("d2") = (long)(arg2);                    \
+       register long _arg3 __asm__ ("d3") = (long)(arg3);                    \
+       register long _arg4 __asm__ ("d4") = (long)(arg4);                    \
+                                                                             \
+       __asm__ volatile (                                                    \
+               "trap #0\n"                                                   \
+               : "+r" (_num)                                                 \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4)              \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _num;                                                                 \
+})
+
+#define my_syscall5(num, arg1, arg2, arg3, arg4, arg5)                        \
+({                                                                            \
+       register long _num __asm__ ("d0") = (num);                            \
+       register long _arg1 __asm__ ("d1") = (long)(arg1);                    \
+       register long _arg2 __asm__ ("d2") = (long)(arg2);                    \
+       register long _arg3 __asm__ ("d3") = (long)(arg3);                    \
+       register long _arg4 __asm__ ("d4") = (long)(arg4);                    \
+       register long _arg5 __asm__ ("d5") = (long)(arg5);                    \
+                                                                             \
+       __asm__ volatile (                                                    \
+               "trap #0\n"                                                   \
+               : "+r" (_num)                                                 \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5)  \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _num;                                                                 \
+})
+
+#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6)                  \
+({                                                                            \
+       register long _num __asm__ ("d0")  = (num);                           \
+       register long _arg1 __asm__ ("d1") = (long)(arg1);                    \
+       register long _arg2 __asm__ ("d2") = (long)(arg2);                    \
+       register long _arg3 __asm__ ("d3") = (long)(arg3);                    \
+       register long _arg4 __asm__ ("d4") = (long)(arg4);                    \
+       register long _arg5 __asm__ ("d5") = (long)(arg5);                    \
+       register long _arg6 __asm__ ("a0") = (long)(arg6);                    \
+                                                                             \
+       __asm__ volatile (                                                    \
+               "trap #0\n"                                                   \
+               : "+r" (_num)                                                 \
+               : "r"(_arg1), "r"(_arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5), \
+                 "r"(_arg6)                                                  \
+               : _NOLIBC_SYSCALL_CLOBBERLIST                                 \
+       );                                                                    \
+       _num;                                                                 \
+})
+
+void _start(void);
+void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
+{
+       __asm__ volatile (
+               "movel %sp, %sp@-\n"
+               "jsr _start_c\n"
+       );
+       __nolibc_entrypoint_epilogue();
+}
+
+#endif /* _NOLIBC_ARCH_M68K_H */
index b8c1da9a88d1593d5a97f60909ede5d0c17699eb..d20b2304aac21bf817f02a085653d5a170546072 100644 (file)
@@ -35,6 +35,8 @@
 #include "arch-loongarch.h"
 #elif defined(__sparc__)
 #include "arch-sparc.h"
+#elif defined(__m68k__)
+#include "arch-m68k.h"
 #else
 #error Unsupported Architecture
 #endif
index d17750761d9f418b27c571de1cf3d0f4954877fd..2671383045dbb51682fd62ac8c8df9c317157317 100644 (file)
@@ -80,6 +80,7 @@ IMAGE_s390       = arch/s390/boot/bzImage
 IMAGE_loongarch  = arch/loongarch/boot/vmlinuz.efi
 IMAGE_sparc32    = arch/sparc/boot/image
 IMAGE_sparc64    = arch/sparc/boot/image
+IMAGE_m68k       = vmlinux
 IMAGE            = $(objtree)/$(IMAGE_$(XARCH))
 IMAGE_NAME       = $(notdir $(IMAGE))
 
@@ -103,8 +104,10 @@ DEFCONFIG_s390       = defconfig compat.config
 DEFCONFIG_loongarch  = defconfig
 DEFCONFIG_sparc32    = sparc32_defconfig
 DEFCONFIG_sparc64    = sparc64_defconfig
+DEFCONFIG_m68k       = virt_defconfig
 DEFCONFIG            = $(DEFCONFIG_$(XARCH))
 
+EXTRACONFIG_m68k      = -e CONFIG_BLK_DEV_INITRD
 EXTRACONFIG           = $(EXTRACONFIG_$(XARCH))
 
 # optional tests to run (default = all)
@@ -130,6 +133,7 @@ QEMU_ARCH_s390       = s390x
 QEMU_ARCH_loongarch  = loongarch64
 QEMU_ARCH_sparc32    = sparc
 QEMU_ARCH_sparc64    = sparc64
+QEMU_ARCH_m68k       = m68k
 QEMU_ARCH            = $(QEMU_ARCH_$(XARCH))
 
 QEMU_ARCH_USER_ppc64le = ppc64le
@@ -162,6 +166,7 @@ QEMU_ARGS_s390       = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST
 QEMU_ARGS_loongarch  = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
 QEMU_ARGS_sparc32    = -M SS-5 -m 256M -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
 QEMU_ARGS_sparc64    = -M sun4u -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
+QEMU_ARGS_m68k       = -M virt -append "console=ttyGF0,115200 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 040956a9f5b8dda3e78abc0d4b6073f4fcd9e3ee..8277599e6441a933d9c1ec5003acf49b06df226f 100755 (executable)
@@ -26,6 +26,7 @@ all_archs=(
        s390x s390
        loongarch
        sparc32 sparc64
+       m68k
 )
 archs="${all_archs[@]}"
 
@@ -186,6 +187,10 @@ test_arch() {
                echo "Unsupported configuration"
                return
        fi
+       if [ "$arch" = "m68k" ] && [ "$llvm" = "1" ]; then
+               echo "Unsupported configuration"
+               return
+       fi
 
        mkdir -p "$build_dir"
        swallow_output "${MAKE[@]}" defconfig