Skip to contentSkip to conversation

Minimal build for RISCV

PATCH Superseded Connor Davis 2 participants 7 messages Jun 2, 2021 – Jun 4, 2021 RISC-V

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover Minimal build for RISCV

Hi all,

This series introduces a minimal build for RISCV. It is based on Bobby's previous work from last year[0] rebased onto current Xen.

This series provides the patches necessary to get a minimal build working. The build is "minimal" in the sense that it only supports building TARGET=riscv64/head.o. The arch/riscv/riscv64/head.S is just a simple while(1).

The first patch is a mod to non-RISCV bits that enable building a config with !CONFIG_HAS_NS16550.

The second patch adds the make/Kconfig boilerplate alongside head.S and asm-riscv/config.h (head.S references ENTRY that is defined in asm-riscv/config.h).

[0] https://lore.kernel.org/xen-devel/[email protected]/

Thanks,
Connor

--
Changes since v6:
- Make sure patch versions are consistent

Changes since v5:
- Added missing A-by from Jan to patch 1

Changes since v4:
- Dropped patches 2 and 4 as these have been applied
- Moved arch/riscv/head.S to arch/riscv/riscv64/head.S for consistency with ARM.
- Added Bob and myself to MAINTAINERS

Changes since v3:
- Dropped "xen: Fix build when !CONFIG_GRANT_TABLE" since this was applied by Jan
- Adjusted Kconfig condition for building NS16550
- Use bool rather than bool_t
- Removed riscv memory map, as this should probably be done later once the frametable size is figured out
- Consolidated 64-bit #defines in asm-riscv/config.h
- Renamed riscv64_defconfig to tiny64_defconfig, added CONFIG_DEBUG and CONFIG_DEBUG_INFO
- Fixed logic/alignment/whitespace issues in Kconfig files
- Use upstream archlinux riscv64 cross-compiler packages instead of custom built toolchain in docker container

Changes since v2:
- Reduced number of riscv files added to ease review

Changes since v1:
- Dropped "xen/sched: Fix build when NR_CPUS == 1" since this was

    fixed for 4.15

- Moved #ifdef-ary around iommu_enabled to iommu.h
- Moved struct grant_table declaration above ifdef CONFIG_GRANT_TABLE instead of defining an empty struct when !CONFIG_GRANT_TABLE
--
Connor Davis (2):
xen/char: Default HAS_NS16550 to y only for X86 and ARM
xen: Add files needed for minimal riscv build

 MAINTAINERS                             |  8 +++++
 config/riscv64.mk                       |  5 +++
 xen/Makefile                            |  8 +++--
 xen/arch/riscv/Kconfig                  | 47 +++++++++++++++++++++++++
 xen/arch/riscv/Kconfig.debug            |  0
 xen/arch/riscv/Makefile                 |  2 ++
 xen/arch/riscv/Rules.mk                 |  0
 xen/arch/riscv/arch.mk                  | 14 ++++++++
 xen/arch/riscv/configs/tiny64_defconfig | 13 +++++++
 xen/arch/riscv/riscv64/asm-offsets.c    |  0
 xen/arch/riscv/riscv64/head.S           |  6 ++++
 xen/drivers/char/Kconfig                |  1 +
 xen/include/asm-riscv/config.h          | 47 +++++++++++++++++++++++++
 13 files changed, 149 insertions(+), 2 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Kconfig.debug
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/arch.mk
 create mode 100644 xen/arch/riscv/configs/tiny64_defconfig
 create mode 100644 xen/arch/riscv/riscv64/asm-offsets.c
 create mode 100644 xen/arch/riscv/riscv64/head.S
 create mode 100644 xen/include/asm-riscv/config.h
Signature · 1 line
2.31.1
#1 lore raw

PATCH v7 1/2 xen/char: Default HAS_NS16550 to y only for X86 and ARM

Defaulting to yes only for X86 and ARM reduces the requirements for a minimal build when porting new architectures.

---
 xen/drivers/char/Kconfig | 1 +
 1 file changed, 1 insertion(+)
xen/drivers/char/Kconfig +1 -0
index b572305657..2ff5b288e2 100644
@@ -1,5 +1,6 @@
 config HAS_NS16550
 	bool "NS16550 UART driver" if ARM
+	default n if RISCV
 	default y
 	help
 	  This selects the 16550-series UART support. For most systems, say Y.
Signature · 1 line
2.31.1
Reviewed-by on v7 1/2
#2 lore raw

Re: [PATCH v7 1/2] xen/char: Default HAS_NS16550 to y only for X86 and ARM

Quoted 6 lines · Connor Davis

Defaulting to yes only for X86 and ARM reduces the requirements for a minimal build when porting new architectures.

Alistair

Quoted 18 lines
---
 xen/drivers/char/Kconfig | 1 +
 1 file changed, 1 insertion(+)
xen/drivers/char/Kconfig +1 -1
index b572305657..2ff5b288e2 100644
@@ -1,5 +1,6 @@
 config HAS_NS16550
        bool "NS16550 UART driver" if ARM
+       default n if RISCV
        default y
        help
          This selects the 16550-series UART support. For most systems, say Y.
--

2.31.1

#4 lore raw

PATCH v7 2/2 xen: Add files needed for minimal riscv build

In reply to Connor Davis

Add arch-specific makefiles and configs needed to build for riscv. Also add a minimal head.S that is a simple infinite loop. head.o can be built with

$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen -C xen tiny64_defconfig
$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen -C xen TARGET=riscv64/head.o

No other TARGET is supported at the moment.

---
Bob: I moved back to XEN_TARGET_ARCH=riscv64 because supplying just XEN_TARGET_ARCH=riscv causes TARGET_ARCH == TARGET_SUBARCH, and that broke the build after the recent commit b6ecd5c8bc "build: centralize / unify asm-offsets generation". It also deviates from how x86 and arm work now, so I think this change is for the best for now. That commit is also why the PHONY include target is added in the riscv/Makefile.

---
 MAINTAINERS                             |  8 +++++
 config/riscv64.mk                       |  5 +++
 xen/Makefile                            |  8 +++--
 xen/arch/riscv/Kconfig                  | 47 +++++++++++++++++++++++++
 xen/arch/riscv/Kconfig.debug            |  0
 xen/arch/riscv/Makefile                 |  2 ++
 xen/arch/riscv/Rules.mk                 |  0
 xen/arch/riscv/arch.mk                  | 14 ++++++++
 xen/arch/riscv/configs/tiny64_defconfig | 13 +++++++
 xen/arch/riscv/riscv64/asm-offsets.c    |  0
 xen/arch/riscv/riscv64/head.S           |  6 ++++
 xen/include/asm-riscv/config.h          | 47 +++++++++++++++++++++++++
 12 files changed, 148 insertions(+), 2 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Kconfig.debug
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/arch.mk
 create mode 100644 xen/arch/riscv/configs/tiny64_defconfig
 create mode 100644 xen/arch/riscv/riscv64/asm-offsets.c
 create mode 100644 xen/arch/riscv/riscv64/head.S
 create mode 100644 xen/include/asm-riscv/config.h
MAINTAINERS +8 -0
index d46b08a0d2..956e71220d 100644
@@ -456,6 +456,14 @@ F:	tools/libs/light/libxl_nonetbuffer.c
 F:	tools/hotplug/Linux/remus-netbuf-setup
 F:	tools/hotplug/Linux/block-drbd-probe
 
+RISCV
+M:	Bob Eshleman <[email protected]>
+R:	Connor Davis <[email protected]>
+S:	Supported
+F:	config/riscv64.mk
+F:	xen/arch/riscv/
+F:	xen/include/asm-riscv/
+
 RTDS SCHEDULER
 M:	Dario Faggioli <[email protected]>
 M:	Meng Xu <[email protected]>
config/riscv64.mk new file +5 -0
new file mode 100644
index 0000000000..a5a21e5fa2
@@ -0,0 +1,5 @@
+CONFIG_RISCV := y
+CONFIG_RISCV_64 := y
+CONFIG_RISCV_$(XEN_OS) := y
+
+CONFIG_XEN_INSTALL_SUFFIX :=
xen/Makefile +6 -2
index 7ce7692354..89879fad4c 100644
@@ -26,7 +26,9 @@ MAKEFLAGS += -rR
 EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
 
 ARCH=$(XEN_TARGET_ARCH)
-SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+SRCARCH=$(shell echo $(ARCH) | \
+          sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+              -e s'/riscv.*/riscv/g')
 
 # Don't break if the build process wasn't called from the top level
 # we need XEN_TARGET_ARCH to generate the proper config
@@ -35,7 +37,8 @@ include $(XEN_ROOT)/Config.mk
 # Set ARCH/SUBARCH appropriately.
 export TARGET_SUBARCH  := $(XEN_TARGET_ARCH)
 export TARGET_ARCH     := $(shell echo $(XEN_TARGET_ARCH) | \
-                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+                                -e s'/riscv.*/riscv/g')
 
 # Allow someone to change their config file
 export KCONFIG_CONFIG ?= .config
@@ -335,6 +338,7 @@ _clean: delete-unfresh-files
 	$(MAKE) $(clean) xsm
 	$(MAKE) $(clean) crypto
 	$(MAKE) $(clean) arch/arm
+	$(MAKE) $(clean) arch/riscv
 	$(MAKE) $(clean) arch/x86
 	$(MAKE) $(clean) test
 	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) clean
xen/arch/riscv/Kconfig new file +47 -0

47 lines not on this page · raw message

xen/arch/riscv/Kconfig.debug new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/Makefile new file +2 -0
new file mode 100644
index 0000000000..942e4ffbc1
@@ -0,0 +1,2 @@
+.PHONY: include
+include:
xen/arch/riscv/Rules.mk new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/arch.mk new file +14 -0
new file mode 100644
index 0000000000..53dadb8975
@@ -0,0 +1,14 @@
+########################################
+# RISCV-specific definitions
+
+CFLAGS-$(CONFIG_RISCV_64) += -mabi=lp64
+
+riscv-march-$(CONFIG_RISCV_ISA_RV64IMA) := rv64ima
+riscv-march-$(CONFIG_RISCV_ISA_C)       := $(riscv-march-y)c
+
+# Note that -mcmodel=medany is used so that Xen can be mapped
+# into the upper half _or_ the lower half of the address space.
+# -mcmodel=medlow would force Xen into the lower half.
+
+CFLAGS += -march=$(riscv-march-y) -mstrict-align -mcmodel=medany
+CFLAGS += -I$(BASEDIR)/include
xen/arch/riscv/configs/tiny64_defconfig new file +13 -0
new file mode 100644
index 0000000000..3c9a2ff941
@@ -0,0 +1,13 @@
+# CONFIG_SCHED_CREDIT is not set
+# CONFIG_SCHED_RTDS is not set
+# CONFIG_SCHED_NULL is not set
+# CONFIG_SCHED_ARINC653 is not set
+# CONFIG_TRACEBUFFER is not set
+# CONFIG_HYPFS is not set
+# CONFIG_GRANT_TABLE is not set
+# CONFIG_SPECULATIVE_HARDEN_ARRAY is not set
+
+CONFIG_RISCV_64=y
+CONFIG_DEBUG=y
+CONFIG_DEBUG_INFO=y
+CONFIG_EXPERT=y
xen/arch/riscv/riscv64/asm-offsets.c new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/riscv64/head.S new file +6 -0
new file mode 100644
index 0000000000..0dbc27ba75
@@ -0,0 +1,6 @@
+#include <asm/config.h>
+
+        .text
+
+ENTRY(start)
+        j  start
xen/include/asm-riscv/config.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.31.1
Reviewed-by on v7 2/2
#5 lore raw

Re: [PATCH v7 2/2] xen: Add files needed for minimal riscv build

Quoted 49 lines · Connor Davis

Add arch-specific makefiles and configs needed to build for riscv. Also add a minimal head.S that is a simple infinite loop. head.o can be built with

$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen -C xen tiny64_defconfig
$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen -C xen TARGET=riscv64/head.o

No other TARGET is supported at the moment.

---
Bob: I moved back to XEN_TARGET_ARCH=riscv64 because supplying just XEN_TARGET_ARCH=riscv causes TARGET_ARCH == TARGET_SUBARCH, and that broke the build after the recent commit b6ecd5c8bc "build: centralize / unify asm-offsets generation". It also deviates from how x86 and arm work now, so I think this change is for the best for now. That commit is also why the PHONY include target is added in the riscv/Makefile.

---
 MAINTAINERS                             |  8 +++++
 config/riscv64.mk                       |  5 +++
 xen/Makefile                            |  8 +++--
 xen/arch/riscv/Kconfig                  | 47 +++++++++++++++++++++++++
 xen/arch/riscv/Kconfig.debug            |  0
 xen/arch/riscv/Makefile                 |  2 ++
 xen/arch/riscv/Rules.mk                 |  0
 xen/arch/riscv/arch.mk                  | 14 ++++++++
 xen/arch/riscv/configs/tiny64_defconfig | 13 +++++++
 xen/arch/riscv/riscv64/asm-offsets.c    |  0
 xen/arch/riscv/riscv64/head.S           |  6 ++++
 xen/include/asm-riscv/config.h          | 47 +++++++++++++++++++++++++
 12 files changed, 148 insertions(+), 2 deletions(-)
 create mode 100644 config/riscv64.mk
 create mode 100644 xen/arch/riscv/Kconfig
 create mode 100644 xen/arch/riscv/Kconfig.debug
 create mode 100644 xen/arch/riscv/Makefile
 create mode 100644 xen/arch/riscv/Rules.mk
 create mode 100644 xen/arch/riscv/arch.mk
 create mode 100644 xen/arch/riscv/configs/tiny64_defconfig
 create mode 100644 xen/arch/riscv/riscv64/asm-offsets.c
 create mode 100644 xen/arch/riscv/riscv64/head.S
 create mode 100644 xen/include/asm-riscv/config.h
MAINTAINERS +0 -0
index d46b08a0d2..956e71220d 100644

MAINTAINERS F: tools/libs/light/libxl_nonetbuffer.c · line 465

Quoted 10 lines
MAINTAINERS +7 -0
@@ -456,6 +456,14 @@ F: tools/libs/light/libxl_nonetbuffer.c
 F:     tools/hotplug/Linux/remus-netbuf-setup
 F:     tools/hotplug/Linux/block-drbd-probe
 
+RISCV
+M:     Bob Eshleman <[email protected]>
+R:     Connor Davis <[email protected]>
+S:     Supported
+F:     config/riscv64.mk
+F:     xen/arch/riscv/
+F:     xen/include/asm-riscv/

I volunteer to be a maintainer as well, feel free to say no :)

I did the QEMU RISC-V H extension port and have a pretty good understanding of the RISC-V Hypervisor extension.

Quoted 85 lines
MAINTAINERS +1 -0
+
 RTDS SCHEDULER
 M:     Dario Faggioli <[email protected]>
 M:     Meng Xu <[email protected]>
config/riscv64.mk new file +5 -0
new file mode 100644
index 0000000000..a5a21e5fa2
@@ -0,0 +1,5 @@
+CONFIG_RISCV := y
+CONFIG_RISCV_64 := y
+CONFIG_RISCV_$(XEN_OS) := y
+
+CONFIG_XEN_INSTALL_SUFFIX :=
xen/Makefile +6 -2
index 7ce7692354..89879fad4c 100644
@@ -26,7 +26,9 @@ MAKEFLAGS += -rR
 EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
 
 ARCH=$(XEN_TARGET_ARCH)
-SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+SRCARCH=$(shell echo $(ARCH) | \
+          sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+              -e s'/riscv.*/riscv/g')
 
 # Don't break if the build process wasn't called from the top level
 # we need XEN_TARGET_ARCH to generate the proper config
@@ -35,7 +37,8 @@ include $(XEN_ROOT)/Config.mk
 # Set ARCH/SUBARCH appropriately.
 export TARGET_SUBARCH  := $(XEN_TARGET_ARCH)
 export TARGET_ARCH     := $(shell echo $(XEN_TARGET_ARCH) | \
-                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+                                -e s'/riscv.*/riscv/g')
 
 # Allow someone to change their config file
 export KCONFIG_CONFIG ?= .config
@@ -335,6 +338,7 @@ _clean: delete-unfresh-files
        $(MAKE) $(clean) xsm
        $(MAKE) $(clean) crypto
        $(MAKE) $(clean) arch/arm
+       $(MAKE) $(clean) arch/riscv
        $(MAKE) $(clean) arch/x86
        $(MAKE) $(clean) test
        $(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) clean
xen/arch/riscv/Kconfig new file +31 -0
new file mode 100644
index 0000000000..bd8381c5e0
@@ -0,0 +1,47 @@
+config RISCV
+       def_bool y
+
+config RISCV_64
+       def_bool y
+       select 64BIT
+
+config ARCH_DEFCONFIG
+       string
+       default "arch/riscv/configs/tiny64_defconfig"
+
+menu "Architecture Features"
+
+source "arch/Kconfig"
+
+endmenu
+
+menu "ISA Selection"
+
+choice
+       prompt "Base ISA"
+       default RISCV_ISA_RV64IMA if RISCV_64
+       help
+         This selects the base ISA extensions that Xen will target.
+
+config RISCV_ISA_RV64IMA
+       bool "RV64IMA"
+       help
+         Use the RV64I base ISA, plus the "M" and "A" extensions
+         for integer multiply/divide and atomic instructions, respectively.
+

xen/arch/riscv/Kconfig line 41

Quoted 10 lines
xen/arch/riscv/Kconfig new file +10 -0
+endchoice
+
+config RISCV_ISA_C
+       bool "Compressed extension"
+       help
+         Add "C" to the ISA subsets that the toolchain is allowed to
+         emit when building Xen, which results in compressed instructions
+         in the Xen binary.
+
+         If unsure, say N.

I would change this to y if you are unsure. I don't expect any hardware to have an MMU (yet along the H extension) and no compressed instruction extension. Linux won't run without the C extension.

Otherwise looks good:

Now the hard part of getting it to boot.

Alistair

Quoted 130 lines
xen/arch/riscv/Kconfig new file +6 -0
+
+endmenu
+
+source "common/Kconfig"
+
+source "drivers/Kconfig"
xen/arch/riscv/Kconfig.debug new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/Makefile new file +2 -0
new file mode 100644
index 0000000000..942e4ffbc1
@@ -0,0 +1,2 @@
+.PHONY: include
+include:
xen/arch/riscv/Rules.mk new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/arch.mk new file +14 -0
new file mode 100644
index 0000000000..53dadb8975
@@ -0,0 +1,14 @@
+########################################
+# RISCV-specific definitions
+
+CFLAGS-$(CONFIG_RISCV_64) += -mabi=lp64
+
+riscv-march-$(CONFIG_RISCV_ISA_RV64IMA) := rv64ima
+riscv-march-$(CONFIG_RISCV_ISA_C)       := $(riscv-march-y)c
+
+# Note that -mcmodel=medany is used so that Xen can be mapped
+# into the upper half _or_ the lower half of the address space.
+# -mcmodel=medlow would force Xen into the lower half.
+
+CFLAGS += -march=$(riscv-march-y) -mstrict-align -mcmodel=medany
+CFLAGS += -I$(BASEDIR)/include
xen/arch/riscv/configs/tiny64_defconfig new file +13 -0
new file mode 100644
index 0000000000..3c9a2ff941
@@ -0,0 +1,13 @@
+# CONFIG_SCHED_CREDIT is not set
+# CONFIG_SCHED_RTDS is not set
+# CONFIG_SCHED_NULL is not set
+# CONFIG_SCHED_ARINC653 is not set
+# CONFIG_TRACEBUFFER is not set
+# CONFIG_HYPFS is not set
+# CONFIG_GRANT_TABLE is not set
+# CONFIG_SPECULATIVE_HARDEN_ARRAY is not set
+
+CONFIG_RISCV_64=y
+CONFIG_DEBUG=y
+CONFIG_DEBUG_INFO=y
+CONFIG_EXPERT=y
xen/arch/riscv/riscv64/asm-offsets.c new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/riscv/riscv64/head.S new file +6 -0
new file mode 100644
index 0000000000..0dbc27ba75
@@ -0,0 +1,6 @@
+#include <asm/config.h>
+
+        .text
+
+ENTRY(start)
+        j  start
xen/include/asm-riscv/config.h new file +47 -1
new file mode 100644
index 0000000000..e2ae21de61
@@ -0,0 +1,47 @@
+#ifndef __RISCV_CONFIG_H__
+#define __RISCV_CONFIG_H__
+
+#if defined(CONFIG_RISCV_64)
+# define LONG_BYTEORDER 3
+# define ELFSIZE 64
+# define MAX_VIRT_CPUS 128u
+#else
+# error "Unsupported RISCV variant"
+#endif
+
+#define BYTES_PER_LONG (1 << LONG_BYTEORDER)
+#define BITS_PER_LONG  (BYTES_PER_LONG << 3)
+#define POINTER_ALIGN  BYTES_PER_LONG
+
+#define BITS_PER_LLONG 64
+
+/* xen_ulong_t is always 64 bits */
+#define BITS_PER_XEN_ULONG 64
+
+#define CONFIG_RISCV_L1_CACHE_SHIFT 6
+#define CONFIG_PAGEALLOC_MAX_ORDER  18
+#define CONFIG_DOMU_MAX_ORDER       9
+#define CONFIG_HWDOM_MAX_ORDER      10
+
+#define OPT_CONSOLE_STR "dtuart"
+#define INVALID_VCPU_ID MAX_VIRT_CPUS
+
+/* Linkage for RISCV */
+#ifdef __ASSEMBLY__
+#define ALIGN .align 2
+
+#define ENTRY(name)                                \
+  .globl name;                                     \
+  ALIGN;                                           \
+  name:
+#endif
+
+#endif /* __RISCV_CONFIG_H__ */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--

2.31.1

#6 lore raw

Re: [PATCH v7 2/2] xen: Add files needed for minimal riscv build

Quoted 61 lines · Alistair Francis
Quoted 48 lines · Connor Davis

Add arch-specific makefiles and configs needed to build for riscv. Also add a minimal head.S that is a simple infinite loop. head.o can be built with

$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen -C xen tiny64_defconfig
$ make XEN_TARGET_ARCH=riscv64 SUBSYSTEMS=xen -C xen TARGET=riscv64/head.o

No other TARGET is supported at the moment.

---
Bob: I moved back to XEN_TARGET_ARCH=riscv64 because supplying just XEN_TARGET_ARCH=riscv causes TARGET_ARCH == TARGET_SUBARCH, and that broke the build after the recent commit b6ecd5c8bc "build: centralize / unify asm-offsets generation". It also deviates from how x86 and arm work now, so I think this change is for the best for now. That commit is also why the PHONY include target is added in the riscv/Makefile.

---
  MAINTAINERS                             |  8 +++++
  config/riscv64.mk                       |  5 +++
  xen/Makefile                            |  8 +++--
  xen/arch/riscv/Kconfig                  | 47 +++++++++++++++++++++++++
  xen/arch/riscv/Kconfig.debug            |  0
  xen/arch/riscv/Makefile                 |  2 ++
  xen/arch/riscv/Rules.mk                 |  0
  xen/arch/riscv/arch.mk                  | 14 ++++++++
  xen/arch/riscv/configs/tiny64_defconfig | 13 +++++++
  xen/arch/riscv/riscv64/asm-offsets.c    |  0
  xen/arch/riscv/riscv64/head.S           |  6 ++++
  xen/include/asm-riscv/config.h          | 47 +++++++++++++++++++++++++
  12 files changed, 148 insertions(+), 2 deletions(-)

create mode 100644 config/riscv64.mk
create mode 100644 xen/arch/riscv/Kconfig
create mode 100644 xen/arch/riscv/Kconfig.debug create mode 100644 xen/arch/riscv/Makefile create mode 100644 xen/arch/riscv/Rules.mk create mode 100644 xen/arch/riscv/arch.mk
create mode 100644 xen/arch/riscv/configs/tiny64_defconfig create mode 100644 xen/arch/riscv/riscv64/asm-offsets.c create mode 100644 xen/arch/riscv/riscv64/head.S create mode 100644 xen/include/asm-riscv/config.h

MAINTAINERS +0 -0
index d46b08a0d2..956e71220d 100644

MAINTAINERS F: tools/libs/light/libxl_nonetbuffer.c · line 465

Quoted 10 lines
MAINTAINERS +7 -0
@@ -456,6 +456,14 @@ F: tools/libs/light/libxl_nonetbuffer.c
  F:     tools/hotplug/Linux/remus-netbuf-setup
  F:     tools/hotplug/Linux/block-drbd-probe
 
+RISCV
+M:     Bob Eshleman <[email protected]>
+R:     Connor Davis <[email protected]>
+S:     Supported
+F:     config/riscv64.mk
+F:     xen/arch/riscv/
+F:     xen/include/asm-riscv/

I volunteer to be a maintainer as well, feel free to say no :)

Quoted 2 lines

I did the QEMU RISC-V H extension port and have a pretty good understanding of the RISC-V Hypervisor extension.

Great! I will add you.

Quoted 100 lines
Quoted 85 lines
MAINTAINERS +1 -0
+
  RTDS SCHEDULER
  M:     Dario Faggioli <[email protected]>
  M:     Meng Xu <[email protected]>
config/riscv64.mk new file +5 -0
new file mode 100644
index 0000000000..a5a21e5fa2
@@ -0,0 +1,5 @@
+CONFIG_RISCV := y
+CONFIG_RISCV_64 := y
+CONFIG_RISCV_$(XEN_OS) := y
+
+CONFIG_XEN_INSTALL_SUFFIX :=
xen/Makefile +6 -2
index 7ce7692354..89879fad4c 100644
@@ -26,7 +26,9 @@ MAKEFLAGS += -rR
  EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
 
  ARCH=$(XEN_TARGET_ARCH)
-SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+SRCARCH=$(shell echo $(ARCH) | \
+          sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+              -e s'/riscv.*/riscv/g')
 
  # Don't break if the build process wasn't called from the top level
  # we need XEN_TARGET_ARCH to generate the proper config
@@ -35,7 +37,8 @@ include $(XEN_ROOT)/Config.mk
  # Set ARCH/SUBARCH appropriately.
  export TARGET_SUBARCH  := $(XEN_TARGET_ARCH)
  export TARGET_ARCH     := $(shell echo $(XEN_TARGET_ARCH) | \
-                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
+                            sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
+                                -e s'/riscv.*/riscv/g')
 
  # Allow someone to change their config file
  export KCONFIG_CONFIG ?= .config
@@ -335,6 +338,7 @@ _clean: delete-unfresh-files
         $(MAKE) $(clean) xsm
         $(MAKE) $(clean) crypto
         $(MAKE) $(clean) arch/arm
+       $(MAKE) $(clean) arch/riscv
         $(MAKE) $(clean) arch/x86
         $(MAKE) $(clean) test
         $(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) clean
xen/arch/riscv/Kconfig new file +31 -0
new file mode 100644
index 0000000000..bd8381c5e0
@@ -0,0 +1,47 @@
+config RISCV
+       def_bool y
+
+config RISCV_64
+       def_bool y
+       select 64BIT
+
+config ARCH_DEFCONFIG
+       string
+       default "arch/riscv/configs/tiny64_defconfig"
+
+menu "Architecture Features"
+
+source "arch/Kconfig"
+
+endmenu
+
+menu "ISA Selection"
+
+choice
+       prompt "Base ISA"
+       default RISCV_ISA_RV64IMA if RISCV_64
+       help
+         This selects the base ISA extensions that Xen will target.
+
+config RISCV_ISA_RV64IMA
+       bool "RV64IMA"
+       help
+         Use the RV64I base ISA, plus the "M" and "A" extensions
+         for integer multiply/divide and atomic instructions, respectively.
+

xen/arch/riscv/Kconfig line 41

Quoted 10 lines
xen/arch/riscv/Kconfig new file +10 -0
+endchoice
+
+config RISCV_ISA_C
+       bool "Compressed extension"
+       help
+         Add "C" to the ISA subsets that the toolchain is allowed to
+         emit when building Xen, which results in compressed instructions
+         in the Xen binary.
+
+         If unsure, say N.

I would change this to y if you are unsure. I don't expect any hardware to have an MMU (yet along the H extension) and no compressed instruction extension. Linux won't run without the C extension. Otherwise looks good:

Quoted 1 line

Thanks. I was thinking it may make bring-up easier (at least in assembly glue) if C was turned off, but in the end it will probably be easiest to mimic linux. I will change to Y.

Connor