arch/risc-v: Add support for S-mode flat build

There is no need to use kernel build for S-mode all the time. As cpu
scratch is supported for non kernel mode build, it is possible to use
flat build for S-mode.

Add flat build support for risc-v S mode.

Signed-off-by: Inochi Amaoto <inochiama@outlook.com>
This commit is contained in:
Inochi Amaoto 2024-06-12 10:39:41 +08:00 committed by Xiang Xiao
parent 8ebc3aa9e8
commit e37348aeba
8 changed files with 20 additions and 13 deletions

View File

@ -516,9 +516,9 @@ config RISCV_PERCPU_SCRATCH
#
config ARCH_USE_S_MODE
bool "Run the NuttX kernel in S-mode"
bool "Run NuttX in S-mode"
default n
depends on ARCH_HAVE_S_MODE && BUILD_KERNEL && ARCH_USE_MMU
depends on ARCH_HAVE_S_MODE
select RISCV_PERCPU_SCRATCH
---help---
Most of the RISC-V implementations run in M-mode (flat addressing)

View File

@ -109,7 +109,7 @@ if(CONFIG_RISCV_PERCPU_SCRATCH)
list(APPEND SRCS riscv_percpu.c)
endif()
if(CONFIG_BUILD_KERNEL)
if(CONFIG_ARCH_USE_S_MODE)
add_subdirectory(supervisor)
endif()

View File

@ -18,8 +18,7 @@
#
# ##############################################################################
if(CONFIG_BUILD_KERNEL)
if(CONFIG_ARCH_USE_S_MODE)
set(SRCS)
list(APPEND SRCS riscv_syscall.S riscv_perform_syscall.c riscv_sbi.c)

View File

@ -59,7 +59,7 @@ __start:
/* Preserve a1 by not using it here as it contains DTB */
#ifndef CONFIG_BUILD_KERNEL
#ifndef CONFIG_ARCH_USE_S_MODE
/* Load mhartid (cpuid) */
csrr a0, CSR_MHARTID

View File

@ -122,7 +122,7 @@ void k230_start(int mhartid, const char *dtb)
#endif
}
#ifndef CONFIG_BUILD_KERNEL
#ifndef CONFIG_ARCH_USE_S_MODE
k230_hart_init();
#endif

View File

@ -45,7 +45,7 @@ __start:
/* Preserve a1 as it contains the pointer to DTB */
/* Load mhartid (cpuid) */
#ifndef CONFIG_BUILD_KERNEL
#ifndef CONFIG_ARCH_USE_S_MODE
csrr a0, CSR_MHARTID
#endif

View File

@ -58,7 +58,7 @@
* Extern Function Declarations
****************************************************************************/
#ifdef CONFIG_BUILD_KERNEL
#ifdef CONFIG_ARCH_USE_S_MODE
extern void __start(void);
#endif
@ -80,7 +80,7 @@ static void qemu_rv_clear_bss(void)
}
}
#ifdef CONFIG_BUILD_KERNEL
#ifdef CONFIG_ARCH_USE_S_MODE
static void qemu_boot_secondary(int mhartid, uintptr_t dtb)
{
int i;
@ -101,7 +101,7 @@ static void qemu_boot_secondary(int mhartid, uintptr_t dtb)
* Private Data
****************************************************************************/
#ifdef CONFIG_BUILD_KERNEL
#ifdef CONFIG_ARCH_USE_S_MODE
static bool boot_secondary = false;
#endif
@ -119,7 +119,7 @@ static bool boot_secondary = false;
void qemu_rv_start(int mhartid, const char *dtb)
{
#ifdef CONFIG_BUILD_KERNEL
#ifdef CONFIG_ARCH_USE_S_MODE
/* Boot other cores */
if (!boot_secondary)

View File

@ -18,9 +18,17 @@
*
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_ARCH_USE_S_MODE
#define TEXT_ADDR 0x80200000
#else
#define TEXT_ADDR 0x80000000
#endif
SECTIONS
{
. = 0x80000000;
. = TEXT_ADDR;
/* where the global variable out-of-bounds detection information located */
#ifdef CONFIG_MM_KASAN_GLOBAL