15#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_
16#define ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_
24#if defined(CONFIG_USERSPACE)
35#define ARCH_STACK_PTR_ALIGN 16
37#ifdef CONFIG_PMP_STACK_GUARD
49#define Z_RISCV_STACK_GUARD_SIZE \
50 ROUND_UP(sizeof(z_arch_esf_t) + CONFIG_PMP_STACK_GUARD_MIN_SIZE, \
65#define ARCH_KERNEL_STACK_RESERVED Z_RISCV_STACK_GUARD_SIZE
68#define Z_RISCV_STACK_GUARD_SIZE 0
71#ifdef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
108#define ARCH_THREAD_STACK_RESERVED Z_RISCV_STACK_GUARD_SIZE
109#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
110 Z_POW2_CEIL(MAX(size, CONFIG_PRIVILEGED_STACK_SIZE))
111#define ARCH_THREAD_STACK_OBJ_ALIGN(size) \
112 ARCH_THREAD_STACK_SIZE_ADJUST(size)
131#define ARCH_THREAD_STACK_RESERVED \
132 ROUND_UP(Z_RISCV_STACK_GUARD_SIZE + CONFIG_PRIVILEGED_STACK_SIZE, \
133 ARCH_STACK_PTR_ALIGN)
149#define MSTATUS_IEN (1UL << 3)
150#define MSTATUS_MPP_M (3UL << 11)
151#define MSTATUS_MPIE_EN (1UL << 7)
153#define MSTATUS_FS_OFF (0UL << 13)
154#define MSTATUS_FS_INIT (1UL << 13)
155#define MSTATUS_FS_CLEAN (2UL << 13)
156#define MSTATUS_FS_DIRTY (3UL << 13)
166#define MSTATUS_DEF_RESTORE (MSTATUS_MPP_M | MSTATUS_MPIE_EN)
175#ifdef CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE
176#define ARCH_IRQ_VECTOR_JUMP_CODE(v) "j " STRINGIFY(v)
189#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \
191#define K_MEM_PARTITION_P_RW_U_RO ((k_mem_partition_attr_t) \
193#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \
195#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \
197#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \
199#define K_MEM_PARTITION_P_NA_U_NA ((k_mem_partition_attr_t) \
203#define K_MEM_PARTITION_P_RWX_U_RWX ((k_mem_partition_attr_t) \
204 {PMP_R | PMP_W | PMP_X})
205#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \
217extern void z_irq_spurious(
const void *unused);
225#ifdef CONFIG_RISCV_SOC_HAS_CUSTOM_IRQ_LOCK_OPS
226 return z_soc_irq_lock();
230 __asm__
volatile (
"csrrc %0, mstatus, %1"
245#ifdef CONFIG_RISCV_SOC_HAS_CUSTOM_IRQ_LOCK_OPS
246 z_soc_irq_unlock(
key);
248 __asm__
volatile (
"csrs mstatus, %0"
257#ifdef CONFIG_RISCV_SOC_HAS_CUSTOM_IRQ_LOCK_OPS
258 return z_soc_irq_unlocked(
key);
266 __asm__
volatile(
"nop");
291#if defined(CONFIG_SOC_FAMILY_RISCV_PRIVILEGE)
uint32_t k_mem_partition_attr_t
Definition: arch.h:225
RISC-V public interrupt handling.
RISCV specific syscall header.
Per-arch thread definition.
#define ALWAYS_INLINE
Definition: common.h:124
Public interface for configuring interrupts.
uint64_t sys_clock_cycle_get_64(void)
uint32_t sys_clock_cycle_get_32(void)
static ALWAYS_INLINE void arch_nop(void)
Definition: arch.h:264
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Definition: arch.h:223
#define MSTATUS_IEN
Definition: arch.h:149
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
Definition: arch.h:243
static uint32_t arch_k_cycle_get_32(void)
Definition: arch.h:271
static uint64_t arch_k_cycle_get_64(void)
Definition: arch.h:278
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
Definition: arch.h:255
RISCV public error handling.
RISCV public exception handling.
static k_spinlock_key_t key
Definition: spinlock_error_case.c:15
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
unsigned int pmp_update_nr
Definition: arch.h:214
uint8_t pmp_attr
Definition: arch.h:210
Software-managed ISR table.