Add custom instruction to freedom platform


#1

Hi there,

I have been looking for a guide to add some domain specific custom RISC-V instruction to the freedom platform, but I can’t find a “get started” guide or something like that.

The freedom e300 platform product brief mentioned that the custom instructions can either be added via accelerator or be operated within the existing register set. But where could I find the guide on how to do this?

Thanks,
Dong


(Colin Schmidt) #2

I don’t believe we have a guide for adding them specifically to the freedom platform but there have been guides for adding custom instructions via the RoCC interface to rocket-chip in the past see a brief introducton and a VERY old tutorial. All the documents I know have become out of date as rocket-chip has continued to evolve so I think they would only serve as background on the interface but not a getting started in the current code base.

If you wanted to look at the code base as it stands now there are several simple examples in rocket-chip of RoCC accelerators e.g. here

Hopefully this will help you get started.


#3

Thanks @colins!

I’ve got the accelerator instantiated inside the core by looking into the given example, but is there any way to connect them to the system and platform? (system.scala and platform.scala)?

Thanks,
Dong


(Juan Valverde) #4

Hello,

Did you manage to test the custom instructions? I added the WithRoccExample class to TinyConfig, I generated Verilog and synthesis the bitstream with no errors, but I don’t know how to test the instruction.

I have the TARGET=freedom-e310-arty.


(Jim Wilson) #5

You can use the assembler .insn support to encode non-standard instructions.
https://sourceware.org/binutils/docs-2.33.1/as/RISC_002dV_002dDirectives.html#RISC_002dV_002dDirectives
The .insn directive is mentioned near the bottom, and then the next section describes the instruction format info that goes with the .insn directive.


(Juan Valverde) #6

Thanks, fixed using the examples and updating the MSTATUS register.

I am trying now to add an extra input to the accumulator example in Chisel to connect one of the performance monitors (i.e. mcycle) but with all the classes I cannot find where to add additional input ports.

Juan