Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
Loading...
Searching...
No Matches

Overview

Function definitions for RISCV driver.

Macros

#define csr_swap(csr, val)
 This function is used to swap the value of a CSR with a specified value.
#define csr_read(csr)
 This function is used to read the value of a CSR.
#define csr_write(csr, val)
 This function is used to write a value to a CSR.
#define csr_read_set(csr, val)
 This function is used to read and set a CSR with a specified value.
#define csr_set(csr, val)
 This function is used to set a CSR to a specified value.
#define csr_read_clear(csr, val)
 This function is used for performing a read-clear operation on the specified CSR.
#define csr_clear(csr, val)
 This function is used to clear a CSR.
#define opcode_R(opcode, func3, func7, rs1, rs2)
 Macor for generating the opcode of an R-type instruction.
#define cfu_type_R(func3, func7, rs1, rs2)
 Macros for defining custom R-type instructions with specific opcodes and function fields.
#define cfu_push(func3, func7, rs1, rs2)
 Macros for defining cfu_push and cfu_pop instructions using the CUSTOM1 opcode.
#define cfu_pop2()
#define cfu_pop()

Macro Definition Documentation

◆ cfu_pop

#define cfu_pop ( )

#include <riscv.h>

Value:
({ \
register unsigned long __v; \
asm volatile( \
".word ((0x5B) | (regnum_%0 << 7));" \
: [rd] "=r" (__v) \
: \
); \
__v; \
})

Definition at line 400 of file riscv.h.

◆ cfu_pop2

#define cfu_pop2 ( )

#include <riscv.h>

Value:
({ register unsigned long __v; asm volatile( ".word ((0x5B) | (regnum_%0 << 7));" : [rd] "=r" (__v) : ); __v; })

Definition at line 399 of file riscv.h.

◆ cfu_push

#define cfu_push ( func3,
func7,
rs1,
rs2 )

#include <riscv.h>

Value:
opcode_R(CUSTOM1, func3, func7, rs1, rs2)
#define opcode_R(opcode, func3, func7, rs1, rs2)
Macor for generating the opcode of an R-type instruction.
Definition riscv.h:370

Macros for defining cfu_push and cfu_pop instructions using the CUSTOM1 opcode.

Parameters
func3The 3-bit function field for the cfu_push instruction.
func7The 7-bit function field for the cfu_push instruction.
rs1The source register 1 for the cfu_push instruction.
rs2The source register 2 for the cfu_push instruction.
Note
The cfu_push macro generates an R-type instruction with the CUSTOM1 opcode and the specified function fields and registers. The cfu_pop macro generates an R-type instruction with the CUSTOM1 opcode and a fixed function field for popping values from a custom stack. Both macros return the generated opcode as an unsigned long integer.

Definition at line 398 of file riscv.h.

◆ cfu_type_R

#define cfu_type_R ( func3,
func7,
rs1,
rs2 )

#include <riscv.h>

Value:
opcode_R(CUSTOM0, func3, func7, rs1, rs2)

Macros for defining custom R-type instructions with specific opcodes and function fields.

Parameters
func3The 3-bit function field for the custom instruction.
func7The 7-bit function field for the custom instruction.
rs1The source register 1 for the custom instruction.
rs2The source register 2 for the custom instruction.

Definition at line 388 of file riscv.h.

◆ csr_clear

#define csr_clear ( csr,
val )

#include <riscv.h>

Value:
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrc " #csr ", %0" \
: : "rK" (__v)); \
})

This function is used to clear a CSR.

Parameters
csrThe name of the CSR to be cleared.
valThe value to be used for the operation (unused in clearing).
Note
This macro clears the specified CSR using the "csrc" instruction in RISC-V assembly. It takes the CSR name and a value as parameters, but the value parameter is unused as clearing a CSR typically does not involve any additional value.

Definition at line 263 of file riscv.h.

◆ csr_read

#define csr_read ( csr)

#include <riscv.h>

Value:
({ \
register unsigned long __v; \
__asm__ __volatile__ ("csrr %0, " #csr \
: "=r" (__v)); \
__v; \
})

This function is used to read the value of a CSR.

Parameters
csrThe name of the CSR to be read.
Returns
The value of the CSR.
Note
This macro reads the current value of the specified CSR using CSR instructions in RISC-V assembly. It returns the value of the CSR, allowing for efficient access to CSRs in RISC-V assembly code.

Definition at line 188 of file riscv.h.

◆ csr_read_clear

#define csr_read_clear ( csr,
val )

#include <riscv.h>

Value:
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrc %0, " #csr ", %1" \
: "=r" (__v) : "rK" (__v)); \
__v; \
})

This function is used for performing a read-clear operation on the specified CSR.

Parameters
csrThe Control and Status Register (CSR) to read-clear.
valThe value to use for the operation.
Returns
The previous value of the CSR before the read-clear operation.

Definition at line 247 of file riscv.h.

◆ csr_read_set

#define csr_read_set ( csr,
val )

#include <riscv.h>

Value:
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrs %0, " #csr ", %1" \
: "=r" (__v) : "rK" (__v)); \
__v; \
})

This function is used to read and set a CSR with a specified value.

Parameters
csrThe name of the CSR to be read and set.
valThe value to be ORed with the current value of the CSR.
Returns
The previous value of the CSR before the set operation.
Note
This macro reads the current value of the specified CSR, ORs it with the specified value, and writes the result back to the CSR using CSR instructions in RISC-V assembly. It returns the previous value of the CSR before the set operation.

Definition at line 221 of file riscv.h.

◆ csr_set

#define csr_set ( csr,
val )

#include <riscv.h>

Value:
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrs " #csr ", %0" \
: : "rK" (__v)); \
})

This function is used to set a CSR to a specified value.

Parameters
csrThe name of the CSR to be set.
valThe value to be set for the CSR.

Definition at line 234 of file riscv.h.

◆ csr_swap

#define csr_swap ( csr,
val )

#include <riscv.h>

Value:
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrrw %0, " #csr ", %1" \
: "=r" (__v) : "rK" (__v)); \
__v; \
})

This function is used to swap the value of a CSR with a specified value.

Parameters
csrThe name of the CSR to be swapped.
valThe value to be swapped with the CSR.
Returns
The previous value of the CSR.
Note
This macro performs a swap operation using CSR instructions in RISC-V assembly. It reads the current value of the CSR, writes the specified value to the CSR, and returns the previous value of the CSR before the write operation. It allows for efficient manipulation of CSRs in RISC-V assembly code.

Definition at line 172 of file riscv.h.

◆ csr_write

#define csr_write ( csr,
val )

#include <riscv.h>

Value:
({ \
unsigned long __v = (unsigned long)(val); \
__asm__ __volatile__ ("csrw " #csr ", %0" \
: : "rK" (__v)); \
})

This function is used to write a value to a CSR.

Parameters
csrThe name of the CSR to which the value will be written.
valThe value to be written to the CSR.
Note
This macro writes the specified value to the specified CSR using CSR instructions in RISC-V assembly. It allows for efficient modification of CSRs in RISC-V assembly code.

Definition at line 205 of file riscv.h.

◆ opcode_R

#define opcode_R ( opcode,
func3,
func7,
rs1,
rs2 )

#include <riscv.h>

Value:
({ \
register unsigned long __v; \
asm volatile( \
".word ((" #opcode ") | (regnum_%0 << 7) | (regnum_%1 << 15) | (regnum_%2 << 20) | ((" #func3 ") << 12) | ((" #func7 ") << 25));" \
: [rd] "=r" (__v) \
: "r" (rs1), "r" (rs2) \
); \
__v; \
})

Macor for generating the opcode of an R-type instruction.

Parameters
opcodeThe base opcode value for the instruction.
func3The 3-bit function field.
func7The 7-bit function field.
rs1Register number for source register 1.
rs2Register number for source register 2.
Returns
The generated opcode for the R-type instruction.
Note
This macro generates the opcode for an R-type instruction in RISC-V assembly. It takes the base opcode value, function field values (func3 and func7), and register numbers for source registers rs1 and rs2. The resulting opcode is formed by combining the provided values according to the R-type instruction encoding format and returned as an unsigned long integer.

Definition at line 370 of file riscv.h.