This header provides Ibex-specific functions and enums, such as cycle-accurate busy loops. More...
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/math.h"
#include "sw/device/lib/base/stdasm.h"
Go to the source code of this file.
Data Structures | |
struct | ibex_timeout |
A spinwait timeout type. More... | |
Macros | |
#define | IBEX_SPIN_FOR(expr, timeout_usec) |
Convenience macro to spin with timeout in microseconds. More... | |
#define | IBEX_TRY_SPIN_FOR(expr, timeout_usec) |
Convenience macro to spin with timeout in microseconds. More... | |
Typedefs | |
typedef enum ibex_exc | ibex_exc_t |
An Ibex exception type. More... | |
typedef enum ibex_internal_irq | ibex_internal_irq_t |
An Ibex internal IRQ type. More... | |
typedef struct ibex_timeout | ibex_timeout_t |
A spinwait timeout type. | |
Enumerations | |
enum | ibex_exc { kIbexExcInstrMisaligned = 0, kIbexExcInstrAccessFault = 1, kIbexExcIllegalInstrFault = 2, kIbexExcBreakpoint = 3, kIbexExcLoadAccessFault = 5, kIbexExcStoreAccessFault = 7, kIbexExcUserECall = 8, kIbexExcMachineECall = 11, kIbexExcMax = 31 } |
An Ibex exception type. More... | |
enum | ibex_internal_irq { kIbexInternalIrqLoadInteg = 0xffffffe0, kIbexInternalIrqNmi = 0x8000001f } |
An Ibex internal IRQ type. More... | |
Functions | |
OT_WARN_UNUSED_RESULT uint64_t | ibex_mcycle_read (void) |
Read the cycle counter. More... | |
OT_WARN_UNUSED_RESULT uint32_t | ibex_mcause_read (void) |
Reads the mcause register. More... | |
OT_WARN_UNUSED_RESULT uint32_t | ibex_mtval_read (void) |
Reads the mtval register. More... | |
OT_WARN_UNUSED_RESULT uint32_t | ibex_mepc_read (void) |
Reads the mepc register. More... | |
void | ibex_mepc_write (uint32_t mepc) |
Writes the mepc register. More... | |
OT_WARN_UNUSED_RESULT ibex_timeout_t | ibex_timeout_init (uint32_t timeout_usec) |
Initializes the ibex timeout based on current mcycle count. More... | |
OT_WARN_UNUSED_RESULT bool | ibex_timeout_check (const ibex_timeout_t *timeout) |
Check whether the timeout has expired. More... | |
OT_WARN_UNUSED_RESULT uint64_t | ibex_timeout_elapsed (const ibex_timeout_t *timeout) |
Returns the time elapsed in microseconds since ibex_timeout_init was called. More... | |
This header provides Ibex-specific functions and enums, such as cycle-accurate busy loops.
Definition in file ibex.h.
struct ibex_timeout |
#define IBEX_SPIN_FOR | ( | expr, | |
timeout_usec | |||
) |
Convenience macro to spin with timeout in microseconds.
expr | An expression that is evaluated multiple times until true. |
timeout_usec | Timeout in microseconds. |
#define IBEX_TRY_SPIN_FOR | ( | expr, | |
timeout_usec | |||
) |
Convenience macro to spin with timeout in microseconds.
expr | An expression that is evaluated multiple times until true. |
timeout_usec | Timeout in microseconds. |
kDeadlineExceeded
in case of timeout. typedef enum ibex_exc ibex_exc_t |
An Ibex exception type.
This enum is used to decode RISC-V exception causes generated by Ibex.
typedef enum ibex_internal_irq ibex_internal_irq_t |
An Ibex internal IRQ type.
This enum is used to decode RISC-V internal IRQs generated by Ibex.
enum ibex_exc |
enum ibex_internal_irq |
OT_WARN_UNUSED_RESULT uint32_t ibex_mcause_read | ( | void | ) |
Reads the mcause register.
When an exception is encountered, the corresponding exception code is stored in mcause register.
A list of the exception codes can be found at: https://ibex-core.readthedocs.io/en/latest/03_reference/ exception_interrupts.html::exceptions
|
inline |
Read the cycle counter.
The value of the counter is stored across two 32-bit registers: mcycle
and mcycleh
. This function is guaranteed to return a valid 64-bit cycle counter value, even if mcycle
overflows before reading mcycleh
.
Adapted from: The RISC-V Instruction Set Manual, Volume I: Unprivileged ISA V20191213, pp. 61.
OT_WARN_UNUSED_RESULT uint32_t ibex_mepc_read | ( | void | ) |
Reads the mepc register.
When an exception is encountered, the current program counter is saved in mepc, and the core jumps to the exception address. When an MRET instruction is executed, the value from mepc replaces the current program counter.
From the Ibex documentation (found at https://ibex-core.readthedocs.io/en/latest/03_reference/cs_registers.html)
Please note that in case of a fault, mepc must be modified to hold the address of the next instruction, which can be at the 2byte (16bit) or 4byte (32bit) offset, dependent on the fault cause instruction type (standard or compressed).
void ibex_mepc_write | ( | uint32_t | mepc | ) |
Writes the mepc register.
When an exception is encountered, the current program counter is saved in mepc, and the core jumps to the exception address. When an MRET instruction is executed, the value from mepc replaces the current program counter.
From the Ibex documentation (found at https://ibex-core.readthedocs.io/en/latest/03_reference/cs_registers.html)
Please note that in case of a fault, mepc must be modified to hold the address of the next instruction, which can be at the 2byte (16bit) or 4byte (32bit) offset, dependent on the fault cause instruction type (standard or compressed).
The | new value to be written to the mepc register. |
OT_WARN_UNUSED_RESULT uint32_t ibex_mtval_read | ( | void | ) |
Reads the mtval register.
When an exception is encountered, the Machine Trap Value (mtval) register can holds exception-specific information to assist software in handling the trap.
From the Ibex documentation (found at https://ibex-core.readthedocs.io/en/latest/03_reference/cs_registers.html)
|
inline |
|
inline |
|
inline |