Baremetal-NN
Baremetal-NN API documentation
Loading...
Searching...
No Matches
riscv.h
Go to the documentation of this file.
1
18#ifndef __RISCV_H
19#define __RISCV_H
20
21#ifdef __riscv_xlen
22 #define RISCV_XLEN __riscv_xlen
23#else
24 #warning "__riscv_xlen not defined, defaulting to 64"
25 #define RISCV_XLEN 64
26#endif
27
28#if RISCV_XLEN == 64
29 #define LREG ld
30 #define SREG sd
31 #define REGBYTES 8
32#elif RISCV_XLEN == 32
33 #define LREG lw
34 #define SREG sw
35 #define REGBYTES 4
36#else
37 #error "Unsupported RISCV_XLEN"
38#endif
39
40
41/* ================ RISC-V specific definitions ================ */
42#define READ_CSR(REG) ({ \
43 unsigned long __tmp; \
44 asm volatile ("csrr %0, " REG : "=r"(__tmp)); \
45 __tmp; })
46
47#define WRITE_CSR(REG, VAL) ({ \
48 asm volatile ("csrw " REG ", %0" :: "rK"(VAL)); })
49
50#define SWAP_CSR(REG, VAL) ({ \
51 unsigned long __tmp; \
52 asm volatile ("csrrw %0, " REG ", %1" : "=r"(__tmp) : "rK"(VAL)); \
53 __tmp; })
54
55#define SET_CSR_BITS(REG, BIT) ({ \
56 unsigned long __tmp; \
57 asm volatile ("csrrs %0, " REG ", %1" : "=r"(__tmp) : "rK"(BIT)); \
58 __tmp; })
59
60#define CLEAR_CSR_BITS(REG, BIT) ({ \
61 unsigned long __tmp; \
62 asm volatile ("csrrc %0, " REG ", %1" : "=r"(__tmp) : "rK"(BIT)); \
63 __tmp; })
64
65
66#endif /* __RISCV_H */