15#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_
16#define ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_
23#if defined(CONFIG_USERSPACE)
33#define ARCH_STACK_PTR_ALIGN 16
35#ifdef CONFIG_PMP_STACK_GUARD
36#define Z_RISCV_PMP_ALIGN CONFIG_PMP_STACK_GUARD_MIN_SIZE
37#define Z_RISCV_STACK_GUARD_SIZE Z_RISCV_PMP_ALIGN
39#define Z_RISCV_PMP_ALIGN 4
40#define Z_RISCV_STACK_GUARD_SIZE 0
55#ifdef CONFIG_PMP_STACK_GUARD
56#define ARCH_KERNEL_STACK_RESERVED Z_RISCV_STACK_GUARD_SIZE
57#define ARCH_KERNEL_STACK_OBJ_ALIGN \
58 MAX(Z_RISCV_PMP_ALIGN, ARCH_STACK_PTR_ALIGN)
61#ifdef CONFIG_USERSPACE
69#ifdef CONFIG_PMP_STACK_GUARD
70#ifdef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
89#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
90 Z_POW2_CEIL(ROUND_UP((size), Z_RISCV_PMP_ALIGN))
91#define ARCH_THREAD_STACK_OBJ_ALIGN(size) \
92 ARCH_THREAD_STACK_SIZE_ADJUST(size)
93#define ARCH_THREAD_STACK_RESERVED 0
110#define ARCH_THREAD_STACK_RESERVED (Z_RISCV_STACK_GUARD_SIZE + \
111 CONFIG_PRIVILEGED_STACK_SIZE)
112#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_RISCV_PMP_ALIGN
116#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
117 (ROUND_UP((size), Z_RISCV_PMP_ALIGN))
121#ifdef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
137#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
138 Z_POW2_CEIL(ROUND_UP((size), Z_RISCV_PMP_ALIGN))
139#define ARCH_THREAD_STACK_OBJ_ALIGN(size) \
140 ARCH_THREAD_STACK_SIZE_ADJUST(size)
141#define ARCH_THREAD_STACK_RESERVED 0
157#define ARCH_THREAD_STACK_RESERVED CONFIG_PRIVILEGED_STACK_SIZE
158#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
159 (ROUND_UP((size), Z_RISCV_PMP_ALIGN))
160#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_RISCV_PMP_ALIGN
167#ifdef CONFIG_PMP_STACK_GUARD
182#define ARCH_THREAD_STACK_RESERVED Z_RISCV_STACK_GUARD_SIZE
183#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_RISCV_PMP_ALIGN
191#define RV_OP_LOADREG ld
192#define RV_OP_STOREREG sd
196#define RV_OP_LOADREG lw
197#define RV_OP_STOREREG sw
202#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
203#define RV_OP_LOADFPREG fld
204#define RV_OP_STOREFPREG fsd
206#define RV_OP_LOADFPREG flw
207#define RV_OP_STOREFPREG fsw
214#define MSTATUS_IEN (1UL << 3)
215#define MSTATUS_MPP_M (3UL << 11)
216#define MSTATUS_MPIE_EN (1UL << 7)
217#define MSTATUS_FS_INIT (1UL << 13)
218#define MSTATUS_FS_MASK ((1UL << 13) | (1UL << 14))
229#define MSTATUS_DEF_RESTORE (MSTATUS_MPP_M | MSTATUS_MPIE_EN)
238#define STACK_ROUND_UP(x) ROUND_UP(x, ARCH_STACK_PTR_ALIGN)
241#define DO_TOSTR(s) #s
242#define TOSTR(s) DO_TOSTR(s)
245#define DO_CONCAT(x, y) x ## y
246#define CONCAT(x, y) DO_CONCAT(x, y)
258#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \
260#define K_MEM_PARTITION_P_RW_U_RO ((k_mem_partition_attr_t) \
262#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \
264#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \
266#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \
268#define K_MEM_PARTITION_P_NA_U_NA ((k_mem_partition_attr_t) \
272#define K_MEM_PARTITION_P_RWX_U_RWX ((k_mem_partition_attr_t) \
273 {PMP_R | PMP_W | PMP_X})
274#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \
286void z_irq_spurious(
const void *unused);
288#if defined(CONFIG_RISCV_HAS_PLIC)
289#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
291 Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
292 arch_irq_priority_set(irq_p, priority_p); \
295#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
297 Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
310 __asm__
volatile (
"csrrc %0, mstatus, %1"
327 __asm__
volatile (
"csrrs %0, mstatus, %1"
347 __asm__
volatile(
"nop");
357#ifdef CONFIG_USERSPACE
367#if defined(CONFIG_SOC_FAMILY_RISCV_PRIVILEGE)
uint32_t k_mem_partition_attr_t
Definition: arch.h:267
RISCV specific syscall header.
Per-arch thread definition.
#define ALWAYS_INLINE
Definition: common.h:116
RISCV public exception handling.
unsigned long ulong_t
Definition: types.h:18
void arch_irq_disable(unsigned int irq)
uint32_t sys_clock_cycle_get_32(void)
void arch_irq_enable(unsigned int irq)
static ALWAYS_INLINE void arch_nop(void)
Definition: arch.h:345
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Definition: arch.h:305
#define MSTATUS_IEN
Definition: arch.h:214
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
Definition: arch.h:323
int arch_irq_is_enabled(unsigned int irq)
static uint32_t arch_k_cycle_get_32(void)
Definition: arch.h:352
void arch_irq_priority_set(unsigned int irq, unsigned int prio)
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
Definition: arch.h:333
RISCV public error handling.
static k_spinlock_key_t key
Definition: spinlock_error_case.c:14
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
uint8_t pmp_attr
Definition: arch.h:279
Software-managed ISR table.