1

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?

2
  • 3
    How does accessing the registers accomplish your objective? What is your objective? Commented Jan 29, 2021 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. Commented Jan 29, 2021 at 19:20

1 Answer 1

3

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.