Skip to content

Commit 9c812b0

Browse files
committed
tools/nolibc: add support for 32-bit s390
32-bit s390 is very close to the existing 64-bit implementation. Some special handling is necessary as there is neither LLVM nor QEMU support. Also the kernel itself can not build natively for 32-bit s390, so instead the test program is executed with a 64-bit kernel. Acked-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Thomas Weißschuh <[email protected]>
1 parent 3d1e67c commit 9c812b0

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

tools/include/nolibc/arch-s390.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,13 @@
143143
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
144144
{
145145
__asm__ volatile (
146+
#ifdef __s390x__
146147
"lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
147148
"aghi %r15, -160\n" /* allocate new stackframe */
149+
#else
150+
"lr %r2, %r15\n"
151+
"ahi %r15, -96\n"
152+
#endif
148153
"xc 0(8,%r15), 0(%r15)\n" /* clear backchain */
149154
"brasl %r14, _start_c\n" /* transfer to c runtime */
150155
);

tools/include/nolibc/arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "arch-powerpc.h"
3030
#elif defined(__riscv)
3131
#include "arch-riscv.h"
32-
#elif defined(__s390x__)
32+
#elif defined(__s390x__) || defined(__s390__)
3333
#include "arch-s390.h"
3434
#elif defined(__loongarch__)
3535
#include "arch-loongarch.h"

tools/testing/selftests/nolibc/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ IMAGE_riscv = arch/riscv/boot/Image
7272
IMAGE_riscv32 = arch/riscv/boot/Image
7373
IMAGE_riscv64 = arch/riscv/boot/Image
7474
IMAGE_s390x = arch/s390/boot/bzImage
75+
IMAGE_s390 = arch/s390/boot/bzImage
7576
IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi
7677
IMAGE = $(objtree)/$(IMAGE_$(XARCH))
7778
IMAGE_NAME = $(notdir $(IMAGE))
@@ -91,6 +92,7 @@ DEFCONFIG_riscv = defconfig
9192
DEFCONFIG_riscv32 = rv32_defconfig
9293
DEFCONFIG_riscv64 = defconfig
9394
DEFCONFIG_s390x = defconfig
95+
DEFCONFIG_s390 = defconfig compat.config
9496
DEFCONFIG_loongarch = defconfig
9597
DEFCONFIG = $(DEFCONFIG_$(XARCH))
9698

@@ -114,6 +116,7 @@ QEMU_ARCH_riscv = riscv64
114116
QEMU_ARCH_riscv32 = riscv32
115117
QEMU_ARCH_riscv64 = riscv64
116118
QEMU_ARCH_s390x = s390x
119+
QEMU_ARCH_s390 = s390x
117120
QEMU_ARCH_loongarch = loongarch64
118121
QEMU_ARCH = $(QEMU_ARCH_$(XARCH))
119122

@@ -142,6 +145,7 @@ QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_T
142145
QEMU_ARGS_riscv32 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
143146
QEMU_ARGS_riscv64 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
144147
QEMU_ARGS_s390x = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
148+
QEMU_ARGS_s390 = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
145149
QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
146150
QEMU_ARGS = -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
147151

@@ -160,6 +164,7 @@ CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
160164
CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
161165
CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2)
162166
CFLAGS_s390x = -m64
167+
CFLAGS_s390 = -m31
163168
CFLAGS_mips32le = -EL -mabi=32 -fPIC
164169
CFLAGS_mips32be = -EB -mabi=32
165170
CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))

tools/testing/selftests/nolibc/run-tests.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ all_archs=(
2323
mips32le mips32be
2424
ppc ppc64 ppc64le
2525
riscv32 riscv64
26-
s390x
26+
s390x s390
2727
loongarch
2828
)
2929
archs="${all_archs[@]}"
@@ -179,6 +179,10 @@ test_arch() {
179179
exit 1
180180
esac
181181
printf '%-15s' "$arch:"
182+
if [ "$arch" = "s390" ] && ([ "$llvm" = "1" ] || [ "$test_mode" = "user" ]); then
183+
echo "Unsupported configuration"
184+
return
185+
fi
182186

183187
mkdir -p "$build_dir"
184188
swallow_output "${MAKE[@]}" defconfig

0 commit comments

Comments
 (0)