17#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_
18#define ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_H_
26#if defined(CONFIG_USERSPACE)
36#define ARCH_STACK_PTR_ALIGN 16
38#define Z_RISCV_STACK_PMP_ALIGN \
39 MAX(CONFIG_PMP_GRANULARITY, ARCH_STACK_PTR_ALIGN)
41#ifdef CONFIG_PMP_STACK_GUARD
51#ifdef CONFIG_PMP_POWER_OF_TWO_ALIGNMENT
52#define Z_RISCV_STACK_GUARD_SIZE \
53 Z_POW2_CEIL(MAX(sizeof(struct arch_esf) + CONFIG_PMP_STACK_GUARD_MIN_SIZE, \
54 Z_RISCV_STACK_PMP_ALIGN))
55#define ARCH_KERNEL_STACK_OBJ_ALIGN Z_RISCV_STACK_GUARD_SIZE
57#define Z_RISCV_STACK_GUARD_SIZE \
58 ROUND_UP(sizeof(struct arch_esf) + CONFIG_PMP_STACK_GUARD_MIN_SIZE, \
59 Z_RISCV_STACK_PMP_ALIGN)
60#define ARCH_KERNEL_STACK_OBJ_ALIGN Z_RISCV_STACK_PMP_ALIGN
75#define ARCH_KERNEL_STACK_RESERVED Z_RISCV_STACK_GUARD_SIZE
78#define Z_RISCV_STACK_GUARD_SIZE 0
81#ifdef CONFIG_PMP_POWER_OF_TWO_ALIGNMENT
118#define ARCH_THREAD_STACK_RESERVED Z_RISCV_STACK_GUARD_SIZE
119#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
120 Z_POW2_CEIL(MAX(MAX(size, CONFIG_PRIVILEGED_STACK_SIZE), \
121 Z_RISCV_STACK_PMP_ALIGN))
122#define ARCH_THREAD_STACK_OBJ_ALIGN(size) \
123 ARCH_THREAD_STACK_SIZE_ADJUST(size)
142#define ARCH_THREAD_STACK_RESERVED \
143 ROUND_UP(Z_RISCV_STACK_GUARD_SIZE + CONFIG_PRIVILEGED_STACK_SIZE, \
144 Z_RISCV_STACK_PMP_ALIGN)
142#define ARCH_THREAD_STACK_RESERVED \ …
145#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \
146 ROUND_UP(size, Z_RISCV_STACK_PMP_ALIGN)
145#define ARCH_THREAD_STACK_SIZE_ADJUST(size) \ …
147#define ARCH_THREAD_STACK_OBJ_ALIGN(size) Z_RISCV_STACK_PMP_ALIGN
162#define MSTATUS_IEN (1UL << 3)
163#define MSTATUS_MPP_M (3UL << 11)
164#define MSTATUS_MPIE_EN (1UL << 7)
166#define MSTATUS_FS_OFF (0UL << 13)
167#define MSTATUS_FS_INIT (1UL << 13)
168#define MSTATUS_FS_CLEAN (2UL << 13)
169#define MSTATUS_FS_DIRTY (3UL << 13)
179#define MSTATUS_DEF_RESTORE (MSTATUS_MPP_M | MSTATUS_MPIE_EN)
188#ifdef CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE
189#define ARCH_IRQ_VECTOR_JUMP_CODE(v) "j " STRINGIFY(v)
202#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \
202#define K_MEM_PARTITION_P_RW_U_RW ((k_mem_partition_attr_t) \ …
204#define K_MEM_PARTITION_P_RW_U_RO ((k_mem_partition_attr_t) \
204#define K_MEM_PARTITION_P_RW_U_RO ((k_mem_partition_attr_t) \ …
206#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \
206#define K_MEM_PARTITION_P_RW_U_NA ((k_mem_partition_attr_t) \ …
208#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \
208#define K_MEM_PARTITION_P_RO_U_RO ((k_mem_partition_attr_t) \ …
210#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \
210#define K_MEM_PARTITION_P_RO_U_NA ((k_mem_partition_attr_t) \ …
212#define K_MEM_PARTITION_P_NA_U_NA ((k_mem_partition_attr_t) \
212#define K_MEM_PARTITION_P_NA_U_NA ((k_mem_partition_attr_t) \ …
216#define K_MEM_PARTITION_P_RWX_U_RWX ((k_mem_partition_attr_t) \
217 {PMP_R | PMP_W | PMP_X})
216#define K_MEM_PARTITION_P_RWX_U_RWX ((k_mem_partition_attr_t) \ …
218#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \
218#define K_MEM_PARTITION_P_RX_U_RX ((k_mem_partition_attr_t) \ …
230extern void z_irq_spurious(
const void *unused);
238#ifdef CONFIG_RISCV_SOC_HAS_CUSTOM_IRQ_LOCK_OPS
239 return z_soc_irq_lock();
243 __asm__
volatile (
"csrrc %0, mstatus, %1"
258#ifdef CONFIG_RISCV_SOC_HAS_CUSTOM_IRQ_LOCK_OPS
259 z_soc_irq_unlock(key);
261 __asm__
volatile (
"csrs mstatus, %0"
270#ifdef CONFIG_RISCV_SOC_HAS_CUSTOM_IRQ_LOCK_OPS
271 return z_soc_irq_unlocked(key);
279 __asm__
volatile(
"nop");
304#if defined(CONFIG_RISCV_PRIVILEGED)
static ALWAYS_INLINE void arch_nop(void)
Definition arch.h:348
RISC-V public interrupt handling.
RISCV specific syscall header.
Per-arch thread definition.
uint32_t k_mem_partition_attr_t
Definition arch.h:346
RISCV public error handling.
Public interface for configuring interrupts.
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Definition arch.h:72
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
Definition arch.h:83
uint64_t sys_clock_cycle_get_64(void)
uint32_t sys_clock_cycle_get_32(void)
static uint32_t arch_k_cycle_get_32(void)
Definition arch.h:108
static uint64_t arch_k_cycle_get_64(void)
Definition arch.h:115
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
Definition arch.h:96
#define MSTATUS_IEN
Definition arch.h:162
RISCV public exception handling.
__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:227
uint8_t pmp_attr
Definition arch.h:223
Software-managed ISR table.