new file mode 100644
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#ifndef _ASM_S390X_BARRIER_H_
+#define _ASM_S390X_BARRIER_H_
+
+#include <asm-generic/barrier.h>
+
+#endif
new file mode 100644
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#ifndef _ASMS390X_IO_H_
+#define _ASMS390X_IO_H_
+
+#define __iomem
+
+#include <asm-generic/io.h>
+
+#endif
new file mode 100644
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#ifndef _ASMS390X_PAGE_H_
+#define _ASMS390X_PAGE_H_
+
+#include <asm-generic/page.h>
+
+#endif
new file mode 100644
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#ifndef __ASMS390X_SPINLOCK_H
+#define __ASMS390X_SPINLOCK_H
+
+#include <asm-generic/spinlock.h>
+
+#endif
new file mode 100644
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#ifndef _ASMS390X_STACK_H_
+#define _ASMS390X_STACK_H_
+
+#ifndef _STACK_H_
+#error Do not directly include <asm/stack.h>. Just use <stack.h>.
+#endif
+
+#define HAVE_ARCH_BACKTRACE_FRAME
+#define HAVE_ARCH_BACKTRACE
+
+#endif
new file mode 100644
@@ -0,0 +1,48 @@
+/*
+ * s390x io implementation
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#include <libcflat.h>
+#include <asm/spinlock.h>
+
+extern void setup_args_progname(const char *args);
+extern char ipl_args[];
+
+static struct spinlock lock;
+
+void puts(const char *s)
+{
+ spin_lock(&lock);
+ /* FIXME */
+ (void)s;
+ spin_unlock(&lock);
+}
+
+static void sigp_stop()
+{
+ register unsigned long status asm ("1") = 0;
+ register unsigned long cpu asm ("2") = 0;
+
+ asm volatile(
+ " sigp %0,%1,0(%2)\n"
+ : "+d" (status) : "d" (cpu), "d" (5) : "cc");
+}
+
+void setup()
+{
+ setup_args_progname(ipl_args);
+}
+
+void exit(int code)
+{
+ printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
+ sigp_stop();
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/*
+ * s390x stack implementation
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#include <libcflat.h>
+#include <stack.h>
+
+int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
+{
+ printf("TODO: Implement backtrace_frame(%p, %p, %d) function!\n",
+ frame, return_addrs, max_depth);
+ return 0;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+ printf("TODO: Implement backtrace(%p, %d) function!\n",
+ return_addrs, max_depth);
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,34 @@
+all: directories test_cases
+
+test_cases: $(tests)
+
+CFLAGS += -std=gnu99
+CFLAGS += -ffreestanding
+CFLAGS += -Wextra
+CFLAGS += -I $(SRCDIR)/lib
+CFLAGS += -O2
+CFLAGS += -march=z900
+LDFLAGS += -nostdlib
+
+# We want to keep intermediate files
+.PRECIOUS: %.o
+
+cflatobjs += lib/util.o
+cflatobjs += lib/alloc.o
+cflatobjs += lib/s390x/io.o
+cflatobjs += lib/s390x/stack.o
+
+OBJDIRS += lib/s390x
+
+cstart.o = $(TEST_DIR)/cstart64.o
+
+FLATLIBS = $(libcflat)
+%.elf: %.o $(FLATLIBS) $(SRCDIR)/s390x/flat.lds $(cstart.o)
+ $(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) \
+ $(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$@\"
+ $(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds -Ttext=0x10000 \
+ $(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
+ $(RM) $(@:.elf=.aux.o)
+
+arch_clean:
+ $(RM) $(TEST_DIR)/*.{o,elf} $(TEST_DIR)/.*.d lib/s390x/.*.d
new file mode 100644
@@ -0,0 +1,44 @@
+/*
+ * s390x startup code
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * Thomas Huth <thuth@redhat.com>
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+.section .init
+
+/* entry point - for KVM + TCG we directly start in 64 bit mode */
+ .globl start
+start:
+ /* setup stack */
+ larl %r15, stacktop
+ /* setup initial PSW mask + control registers*/
+ larl %r1, initital_psw
+ lpswe 0(%r1)
+init_psw_cont:
+ larl %r1, initital_cr0
+ lctlg %c0, %c0, 0(%r1)
+ /* call setup() */
+ brasl %r14, setup
+ /* forward test parameter */
+ larl %r2, __argc
+ llgf %r2, 0(%r2)
+ larl %r3, __argv
+ /* call to main() */
+ brasl %r14, main
+ /* forward exit code */
+ lgr %r3, %r2
+ /* call exit() */
+ j exit
+
+ .align 8
+initital_psw:
+ .quad 0x0000000180000000, init_psw_cont
+initital_cr0:
+ /* enable AFP-register control, so FP regs (+BFP instr) can be used */
+ .quad 0x0000000000040000
new file mode 100644
@@ -0,0 +1,42 @@
+SECTIONS
+{
+ .text : {
+ *(.init)
+ . = 0x480;
+ ipl_args = .;
+ . = 0x600;
+ *(.text)
+ *(.text.*)
+ }
+ . = ALIGN(64K);
+ etext = .;
+ .opd : { *(.opd) }
+ . = ALIGN(16);
+ .dynamic : {
+ dynamic_start = .;
+ *(.dynamic)
+ }
+ .dynsym : {
+ dynsym_start = .;
+ *(.dynsym)
+ }
+ .rela.dyn : { *(.rela*) }
+ . = ALIGN(16);
+ .data : {
+ *(.data)
+ *(.data.rel*)
+ }
+ . = ALIGN(16);
+ .rodata : { *(.rodata) *(.rodata.*) }
+ . = ALIGN(16);
+ .bss : { *(.bss) }
+ . = ALIGN(64K);
+ edata = .;
+ . += 64K;
+ . = ALIGN(64K);
+ /*
+ * stackptr set with initial stack frame preallocated
+ */
+ stackptr = . - 160;
+ stacktop = .;
+}
new file mode 100755
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+if [ -z "$STANDALONE" ]; then
+ if [ ! -f config.mak ]; then
+ echo "run ./configure && make first. See ./configure -h"
+ exit 2
+ fi
+ source config.mak
+ source scripts/arch-run.bash
+fi
+
+if [ -c /dev/kvm ]; then
+ if [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]; then
+ kvm_available=yes
+ fi
+fi
+
+if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
+ echo "KVM is needed, but not available on this host"
+ exit 2
+fi
+
+if [ -z "$ACCEL" ]; then
+ if [ "$kvm_available" = "yes" ]; then
+ ACCEL="kvm"
+ else
+ ACCEL="tcg"
+ fi
+fi
+
+qemu=$(search_qemu_binary)
+
+M='-machine s390-ccw-virtio'
+M+=",accel=$ACCEL"
+command="$qemu -nodefaults -nographic $M"
+command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
+command+=" -kernel"
+command="$(timeout_cmd) $command"
+echo $command "$@"
+
+# We return the exit code via stdout, not via the QEMU return code
+lines=$(run_qemu $command "$@")
+ret=$?
+echo "$lines"
+if [ $ret -eq 1 ]; then
+ testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
+ if [ "$testret" ]; then
+ if [ $testret -eq 1 ]; then
+ ret=0
+ else
+ ret=$testret
+ fi
+ fi
+fi
+exit $ret
new file mode 100644
@@ -0,0 +1,19 @@
+##############################################################################
+# unittest configuration
+#
+# [unittest_name]
+# file = <name>.elf # Name of the elf file to be used.
+# extra_params = -append <params...> # Additional parameters used.
+# groups = <group_name1> <group_name2> ... # Used to identify test cases
+# # with run_tests -g ...
+# # Specify group_name=nodefault
+# # to have test not run by default
+# accel = kvm|tcg # Optionally specify if test must run with
+# # kvm or tcg. If not specified, then kvm will
+# # be used when available.
+# timeout = <duration> # Optionally specify a timeout.
+# check = <path>=<value> # check a file for a particular value before running
+# # a test. The check line can contain multiple files
+# # to check separated by a space but each check
+# # parameter needs to be of the form <path>=<value>
+##############################################################################