47#define RISCV_MSTATUS_MIE 0x8
48#define RISCV_MSTATUS_MDT 0x40000000000
49#define RISCV_MSTATUSH_MDT 0x400
51#define CPU_ISR_PASSES_FRAME_POINTER FALSE
53#define CPU_HARDWARE_FP FALSE
54#define CPU_SOFTWARE_FP FALSE
55#define CPU_ALL_TASKS_ARE_FP FALSE
56#define CPU_IDLE_TASK_IS_FP FALSE
57#define CPU_USE_DEFERRED_FP_SWITCH FALSE
59#define CPU_ENABLE_ROBUST_THREAD_DISPATCH TRUE
61#define CPU_STACK_GROWS_UP FALSE
63#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (64)))
64#define CPU_BIG_ENDIAN FALSE
65#define CPU_LITTLE_ENDIAN TRUE
66#define CPU_MODES_INTERRUPT_MASK 0x0000000000000001
68#define CPU_CACHE_LINE_BYTES 64
72#define CPU_SIZEOF_POINTER 4
74#define CPU_STACK_MINIMUM_SIZE 4096
76#elif __riscv_xlen == 64
78#define CPU_SIZEOF_POINTER 8
80#define CPU_STACK_MINIMUM_SIZE 8192
85#define CPU_ALIGNMENT 16
87#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
90#define CPU_STACK_ALIGNMENT 16
92#define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
100#if __riscv_flen == 32
101typedef float RISCV_Float;
102#elif __riscv_flen == 64
103typedef double RISCV_Float;
108 volatile uint32_t is_executing;
112 uint32_t isr_dispatch_disable;
145#define _CPU_Context_Get_SP( _context ) \
146 (uintptr_t)(_context)->sp
148#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
150#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
152static inline uint32_t riscv_interrupt_disable(
void )
154 unsigned long mstatus;
158 ".option arch, +zicsr\n"
159 "csrrc %0, mstatus, " RTEMS_XSTRING( RISCV_MSTATUS_MIE )
"\n"
164 return mstatus & RISCV_MSTATUS_MIE;
167static inline void riscv_interrupt_enable( uint32_t level )
171 ".option arch, +zicsr\n"
172 "csrrs zero, mstatus, %0\n"
179#define _CPU_ISR_Disable( _level ) \
180 _level = riscv_interrupt_disable()
182#define _CPU_ISR_Enable( _level ) \
183 riscv_interrupt_enable( _level )
185#define _CPU_ISR_Flash( _level ) \
187 _CPU_ISR_Enable( _level ); \
188 riscv_interrupt_disable(); \
191static inline bool _CPU_ISR_Is_enabled(
unsigned long level )
193 return ( level & RISCV_MSTATUS_MIE ) != 0;
196static inline void _CPU_ISR_Set_level( uint32_t level )
207 ".option arch, +zicsr\n"
208 "csrrs zero, mstatus, " RTEMS_XSTRING( RISCV_MSTATUS_MIE )
"\n"
217void _CPU_Context_Initialize(
219 void *stack_area_begin,
220 size_t stack_area_size,
222 void ( *entry_point )(
void ),
227#define _CPU_Context_Restart_self( _the_context ) \
228 _CPU_Context_restore( (_the_context) )
230#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
232#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
234#define CPU_USE_LIBC_INIT_FINI_ARRAY TRUE
236#define CPU_MAXIMUM_PROCESSORS 32
238typedef uint16_t Priority_bit_map_Word;
246 RISCV_INTERRUPT_SOFTWARE_USER = 0,
247 RISCV_INTERRUPT_SOFTWARE_SUPERVISOR = 1,
248 RISCV_INTERRUPT_SOFTWARE_MACHINE = 3,
249 RISCV_INTERRUPT_TIMER_USER = 4,
250 RISCV_INTERRUPT_TIMER_SUPERVISOR = 5,
251 RISCV_INTERRUPT_TIMER_MACHINE = 7,
252 RISCV_INTERRUPT_EXTERNAL_USER = 8,
253 RISCV_INTERRUPT_EXTERNAL_SUPERVISOR = 9,
254 RISCV_INTERRUPT_EXTERNAL_MACHINE = 11
255} RISCV_Interrupt_code;
263 RISCV_EXCEPTION_INSTRUCTION_ADDRESS_MISALIGNED = 0,
264 RISCV_EXCEPTION_INSTRUCTION_ACCESS_FAULT = 1,
265 RISCV_EXCEPTION_ILLEGAL_INSTRUCTION = 2,
266 RISCV_EXCEPTION_BREAKPOINT = 3,
267 RISCV_EXCEPTION_LOAD_ADDRESS_MISALIGNED = 4,
268 RISCV_EXCEPTION_LOAD_ACCESS_FAULT = 5,
269 RISCV_EXCEPTION_STORE_OR_AMO_ADDRESS_MISALIGNED = 6,
270 RISCV_EXCEPTION_STORE_OR_AMO_ACCESS_FAULT = 7,
271 RISCV_EXCEPTION_ENVIRONMENT_CALL_FROM_U_MODE = 8,
272 RISCV_EXCEPTION_ENVIRONMENT_CALL_FROM_S_MODE = 9,
273 RISCV_EXCEPTION_ENVIRONMENT_CALL_FROM_M_MODE = 11,
274 RISCV_EXCEPTION_INSTRUCTION_PAGE_FAULT = 12,
275 RISCV_EXCEPTION_LOAD_PAGE_FAULT = 13,
276 RISCV_EXCEPTION_STORE_OR_AMO_PAGE_FAULT = 15
277} RISCV_Exception_code;
436static inline uint32_t CPU_swap_u32(
440 uint32_t byte1, byte2, byte3, byte4, swapped;
442 byte4 = (value >> 24) & 0xff;
443 byte3 = (value >> 16) & 0xff;
444 byte2 = (value >> 8) & 0xff;
445 byte1 = value & 0xff;
447 swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
451#define CPU_swap_u16( value ) \
452 (((value&0xff) << 8) | ((value >> 8)&0xff))
454typedef uint32_t CPU_Counter_ticks;
458extern volatile uint32_t *
const _RISCV_Counter;
464uint32_t _CPU_SMP_Initialize(
void );
466bool _CPU_SMP_Start_processor( uint32_t cpu_index );
468void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
470void _CPU_SMP_Prepare_start_multitasking(
void );
472static inline uint32_t _CPU_SMP_Get_current_processor(
void )
474 unsigned long mhartid;
478 ".option arch, +zicsr\n"
484 return (uint32_t) mhartid - RISCV_BOOT_HARTID;
487void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
489static inline bool _CPU_Context_Get_is_executing(
493 return context->is_executing;
496static inline void _CPU_Context_Set_is_executing(
501 context->is_executing = is_executing;
506#define _CPU_Start_multitasking( _heir ) _RISCV_Start_multitasking( _heir )
This header file provides basic definitions used by the API and the implementation.
#define RTEMS_XSTRING(...)
Stringifies the expansion of the arguments.
Definition: basedefs.h:1012
#define RTEMS_NO_RETURN
Tells the compiler in a function declaration that this function does not return.
Definition: basedefs.h:386
uint32_t _CPU_ISR_Get_level(void)
Returns the interrupt level of the executing thread.
Definition: cpu.c:167
void * _CPU_Thread_Idle_body(uintptr_t ignored)
Definition: m68kidle.c:39
void _CPU_Initialize(void)
CPU initialization.
Definition: cpu.c:47
uintptr_t CPU_Uint32ptr
Definition: cpu.h:611
void _CPU_Exception_frame_print(const CPU_Exception_frame *frame)
Prints the exception frame via printk().
Definition: vectorexceptions.c:64
uint32_t _CPU_Counter_frequency(void)
Gets the current CPU counter frequency in Hz.
Definition: system-clocks.c:125
void _CPU_Context_switch(Context_Control *run, Context_Control *heir)
CPU switch context.
Definition: cpu_asm.c:110
CPU_Counter_ticks _CPU_Counter_read(void)
Gets the current CPU counter value.
Definition: system-clocks.c:130
#define ra
return address */
Definition: regs.h:66
#define sp
stack-pointer */
Definition: regs.h:64
#define gp
global data pointer */
Definition: regs.h:63
The set of registers that specifies the complete processor state.
Definition: cpu.h:500
Interrupt stack frame (ISF).
Definition: cpuimpl.h:64
Thread register context.
Definition: cpu.h:173