arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
# Copyright (c) 2016 Jean-Paul Etienne <fractalclone@gmail.com>
|
2024-07-09 13:25:46 +02:00
|
|
|
# Copyright (c) 2024 Antmicro <www.antmicro.com>
|
2017-01-18 17:01:01 -08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2019-07-17 13:17:05 -04:00
|
|
|
menu "RISCV Options"
|
|
|
|
|
depends on RISCV
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
|
config ARCH
|
|
|
|
|
string
|
2024-02-07 11:23:28 +01:00
|
|
|
default "riscv"
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2020-04-07 15:24:36 -07:00
|
|
|
config FLOAT_HARD
|
2022-03-09 12:05:12 +01:00
|
|
|
bool "Hard-float calling convention"
|
2020-04-07 15:24:36 -07:00
|
|
|
default y
|
2020-04-23 17:27:24 +09:00
|
|
|
depends on FPU
|
2025-10-28 13:49:22 +01:00
|
|
|
depends on !RISCV_ISA_RV32E
|
|
|
|
|
depends on RISCV_ISA_EXT_F
|
2020-04-07 15:24:36 -07:00
|
|
|
help
|
|
|
|
|
This option enables the hard-float calling convention.
|
2025-10-28 13:49:22 +01:00
|
|
|
Adds eight floating-point argument registers.
|
2020-04-07 15:24:36 -07:00
|
|
|
|
2025-11-29 02:16:08 +08:00
|
|
|
config RISCV_USE_MSAVE_RESTORE
|
|
|
|
|
bool "Compile with -msave-restore to reduce some code footprint"
|
|
|
|
|
help
|
|
|
|
|
The `-msave-restore` option enables the compiler to emit calls to library
|
|
|
|
|
routines `__riscv_save_X` and `__riscv_restore_X` for preserving the
|
|
|
|
|
callee-saved registers instead of inlining them in every function. This
|
|
|
|
|
can reduce code size in some large functions. However, it introduces extra
|
|
|
|
|
branching overhead, which may impact the performance in hot paths.
|
|
|
|
|
|
|
|
|
|
If supported by your SoC, the `Zcmp` ISA extension should be preferred.
|
|
|
|
|
|
2024-11-25 12:54:01 +08:00
|
|
|
choice RISCV_GP_PURPOSE
|
|
|
|
|
prompt "Purpose of the global pointer (GP) register"
|
|
|
|
|
default RISCV_GP if RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
|
|
|
|
|
|
2021-08-17 02:38:33 +08:00
|
|
|
config RISCV_GP
|
2022-03-09 12:05:12 +01:00
|
|
|
bool "RISC-V global pointer relative addressing"
|
2024-11-25 12:54:01 +08:00
|
|
|
depends on RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
|
2021-08-17 02:38:33 +08:00
|
|
|
help
|
|
|
|
|
Use global pointer relative addressing for small globals declared
|
|
|
|
|
anywhere in the executable. It can benefit performance and reduce
|
|
|
|
|
the code size.
|
|
|
|
|
|
|
|
|
|
Note: To support this feature, RISC-V SoC needs to initialize
|
|
|
|
|
global pointer at program start or earlier than any instruction
|
|
|
|
|
using GP relative addressing.
|
|
|
|
|
|
2024-11-01 12:12:41 +08:00
|
|
|
config RISCV_CURRENT_VIA_GP
|
|
|
|
|
bool "Store current thread into the global pointer (GP) register"
|
|
|
|
|
depends on MP_MAX_NUM_CPUS > 1
|
|
|
|
|
select ARCH_HAS_CUSTOM_CURRENT_IMPL
|
|
|
|
|
help
|
|
|
|
|
Store the current thread's pointer into the global pointer (GP) register.
|
2025-01-07 12:00:43 -05:00
|
|
|
When is enabled, calls to `_current` & `k_sched_current_thread_query()` will
|
2024-11-01 12:12:41 +08:00
|
|
|
be reduced to a single register read.
|
|
|
|
|
|
2024-11-25 12:54:01 +08:00
|
|
|
endchoice # RISCV_GP_PURPOSE
|
|
|
|
|
|
2022-06-30 14:40:52 +02:00
|
|
|
config RISCV_ALWAYS_SWITCH_THROUGH_ECALL
|
|
|
|
|
bool "Do not use mret outside a trap handler context"
|
2023-05-30 16:30:56 -04:00
|
|
|
depends on MULTITHREADING
|
2022-06-30 14:40:52 +02:00
|
|
|
help
|
|
|
|
|
Use mret instruction only when in a trap handler.
|
|
|
|
|
This is for RISC-V implementations that require every mret to be
|
|
|
|
|
balanced with an ecall. This is not required by the RISC-V spec
|
|
|
|
|
and most people should say n here to minimize context switching
|
|
|
|
|
overhead.
|
|
|
|
|
|
2026-04-30 12:47:10 +01:00
|
|
|
DT_CHOSEN_Z_SRAM = zephyr,sram
|
|
|
|
|
|
2025-07-03 14:40:14 +09:00
|
|
|
choice RISCV_CMODEL
|
|
|
|
|
prompt "RISC-V Code Model"
|
2026-04-30 12:47:10 +01:00
|
|
|
default RISCV_CMODEL_LARGE if (SRAM_DEPRECATED_KCONFIG_SET && SRAM_BASE_ADDRESS > 0xffffffff) || \
|
|
|
|
|
(!SRAM_DEPRECATED_KCONFIG_SET && $(dt_chosen_reg_addr_int,$(DT_CHOSEN_Z_SRAM),0) > 0xffffffff) || \
|
|
|
|
|
(KERNEL_VM_BASE > 0xffffffff)
|
2025-07-03 14:40:14 +09:00
|
|
|
default RISCV_CMODEL_MEDANY if 64BIT
|
|
|
|
|
default RISCV_CMODEL_MEDLOW
|
|
|
|
|
|
|
|
|
|
config RISCV_CMODEL_MEDLOW
|
|
|
|
|
bool "Medium-low code model"
|
|
|
|
|
help
|
|
|
|
|
In medium-low code model (medlow), the program and its statically defined symbols must lie
|
|
|
|
|
within a single 2 GiB address range and between absolute addresses -2 GiB and +2 GiB.
|
|
|
|
|
|
|
|
|
|
config RISCV_CMODEL_MEDANY
|
|
|
|
|
bool "Medium-any code model"
|
|
|
|
|
help
|
|
|
|
|
In medium-any code model (medany), the program and its statically defined symbols must be
|
|
|
|
|
within any single 2 GiB address range. The code generated by this model is
|
|
|
|
|
position-independent.
|
|
|
|
|
|
|
|
|
|
config RISCV_CMODEL_LARGE
|
|
|
|
|
bool "Large code model"
|
|
|
|
|
help
|
|
|
|
|
In large code model (large), the program and its statically defined symbols have no
|
|
|
|
|
restrictions on size and placement.
|
|
|
|
|
|
|
|
|
|
endchoice
|
|
|
|
|
|
2024-11-12 13:15:24 +08:00
|
|
|
choice RISCV_SMP_IPI_IMPL
|
|
|
|
|
prompt "RISC-V SMP IPI implementation"
|
|
|
|
|
depends on SMP
|
|
|
|
|
default RISCV_SMP_IPI_CLINT if DT_HAS_SIFIVE_CLINT0_ENABLED
|
|
|
|
|
default RISCV_SMP_IPI_CUSTOM
|
|
|
|
|
|
|
|
|
|
config RISCV_SMP_IPI_CLINT
|
|
|
|
|
bool "CLINT-based IPI"
|
|
|
|
|
depends on DT_HAS_SIFIVE_CLINT0_ENABLED
|
|
|
|
|
help
|
|
|
|
|
Use CLINT-based IPI implementation.
|
|
|
|
|
|
2026-08-29 00:56:01 +05:30
|
|
|
config RISCV_SMP_IPI_SBI
|
|
|
|
|
bool "SBI-based IPI"
|
|
|
|
|
depends on RISCV_S_MODE_EXTERNAL_SBI
|
|
|
|
|
help
|
|
|
|
|
Use the SBI IPI extension (sbi_send_ipi) to raise the supervisor
|
|
|
|
|
software interrupt on the target hart. This is the implementation to
|
|
|
|
|
use when Zephyr runs in S-mode as a payload of an external SBI such
|
|
|
|
|
as OpenSBI, which owns the CLINT.
|
|
|
|
|
|
2024-11-12 13:15:24 +08:00
|
|
|
config RISCV_SMP_IPI_CUSTOM
|
|
|
|
|
bool "Custom IPI implementation"
|
|
|
|
|
help
|
|
|
|
|
Allow custom IPI implementation.
|
|
|
|
|
|
|
|
|
|
When this is selected, the following functions must be provided:
|
|
|
|
|
- arch_sched_directed_ipi()
|
|
|
|
|
- arch_flush_fpu_ipi() if CONFIG_FPU_SHARING
|
|
|
|
|
- arch_spin_relax() if CONFIG_FPU_SHARING
|
|
|
|
|
- arch_smp_init()
|
|
|
|
|
|
|
|
|
|
endchoice # RISCV_SMP_IPI_IMPL
|
|
|
|
|
|
2019-07-17 13:17:05 -04:00
|
|
|
menu "RISCV Processor Options"
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
|
|
|
|
config INCLUDE_RESET_VECTOR
|
2024-06-28 14:02:27 +08:00
|
|
|
bool "Jumps to __initialize directly"
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
help
|
2024-06-28 14:02:27 +08:00
|
|
|
Select 'y' here to use the Zephyr provided default implementation that
|
|
|
|
|
jumps to `__initialize` directly. Otherwise a SOC needs to provide its
|
|
|
|
|
custom `__reset` routine.
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2024-01-03 12:39:36 +01:00
|
|
|
config RISCV_PRIVILEGED
|
|
|
|
|
bool
|
|
|
|
|
select ARCH_HAS_RAMFUNC_SUPPORT if XIP
|
|
|
|
|
help
|
|
|
|
|
Option selected by SoCs implementing the RISC-V privileged ISA.
|
|
|
|
|
|
2022-12-27 20:14:51 +01:00
|
|
|
config RISCV_SOC_HAS_ISR_STACKING
|
|
|
|
|
bool
|
|
|
|
|
depends on !USERSPACE
|
|
|
|
|
help
|
|
|
|
|
Enable low-level SOC-specific hardware stacking / unstacking
|
|
|
|
|
operations during ISR. This hidden option needs to be selected by SoC
|
|
|
|
|
if this feature is supported.
|
|
|
|
|
|
|
|
|
|
Some SOCs implement a mechanism for which, on interrupt handling,
|
|
|
|
|
part of the context is automatically saved by the hardware on the
|
|
|
|
|
stack according to a custom ESF format. The same part of the context
|
|
|
|
|
is automatically restored by hardware on mret.
|
|
|
|
|
|
|
|
|
|
Enabling this option requires that the SoC provides a
|
|
|
|
|
soc_isr_stacking.h header which defines the following:
|
|
|
|
|
|
|
|
|
|
- SOC_ISR_SW_STACKING: macro guarded by _ASMLANGUAGE called by the
|
|
|
|
|
IRQ wrapper assembly code on ISR entry to save in the ESF the
|
|
|
|
|
remaining part of the context not pushed already on the stack by
|
|
|
|
|
the hardware.
|
|
|
|
|
|
|
|
|
|
- SOC_ISR_SW_UNSTACKING: macro guarded by _ASMLANGUAGE called by the
|
|
|
|
|
IRQ wrapper assembly code on ISR exit to restore the part of the
|
|
|
|
|
context from the ESF that won't be restored by hardware on mret.
|
|
|
|
|
|
|
|
|
|
- SOC_ISR_STACKING_ESF_DECLARE: structure declaration for the ESF
|
|
|
|
|
guarded by !_ASMLANGUAGE. The ESF should be defined to account for
|
|
|
|
|
the hardware stacked registers in the proper order as they are
|
|
|
|
|
saved on the stack by the hardware, and the registers saved by the
|
2024-06-01 10:26:04 +08:00
|
|
|
software macros. The structure must be called 'struct arch_esf'.
|
2022-12-27 20:14:51 +01:00
|
|
|
|
2025-01-16 09:36:08 +01:00
|
|
|
- SOC_ISR_STACKING_ESR_INIT: macro guarded by !_ASMLANGUAGE.
|
|
|
|
|
Some hardware stacked registers should be initialized on init
|
|
|
|
|
stack with proper values. This prevents from incorrect behavior
|
|
|
|
|
on entry context switch when initial stack is restored.
|
|
|
|
|
|
2023-12-21 12:41:59 +00:00
|
|
|
config RISCV_SOC_HAS_CUSTOM_IRQ_HANDLING
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
This allows the SoC to overwrite the irq handling. If enabled, the
|
|
|
|
|
function __soc_handle_all_irqs has to be implemented. It shall service
|
|
|
|
|
and clear all pending interrupts.
|
|
|
|
|
|
2023-01-03 17:56:18 +01:00
|
|
|
config RISCV_SOC_HAS_CUSTOM_IRQ_LOCK_OPS
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Hidden option to allow SoC to overwrite arch_irq_lock(),
|
|
|
|
|
arch_irq_unlock() and arch_irq_unlocked() functions with
|
|
|
|
|
platform-specific versions named z_soc_irq_lock(), z_soc_irq_unlock()
|
|
|
|
|
and z_soc_irq_unlocked().
|
|
|
|
|
|
|
|
|
|
Enable this hidden option and specialize the z_soc_* functions when
|
|
|
|
|
the RISC-V SoC needs to do something different and more than reading and
|
|
|
|
|
writing the mstatus register to lock and unlock the IRQs.
|
|
|
|
|
|
2023-07-25 17:50:40 +08:00
|
|
|
config RISCV_SOC_HAS_CUSTOM_SYS_IO
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Hidden option to allow SoC to overwrite sys_read*(), sys_write*() functions with
|
|
|
|
|
platform-specific versions named z_soc_sys_read*() and z_soc_sys_write*().
|
|
|
|
|
|
|
|
|
|
Enable this hidden option and specialize the z_soc_* functions when
|
|
|
|
|
the RISC-V SoC needs to do something different and more than reading and
|
|
|
|
|
writing the registers.
|
|
|
|
|
|
arch: riscv: add soc hook to mask syscall interrupts
Some RISC-V SoCs cannot take an interrupt in the syscall body: an
interrupt, or another asynchronously reported event such as an
imprecise access fault, taken while the ECALL exception is still
being handled locks the CPU up, with no fault delivered to
software. Precise synchronous traps, such as the ECALL used to
switch out of the body, nest normally. The syscall path sets
mstatus.MIE before running the body, so such a SoC must hold
interrupts off another way.
This is not the Smdbltrp double trap. On the affected cores
reading mstatush traps, so there is no mstatus.MDT to clear, and
the vendor status CSR exposes the in-exception state as a
read-only bit that stays set until mret. Software cannot end the
exception window early, so the only option is to keep interrupts
from being taken while it is open.
Add the hidden RISCV_SOC_HAS_SYSCALL_INTMASK option following
the existing RISCV_SOC_HAS_* hook pattern. When a SoC selects it,
the IRQ wrapper invokes a SoC-provided SOC_SYSCALL_INTMASK macro
on syscall entry, typically raising a hardware interrupt level
threshold, while the generic code carries no SoC register
knowledge. This is a SoC hook rather than part of the generic
CLIC interrupt level support because the SoCs that need it drive
their interrupt controller from SoC code and do not select
RISCV_HAS_CLIC.
The mask is per exception frame. The SoC context hooks save the
state on entry and restore it on the exception exit path, and
with RISCV_ALWAYS_SWITCH_THROUGH_ECALL every context switch goes
through that path: a thread that blocks in the body hands the
CPU to a thread that restores its own saved state, and a new
thread starts from SOC_ESF_INIT. The option therefore depends on
both. While the mask is raised the body is not preemptible and
pending interrupts, the tick included, wait for the syscall to
return or block; the help text says so.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-07-05 15:31:01 -03:00
|
|
|
config RISCV_SOC_HAS_SYSCALL_INTMASK
|
|
|
|
|
bool
|
|
|
|
|
depends on USERSPACE
|
|
|
|
|
depends on RISCV_SOC_CONTEXT_SAVE
|
|
|
|
|
depends on RISCV_ALWAYS_SWITCH_THROUGH_ECALL
|
|
|
|
|
help
|
|
|
|
|
Hidden option for SoCs where an interrupt, or another asynchronously
|
|
|
|
|
reported event such as an imprecise access fault, taken while the ECALL
|
|
|
|
|
exception of a user-mode syscall is still being handled cannot be
|
|
|
|
|
delivered safely. Precise synchronous traps, such as the ECALL used to
|
|
|
|
|
switch out of the syscall body, nest normally. The syscall path sets
|
|
|
|
|
mstatus.MIE before running the syscall body, so such a SoC must hold
|
|
|
|
|
interrupts off another way.
|
|
|
|
|
|
|
|
|
|
Enable this hidden option and provide a soc_syscall.h header defining
|
|
|
|
|
the SOC_SYSCALL_INTMASK macro (guarded by _ASMLANGUAGE). The IRQ
|
|
|
|
|
wrapper invokes it on syscall entry, after the SoC context has been
|
|
|
|
|
saved and at a point where the caller-saved temporaries are free, so
|
|
|
|
|
the macro may clobber them. Typically it raises a hardware interrupt
|
|
|
|
|
level threshold. This is a SoC hook rather than part of the generic
|
|
|
|
|
CLIC interrupt level support because the SoCs that need it drive
|
|
|
|
|
their interrupt controller from SoC code and do not select
|
|
|
|
|
RISCV_HAS_CLIC, so the generic code has no view of their threshold.
|
|
|
|
|
|
|
|
|
|
The mask is per exception frame: the SoC context save/restore hooks
|
|
|
|
|
(RISCV_SOC_CONTEXT_SAVE) save the state on trap entry and restore it
|
|
|
|
|
on the exception exit path. Because every context switch goes through
|
|
|
|
|
that path (RISCV_ALWAYS_SWITCH_THROUGH_ECALL), a thread that blocks in
|
|
|
|
|
the syscall body hands the CPU to a thread that restores its own saved
|
|
|
|
|
state, and a new thread starts from SOC_ESF_INIT. The mask therefore
|
|
|
|
|
ends when the syscall returns or the thread switches out, never later.
|
|
|
|
|
|
|
|
|
|
The cost is that the syscall body is not preemptible: nothing is
|
|
|
|
|
delivered while the mask is raised, so interrupts, including the
|
|
|
|
|
system tick, stay pending until the syscall returns or blocks.
|
|
|
|
|
arch_irq_unlocked() is true only formally during that time, and a
|
|
|
|
|
body that bounds a busy wait with tick-derived uptime never times
|
|
|
|
|
out when the kernel is not tickless.
|
|
|
|
|
|
2026-09-08 10:53:19 -03:00
|
|
|
config RISCV_SOC_SYSCALL_CLOSE_ECALL
|
|
|
|
|
bool
|
|
|
|
|
depends on USERSPACE
|
|
|
|
|
help
|
|
|
|
|
Hidden option for SoCs that cannot deliver a fault raised by the
|
|
|
|
|
syscall body itself while the ECALL exception of a user-mode syscall
|
|
|
|
|
is still being handled. The stack guard below the privileged stack
|
|
|
|
|
catches a syscall whose call chain runs too deep, but on such a SoC
|
|
|
|
|
that access fault is reported asynchronously inside the open ECALL
|
|
|
|
|
and locks the core up, resetting the chip with nothing delivered to
|
|
|
|
|
software. Masking interrupts does not help: the fault comes from the
|
|
|
|
|
body, not from an interrupt controller.
|
|
|
|
|
|
|
|
|
|
Enable this hidden option to leave the exception before the syscall
|
|
|
|
|
body runs. The IRQ wrapper returns to the following instruction with
|
|
|
|
|
a trap return that stays in machine mode, so the body runs on the
|
|
|
|
|
same privileged stack with the same privileges, but outside the
|
|
|
|
|
exception. A fault taken in the body is then an ordinary top-level
|
|
|
|
|
trap the SoC delivers normally, and a syscall that overflows the
|
|
|
|
|
privileged stack is reported as a stack overflow and kills only the
|
|
|
|
|
offending thread.
|
|
|
|
|
|
|
|
|
|
The exception exit path reloads the exception program counter and
|
|
|
|
|
status register from the saved frame, so borrowing them here does
|
|
|
|
|
not disturb the return to user mode.
|
|
|
|
|
|
2024-11-25 12:54:01 +08:00
|
|
|
config RISCV_SOC_HAS_GP_RELATIVE_ADDRESSING
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Selected when SoC has implemented the initialization of global pointer (GP)
|
|
|
|
|
at program start, or earlier than any instruction using GP relative addressing.
|
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
config RISCV_SOC_CONTEXT_SAVE
|
2022-03-09 12:05:12 +01:00
|
|
|
bool "SOC-based context saving in IRQ handlers"
|
2018-12-02 18:46:26 -06:00
|
|
|
select RISCV_SOC_OFFSETS
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
help
|
2018-11-01 22:25:13 -06:00
|
|
|
Enable low-level SOC-specific context management, for SOCs
|
|
|
|
|
with extra state that must be saved when entering an
|
|
|
|
|
interrupt/exception, and restored on exit. If unsure, leave
|
|
|
|
|
this at the default value.
|
|
|
|
|
|
|
|
|
|
Enabling this option requires that the SoC provide a
|
|
|
|
|
soc_context.h header which defines the following macros:
|
|
|
|
|
|
|
|
|
|
- SOC_ESF_MEMBERS: structure component declarations to
|
|
|
|
|
allocate space for. The last such declaration should not
|
|
|
|
|
end in a semicolon, for portability. The generic RISC-V
|
|
|
|
|
architecture code will allocate space for these members in
|
|
|
|
|
a "struct soc_esf" type (typedefed to soc_esf_t), which will
|
|
|
|
|
be available if arch.h is included.
|
|
|
|
|
|
|
|
|
|
- SOC_ESF_INIT: structure contents initializer for struct soc_esf
|
|
|
|
|
state. The last initialized member should not end in a comma.
|
|
|
|
|
|
|
|
|
|
The generic architecture IRQ wrapper will also call
|
2018-12-07 09:29:14 -08:00
|
|
|
\_\_soc_save_context and \_\_soc_restore_context routines at
|
2018-11-01 22:25:13 -06:00
|
|
|
ISR entry and exit, respectively. These should typically
|
|
|
|
|
be implemented in assembly. If they were C functions, they
|
|
|
|
|
would have these signatures:
|
|
|
|
|
|
|
|
|
|
``void __soc_save_context(soc_esf_t *state);``
|
|
|
|
|
|
|
|
|
|
``void __soc_restore_context(soc_esf_t *state);``
|
|
|
|
|
|
|
|
|
|
The calls obey standard calling conventions; i.e., the state
|
|
|
|
|
pointer address is in a0, and ra contains the return address.
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2018-12-02 18:46:26 -06:00
|
|
|
config RISCV_SOC_OFFSETS
|
2022-03-09 12:05:12 +01:00
|
|
|
bool "SOC-based offsets"
|
2018-12-02 18:46:26 -06:00
|
|
|
help
|
|
|
|
|
Enabling this option requires that the SoC provide a soc_offsets.h
|
|
|
|
|
header which defines the following macros:
|
|
|
|
|
|
|
|
|
|
- GEN_SOC_OFFSET_SYMS(): a macro which expands to
|
|
|
|
|
GEN_OFFSET_SYM(soc_esf_t, soc_specific_member) calls
|
|
|
|
|
to ensure offset macros for SOC_ESF_MEMBERS are defined
|
|
|
|
|
in offsets.h. The last one should not end in a semicolon.
|
|
|
|
|
See gen_offset.h for more details.
|
|
|
|
|
|
2024-01-16 16:01:41 +01:00
|
|
|
config RISCV_HAS_PLIC
|
|
|
|
|
bool
|
|
|
|
|
depends on RISCV_PRIVILEGED
|
|
|
|
|
help
|
|
|
|
|
Does the SOC provide support for a Platform Level Interrupt Controller (PLIC).
|
|
|
|
|
|
|
|
|
|
config RISCV_HAS_CLIC
|
|
|
|
|
bool
|
|
|
|
|
depends on RISCV_PRIVILEGED
|
2024-07-03 17:11:12 +08:00
|
|
|
select RISCV_ALWAYS_SWITCH_THROUGH_ECALL if MULTITHREADING
|
|
|
|
|
select CLIC_SUPPORT_INTERRUPT_LEVEL if !NRFX_CLIC
|
2024-01-16 16:01:41 +01:00
|
|
|
help
|
|
|
|
|
Does the SOC provide support for a Core-Local Interrupt Controller (CLIC).
|
|
|
|
|
|
2026-01-02 23:20:02 +00:00
|
|
|
config RISCV_HAS_AIA
|
|
|
|
|
bool
|
|
|
|
|
depends on RISCV_PRIVILEGED
|
|
|
|
|
help
|
|
|
|
|
Does the SOC provide support for the Advanced Interrupt Architecture (AIA),
|
|
|
|
|
which includes APLIC (Advanced Platform-Level Interrupt Controller) and
|
|
|
|
|
IMSIC (Incoming Message-Signaled Interrupt Controller).
|
|
|
|
|
|
2024-07-03 17:11:12 +08:00
|
|
|
config CLIC_SUPPORT_INTERRUPT_LEVEL
|
|
|
|
|
bool
|
|
|
|
|
depends on RISCV_HAS_CLIC
|
|
|
|
|
help
|
|
|
|
|
For CLIC implementations with extended interrupt level, where
|
|
|
|
|
higher-numbered interrupt levels can preempt lower-numbered interrupt
|
|
|
|
|
levels. This option handles interrupt level in ISR to ensure proper
|
|
|
|
|
nested ISR exits.
|
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
config RISCV_SOC_INTERRUPT_INIT
|
2022-03-09 12:05:12 +01:00
|
|
|
bool "SOC-based interrupt initialization"
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
help
|
2017-12-13 10:08:21 -05:00
|
|
|
Enable SOC-based interrupt initialization
|
|
|
|
|
(call soc_interrupt_init, within _IntLibInit when enabled)
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2024-01-10 15:53:24 +01:00
|
|
|
config RISCV_MCAUSE_EXCEPTION_MASK
|
2020-03-03 21:27:10 +09:00
|
|
|
hex
|
|
|
|
|
default 0x7FFFFFFFFFFFFFFF if 64BIT
|
|
|
|
|
default 0x7FFFFFFF
|
|
|
|
|
help
|
|
|
|
|
Specify the bits to use for exception code in mcause register.
|
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
config RISCV_GENERIC_TOOLCHAIN
|
|
|
|
|
bool "Compile using generic riscv32 toolchain"
|
|
|
|
|
default y
|
|
|
|
|
help
|
2017-12-13 10:08:21 -05:00
|
|
|
Compile using generic riscv32 toolchain.
|
|
|
|
|
Allow SOCs that have custom extended riscv ISA to still
|
|
|
|
|
compile with generic riscv32 toolchain.
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
|
2025-07-30 10:11:47 +02:00
|
|
|
config USE_ISR_WRAPPER
|
|
|
|
|
bool "Use isr_wrapper to handle interrupt and/or exception/fault"
|
|
|
|
|
default y if MULTITHREADING
|
|
|
|
|
help
|
|
|
|
|
This is helper config to be able to use exception handling from
|
|
|
|
|
_isr_wrapper when GEN_SW_ISR_TABLE is not enabled. E.g. MULTITHREADING
|
|
|
|
|
needs exception handling and thread entry/switch functions but may
|
|
|
|
|
use only irq vector table.
|
|
|
|
|
|
2017-02-13 10:11:54 -08:00
|
|
|
config GEN_ISR_TABLES
|
|
|
|
|
default y
|
|
|
|
|
|
2025-07-30 10:11:47 +02:00
|
|
|
config GEN_SW_ISR_TABLE
|
|
|
|
|
default y
|
2026-09-17 14:18:05 -07:00
|
|
|
depends on GEN_ISR_TABLES
|
2025-07-30 10:11:47 +02:00
|
|
|
select USE_ISR_WRAPPER
|
|
|
|
|
|
2017-02-13 10:11:54 -08:00
|
|
|
config GEN_IRQ_VECTOR_TABLE
|
|
|
|
|
default n
|
|
|
|
|
|
2023-06-07 16:03:45 +02:00
|
|
|
config RISCV_RESERVED_IRQ_ISR_TABLES_OFFSET
|
|
|
|
|
int
|
|
|
|
|
default 0
|
|
|
|
|
depends on GEN_ISR_TABLES
|
|
|
|
|
help
|
kconfig: fix typo in (arch, boards, kernel, modules, samples, share)
Utilize a code spell-checking tool to scan for and correct spelling errors
in `Kconfig` files within the `arch`, `boards`, `kernel`, `modules`,
`samples`, and `share` directory.
Additionally, incorporates a fix recommended by the reviewer.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-06-28 02:50:25 +07:00
|
|
|
On some RISCV platform the first interrupt vectors are primarily
|
2023-06-07 16:03:45 +02:00
|
|
|
intended for inter-hart interrupt signaling and so retained for that
|
|
|
|
|
purpose and not available. When this option is set, all the IRQ
|
|
|
|
|
vectors are shifted by this offset value when installed into the
|
|
|
|
|
software ISR table and the IRQ vector table. CONFIG_NUM_IRQS must be
|
|
|
|
|
properly sized to take into account this offset. This is a hidden
|
|
|
|
|
option which needs to be set per architecture and left alone.
|
|
|
|
|
|
2019-10-25 12:01:04 +02:00
|
|
|
config NUM_IRQS
|
|
|
|
|
int
|
|
|
|
|
|
2023-01-16 13:53:06 +00:00
|
|
|
config RV_BOOT_HART
|
|
|
|
|
int "Starting HART ID"
|
|
|
|
|
default 0
|
|
|
|
|
help
|
|
|
|
|
This option sets the starting HART ID for the SMP core.
|
|
|
|
|
For RISC-V systems such as MPFS and FU540 this would be set to 1 to
|
|
|
|
|
skip the E51 HART 0 as it is not usable in SMP configurations.
|
|
|
|
|
|
2024-03-08 00:00:36 +08:00
|
|
|
config RISCV_HART_MASK
|
|
|
|
|
int
|
|
|
|
|
default -1
|
|
|
|
|
help
|
|
|
|
|
Configures the mask for the HART ID.
|
|
|
|
|
For RISC-V systems with HART ID starting from non-zero value,
|
|
|
|
|
i.e. 128, 129, ..(0x80, 8x81, ..), this can be configured to 63 (0x7f)
|
|
|
|
|
such that we can extract the bits that start from 0.
|
|
|
|
|
|
2026-09-01 15:50:25 +02:00
|
|
|
config RISCV_USER_COUNTER_ACCESS
|
|
|
|
|
bool
|
|
|
|
|
depends on RISCV_ISA_EXT_ZICNTR
|
|
|
|
|
default y if USERSPACE
|
|
|
|
|
help
|
|
|
|
|
Set mcounteren, and scounteren on harts that implement S-mode, so
|
|
|
|
|
that user threads can read the Zicntr counters directly instead of
|
|
|
|
|
taking an illegal instruction exception.
|
|
|
|
|
|
2022-05-13 00:00:19 -04:00
|
|
|
config RISCV_PMP
|
2020-07-21 15:59:23 +02:00
|
|
|
bool "RISC-V PMP Support"
|
arch: riscv: add Supervisor-mode (S-mode) support
Introduce CONFIG_RISCV_S_MODE to select Supervisor-mode execution.
Add depends on !RISCV_S_MODE to RISCV_PMP since PMP CSRs are
inaccessible from S-mode.
Add an M-mode SBI shim (reset.S + sbi.S) that configures exception
delegation, PMP, and counter access before dropping to S-mode via mret.
The shim handles SBI_SET_TIMER ecalls from S-mode and forwards MTIP to
STIP so the supervisor timer driver works without a full SBI firmware.
Introduce privilege-level abstractions in isr.S (RV_CAUSE, RV_EPC,
RV_STATUS, RV_TVAL, etc.) and update all runtime code that previously
accessed M-mode-only CSRs (mcause, mtval, mstatus, mie, mip) to use the
S-mode equivalents when CONFIG_RISCV_S_MODE is set.
ARCH_EXCEPT in kernel context uses ebreak (cause=3, Breakpoint) instead
of a direct z_riscv_fatal_error() call. In S-mode, ecall (cause=9) is
kept in M-mode for SBI and never reaches the S-mode exception handler;
a direct call with NULL esf caused the stack unwinder to crash into an
infinite fault loop. ebreak is delegated to S-mode by our medeleg
configuration; isr.S treats ebreak with t0=RV_ECALL_RUNTIME_EXCEPT the
same way M-mode treats ecall-based ARCH_EXCEPT.
Signed-off-by: Alexios Lyrakis <alexios.lyrakis@gmail.com>
2026-03-28 15:34:55 +00:00
|
|
|
depends on !RISCV_S_MODE
|
2020-07-21 15:59:23 +02:00
|
|
|
select THREAD_STACK_INFO
|
2020-11-05 14:30:20 -08:00
|
|
|
select CPU_HAS_MPU
|
2022-05-13 00:00:19 -04:00
|
|
|
select ARCH_HAS_USERSPACE
|
2022-10-24 13:32:58 -04:00
|
|
|
select ARCH_HAS_STACK_PROTECTION
|
2020-11-05 14:30:20 -08:00
|
|
|
select MPU
|
|
|
|
|
select SRAM_REGION_PERMISSIONS
|
2020-07-21 15:59:23 +02:00
|
|
|
select ARCH_MEM_DOMAIN_SYNCHRONOUS_API if USERSPACE
|
2022-04-06 22:03:54 -04:00
|
|
|
select ARCH_MEM_DOMAIN_DATA if USERSPACE
|
2022-06-07 09:37:59 -04:00
|
|
|
select THREAD_LOCAL_STORAGE if USERSPACE
|
2024-04-25 12:10:03 -07:00
|
|
|
select ARCH_MEM_DOMAIN_SUPPORTS_ISOLATED_STACKS
|
2026-03-10 10:58:16 -04:00
|
|
|
select MEM_DOMAIN_ISOLATED_STACKS if USERSPACE
|
riscv: pmp: Support custom entries from Device Tree for memory attributes
The Physical Memory Protection (PMP) initialization is updated to support
custom entries defined in the Device Tree (DT) using the `zephyr,memattr`
property, contingent on `CONFIG_MEM_ATTR` being enabled. A new function,
`set_pmp_mem_attr()`, iterates over DT-defined regions and programs PMP
entries in `z_riscv_pmp_init()`, allowing for early, flexible, and
hardware-specific R/W/X protection for critical memory areas. DT-based
entries are also installed in `z_riscv_pmp_kernelmode_prepare()` for
thread-specific configuration. The logic for the temporary PMP "catch-all"
entry is adjusted to account for new DT entries. Furthermore, the PMP
domain resync logic now masks user partition permissions against DT-defined
region permissions, preventing privilege escalation. `CONFIG_RISCV_PMP` is
updated to select `PMP_KERNEL_MODE_DYNAMIC` if `MEM_ATTR`. Finally, the
`pmp_cfg` array in `z_riscv_pmp_init()` is initialized to zero to prevent
writing uninitialized stack data to unused PMP entries.
Signed-off-by: Firas Sammoura <fsammoura@google.com>
2025-09-18 20:37:57 +00:00
|
|
|
select PMP_KERNEL_MODE_DYNAMIC if MEM_ATTR
|
2026-05-22 17:48:48 +02:00
|
|
|
select ARCH_HAS_EXECUTABLE_PAGE_BIT
|
2020-07-21 15:59:23 +02:00
|
|
|
help
|
|
|
|
|
MCU implements Physical Memory Protection.
|
|
|
|
|
|
|
|
|
|
if RISCV_PMP
|
2022-04-06 22:03:54 -04:00
|
|
|
|
2022-04-07 15:44:42 -04:00
|
|
|
config PMP_SLOTS
|
2022-04-06 22:03:54 -04:00
|
|
|
int "Number of PMP slots"
|
|
|
|
|
default 8
|
|
|
|
|
help
|
|
|
|
|
This is the number of PMP entries implemented by the hardware.
|
|
|
|
|
Typical values are 8 or 16.
|
|
|
|
|
|
2023-02-09 13:15:45 -05:00
|
|
|
config PMP_NO_TOR
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Set this if TOR (Top Of Range) mode is not supported.
|
|
|
|
|
|
|
|
|
|
config PMP_NO_NA4
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Set this if NA4 (Naturally Aligned 4-byte) mode is not supported.
|
|
|
|
|
|
|
|
|
|
config PMP_NO_NAPOT
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Set this if NAPOT (Naturally Aligned Power Of Two) is not supported.
|
|
|
|
|
|
2022-04-06 22:03:54 -04:00
|
|
|
config PMP_POWER_OF_TWO_ALIGNMENT
|
arch: riscv: pmp: add NAPOT multi-slot mode for non-aligned regions
When TOR is unsupported (PMP_NO_TOR), the Kconfig forced
PMP_POWER_OF_TWO_ALIGNMENT=y, wasting memory: 33 KB of code+rodata
aligns to 64 KB, 257 KB aligns to 512 KB.
Add PMP_NAPOT_USE_MULTI_SLOTS: splits a non-naturally-aligned region
into multiple NAPOT entries, each covering the largest naturally-
aligned block at the current address. [0x1800, 0x3800) becomes
0x800 + 0x1000 + 0x800 (3 slots instead of padding to 8192).
Depends on !USERSPACE: arch_mem_domain_max_partitions_get() assumes
1-2 slots per partition and resync_pmp_domain() can only log on
failure, so a partition needing more slots would run unmapped (silent
loss of protection). Help text documents that disabling
PMP_POWER_OF_TWO_ALIGNMENT also splits stack guards and u-mode stacks,
and that PMP_GRANULARITY=64 cuts both ways for that case.
try_multi_entries_set() uses clz/ctz builtins, clears already-written
config bytes on failure before restoring *index_p (otherwise the
trailing write_pmp_entries(0, PMP_SLOTS) in z_riscv_pmp_init() would
program locked partial entries), and folds start/size into the inner
failure logs.
Signed-off-by: Liu Qian <liuqian.andy@picoheart.com>
2026-09-07 16:09:54 +08:00
|
|
|
bool "Enforce power-of-two alignment on PMP memory areas"
|
2022-04-06 22:03:54 -04:00
|
|
|
default y if TEST_USERSPACE
|
2022-04-07 15:44:42 -04:00
|
|
|
default y if (PMP_SLOTS = 8)
|
2023-02-09 13:15:45 -05:00
|
|
|
default y if PMP_NO_TOR
|
2022-04-06 22:03:54 -04:00
|
|
|
select MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
|
|
|
|
|
select GEN_PRIV_STACKS
|
|
|
|
|
help
|
|
|
|
|
This option reduces the PMP slot usage but increases
|
2022-05-13 00:00:19 -04:00
|
|
|
memory consumption. Useful when enabling userspace mode with
|
|
|
|
|
many memory domains and/or few PMP slots available.
|
2022-04-06 22:03:54 -04:00
|
|
|
|
arch: riscv: pmp: add NAPOT multi-slot mode for non-aligned regions
When TOR is unsupported (PMP_NO_TOR), the Kconfig forced
PMP_POWER_OF_TWO_ALIGNMENT=y, wasting memory: 33 KB of code+rodata
aligns to 64 KB, 257 KB aligns to 512 KB.
Add PMP_NAPOT_USE_MULTI_SLOTS: splits a non-naturally-aligned region
into multiple NAPOT entries, each covering the largest naturally-
aligned block at the current address. [0x1800, 0x3800) becomes
0x800 + 0x1000 + 0x800 (3 slots instead of padding to 8192).
Depends on !USERSPACE: arch_mem_domain_max_partitions_get() assumes
1-2 slots per partition and resync_pmp_domain() can only log on
failure, so a partition needing more slots would run unmapped (silent
loss of protection). Help text documents that disabling
PMP_POWER_OF_TWO_ALIGNMENT also splits stack guards and u-mode stacks,
and that PMP_GRANULARITY=64 cuts both ways for that case.
try_multi_entries_set() uses clz/ctz builtins, clears already-written
config bytes on failure before restoring *index_p (otherwise the
trailing write_pmp_entries(0, PMP_SLOTS) in z_riscv_pmp_init() would
program locked partial entries), and folds start/size into the inner
failure logs.
Signed-off-by: Liu Qian <liuqian.andy@picoheart.com>
2026-09-07 16:09:54 +08:00
|
|
|
config PMP_NAPOT_USE_MULTI_SLOTS
|
|
|
|
|
bool "Use multiple NAPOT entries to cover non-aligned memory regions"
|
|
|
|
|
depends on PMP_NO_TOR
|
|
|
|
|
depends on !PMP_POWER_OF_TWO_ALIGNMENT
|
|
|
|
|
depends on !PMP_NO_NAPOT
|
|
|
|
|
depends on !USERSPACE
|
|
|
|
|
default y
|
|
|
|
|
help
|
|
|
|
|
Enable splitting non-naturally-aligned memory regions into multiple
|
|
|
|
|
NAPOT entries. This allows PMP to protect memory regions that are
|
|
|
|
|
not power-of-2 aligned in both start address and size.
|
|
|
|
|
|
|
|
|
|
When enabled, a region like [0x1800, 0x3800) will be split into
|
|
|
|
|
multiple naturally-aligned blocks (e.g., 0x800+0x1000+0x800 bytes),
|
|
|
|
|
each protected by a separate NAPOT entry.
|
|
|
|
|
|
|
|
|
|
This option is useful when TOR mode is not supported and memory
|
|
|
|
|
regions are not naturally aligned. It consumes more PMP slots
|
|
|
|
|
but provides flexible memory protection coverage.
|
|
|
|
|
|
|
|
|
|
Note: disabling PMP_POWER_OF_TWO_ALIGNMENT affects more than the
|
|
|
|
|
code+rodata region. The kernel-mode stack guard
|
|
|
|
|
(Z_RISCV_STACK_GUARD_SIZE) is then rounded up to Z_RISCV_STACK_PMP_ALIGN
|
|
|
|
|
instead of to a power of two, and ARCH_KERNEL_STACK_OBJ_ALIGN drops to
|
|
|
|
|
the PMP granularity. As a result, every kernel-mode stack guard and,
|
|
|
|
|
under CONFIG_USERSPACE, every user-mode stack region is also split into
|
|
|
|
|
multiple NAPOT entries. With the typical PMP_SLOTS=8 or 16, this is
|
|
|
|
|
where the slot budget is actually consumed.
|
|
|
|
|
|
|
|
|
|
Setting PMP_GRANULARITY to 64 reduces the number of split entries for
|
|
|
|
|
code+rodata, but it also makes the stack guard a multiple of 64 that
|
|
|
|
|
is generally not a power of two, so the guard itself still needs to be
|
|
|
|
|
split. Weigh both effects when choosing a granularity.
|
|
|
|
|
|
|
|
|
|
Depends on !USERSPACE: under CONFIG_USERSPACE, arch_mem_domain_max_partitions_get()
|
|
|
|
|
assumes 1 or 2 PMP slots per partition, and resync_pmp_domain() can
|
|
|
|
|
only log an error (compiles out __ASSERT) when a partition needs more
|
|
|
|
|
slots than remain. The domain would then run with partitions unmapped,
|
|
|
|
|
a silent loss of protection rather than a visible failure. Until the
|
|
|
|
|
slot estimate and the failure path handle a partition requiring an
|
|
|
|
|
arbitrary number of slots, this option is limited to the M-mode
|
|
|
|
|
code+rodata region case.
|
|
|
|
|
|
2023-03-28 10:46:14 +08:00
|
|
|
config PMP_GRANULARITY
|
|
|
|
|
int "The granularity of PMP address matching"
|
|
|
|
|
default 8 if (PMP_NO_TOR && PMP_NO_NA4)
|
|
|
|
|
default 4
|
|
|
|
|
help
|
|
|
|
|
The granularity must be a power of 2 greater than or equal to 4
|
|
|
|
|
(ie 4, 8, 16, ...), but if neither TOR mode nor NA4 mode is
|
|
|
|
|
supported, the minimum granularity is 8.
|
|
|
|
|
|
2025-11-06 18:50:26 +00:00
|
|
|
config PMP_NO_LOCK_GLOBAL
|
|
|
|
|
bool "Do not lock the global PMP entries"
|
|
|
|
|
select PMP_KERNEL_MODE_DYNAMIC
|
|
|
|
|
help
|
|
|
|
|
Configure the PMP entries as unlocked (L=0) to implement PMP relative
|
|
|
|
|
features. This allows application to dynamically reconfigure PMP
|
|
|
|
|
entries without requiring hard reset.
|
|
|
|
|
|
2026-02-04 11:05:58 +00:00
|
|
|
config PMP_UNLOCK_ROM_FOR_DEBUG
|
|
|
|
|
bool "Unlock ROM region for debugger access"
|
|
|
|
|
default n
|
|
|
|
|
help
|
|
|
|
|
When enabled, the ROM region PMP entry is configured without
|
|
|
|
|
the lock bit (L=0), allowing debuggers running in machine mode
|
|
|
|
|
to set breakpoints and read instructions. NULL pointer guards
|
|
|
|
|
and stack guards remain locked to catch critical bugs during
|
|
|
|
|
development. Only enable for debug builds.
|
|
|
|
|
|
2020-07-21 15:59:23 +02:00
|
|
|
endif #RISCV_PMP
|
|
|
|
|
|
2026-07-27 16:54:33 +05:30
|
|
|
config RISCV_LANDING_PADS
|
|
|
|
|
bool "Landing Pad Enforcement (Zicfilp)"
|
|
|
|
|
depends on RISCV_ISA_EXT_ZICFILP
|
|
|
|
|
default y
|
|
|
|
|
help
|
|
|
|
|
Enables forward-edge control-flow integrity by configuring
|
|
|
|
|
environment registers to enforce landing pad (lpad) instructions at
|
|
|
|
|
indirect branch targets.
|
|
|
|
|
|
2022-05-13 00:00:19 -04:00
|
|
|
config PMP_STACK_GUARD
|
2026-02-05 15:01:32 +08:00
|
|
|
bool
|
2022-05-13 00:00:19 -04:00
|
|
|
depends on HW_STACK_PROTECTION
|
2025-10-24 16:17:28 +00:00
|
|
|
select PMP_KERNEL_MODE_DYNAMIC if MULTITHREADING
|
2022-05-13 00:00:19 -04:00
|
|
|
|
|
|
|
|
config PMP_STACK_GUARD_MIN_SIZE
|
|
|
|
|
int "Stack Guard area size"
|
|
|
|
|
depends on PMP_STACK_GUARD
|
|
|
|
|
default 1024 if 64BIT
|
|
|
|
|
default 512
|
|
|
|
|
help
|
|
|
|
|
The Hardware Stack Protection implements a guard area at the bottom
|
|
|
|
|
of the stack using the PMP to catch stack overflows by marking that
|
|
|
|
|
guard area not accessible.
|
|
|
|
|
|
|
|
|
|
This is the size of the guard area. This should be large enough to
|
|
|
|
|
catch any sudden jump in stack pointer decrement, plus some
|
|
|
|
|
wiggle room to accommodate the eventual overflow exception
|
|
|
|
|
stack usage.
|
|
|
|
|
|
2026-03-31 14:13:37 +02:00
|
|
|
config PMP_DATA_EXECUTION_PREVENTION
|
|
|
|
|
bool "Prevent data execution"
|
|
|
|
|
default y
|
|
|
|
|
depends on PMP_SLOTS >= 8 && !PMP_NO_NAPOT && !PMP_NO_LOCK_GLOBAL && !CODE_DATA_RELOCATION
|
|
|
|
|
select PMP_KERNEL_MODE_DYNAMIC if USERSPACE
|
|
|
|
|
help
|
|
|
|
|
Configure PMP to prevent execution of data sections. This requires locked
|
|
|
|
|
entries and currently does not work with relocation, because the target
|
|
|
|
|
memory would need to be marked as executable after copying the code.
|
|
|
|
|
For user threads a dedicated PMP register needs to be enabled, requiring
|
|
|
|
|
dynamic kernel mode.
|
|
|
|
|
|
2025-10-24 16:17:28 +00:00
|
|
|
config PMP_KERNEL_MODE_DYNAMIC
|
|
|
|
|
bool
|
2026-03-31 14:13:37 +02:00
|
|
|
select PMP_KERNEL_MODE_DYNAMIC_CATCHALL if !PMP_DATA_EXECUTION_PREVENTION
|
2025-10-24 16:17:28 +00:00
|
|
|
help
|
|
|
|
|
Enable this to dynamically reconfigure and activate PMP entries for
|
|
|
|
|
Machine mode when switching between kernel (ISR, syscall) and threads.
|
|
|
|
|
|
2026-03-31 14:13:37 +02:00
|
|
|
config PMP_KERNEL_MODE_DYNAMIC_CATCHALL
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Require a catch-all entry to be configured for kernel threads.
|
|
|
|
|
PMP_DATA_EXECUTION_PREVENTION always creates a catch-all entry and
|
|
|
|
|
therefore does not need this.
|
|
|
|
|
|
2023-05-23 11:55:43 +08:00
|
|
|
# Implement the null pointer detection using the Physical Memory Protection
|
|
|
|
|
# (PMP) Unit.
|
|
|
|
|
config NULL_POINTER_EXCEPTION_DETECTION_PMP
|
|
|
|
|
bool "Use PMP for null pointer exception detection"
|
|
|
|
|
depends on RISCV_PMP
|
|
|
|
|
help
|
|
|
|
|
Null pointer dereference detection implemented
|
|
|
|
|
using PMP functionality.
|
|
|
|
|
|
|
|
|
|
if NULL_POINTER_EXCEPTION_DETECTION_PMP
|
|
|
|
|
|
|
|
|
|
config NULL_POINTER_EXCEPTION_REGION_SIZE
|
|
|
|
|
hex "Inaccessible region to implement null pointer detection"
|
|
|
|
|
default 0x10
|
|
|
|
|
help
|
|
|
|
|
Use a PMP slot to make region (starting at address 0x0) inaccessible for
|
|
|
|
|
detecting null pointer dereferencing (raising a CPU access fault).
|
2026-09-29 10:57:19 +02:00
|
|
|
Minimum is 4 bytes. The size is rounded up to PMP_GRANULARITY.
|
2023-05-23 11:55:43 +08:00
|
|
|
|
|
|
|
|
endif # NULL_POINTER_EXCEPTION_DETECTION_PMP
|
|
|
|
|
|
2026-07-05 15:30:21 -03:00
|
|
|
config RISCV_USER_STRING_NLEN_VALIDATE
|
|
|
|
|
bool "Pre-validate the pointer in arch_user_string_nlen()"
|
|
|
|
|
depends on USERSPACE
|
|
|
|
|
depends on RISCV_PMP
|
|
|
|
|
help
|
|
|
|
|
arch_user_string_nlen() dereferences a user pointer and recovers from a
|
|
|
|
|
bad address through a fault fixup that matches the faulting mepc against
|
|
|
|
|
the load instruction's address range. On some RISC-V SoCs the load access
|
|
|
|
|
fault is imprecise: the reported mepc lands a variable distance past the
|
|
|
|
|
faulting load (sometimes in a different function), so the fixup does not
|
|
|
|
|
recognize the fault and it escalates to a fatal reset instead of the
|
|
|
|
|
intended recoverable error.
|
|
|
|
|
|
|
|
|
|
Enable this to validate the string with arch_buffer_validate() before
|
|
|
|
|
reading it: the whole range first, then chunk by chunk at PMP
|
|
|
|
|
granularity when the range is only partly accessible, so no load that
|
|
|
|
|
could fault is ever issued. Leave disabled on SoCs with precise load
|
|
|
|
|
faults, where the fixup works unaided.
|
|
|
|
|
|
2024-07-09 13:25:46 +02:00
|
|
|
config RISCV_IMPRECISE_FPU_STATE_TRACKING
|
|
|
|
|
bool "Imprecise implementation of FPU state tracking"
|
|
|
|
|
depends on FPU
|
|
|
|
|
help
|
|
|
|
|
According to the RISC-V Instruction Set Manual: Volume II, Version 20240411
|
|
|
|
|
(Section 3.1.6.6), some implementations may choose to track the dirtiness of
|
|
|
|
|
the floating-point register state imprecisely by reporting the state to be
|
|
|
|
|
dirty even when it has not been modified. This option reflects that.
|
|
|
|
|
|
2025-07-28 19:51:48 +01:00
|
|
|
config RISCV_SMRNMI_ENABLE_NMI_DELIVERY
|
|
|
|
|
bool "NMI delivery on SMRNMI hardware (MNSTATUS.NMIE=1)"
|
|
|
|
|
select RISCV_ISA_EXT_ZICSR
|
|
|
|
|
help
|
|
|
|
|
Set MNSTATUS.NMIE bit to 1 during boot to enable NMI delivery on
|
|
|
|
|
RISC-V hardware implementing the SMRNMI extension.
|
|
|
|
|
|
|
|
|
|
This option only enables NMI delivery. It does not provide RNMI
|
|
|
|
|
handlers or mnret instruction support. Proper RNMI handlers must
|
|
|
|
|
be implemented in SoC-specific code to handle NMI events.
|
|
|
|
|
|
2026-02-05 15:01:32 +08:00
|
|
|
config RISCV_HAS_CUSTOM_STACK_GUARD
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Selected when the hardware provides a custom stack guard.
|
|
|
|
|
|
|
|
|
|
config CUSTOM_STACK_GUARD
|
|
|
|
|
bool "Thread Stack Guards based on custom stack guard"
|
|
|
|
|
depends on RISCV_HAS_CUSTOM_STACK_GUARD
|
|
|
|
|
select THREAD_STACK_INFO
|
|
|
|
|
help
|
|
|
|
|
Enable Thread/Interrupt Stack Guards via custom stack guard.
|
|
|
|
|
The functionality must be supported by HW.
|
|
|
|
|
|
|
|
|
|
config CUSTOM_STACK_GUARD_RESERVED_SIZE
|
|
|
|
|
int "Custom stack guard reserved area size"
|
|
|
|
|
depends on CUSTOM_STACK_GUARD
|
|
|
|
|
default 1024 if 64BIT
|
|
|
|
|
default 768
|
|
|
|
|
help
|
|
|
|
|
This is the size of the custom stack guard reserved area.
|
|
|
|
|
This should be large enough to catch any sudden jump in stack pointer
|
|
|
|
|
decrement, plus some wiggle room to accommodate the eventual overflow
|
|
|
|
|
exception stack usage.
|
|
|
|
|
|
|
|
|
|
config RISCV_STACK_PROTECTION
|
|
|
|
|
bool
|
|
|
|
|
default y if HW_STACK_PROTECTION
|
|
|
|
|
imply CUSTOM_STACK_GUARD if RISCV_HAS_CUSTOM_STACK_GUARD
|
|
|
|
|
select PMP_STACK_GUARD if (!CUSTOM_STACK_GUARD && RISCV_PMP)
|
|
|
|
|
help
|
|
|
|
|
This option enables either:
|
|
|
|
|
- The custom stack guard, or
|
|
|
|
|
- the PMP-based stack guard
|
|
|
|
|
to cause a system fatal error
|
|
|
|
|
if the bounds of the current process stack are overflowed.
|
|
|
|
|
The two stack guard options are mutually exclusive. The
|
|
|
|
|
selection of the custom stack guard is prioritized over the
|
|
|
|
|
PMP-based stack guard. The developer still has the option to
|
|
|
|
|
manually select the PMP-based stack guard, if this is desired.
|
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
endmenu
|
|
|
|
|
|
2021-01-07 21:16:10 +01:00
|
|
|
config MAIN_STACK_SIZE
|
|
|
|
|
default 4096 if 64BIT
|
2022-04-30 15:12:31 -04:00
|
|
|
default 2048 if PMP_STACK_GUARD
|
2021-01-07 21:16:10 +01:00
|
|
|
|
2026-06-03 16:44:55 +02:00
|
|
|
config PRIVILEGED_STACK_SIZE
|
|
|
|
|
default 2048 if 64BIT && ASSERT
|
|
|
|
|
|
2026-07-14 12:53:58 +02:00
|
|
|
config IDLE_STACK_SIZE
|
|
|
|
|
default 1024 if 64BIT && SMP
|
|
|
|
|
|
2022-02-17 17:09:09 +01:00
|
|
|
config TEST_EXTRA_STACK_SIZE
|
2025-05-16 09:16:00 -07:00
|
|
|
default 4096 if CPP_EXCEPTIONS
|
2023-01-31 21:08:13 -05:00
|
|
|
default 1536
|
2021-01-07 21:16:10 +01:00
|
|
|
|
2026-05-21 11:09:18 +02:00
|
|
|
config SYSTEM_WORKQUEUE_STACK_SIZE
|
|
|
|
|
default 4096 if 64BIT
|
|
|
|
|
|
2021-01-07 21:16:10 +01:00
|
|
|
config CMSIS_THREAD_MAX_STACK_SIZE
|
|
|
|
|
default 1024 if 64BIT
|
|
|
|
|
|
|
|
|
|
config CMSIS_V2_THREAD_MAX_STACK_SIZE
|
|
|
|
|
default 1024 if 64BIT
|
|
|
|
|
|
2022-06-27 10:51:28 +02:00
|
|
|
config ARCH_IRQ_VECTOR_TABLE_ALIGN
|
|
|
|
|
default 256
|
|
|
|
|
|
2023-09-01 13:55:07 +03:00
|
|
|
config RISCV_TRAP_HANDLER_ALIGNMENT
|
|
|
|
|
int "Alignment of RISC-V trap handler in bytes"
|
2024-05-22 22:04:55 +02:00
|
|
|
default 64 if RISCV_HAS_CLIC
|
2023-09-01 13:55:07 +03:00
|
|
|
default 4
|
|
|
|
|
help
|
|
|
|
|
This value configures the alignment of RISC-V trap handling
|
|
|
|
|
code. The requirement for a particular alignment arises from
|
|
|
|
|
the format of MTVEC register which is RISC-V platform-specific.
|
|
|
|
|
The minimum alignment is 4 bytes according to the Spec.
|
|
|
|
|
|
2022-07-30 10:26:45 +09:00
|
|
|
config ARCH_HAS_SINGLE_THREAD_SUPPORT
|
|
|
|
|
default y if !SMP
|
|
|
|
|
|
2024-08-14 16:39:03 +08:00
|
|
|
config ARCH_HAS_STACKWALK
|
|
|
|
|
bool
|
|
|
|
|
default y
|
|
|
|
|
imply THREAD_STACK_INFO
|
|
|
|
|
help
|
|
|
|
|
Internal config to indicate that the arch_stack_walk() API is implemented
|
|
|
|
|
and it can be enabled.
|
|
|
|
|
|
2025-07-25 17:32:02 +01:00
|
|
|
config RISCV_NO_MTVAL_ON_FP_TRAP
|
|
|
|
|
bool
|
|
|
|
|
default y if QEMU_TARGET
|
|
|
|
|
help
|
|
|
|
|
This implementation does not provide useful information in the mtval
|
|
|
|
|
CSR (Machine Trap Value register) when floating-point illegal
|
|
|
|
|
instruction exceptions occur.
|
|
|
|
|
|
|
|
|
|
The RISC-V specification allows implementations to decide on a
|
|
|
|
|
case-by-case basis when mtval contains meaningful values. The spec
|
|
|
|
|
states that mtval is "either set to zero or written with
|
|
|
|
|
exception-specific information" on traps. However, this
|
|
|
|
|
"exception-specific information" may not necessarily be the faulting
|
|
|
|
|
instruction value, and implementations have flexibility in what they
|
|
|
|
|
provide.
|
|
|
|
|
|
|
|
|
|
When this option is enabled, the mtval content cannot be relied upon
|
|
|
|
|
to contain the faulting FP instruction, requiring alternative methods
|
|
|
|
|
to handle FP exceptions.
|
|
|
|
|
|
2026-05-13 10:09:00 +02:00
|
|
|
if RISCV_NO_MTVAL_ON_FP_TRAP
|
|
|
|
|
|
|
|
|
|
config RISCV_NO_MTVAL_ON_FP_TRAP_UNALIGNED
|
|
|
|
|
bool
|
|
|
|
|
help
|
|
|
|
|
Fetch the faulting FP instruction halfword-by-halfword when mepc is not
|
|
|
|
|
4-byte aligned. Avoids an unaligned-load exception in the
|
|
|
|
|
no-MTVAL FP trap handler.
|
|
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
arch: riscv: add Supervisor-mode (S-mode) support
Introduce CONFIG_RISCV_S_MODE to select Supervisor-mode execution.
Add depends on !RISCV_S_MODE to RISCV_PMP since PMP CSRs are
inaccessible from S-mode.
Add an M-mode SBI shim (reset.S + sbi.S) that configures exception
delegation, PMP, and counter access before dropping to S-mode via mret.
The shim handles SBI_SET_TIMER ecalls from S-mode and forwards MTIP to
STIP so the supervisor timer driver works without a full SBI firmware.
Introduce privilege-level abstractions in isr.S (RV_CAUSE, RV_EPC,
RV_STATUS, RV_TVAL, etc.) and update all runtime code that previously
accessed M-mode-only CSRs (mcause, mtval, mstatus, mie, mip) to use the
S-mode equivalents when CONFIG_RISCV_S_MODE is set.
ARCH_EXCEPT in kernel context uses ebreak (cause=3, Breakpoint) instead
of a direct z_riscv_fatal_error() call. In S-mode, ecall (cause=9) is
kept in M-mode for SBI and never reaches the S-mode exception handler;
a direct call with NULL esf caused the stack unwinder to crash into an
infinite fault loop. ebreak is delegated to S-mode by our medeleg
configuration; isr.S treats ebreak with t0=RV_ECALL_RUNTIME_EXCEPT the
same way M-mode treats ecall-based ARCH_EXCEPT.
Signed-off-by: Alexios Lyrakis <alexios.lyrakis@gmail.com>
2026-03-28 15:34:55 +00:00
|
|
|
RISCV_PRIV_MODES_PROP := riscv,privilege-modes
|
|
|
|
|
|
|
|
|
|
choice RISCV_PRIVILEGE_MODE
|
|
|
|
|
prompt "RISC-V privilege level"
|
|
|
|
|
default RISCV_M_MODE
|
|
|
|
|
help
|
|
|
|
|
Select the privilege level at which the kernel runs.
|
|
|
|
|
|
|
|
|
|
config RISCV_M_MODE
|
|
|
|
|
bool "Machine mode (M-mode)"
|
|
|
|
|
depends on $(dt_compat_all_has_prop,riscv,$(RISCV_PRIV_MODES_PROP),m)
|
|
|
|
|
help
|
|
|
|
|
Run the kernel in Machine mode (M-mode). This is the default
|
|
|
|
|
privilege level for RISC-V.
|
|
|
|
|
|
|
|
|
|
config RISCV_S_MODE
|
|
|
|
|
bool "Supervisor mode (S-mode)"
|
|
|
|
|
depends on $(dt_compat_all_has_prop,riscv,$(RISCV_PRIV_MODES_PROP),s)
|
|
|
|
|
help
|
2026-07-15 21:32:14 +05:30
|
|
|
Indicates that the kernel runs in Supervisor mode (S-mode).
|
arch: riscv: add Supervisor-mode (S-mode) support
Introduce CONFIG_RISCV_S_MODE to select Supervisor-mode execution.
Add depends on !RISCV_S_MODE to RISCV_PMP since PMP CSRs are
inaccessible from S-mode.
Add an M-mode SBI shim (reset.S + sbi.S) that configures exception
delegation, PMP, and counter access before dropping to S-mode via mret.
The shim handles SBI_SET_TIMER ecalls from S-mode and forwards MTIP to
STIP so the supervisor timer driver works without a full SBI firmware.
Introduce privilege-level abstractions in isr.S (RV_CAUSE, RV_EPC,
RV_STATUS, RV_TVAL, etc.) and update all runtime code that previously
accessed M-mode-only CSRs (mcause, mtval, mstatus, mie, mip) to use the
S-mode equivalents when CONFIG_RISCV_S_MODE is set.
ARCH_EXCEPT in kernel context uses ebreak (cause=3, Breakpoint) instead
of a direct z_riscv_fatal_error() call. In S-mode, ecall (cause=9) is
kept in M-mode for SBI and never reaches the S-mode exception handler;
a direct call with NULL esf caused the stack unwinder to crash into an
infinite fault loop. ebreak is delegated to S-mode by our medeleg
configuration; isr.S treats ebreak with t0=RV_ECALL_RUNTIME_EXCEPT the
same way M-mode treats ecall-based ARCH_EXCEPT.
Signed-off-by: Alexios Lyrakis <alexios.lyrakis@gmail.com>
2026-03-28 15:34:55 +00:00
|
|
|
|
|
|
|
|
endchoice # RISCV_PRIVILEGE_MODE
|
|
|
|
|
|
2026-07-15 21:32:14 +05:30
|
|
|
choice RISCV_S_MODE_SBI
|
|
|
|
|
prompt "RISC-V SBI Implementation"
|
|
|
|
|
depends on RISCV_S_MODE
|
|
|
|
|
default RISCV_S_MODE_INTERNAL_SBI
|
|
|
|
|
help
|
|
|
|
|
Select the Supervisor Binary Interface (SBI) implementation to use
|
|
|
|
|
when running in Supervisor mode (S-mode).
|
|
|
|
|
|
|
|
|
|
config RISCV_S_MODE_INTERNAL_SBI
|
|
|
|
|
bool "Use built-in minimal SBI runtime"
|
|
|
|
|
help
|
|
|
|
|
Enable this to have the boot code handle the transition from
|
|
|
|
|
Machine mode (M-mode) to Supervisor mode (S-mode) internally.
|
|
|
|
|
A minimal SBI runtime will remain resident in M-mode to service
|
|
|
|
|
timer interrupts and ecall requests.
|
|
|
|
|
|
|
|
|
|
config RISCV_S_MODE_EXTERNAL_SBI
|
|
|
|
|
bool "Enter S-mode directly, relying on an external SBI (e.g. OpenSBI)"
|
|
|
|
|
help
|
|
|
|
|
Skip the in-tree M-mode boot sequence (PMP/medeleg/mideleg/
|
|
|
|
|
mcounteren/mtvec setup and the mret drop to S-mode). Use this when
|
|
|
|
|
Zephyr is launched as a payload by a bootloader (e.g. U-Boot) that
|
|
|
|
|
is already running in S-mode under an external M-mode SBI
|
|
|
|
|
implementation such as OpenSBI, which has already performed the
|
|
|
|
|
M-mode setup and delegation.
|
|
|
|
|
|
|
|
|
|
endchoice # RISCV_S_MODE_SBI
|
|
|
|
|
|
arch: riscv: add Supervisor-mode (S-mode) support
Introduce CONFIG_RISCV_S_MODE to select Supervisor-mode execution.
Add depends on !RISCV_S_MODE to RISCV_PMP since PMP CSRs are
inaccessible from S-mode.
Add an M-mode SBI shim (reset.S + sbi.S) that configures exception
delegation, PMP, and counter access before dropping to S-mode via mret.
The shim handles SBI_SET_TIMER ecalls from S-mode and forwards MTIP to
STIP so the supervisor timer driver works without a full SBI firmware.
Introduce privilege-level abstractions in isr.S (RV_CAUSE, RV_EPC,
RV_STATUS, RV_TVAL, etc.) and update all runtime code that previously
accessed M-mode-only CSRs (mcause, mtval, mstatus, mie, mip) to use the
S-mode equivalents when CONFIG_RISCV_S_MODE is set.
ARCH_EXCEPT in kernel context uses ebreak (cause=3, Breakpoint) instead
of a direct z_riscv_fatal_error() call. In S-mode, ecall (cause=9) is
kept in M-mode for SBI and never reaches the S-mode exception handler;
a direct call with NULL esf caused the stack unwinder to crash into an
infinite fault loop. ebreak is delegated to S-mode by our medeleg
configuration; isr.S treats ebreak with t0=RV_ECALL_RUNTIME_EXCEPT the
same way M-mode treats ecall-based ARCH_EXCEPT.
Signed-off-by: Alexios Lyrakis <alexios.lyrakis@gmail.com>
2026-03-28 15:34:55 +00:00
|
|
|
config RISCV_M_MODE_STACK_SIZE
|
|
|
|
|
int "M-mode SBI handler stack size (bytes)"
|
|
|
|
|
default 256
|
2026-07-15 21:32:14 +05:30
|
|
|
depends on RISCV_S_MODE_INTERNAL_SBI
|
arch: riscv: add Supervisor-mode (S-mode) support
Introduce CONFIG_RISCV_S_MODE to select Supervisor-mode execution.
Add depends on !RISCV_S_MODE to RISCV_PMP since PMP CSRs are
inaccessible from S-mode.
Add an M-mode SBI shim (reset.S + sbi.S) that configures exception
delegation, PMP, and counter access before dropping to S-mode via mret.
The shim handles SBI_SET_TIMER ecalls from S-mode and forwards MTIP to
STIP so the supervisor timer driver works without a full SBI firmware.
Introduce privilege-level abstractions in isr.S (RV_CAUSE, RV_EPC,
RV_STATUS, RV_TVAL, etc.) and update all runtime code that previously
accessed M-mode-only CSRs (mcause, mtval, mstatus, mie, mip) to use the
S-mode equivalents when CONFIG_RISCV_S_MODE is set.
ARCH_EXCEPT in kernel context uses ebreak (cause=3, Breakpoint) instead
of a direct z_riscv_fatal_error() call. In S-mode, ecall (cause=9) is
kept in M-mode for SBI and never reaches the S-mode exception handler;
a direct call with NULL esf caused the stack unwinder to crash into an
infinite fault loop. ebreak is delegated to S-mode by our medeleg
configuration; isr.S treats ebreak with t0=RV_ECALL_RUNTIME_EXCEPT the
same way M-mode treats ecall-based ARCH_EXCEPT.
Signed-off-by: Alexios Lyrakis <alexios.lyrakis@gmail.com>
2026-03-28 15:34:55 +00:00
|
|
|
help
|
|
|
|
|
Size in bytes of the dedicated stack used by the in-tree M-mode SBI
|
|
|
|
|
runtime handler. Increase this if the handler is extended with
|
|
|
|
|
functionality that requires more stack space.
|
|
|
|
|
|
2026-03-06 14:36:08 +05:30
|
|
|
config RISCV_FPU_INSN_VALIDATE
|
|
|
|
|
bool
|
|
|
|
|
depends on FPU_SHARING
|
|
|
|
|
depends on ASSERT
|
|
|
|
|
default y
|
|
|
|
|
help
|
|
|
|
|
Derived debug-only symbol. When enabled, the FPU trap handler will
|
|
|
|
|
explicitly decode the trapping instruction to ensure it is a valid
|
|
|
|
|
floating-point instruction. This catches edge cases where non-FPU
|
|
|
|
|
instructions (like Vector instructions) might accidentally trigger
|
|
|
|
|
an FP trap.
|
|
|
|
|
|
2022-05-12 12:03:47 +02:00
|
|
|
rsource "Kconfig.isa"
|
|
|
|
|
|
2025-07-22 18:11:38 +08:00
|
|
|
rsource "custom/Kconfig"
|
|
|
|
|
|
arch: added support for the riscv32 architecture
RISC-V is an open-source instruction set architecture.
Added support for the 32bit version of RISC-V to Zephyr.
1) exceptions/interrupts/faults are handled at the architecture
level via the __irq_wrapper handler. Context saving/restoring
of registers can be handled at both architecture and SOC levels.
If SOC-specific registers need to be saved, SOC level needs to
provide __soc_save_context and __soc_restore_context functions
that shall be accounted by the architecture level, when
corresponding config variable RISCV_SOC_CONTEXT_SAVE is set.
2) As RISC-V architecture does not provide a clear ISA specification
about interrupt handling, each RISC-V SOC handles it in its own
way. Hence, at the architecture level, the __irq_wrapper handler
expects the following functions to be provided by the SOC level:
__soc_is_irq: to check if the exception is the result of an
interrupt or not.
__soc_handle_irq: handle pending IRQ at SOC level (ex: clear
pending IRQ in SOC-specific IRQ register)
3) Thread/task scheduling, as well as IRQ offloading are handled via
the RISC-V system call ("ecall"), which is also handled via the
__irq_wrapper handler. The _Swap asm function just calls "ecall"
to generate an exception.
4) As there is no conventional way of handling CPU power save in
RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle
functions just unlock interrupts and return to the caller, without
issuing any CPU power saving instruction. Nonetheless, to allow
SOC-level to implement proper CPU power save, nano_cpu_idle and
nano_cpu_atomic_idle functions are defined as __weak
at the architecture level.
Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 00:24:30 +01:00
|
|
|
endmenu
|