I want to access the register file of the RISC-V using the C Program. is there any way I can write and read directly into the register file of the RISC-V using C Program?
-
3How does accessing the registers accomplish your objective? What *is* your objective? – Erik Eidt Jan 29 '21 at 19:11
-
In particular, the compiler is also using those registers. So in order to have any certainty as to what you will read, or what will happen when you write, you have to define your problem more precisely. As it stands this might be an XY problem. – Nate Eldredge Jan 29 '21 at 19:20
1 Answers
There is no portable way to access registers using the C language, as C works at a level of abstraction above registers / RTL (roughly speaking).
However there may be compiler-specific ways to do this, using built-in compiler intrinsic functions. See:
https://gcc.gnu.org/onlinedocs/gcc/Target-Builtins.html
https://gcc.gnu.org/onlinedocs/gcc/Explicit-Register-Variables.html
https://gcc.gnu.org/onlinedocs/gcc/Global-Register-Variables.html
https://gcc.gnu.org/onlinedocs/gccint/Registers.html
See these other StackOverflow questions:
Accessing a register without using inline assembly with gcc
Reading a register value into a C variable
EDIT
RISC-V register access doesn't seem supported with C-intrinsics using GCC. You may have to use (inline) assembly to get at it.
EDIT2
Some (most?) embedded processors running bare-metal without OS (i.e. NOT in a virtual-memory system) can access their registers if you know their address. But it depends much on the hardware you're running on. As Erik Eidt asks: What are you trying to do?
- 5,818
- 3
- 43
- 55