Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22460

How to interact with RISC-V CSRs by using GCC C code?

$
0
0

this is my first question to be asked here on stackoverflow, so please be kind with me ;)

I'm new to RISC-V and low level C coding and I'm wondering how to manipulate the RISC-V CSRs using GCC C code.

A read of a specific CSR (e.g. MISA) looks easy: csrr rd, 0x301 which is short for csrrs rd, 0x301, x0 can be done e.g. with

int result;
asm("csrr %0, 0x301" : "=r"(result) : );

How can I convert the code above into some kind of function / callable unit with the following interface: int read_csr(int csr_number)?

Since the CSR number must be an immediate value in machine code, is it possible without generating the code on the fly (self modifying code)?

Thanks for your replies and discussion.

Joachim


Viewing all articles
Browse latest Browse all 22460

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>