strategy:
matrix:
- arch: [x86, arm32, arm64]
+ arch: [x86, arm32, arm64, riscv32, riscv64]
compiler: [llvm-12, llvm-13, llvm-14, llvm-15]
include:
- arch: arm64
compiler: gcc-aarch64-linux-gnu
+ - arch: riscv64
+ compiler: gcc-riscv64-linux-gnu
+
runs-on: ubuntu-22.04
steps:
case $a in
arm32) CROSS="CROSS_COMPILE=arm-linux-gnueabihf-" ;;
arm64) CROSS="CROSS_COMPILE=aarch64-linux-gnu-" ;;
+ riscv32) CROSS="CROSS_COMPILE=riscv32-linux-gnu-" ;;
+ riscv64) CROSS="CROSS_COMPILE=riscv64-linux-gnu-" ;;
esac
# Select appropriate LLVM= or CC=
xtftestdir := $(xtfdir)/tests
# Supported architectures
-SUPPORTED_ARCH := x86 arm64 arm32
+SUPPORTED_ARCH := x86 arm64 arm32 riscv32 riscv64
# Default architecture
ARCH ?= x86
# Check if specified architecture is supported
--- /dev/null
+#include <arch/page.h>
+
+ .section ".text.head", "ax", %progbits
+
+.globl _start
+_start:
+ /* sp = &stack[PAGE_SIZE] */
+ la sp, stack
+ li t0, PAGE_SIZE
+ add sp, sp, t0
+
+ call test_main
+
+1: j 1b
+
+ .type _start, %function
+ .size _start, . - _start
+
+/*
+ * Local variables:
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+#define XTF_VIRT_START (4 << 20)
--- /dev/null
+#ifdef LINKER_HEADER
+
+#ifndef __riscv
+# error Bad architecture to link with
+#endif
+
+#if __riscv_xlen == 32
+OUTPUT_FORMAT("elf32-littleriscv")
+#elif __riscv_xlen == 64
+OUTPUT_FORMAT("elf64-littleriscv")
+#else
+# error Bad __riscv_xlen to link with
+#endif
+
+OUTPUT_ARCH(riscv)
+ENTRY(_start)
+
+#endif /* LINKER_HEADER */
--- /dev/null
+#define PAGE_SIZE 4096
--- /dev/null
+# Common makefile for riscv
+
+COMMON_AFLAGS += -mno-relax
+COMMON_CFLAGS += -mno-relax
+
+# Compilation recipe
+# riscv needs linking normally, then converting to a binary format
+define build-$(ARCH)
+ $(LD) $$(LDFLAGS_$(ARCH)) $$(DEPS-$(ARCH)) -o $$@-syms
+ $(OBJCOPY) $$@-syms -O binary $$@
+endef
--- /dev/null
+# Architecture specific configuration for riscv32
+
+ARCH_PATH := $(ROOT)/arch/riscv
+ALL_ENVIRONMENTS := riscv32
+
+riscv32_arch := riscv32
+riscv32_guest := riscv32
+defcfg-riscv32 := $(ROOT)/config/default-riscv.cfg.in
+
+# Include riscv common makefile
+include $(ROOT)/build/riscv-common/arch-common.mk
--- /dev/null
+# Architecture specific files compiled and linked for riscv32
+
+# Include riscv common files
+include $(ROOT)/build/riscv-common/arch-files.mk
+
+# Specific files for riscv32
+obj-perenv += $(ROOT)/arch/riscv/head.o
--- /dev/null
+# Supported tests by riscv32
+
+# Currently only example test is supported
+TESTS := $(ROOT)/tests/stubriscv
--- /dev/null
+# Architecture specific configuration for riscv64
+
+ARCH_PATH := $(ROOT)/arch/riscv
+ALL_ENVIRONMENTS := riscv64
+
+riscv64_arch := riscv64
+riscv64_guest := riscv64
+defcfg-riscv64 := $(ROOT)/config/default-riscv.cfg.in
+
+# Include riscv common makefile
+include $(ROOT)/build/riscv-common/arch-common.mk
--- /dev/null
+# Architecture specific files compiled and linked for riscv64
+
+# Include riscv common files
+include $(ROOT)/build/riscv-common/arch-files.mk
+
+# Specific files for riscv64
+obj-perenv += $(ROOT)/arch/riscv/head.o
--- /dev/null
+# Supported tests by riscv64
+
+# Currently only example test is supported
+TESTS := $(ROOT)/tests/stubriscv
--- /dev/null
+name="test-@@ENV@@-@@NAME@@@@VARIATION@@"
+
+vcpus=@@VCPUS@@
+
+memory=128
+kernel="@@XTFDIR@@/tests/@@NAME@@/test-@@ENV@@-@@NAME@@"
--- /dev/null
+include $(ROOT)/build/common.mk
+
+NAME := stubriscv
+CATEGORY := special
+TEST-ENVS := $(ALL_ENVIRONMENTS)
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
--- /dev/null
+/**
+ * Minimal C logic
+ */
+
+#if defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
+# define COND(_32, _64) _64
+#else
+# define COND(_32, _64) _32
+#endif
+
+const char test_title[] = "Hello from RISC-V" COND("32", "64") "\n";
+
+char __attribute__((section(".bss.page_aligned"))) stack[4096];
+
+void test_main(void)
+{
+#if defined(__riscv)
+ register unsigned long nr asm ("a7");
+ register unsigned long a0 asm ("a0");
+ register unsigned long a1 asm ("a1");
+ register unsigned long a2 asm ("a2");
+
+ nr = 18; /* __HYPERVISOR_console_io */
+ a0 = 0; /* CONSOLEIO_write */
+ a1 = sizeof(test_title); /* len */
+ a2 = (unsigned long)test_title; /* ptr */
+ asm volatile ("ecall"
+ : [nr] "+r" (nr), [a0] "+r" (a0),
+ [a1] "+r" (a1), [a2] "+r" (a2)
+ :
+ : "memory");
+
+ unsigned int reason = 0; /* SHUTDOWN_poweroff */
+
+ nr = 29; /* __HYPERVISOR_sched_op */
+ a0 = 2; /* SCHEDOP_shutdown */
+ a1 = (unsigned long)&reason; /* ptr */
+ asm volatile ("ecall"
+ : [nr] "+r" (nr), [a0] "+r" (a0), [a1] "+r" (a1)
+ :
+ : "memory");
+#endif
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */