Skip to content

Commit

Permalink
[arch][riscv] add a way for platforms to set optional riscv ISA exten…
Browse files Browse the repository at this point in the history
…sions

A pretty simple mechanism, a list of extensions added to
RISCV_EXTENSION_LIST make variable is expanded to an underscore
delimited string appended to the end of -march=

Pretty simple but it should work for now.
  • Loading branch information
travisg committed Apr 8, 2024
1 parent 00b06a8 commit 03eb343
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
21 changes: 17 additions & 4 deletions arch/riscv/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RISCV_MMU ?= none
RISCV_FPU ?= false
SUBARCH ?= 32
RISCV_MODE ?= machine
RISCV_EXTENSION_LIST ?=
ARCH_RISCV_EMBEDDED ?= false
ARCH_RISCV_TWOSEGMENT ?= false

Expand Down Expand Up @@ -134,6 +135,16 @@ ifeq (true,$(call TOBOOL,$(RISCV_FPU)))
GLOBAL_DEFINES += RISCV_FPU=1
endif

# based on a list of optional extensions passed in, collapse the extensions into
# a string appended to the end of the -march line below
$(info RISCV_EXTENSION_LIST = $(RISCV_EXTENSION_LIST))
ifneq ($(RISCV_EXTENSION_LIST),)
RISCV_MARCH_EXTENSIONS := _$(subst $(SPACE),_,$(RISCV_EXTENSION_LIST))
else
RISCV_MARCH_EXTENSIONS :=
endif
#$(info RISCV_MARCH_EXTENSIONS = $(RISCV_MARCH_EXTENSIONS))

# for the moment simply build all sources the same way, with or without float based on
# the configuration of the platform
ARCH_COMPILEFLAGS_FLOAT :=
Expand All @@ -143,9 +154,9 @@ ARCH_COMPILEFLAGS_NOFLOAT :=
# compiler codegen flags
ifeq ($(SUBARCH),32)
ifeq (true,$(call TOBOOL,$(RISCV_FPU)))
ARCH_COMPILEFLAGS := -march=rv32gc -mabi=ilp32d
ARCH_COMPILEFLAGS := -march=rv32gc$(RISCV_MARCH_EXTENSIONS) -mabi=ilp32d
else
ARCH_COMPILEFLAGS := -march=rv32imac -mabi=ilp32
ARCH_COMPILEFLAGS := -march=rv32imac$(RISCV_MARCH_EXTENSIONS) -mabi=ilp32
endif

# override machine for ld -r
Expand All @@ -157,9 +168,9 @@ else ifeq ($(SUBARCH),64)
# HACK: use rv64imafdc instead of the equivalent rv64gc due to
# older toolchains not supporting the mapping of one to the other
# when selecting libgcc.
ARCH_COMPILEFLAGS := -march=rv64imafdc -mabi=lp64d -mcmodel=medany
ARCH_COMPILEFLAGS := -march=rv64imafdc$(RISCV_MARCH_EXTENSIONS) -mabi=lp64d -mcmodel=medany
else
ARCH_COMPILEFLAGS := -march=rv64imac -mabi=lp64 -mcmodel=medany
ARCH_COMPILEFLAGS := -march=rv64imac$(RISCV_MARCH_EXTENSIONS) -mabi=lp64 -mcmodel=medany
endif

# override machine for ld -r
Expand All @@ -168,6 +179,8 @@ else
$(error SUBARCH not set or set to something unknown)
endif

undefine RISCV_MARCH_EXTENSIONS

# test to see if -misa-spec=2.2 is a valid switch.
# misa-spec is added to make sure the compiler picks up the zicsr extension by default.
MISA_SPEC := $(shell $(TOOLCHAIN_PREFIX)gcc $(ARCH_COMPILEFLAGS) -misa-spec=2.2 -E - < /dev/null > /dev/null 2>1 && echo supported)
Expand Down
1 change: 1 addition & 0 deletions platform/jh7110/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SMP_MAX_CPUS ?= 4
LK_HEAP_IMPLEMENTATION ?= dlmalloc
RISCV_FPU ?= true
RISCV_MMU ?= sv39
RISCV_EXTENSION_LIST ?= zba zbb

MODULE_DEPS += lib/cbuf
MODULE_DEPS += lib/fdt
Expand Down
1 change: 1 addition & 0 deletions platform/qemu-virt-riscv/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WITH_SMP ?= true
SMP_MAX_CPUS ?= 8
LK_HEAP_IMPLEMENTATION ?= dlmalloc
RISCV_FPU ?= true
RISCV_EXTENSION_LIST ?= zba zbb zbc zbs

ifeq ($(RISCV_MODE),supervisor)
ifeq ($(SUBARCH),32)
Expand Down

0 comments on commit 03eb343

Please sign in to comment.