Trying to Compile FreeRtos for Riscv .Error: Instruction csrr requires absolute expression

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Trying to Compile FreeRtos for Riscv .Error: Instruction csrr requires absolute expression



i am trying to compile the FreeRTOS riscv_spike port, with riscv32-unknown-linux-gnu-gcc toolchain but got his error



Error:
../../Source/portable/GCC/RISCV/port.c:121: Error: Instruction csrr requires absolute expression



The following code is from port.c of freeRtos Source


__asm volatile("csrr t0,mtime");
__asm volatile("add t0,t0,%0" :: "r"(configTICK_CLOCK_HZ/configTICK_RATE_HZ));
__asm volatile("csrw mtimecmp,t0");



can anyone describe me what changes i need to make?
i guess the mtime, mtimecmp is invalid
can i add this required definition in "encoding" file by reading the spec?



thanks,




1 Answer
1



As per riscv-privildged-v1.10 in § 3.1.15, mtime & mtimecmp are exposed as a memory-mapped machine-mode register. They are accessed by store (sw) and load instructions (lw), and not by csr* instructions.


sw


lw


csr*



They are therefore platform implementation dependent - in particular their address depend on the platform.



Your code cannot be assembled because the csrr & csrw expect both a value and not a relocatable expression as you have written. But as mentionned at the beginning, you have to use sw and lw instructions - and take care that mtime & mtimecmp are implemented and at which address they can be accessed.


csrr


csrw





hi, what about mtohost and fromhost ??
– aditya
Aug 11 at 2:58





I do not know what mtohost and fromhost are. Can you elaborate ?
– Pierre G.
Aug 11 at 6:12





they are also registers like mtime and mtimecmp, i think the same procedure which you mentioned applies for mtohost and fromhost ?You can refer the previous version architecture.Can you give me any example, how i can achieve that using lw and sw instruction?
– aditya
Aug 11 at 6:29





You can have a look at github.com/padmaraob/FreeRTOS-RISCV/blob/master/Source/portable/… which does not need to use __asm to manipulate mtime & mtimecmp (memory mapped reg). Regarding mtohost & fromhost, if they are memory mapped, you just have to do the same.
– Pierre G.
Aug 11 at 6:38





Now understood how i can do it. Do you know when compiling the source it needs encoding.h file, which file in the toolchain, i must copy to the source folder when compiling the Demo source
– aditya
Aug 11 at 7:00







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered