This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 670891d841c arch/risc-v: organize SBI implementations
670891d841c is described below
commit 670891d841c1fb46a521d70d6c078b61bff1bc8c
Author: Zhouqi Jiang <[email protected]>
AuthorDate: Mon Nov 16 13:48:27 2026 +0800
arch/risc-v: organize SBI implementations
Keep each RISC-V SBI implementation under its own directory below
arch/risc-v/src/sbi. Move NuttSBI and OpenSBI there and update the
Make, CMake, Kconfig, and include paths accordingly.
Assisted-by: Codex:gpt-6.1-terra
Signed-off-by: Zhouqi Jiang <[email protected]>
---
arch/risc-v/Kconfig | 1 -
arch/risc-v/src/CMakeLists.txt | 1 -
arch/risc-v/src/Makefile | 4 --
arch/risc-v/src/opensbi/Make.defs | 72 ----------------------
arch/risc-v/src/sbi/CMakeLists.txt | 14 ++---
arch/risc-v/src/sbi/Kconfig | 42 +------------
arch/risc-v/src/sbi/Make.defs | 16 ++---
arch/risc-v/src/sbi/{ => nuttsbi}/CMakeLists.txt | 14 ++---
arch/risc-v/src/sbi/nuttsbi/Kconfig | 45 ++++++++++++++
arch/risc-v/src/sbi/{ => nuttsbi}/Make.defs | 12 +---
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_head.S | 2 +-
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_internal.h | 8 +--
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_ipi.c | 2 +-
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_mcall.c | 60 +++++++++---------
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_mcall.h | 8 +--
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_mexception.c | 2 +-
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_mscratch.c | 2 +-
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_mtimer.c | 2 +-
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_mtrap.S | 2 +-
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_start.c | 3 +-
arch/risc-v/src/sbi/{ => nuttsbi}/sbi_vectors.S | 2 +-
arch/risc-v/src/{ => sbi}/opensbi/.gitignore | 0
arch/risc-v/src/sbi/{ => opensbi}/CMakeLists.txt | 15 +----
arch/risc-v/src/{ => sbi}/opensbi/Kconfig | 2 +-
arch/risc-v/src/sbi/opensbi/Make.defs | 68 ++++++++++++++++++++
25 files changed, 184 insertions(+), 215 deletions(-)
diff --git a/arch/risc-v/Kconfig b/arch/risc-v/Kconfig
index efb0e0bc93e..442ed594640 100644
--- a/arch/risc-v/Kconfig
+++ b/arch/risc-v/Kconfig
@@ -1002,7 +1002,6 @@ endchoice # LITEX Core Selection
endif # ARCH_CHIP_LITEX
-source "arch/risc-v/src/opensbi/Kconfig"
source "arch/risc-v/src/sbi/Kconfig"
if ARCH_CHIP_FE310
diff --git a/arch/risc-v/src/CMakeLists.txt b/arch/risc-v/src/CMakeLists.txt
index 2e0b4192764..796c6828b4d 100644
--- a/arch/risc-v/src/CMakeLists.txt
+++ b/arch/risc-v/src/CMakeLists.txt
@@ -25,7 +25,6 @@ add_subdirectory(common)
if(CONFIG_BUILD_KERNEL)
add_subdirectory(sbi)
- target_include_directories(arch BEFORE PUBLIC ${NUTTX_CHIP_ABS_DIR} sbi)
endif()
# Include directories (before system ones) as PUBLIC so that it can be exposed
diff --git a/arch/risc-v/src/Makefile b/arch/risc-v/src/Makefile
index 7864e675013..63a65dc42e5 100644
--- a/arch/risc-v/src/Makefile
+++ b/arch/risc-v/src/Makefile
@@ -22,11 +22,7 @@
include $(TOPDIR)/tools/Make.defs
include chip/Make.defs
-ifeq ($(CONFIG_OPENSBI),y)
-include opensbi/Make.defs
-else ifeq ($(CONFIG_NUTTSBI),y)
include sbi/Make.defs
-endif
ARCH_SRCDIR = $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src
diff --git a/arch/risc-v/src/opensbi/Make.defs
b/arch/risc-v/src/opensbi/Make.defs
deleted file mode 100644
index 319ba7a1930..00000000000
--- a/arch/risc-v/src/opensbi/Make.defs
+++ /dev/null
@@ -1,72 +0,0 @@
-############################################################################
-# arch/risc-v/src/opensbi/Make.defs
-#
-# SPDX-License-Identifier: Apache-2.0
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership. The
-# ASF licenses this file to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance with the
-# License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-############################################################################
-
-ifeq ($(CONFIG_OPENSBI),y)
-
-DEPPATH += --dep-path opensbi/opensbi-3rdparty
-VPATH += :opensbi/opensbi-3rdparty
-
-SBI_CSRCS = $(wildcard opensbi/opensbi-3rdparty/lib/sbi/*.c)
-SBI_CSRCS += opensbi/opensbi-3rdparty/lib/utils/ipi/aclint_mswi.c
-SBI_CSRCS += opensbi/opensbi-3rdparty/lib/utils/irqchip/plic.c
-SBI_CSRCS += opensbi/opensbi-3rdparty/lib/utils/timer/aclint_mtimer.c
-
-EXCLUDED_FILES = opensbi/opensbi-3rdparty/lib/sbi/sbi_pmu.c
-EXCLUDED_FILES += opensbi/opensbi-3rdparty/lib/sbi/sbi_ecall_dbcn.c
-
-TMPVAR := $(SBI_CSRCS)
-SBI_CSRCS = $(filter-out $(EXCLUDED_FILES), $(TMPVAR))
-
-SBI_ASRCS += opensbi/opensbi-3rdparty/lib/sbi/sbi_expected_trap.S
-SBI_ASRCS += opensbi/opensbi-3rdparty/lib/sbi/sbi_hfence.S
-SBI_ASRCS += opensbi/opensbi-3rdparty/lib/sbi/riscv_hardfp.S
-
-INCLUDES +=
${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)opensbi$(DELIM)opensbi-3rdparty$(DELIM)include
-
-SBI_DIR := opensbi
-
-OPENSBI_UNPACK = opensbi-3rdparty
-OPENSBI_COMMIT = fbaaafe808f3da7745760d757c436ef1b293d3ed
-OPENSBI_URL = https://github.com/riscv-software-src/opensbi/tarball
-OPENSBI_TARBALL = opensbi.tar.gz
-OPENSBI_DIR = riscv-software-src-opensbi-fbaaafe
-
-$(OPENSBI_TARBALL):
- $(call
DOWNLOAD,$(OPENSBI_URL),$(OPENSBI_COMMIT),opensbi/$(OPENSBI_TARBALL))
-
-.opensbi_unpack: $(OPENSBI_TARBALL)
- $(Q) echo "Unpacking: OpenSBI"
- $(Q) tar xzf opensbi/$(OPENSBI_TARBALL) -C opensbi
- $(Q) mv opensbi/$(OPENSBI_DIR) opensbi/$(OPENSBI_UNPACK)
- $(Q) touch opensbi/.opensbi_unpack
- $(Q) opensbi/$(OPENSBI_UNPACK)/scripts/carray.sh -i
opensbi/$(OPENSBI_UNPACK)/lib/sbi/sbi_ecall_exts.carray -l "ecall_base
ecall_hsm ecall_ipi ecall_rfence ecall_time ecall_vendor" >
opensbi/$(OPENSBI_UNPACK)/lib/sbi/sbi_ecall_exts.c
-
-ifeq ($(wildcard opensbi/$(OPENSBI_UNPACK)/.git),)
-context:: .opensbi_unpack
-
-distclean::
- $(call DELFILE, opensbi/.opensbi_unpack)
- $(call DELFILE, opensbi/$(OPENSBI_TARBALL))
- $(call DELDIR, opensbi/$(OPENSBI_UNPACK))
-endif
-
-endif
diff --git a/arch/risc-v/src/sbi/CMakeLists.txt
b/arch/risc-v/src/sbi/CMakeLists.txt
index 69bb3c2cdb9..565d5b9d156 100644
--- a/arch/risc-v/src/sbi/CMakeLists.txt
+++ b/arch/risc-v/src/sbi/CMakeLists.txt
@@ -20,14 +20,8 @@
#
#
##############################################################################
-if(CONFIG_NUTTSBI)
-
- set(SRCS sbi_head.S sbi_mtrap.S sbi_vectors.S sbi_start.c)
-
- list(APPEND SRCS sbi_mtimer.c sbi_mexception.c sbi_mcall.c sbi_mscratch.c)
-
- list(APPEND SRCS sbi_ipi.c)
-
- target_sources(arch PRIVATE ${SRCS})
-
+if(CONFIG_OPENSBI)
+ add_subdirectory(opensbi)
+elseif(CONFIG_NUTTSBI)
+ add_subdirectory(nuttsbi)
endif()
diff --git a/arch/risc-v/src/sbi/Kconfig b/arch/risc-v/src/sbi/Kconfig
index ed5a2be76cc..324d2297cb3 100644
--- a/arch/risc-v/src/sbi/Kconfig
+++ b/arch/risc-v/src/sbi/Kconfig
@@ -24,43 +24,5 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
-
-# S-mode requires a Supervisor Binary Interface (SBI) in order to access
-# M-mode ISA. A minimalistic SBI is provided here natively.
-
-config NUTTSBI
- bool "Use NuttX native SBI"
- default n
- depends on ARCH_RISCV && ARCH_USE_S_MODE
- ---help---
- Use NuttX minimalistic SBI
-
-if NUTTSBI
-
-config NUTTSBI_HART_CNT
- int "Amount of harts in SoC"
- default 1
-
-config NUTTSBI_IPI_BASE
- hex "MSWI base address"
- default 0
- ---help---
- Sets the address of mtimecmp memory mapped register
-
-config NUTTSBI_MTIME_BASE
- hex "MTIME base address"
- default 0
- ---help---
- Sets the address of mtime memory mapped register
-
-config NUTTSBI_MTIMECMP_BASE
- hex "MTIMECMP base address"
- default 0
- ---help---
- Sets the address of mtimecmp memory mapped register
-
-config NUTTSBI_LATE_INIT
- bool "Target has sbi_late_init() implementation"
- default n
-
-endif
+source "arch/risc-v/src/sbi/opensbi/Kconfig"
+source "arch/risc-v/src/sbi/nuttsbi/Kconfig"
diff --git a/arch/risc-v/src/sbi/Make.defs b/arch/risc-v/src/sbi/Make.defs
index 35ea232a9d3..9bfb9b14f80 100644
--- a/arch/risc-v/src/sbi/Make.defs
+++ b/arch/risc-v/src/sbi/Make.defs
@@ -20,16 +20,8 @@
#
############################################################################
-# If NuttX SBI is needed
-
-ifeq ($(CONFIG_NUTTSBI),y)
-
-SBI_ASRCS += sbi_mtrap.S sbi_vectors.S sbi_head.S
-SBI_CSRCS += sbi_mscratch.c sbi_mcall.c sbi_start.c
-SBI_CSRCS += sbi_mexception.c sbi_mtimer.c sbi_ipi.c
-
-INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)sbi
-
-SBI_DIR := sbi
-
+ifeq ($(CONFIG_OPENSBI),y)
+include sbi/opensbi/Make.defs
+else ifeq ($(CONFIG_NUTTSBI),y)
+include sbi/nuttsbi/Make.defs
endif
diff --git a/arch/risc-v/src/sbi/CMakeLists.txt
b/arch/risc-v/src/sbi/nuttsbi/CMakeLists.txt
similarity index 75%
copy from arch/risc-v/src/sbi/CMakeLists.txt
copy to arch/risc-v/src/sbi/nuttsbi/CMakeLists.txt
index 69bb3c2cdb9..7d698839cf6 100644
--- a/arch/risc-v/src/sbi/CMakeLists.txt
+++ b/arch/risc-v/src/sbi/nuttsbi/CMakeLists.txt
@@ -1,5 +1,5 @@
#
##############################################################################
-# arch/risc-v/src/sbi/CMakeLists.txt
+# arch/risc-v/src/sbi/nuttsbi/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -20,14 +20,12 @@
#
#
##############################################################################
-if(CONFIG_NUTTSBI)
+target_include_directories(arch BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
- set(SRCS sbi_head.S sbi_mtrap.S sbi_vectors.S sbi_start.c)
+set(SRCS sbi_head.S sbi_mtrap.S sbi_vectors.S sbi_start.c)
- list(APPEND SRCS sbi_mtimer.c sbi_mexception.c sbi_mcall.c sbi_mscratch.c)
+list(APPEND SRCS sbi_mtimer.c sbi_mexception.c sbi_mcall.c sbi_mscratch.c)
- list(APPEND SRCS sbi_ipi.c)
+list(APPEND SRCS sbi_ipi.c)
- target_sources(arch PRIVATE ${SRCS})
-
-endif()
+target_sources(arch PRIVATE ${SRCS})
diff --git a/arch/risc-v/src/sbi/nuttsbi/Kconfig
b/arch/risc-v/src/sbi/nuttsbi/Kconfig
new file mode 100644
index 00000000000..bb602b1587c
--- /dev/null
+++ b/arch/risc-v/src/sbi/nuttsbi/Kconfig
@@ -0,0 +1,45 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+
+# S-mode requires a Supervisor Binary Interface (SBI) in order to access
+# M-mode ISA. A minimalistic SBI is provided here natively.
+
+config NUTTSBI
+ bool "Use NuttX native SBI"
+ default n
+ depends on ARCH_RISCV && ARCH_USE_S_MODE
+ ---help---
+ Use NuttX minimalistic SBI
+
+if NUTTSBI
+
+config NUTTSBI_HART_CNT
+ int "Amount of harts in SoC"
+ default 1
+
+config NUTTSBI_IPI_BASE
+ hex "MSWI base address"
+ default 0
+ ---help---
+ Sets the address of mtimecmp memory mapped register
+
+config NUTTSBI_MTIME_BASE
+ hex "MTIME base address"
+ default 0
+ ---help---
+ Sets the address of mtime memory mapped register
+
+config NUTTSBI_MTIMECMP_BASE
+ hex "MTIMECMP base address"
+ default 0
+ ---help---
+ Sets the address of mtimecmp memory mapped register
+
+config NUTTSBI_LATE_INIT
+ bool "Target has sbi_late_init() implementation"
+ default n
+
+endif
diff --git a/arch/risc-v/src/sbi/Make.defs
b/arch/risc-v/src/sbi/nuttsbi/Make.defs
similarity index 87%
copy from arch/risc-v/src/sbi/Make.defs
copy to arch/risc-v/src/sbi/nuttsbi/Make.defs
index 35ea232a9d3..bab0a1bd3f7 100644
--- a/arch/risc-v/src/sbi/Make.defs
+++ b/arch/risc-v/src/sbi/nuttsbi/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# arch/risc-v/src/sbi/Make.defs
+# arch/risc-v/src/sbi/nuttsbi/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -20,16 +20,10 @@
#
############################################################################
-# If NuttX SBI is needed
-
-ifeq ($(CONFIG_NUTTSBI),y)
-
SBI_ASRCS += sbi_mtrap.S sbi_vectors.S sbi_head.S
SBI_CSRCS += sbi_mscratch.c sbi_mcall.c sbi_start.c
SBI_CSRCS += sbi_mexception.c sbi_mtimer.c sbi_ipi.c
-INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)sbi
-
-SBI_DIR := sbi
+INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)sbi$(DELIM)nuttsbi
-endif
+SBI_DIR := sbi/nuttsbi
diff --git a/arch/risc-v/src/sbi/sbi_head.S
b/arch/risc-v/src/sbi/nuttsbi/sbi_head.S
similarity index 98%
rename from arch/risc-v/src/sbi/sbi_head.S
rename to arch/risc-v/src/sbi/nuttsbi/sbi_head.S
index bca1fd379e4..7ef04d1de5f 100644
--- a/arch/risc-v/src/sbi/sbi_head.S
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_head.S
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_head.S
+ * arch/risc-v/src/sbi/nuttsbi/sbi_head.S
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/risc-v/src/sbi/sbi_internal.h
b/arch/risc-v/src/sbi/nuttsbi/sbi_internal.h
similarity index 96%
rename from arch/risc-v/src/sbi/sbi_internal.h
rename to arch/risc-v/src/sbi/nuttsbi/sbi_internal.h
index 628f7fe3779..3441a8a4816 100644
--- a/arch/risc-v/src/sbi/sbi_internal.h
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_internal.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_internal.h
+ * arch/risc-v/src/sbi/nuttsbi/sbi_internal.h
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -20,8 +20,8 @@
*
****************************************************************************/
-#ifndef __ARCH_RISC_V_SRC_SBI_SBI_INTERNAL_H
-#define __ARCH_RISC_V_SRC_SBI_SBI_INTERNAL_H
+#ifndef __ARCH_RISC_V_SRC_SBI_NUTTSBI_SBI_INTERNAL_H
+#define __ARCH_RISC_V_SRC_SBI_NUTTSBI_SBI_INTERNAL_H
/****************************************************************************
* Included Files
@@ -176,4 +176,4 @@ void sbi_late_initialize(void);
#endif
#endif /* __ASSEMBLY__ */
-#endif /* __ARCH_RISC_V_SRC_SBI_SBI_INTERNAL_H */
+#endif /* __ARCH_RISC_V_SRC_SBI_NUTTSBI_SBI_INTERNAL_H */
diff --git a/arch/risc-v/src/sbi/sbi_ipi.c
b/arch/risc-v/src/sbi/nuttsbi/sbi_ipi.c
similarity index 97%
rename from arch/risc-v/src/sbi/sbi_ipi.c
rename to arch/risc-v/src/sbi/nuttsbi/sbi_ipi.c
index d2b4e804267..b505cda28ff 100644
--- a/arch/risc-v/src/sbi/sbi_ipi.c
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_ipi.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_ipi.c
+ * arch/risc-v/src/sbi/nuttsbi/sbi_ipi.c
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/risc-v/src/sbi/sbi_mcall.c
b/arch/risc-v/src/sbi/nuttsbi/sbi_mcall.c
similarity index 70%
rename from arch/risc-v/src/sbi/sbi_mcall.c
rename to arch/risc-v/src/sbi/nuttsbi/sbi_mcall.c
index 5493136be18..70116ee8fbf 100644
--- a/arch/risc-v/src/sbi/sbi_mcall.c
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_mcall.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/nuttsbi/sbi_mcall.c
+ * arch/risc-v/src/sbi/nuttsbi/sbi_mcall.c
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -55,39 +55,41 @@ void sbi_mcall_handle(uintptr_t *regs)
/* Check the environment call number */
switch (regs[REG_A7])
- {
- case SBI_EXT_IPI:
- sbi_send_ipi(regs[REG_A0], regs[REG_A1]);
- break;
- case SBI_EXT_TIME:
- switch (regs[REG_A6])
- {
- case SBI_EXT_TIME_SET_TIMER:
+ {
+ case SBI_EXT_IPI:
+ sbi_send_ipi(regs[REG_A0], regs[REG_A1]);
+ break;
+ case SBI_EXT_TIME:
+ switch (regs[REG_A6])
+ {
+ case SBI_EXT_TIME_SET_TIMER:
#ifdef CONFIG_ARCH_RV64
- sbi_set_mtimecmp(regs[REG_A0]);
+ sbi_set_mtimecmp(regs[REG_A0]);
#else
- sbi_set_mtimecmp(regs[REG_A0] + ((uint64_t)regs[REG_A1] << 32));
+ sbi_set_mtimecmp(regs[REG_A0] +
+ ((uint64_t)regs[REG_A1] << 32));
#endif
- CLEAR_CSR(CSR_MIP, MIP_STIP);
- SET_CSR(CSR_MIE, MIE_MTIE);
- break;
- default:
- break;
- }
- break;
- case SBI_EXT_FIRMWARE:
+ CLEAR_CSR(CSR_MIP, MIP_STIP);
+ SET_CSR(CSR_MIE, MIE_MTIE);
+ break;
+ default:
+ break;
+ }
+ break;
+ case SBI_EXT_FIRMWARE:
#ifdef CONFIG_ARCH_RV64
- regs[REG_A0] = sbi_get_mtime();
+ regs[REG_A0] = sbi_get_mtime();
#else
- {
- uint64_t time = sbi_get_mtime();
- regs[REG_A0] = (uint32_t)time;
- regs[REG_A1] = (uint32_t)(time >> 32);
- }
+ {
+ uint64_t time = sbi_get_mtime();
+
+ regs[REG_A0] = (uint32_t)time;
+ regs[REG_A1] = (uint32_t)(time >> 32);
+ }
#endif
- break;
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
}
diff --git a/arch/risc-v/src/sbi/sbi_mcall.h
b/arch/risc-v/src/sbi/nuttsbi/sbi_mcall.h
similarity index 88%
rename from arch/risc-v/src/sbi/sbi_mcall.h
rename to arch/risc-v/src/sbi/nuttsbi/sbi_mcall.h
index 361030f38a1..66c117f6630 100644
--- a/arch/risc-v/src/sbi/sbi_mcall.h
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_mcall.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_mcall.h
+ * arch/risc-v/src/sbi/nuttsbi/sbi_mcall.h
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -20,8 +20,8 @@
*
****************************************************************************/
-#ifndef __ARCH_RISC_V_SRC_NUTTSBI_SBI_MCALL_H
-#define __ARCH_RISC_V_SRC_NUTTSBI_SBI_MCALL_H
+#ifndef __ARCH_RISC_V_SRC_SBI_NUTTSBI_SBI_MCALL_H
+#define __ARCH_RISC_V_SRC_SBI_NUTTSBI_SBI_MCALL_H
/****************************************************************************
* Included Files
@@ -38,4 +38,4 @@
#define SBI_EXT_FIRMWARE 0x0A000000
#define SBI_EXT_FIRMWARE_GET_MTIME 0x0
-#endif /* __ARCH_RISC_V_SRC_NUTTSBI_SBI_MCALL_H */
+#endif /* __ARCH_RISC_V_SRC_SBI_NUTTSBI_SBI_MCALL_H */
diff --git a/arch/risc-v/src/sbi/sbi_mexception.c
b/arch/risc-v/src/sbi/nuttsbi/sbi_mexception.c
similarity index 97%
rename from arch/risc-v/src/sbi/sbi_mexception.c
rename to arch/risc-v/src/sbi/nuttsbi/sbi_mexception.c
index 9ba65542188..0146a41bf7b 100644
--- a/arch/risc-v/src/sbi/sbi_mexception.c
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_mexception.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_mexception.c
+ * arch/risc-v/src/sbi/nuttsbi/sbi_mexception.c
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/risc-v/src/sbi/sbi_mscratch.c
b/arch/risc-v/src/sbi/nuttsbi/sbi_mscratch.c
similarity index 98%
rename from arch/risc-v/src/sbi/sbi_mscratch.c
rename to arch/risc-v/src/sbi/nuttsbi/sbi_mscratch.c
index 97a72269017..3ea56de4b0e 100644
--- a/arch/risc-v/src/sbi/sbi_mscratch.c
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_mscratch.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_mscratch.c
+ * arch/risc-v/src/sbi/nuttsbi/sbi_mscratch.c
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/risc-v/src/sbi/sbi_mtimer.c
b/arch/risc-v/src/sbi/nuttsbi/sbi_mtimer.c
similarity index 98%
rename from arch/risc-v/src/sbi/sbi_mtimer.c
rename to arch/risc-v/src/sbi/nuttsbi/sbi_mtimer.c
index a41cb1d2eb0..6a5e489b2bc 100644
--- a/arch/risc-v/src/sbi/sbi_mtimer.c
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_mtimer.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_mtimer.c
+ * arch/risc-v/src/sbi/nuttsbi/sbi_mtimer.c
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/risc-v/src/sbi/sbi_mtrap.S
b/arch/risc-v/src/sbi/nuttsbi/sbi_mtrap.S
similarity index 98%
rename from arch/risc-v/src/sbi/sbi_mtrap.S
rename to arch/risc-v/src/sbi/nuttsbi/sbi_mtrap.S
index 3687176dfdc..e2a98d07589 100644
--- a/arch/risc-v/src/sbi/sbi_mtrap.S
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_mtrap.S
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_machine_trap.S
+ * arch/risc-v/src/sbi/nuttsbi/sbi_machine_trap.S
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/risc-v/src/sbi/sbi_start.c
b/arch/risc-v/src/sbi/nuttsbi/sbi_start.c
similarity index 98%
rename from arch/risc-v/src/sbi/sbi_start.c
rename to arch/risc-v/src/sbi/nuttsbi/sbi_start.c
index bff85f18b95..4ea474b15c9 100644
--- a/arch/risc-v/src/sbi/sbi_start.c
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_start.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/nuttsbi/sbi_start.c
+ * arch/risc-v/src/sbi/nuttsbi/sbi_start.c
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -132,6 +132,7 @@ void sbi_start(void)
/* Then jump to the S-mode start function */
register long r0 asm("a0") = (long) hartid;
+
__asm__ __volatile__("mret" : : "r"(r0));
PANIC();
diff --git a/arch/risc-v/src/sbi/sbi_vectors.S
b/arch/risc-v/src/sbi/nuttsbi/sbi_vectors.S
similarity index 96%
rename from arch/risc-v/src/sbi/sbi_vectors.S
rename to arch/risc-v/src/sbi/nuttsbi/sbi_vectors.S
index 330bb8d31df..8a9f7032b2b 100644
--- a/arch/risc-v/src/sbi/sbi_vectors.S
+++ b/arch/risc-v/src/sbi/nuttsbi/sbi_vectors.S
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/risc-v/src/sbi/sbi_machine_vectors.S
+ * arch/risc-v/src/sbi/nuttsbi/sbi_machine_vectors.S
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/risc-v/src/opensbi/.gitignore
b/arch/risc-v/src/sbi/opensbi/.gitignore
similarity index 100%
rename from arch/risc-v/src/opensbi/.gitignore
rename to arch/risc-v/src/sbi/opensbi/.gitignore
diff --git a/arch/risc-v/src/sbi/CMakeLists.txt
b/arch/risc-v/src/sbi/opensbi/CMakeLists.txt
similarity index 78%
copy from arch/risc-v/src/sbi/CMakeLists.txt
copy to arch/risc-v/src/sbi/opensbi/CMakeLists.txt
index 69bb3c2cdb9..38ac59757e5 100644
--- a/arch/risc-v/src/sbi/CMakeLists.txt
+++ b/arch/risc-v/src/sbi/opensbi/CMakeLists.txt
@@ -1,5 +1,5 @@
#
##############################################################################
-# arch/risc-v/src/sbi/CMakeLists.txt
+# arch/risc-v/src/sbi/opensbi/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -20,14 +20,5 @@
#
#
##############################################################################
-if(CONFIG_NUTTSBI)
-
- set(SRCS sbi_head.S sbi_mtrap.S sbi_vectors.S sbi_start.c)
-
- list(APPEND SRCS sbi_mtimer.c sbi_mexception.c sbi_mcall.c sbi_mscratch.c)
-
- list(APPEND SRCS sbi_ipi.c)
-
- target_sources(arch PRIVATE ${SRCS})
-
-endif()
+target_include_directories(
+ arch BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/opensbi-3rdparty/include)
diff --git a/arch/risc-v/src/opensbi/Kconfig
b/arch/risc-v/src/sbi/opensbi/Kconfig
similarity index 97%
rename from arch/risc-v/src/opensbi/Kconfig
rename to arch/risc-v/src/sbi/opensbi/Kconfig
index 6e281c54478..bcac606f635 100644
--- a/arch/risc-v/src/opensbi/Kconfig
+++ b/arch/risc-v/src/sbi/opensbi/Kconfig
@@ -1,5 +1,5 @@
############################################################################
-# arch/risc-v/src/opensbi/Kconfig
+# arch/risc-v/src/sbi/opensbi/Kconfig
#
# SPDX-License-Identifier: Apache-2.0
#
diff --git a/arch/risc-v/src/sbi/opensbi/Make.defs
b/arch/risc-v/src/sbi/opensbi/Make.defs
new file mode 100644
index 00000000000..ac429af76f7
--- /dev/null
+++ b/arch/risc-v/src/sbi/opensbi/Make.defs
@@ -0,0 +1,68 @@
+############################################################################
+# arch/risc-v/src/sbi/opensbi/Make.defs
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+DEPPATH += --dep-path sbi/opensbi/opensbi-3rdparty
+VPATH += :sbi/opensbi/opensbi-3rdparty
+
+SBI_CSRCS = $(wildcard sbi/opensbi/opensbi-3rdparty/lib/sbi/*.c)
+SBI_CSRCS += sbi/opensbi/opensbi-3rdparty/lib/utils/ipi/aclint_mswi.c
+SBI_CSRCS += sbi/opensbi/opensbi-3rdparty/lib/utils/irqchip/plic.c
+SBI_CSRCS += sbi/opensbi/opensbi-3rdparty/lib/utils/timer/aclint_mtimer.c
+
+EXCLUDED_FILES = sbi/opensbi/opensbi-3rdparty/lib/sbi/sbi_pmu.c
+EXCLUDED_FILES += sbi/opensbi/opensbi-3rdparty/lib/sbi/sbi_ecall_dbcn.c
+
+TMPVAR := $(SBI_CSRCS)
+SBI_CSRCS = $(filter-out $(EXCLUDED_FILES), $(TMPVAR))
+
+SBI_ASRCS += sbi/opensbi/opensbi-3rdparty/lib/sbi/sbi_expected_trap.S
+SBI_ASRCS += sbi/opensbi/opensbi-3rdparty/lib/sbi/sbi_hfence.S
+SBI_ASRCS += sbi/opensbi/opensbi-3rdparty/lib/sbi/riscv_hardfp.S
+
+INCLUDES +=
${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)sbi$(DELIM)opensbi$(DELIM)opensbi-3rdparty$(DELIM)include
+
+SBI_DIR := sbi/opensbi
+
+OPENSBI_UNPACK = opensbi-3rdparty
+OPENSBI_COMMIT = fbaaafe808f3da7745760d757c436ef1b293d3ed
+OPENSBI_URL = https://github.com/riscv-software-src/opensbi/tarball
+OPENSBI_TARBALL = opensbi.tar.gz
+OPENSBI_DIR = riscv-software-src-opensbi-fbaaafe
+
+$(OPENSBI_TARBALL):
+ $(call
DOWNLOAD,$(OPENSBI_URL),$(OPENSBI_COMMIT),sbi/opensbi/$(OPENSBI_TARBALL))
+
+.opensbi_unpack: $(OPENSBI_TARBALL)
+ $(Q) echo "Unpacking: OpenSBI"
+ $(Q) tar xzf sbi/opensbi/$(OPENSBI_TARBALL) -C sbi/opensbi
+ $(Q) mv sbi/opensbi/$(OPENSBI_DIR) sbi/opensbi/$(OPENSBI_UNPACK)
+ $(Q) touch sbi/opensbi/.opensbi_unpack
+ $(Q) sbi/opensbi/$(OPENSBI_UNPACK)/scripts/carray.sh -i
sbi/opensbi/$(OPENSBI_UNPACK)/lib/sbi/sbi_ecall_exts.carray -l "ecall_base
ecall_hsm ecall_ipi ecall_rfence ecall_time ecall_vendor" >
sbi/opensbi/$(OPENSBI_UNPACK)/lib/sbi/sbi_ecall_exts.c
+
+ifeq ($(wildcard sbi/opensbi/$(OPENSBI_UNPACK)/.git),)
+context:: .opensbi_unpack
+
+distclean::
+ $(call DELFILE, sbi/opensbi/.opensbi_unpack)
+ $(call DELFILE, sbi/opensbi/$(OPENSBI_TARBALL))
+ $(call DELDIR, sbi/opensbi/$(OPENSBI_UNPACK))
+endif