Core CSR Register Access

Click Nuclei Core CSR to learn about Core CSR in Nuclei ISA Spec.

group NMSIS_Core_CSR_Register_Access

Functions to access the Core CSR Registers.

The following functions or macros provide access to Core CSR registers.

Defines

__RV_CSR_SWAP(csr, val)

CSR operation Macro for csrrw instruction.

Read the content of csr register to __v, then write content of val into csr register, then return __v

Return

the CSR register value before written

Parameters

__RV_CSR_READ(csr)

CSR operation Macro for csrr instruction.

Read the content of csr register to __v and return it

Return

the CSR register value

Parameters

__RV_CSR_WRITE(csr, val)

CSR operation Macro for csrw instruction.

Write the content of val to csr register

Parameters

__RV_CSR_READ_SET(csr, val)

CSR operation Macro for csrrs instruction.

Read the content of csr register to __v, then set csr register to be __v | val, then return __v

Return

the CSR register value before written

Parameters

__RV_CSR_SET(csr, val)

CSR operation Macro for csrs instruction.

Set csr register to be csr_content | val

Parameters

__RV_CSR_READ_CLEAR(csr, val)

CSR operation Macro for csrrc instruction.

Read the content of csr register to __v, then set csr register to be __v & ~val, then return __v

Return

the CSR register value before written

Parameters

__RV_CSR_CLEAR(csr, val)

CSR operation Macro for csrc instruction.

Set csr register to be csr_content & ~val

Parameters

Functions

__STATIC_FORCEINLINE void __enable_irq(void)

Enable IRQ Interrupts.

Enables IRQ interrupts by setting the MIE-bit in the MSTATUS Register.

Remark

Can only be executed in Privileged modes.

__STATIC_FORCEINLINE void __disable_irq(void)

Disable IRQ Interrupts.

Disables IRQ interrupts by clearing the MIE-bit in the MSTATUS Register.

Remark

Can only be executed in Privileged modes.

__STATIC_FORCEINLINE uint64_t __get_rv_cycle(void)

Read whole 64 bits value of mcycle counter.

This function will read the whole 64 bits of MCYCLE register

Return

The whole 64 bits value of MCYCLE

Remark

It will work for both RV32 and RV64 to get full 64bits value of MCYCLE

__STATIC_FORCEINLINE uint64_t __get_rv_instret(void)

Read whole 64 bits value of machine instruction-retired counter.

This function will read the whole 64 bits of MINSTRET register

Return

The whole 64 bits value of MINSTRET

Remark

It will work for both RV32 and RV64 to get full 64bits value of MINSTRET

__STATIC_FORCEINLINE uint64_t __get_rv_time(void)

Read whole 64 bits value of real-time clock.

This function will read the whole 64 bits of TIME register

Return

The whole 64 bits value of TIME CSR

Remark

It will work for both RV32 and RV64 to get full 64bits value of TIME

Attention

only available when user mode available