RISC-V rv32i or rv32im in VHDL? With a stable Windows toolchain?

I've been trying to find a stable VHDL implementation of rv32im, or failing that rv32i. I also need a stable Windows toolchain for it. So far these two requirements seem mutually exclusive.

For example I found the rv32i potato processor, but I can't find a pre-built Windows toolchain that will work with this, nor have I seen any decent instructions on how to build one. I tried a Windows build of GNU MCU Eclipse RISC-V but while it will compile 32-bit architectures ld refuses to link 32-bit object files.

Does anyone know of any projects that actually fit these requirements? I'm pretty disappointed that the second requirement seems to be harder to meet than the first.

Posted Feb 26, 2019, 7:19 PM UTC

216
captain_wiggles_•

Why does the toolchain have to be for windows? What about none pre-built ones? It shouldn't be hard to build your own.

In the README of that potatoe processor it says:

Compiler Toolchain To program the processor, you need an appropriate compiler toolchain. Follow the instructions on the RISCV GNU toolchain repository site to build and install a 32-bit RISC-V toolchain.

Did you try that? What happened? The instructions are linux / mac, but that should be surmountable. Try using cygwin, install the packages they mention, then run the build steps. You may have to jump through some hoops but it should work.

3
FieldProgrammableOPIntel User•

As you said, the instructions don't cover building with Windows, a quick look through the GIT issues shows other users are struggling to build for Windows.

This is exactly the situation that puts me off using 90% of open source processors. I don't have Linux, nor do I want to use it, I don't have a Mac, I'm not going to spend hours trying to learn how to build a toolchain in an environment I've never used, just so I can evaluate a processor core.

Before anyone accuses me of being "lazy". The last open source core I picked up included a pre-built Windows GCC toolchain and batch files to compile and link. This allowed me to evaluate the core, identify a critical bug in the ALU and areas for improvement in the peripherals, I communicated these to the original author together with details of how they should be resolved. But if this anti-Windows intransigence is typical of most open-source projects I guess I won't be doing so with anything else.

1
captain_wiggles_•

Not having linux / mac isn't an issue. You can install command line only linux in virtual box. You can use cygwin for 95% of stuff. You can use bash for windows too (although I haven't got this working properly yet, due to not being able to launch native windows apps).

If you want to work with open source stuff you need to get used to building stuff. It can be a pain in the ass, it can take days to get it right, but that's the way of it. Otherwise you can go pay thousands for a CPU core and closed source tool chain.

As a profesional embedded developer, this is the boring shit that just has to be done. Get used to it.

1
FieldProgrammableOPIntel User•

As a professional embedded developer, with a small team of firmware developers working under me, I can say that, no we don't have to do this "boring shit" as part of our day to day work, we have never needed to do so in the past and are in general agreement that we will not do so in the future either.

We also have a staff of 20 software developers, none of them need to use Linux in their daily work (I will try to do a survey on how many of them have ever compiled GCC though).

I don't know what currency you are using, but last time I checked none of the closed source CPU cores provided by the major vendors cost thousands of $. Microblaze was $500 now free, Nios II/e free, Nios II/f $500, Mico32 free. Then there's the ARM SoC offerings, IIRC Intel and Xilinx both offer free Windows toolchains.

I recently used the Nios II/e, it doesn't have an instruction or data cache, so I made my own, it doesn't have a multiplier or divider, so I added my own as custom instructions. I compiled it and its software in the free version of the toolchain and shipped.

The open source core we are currently using (an MSP430 clone) didn't require us to build our own toolchain, we've contributed to its open source distribution and built a collection of custom hardware extensions for it. I guess we won't be contributing to anything else, but don't worry we'll get used to it.

-1
mbitsnbites•

Disclaimer: I know this is not an answer and it won't help short term, but I still have to say: Linux is where it's happening. Ten years ago I wouldn't be so sure, but now the trend is clear to me: as a development platform, Linux is killing Windows (slowly, but surely). Only a minority of the many SW development professionals that I have worked with (from different industries) prefer Windows these days - it's lagging behind, both technically and from a tools perspective, which is clear to see from how MS is embracing Linux and open source on every level not to loose customers (WSL, Azure, Docker, VS Code, SQL Server, GitHub, and the list goes on...).

Now, the FPGA industry seems to be about a decade or two behind the SW industry in terms of tooling and embracing open source, but I'm confident that they will move more towards Linux too in the years to come.

My point: Dismissing Linux altogether is likely to bite you further down the road. I wouldn't be surprised if Windows is not even going to be an option for most developers a decade from now, and then you risk missing out on lots of technology and innovation if you stick with Windows.

And this is not just an opinion, it's a very obvious trend.

4
bonfire_processor•

I tried a Windows build of GNU MCU Eclipse RISC-V but while it will compile 32-bit architectures ld refuses to link 32-bit object files.

I cant directly help you with Windows, because I haven't tested it, but the GNU MCU Ecplipse RISC-V GCC can definitively compile and link RV32 binaries. According to this page https://gnu-mcu-eclipse.github.io/toolchain/riscv/

the default builds contain runtime libraries for RV32I and RV32IM, so you should be able to compile both. If you have a problem, maybe post your command line and your linker script (*.ld file) here.

Indeed one of the problems of RISC-V currently is, that there is no "golden toolchain". Everybody in the ecosystem deliveries "his" toolchain. Basically they are all the same, but often different commits from the upstream and some different configurations.

​

If you are interested in a VHDL rv32im core you can checkout my variant: bonfirecpu.eu

I must confess that I usually work also under Linux, just because in the long run it is easier to learn Linux once, instead of always fighting with adapting Linux/Unix tools to Windows (the first is a one time effort, the second repeats endlessly). And GCC basically is a Unix software, this is the core problem.

​

But nevertheless, the VHDL code is operating system independent. If you are addressing Xilinx devices, I have also a full design working on an Arty Board. I know from other that they have been able to rebuilt with Vivado on Windows.

GNU MCU Eclipse also works with the core, it is the toolchain I also recommend.

​

​

​

​

2
FieldProgrammableOPIntel User•

Thanks, I did look at the bonfire CPU, I noticed the commit comments about the instruction cache not working yet. Is that still the case? If the core itself is stable (and I had a working Windows toolchain!), maybe I can help get an icache working. I previously made a direct mapped, critical word first icache and a write-back/allocate dcache to speed up my Nios II/e designs.

If I can make another suggestion to core authors, it really would be nice if their synthesis results (whether they be just for one FPGA or ten) were posted on their GIT readmes. Performance does matter for people looking at cores with serious use cases in mind and it isn't trivial to constrain, synthesise, P&R a core just to see roughly how big/fast it is.

As I said, compilation is always fine, I can get object files for the startup code and main.c, but when I try to link these two using ld I get an error.

So for start.s and main.c I'm using: riscv-none-embed-gcc -c -march=rv32i -mabi=ilp32 -nostartfiles -Wall -Os -fomit-frame-pointer -ffreestanding -fno-builtin -std=gnu99 -Wall -Werror=implicit-function-declaration -fdata-sections -ffunction-sections

Then riscv-none-embed-ld -nostartfiles -T potato.ld main.o start.o -o main.elf gives the error: ABI is incompatible with that of the selected emulation: target emulation elf32-littleriscv' does not match elf64-littleriscv'

If I try: riscv-none-embed-ld -nostartfiles -T potato.ld -march=rv32i

I get riscv-none-embed-ld: unrecognised emulation mode: arch=rv32i Supported emulations: elf64lriscv elf32lriscv

Same for -march=elf32lriscv

1
bonfire_processor•

I noticed the commit comments about the instruction cache not working yet. Is that still the case?

It has working instruction and data caches. The toplevel bonfire_cpu_top contains the instruction cache. It is direct mapped and can be configured with generics.

The data cache is not part of the core, it is in an extra git repo https://github.com/bonfireprocessor/bonfire-dcache

​

I recommend using https://github.com/bonfireprocessor/bonfire_axi , this is the core with instruction and data caches and AXI4 bridges. I work with Xilinx FPGAs, and this toplevel also contains all the necessary attributes, that it can be used with Vivado IP Integrator. The interfacing is very similar to Microblaze, so the idea is to simplify replacing it in Vivado designs.

f I can make another suggestion to core authors, it really would be nice if their synthesis results (whether they be just for one FPGA or ten) were posted on their GIT readmes.

Indeed a good idea, I thought it was in my readme, but noticed that it is not part anymore on the latest version. I just took a look into the utilization report of my last implementation build in Vivado 2018.2.

bonfire_axi_top:

LUTsRegistersSlicesBRAM TilesDSP48
21501386703174

This is the cpu with 32KB I-Cache and 32KB D-Cache. The cpu core itself is 515 slices.

The current design is synthesized with 83 Mhz CPU clock, because of limitation how the Xilinx DRAM interface (MIG) works. On an Artix-7 the core can reach about 120 Mhz when using distributed RAM as register file. With registers file implemented as BRAM it is a bit slower.

​

ABI is incompatible with that of the selected emulation: target emulation

elf32-littleriscv' does not match

elf64-littleriscv'

The problem is, that the potato examples where done with a very old RISC-V toolchain. In newer versions you need to add the -mabi=ilp32 option to compiler and linker calls. Than it should work.

​

The good thing with Bonfire is, that it I'm using it with an adapted version if elua https://github.com/ThomasHornschuh/elua which is a complex piece of software. So the core is used with more than a few test programs. And it runs very stable with it. And with everything I ported to it (e.g. fatfs, currently picotcp) I never run into processor related issues (e.g. lock ups). So although the core is not formally verified, I don't think that it contains serious flaws.

BTW: You may take a look into bonfirecpu.eu

1
FieldProgrammableOPIntel User•

riscv-none-embed-ld -nostartfiles -T riscv_linker_script.x -march=rv32i -mabi=ilp32 main.o start.o -o main.elf

riscv-none-embed-ld: unrecognised emulation mode: abi=ilp32 Supported emulations: elf64lriscv elf32lriscv

Pretty sure this build is just broken. But! I've cajoled one of my colleagues (or at least moaned about this so much during our lunch breaks) that he has tried to build it, he has slightly more patience for Linux than myself. He mentioned today that after a couple of attempts (three hours a piece) he thinks he has a working non-multilib Windows build, but he hasn't passed me a copy yet.

1
bonfire_processor•

Ok. If the build is really broken, you can open an issue. The author of GNU MCU eclipse usually answers. BTW: Have you ever tried the Linux Subsystem for Windows? It allows to run e.g. Ubuntu Usermode applications on Windows. After installation the subsystem can be invoked with the „bash“ command. It is possible with this to use or build a Linux toolchain, without the need to switch to Linux completely. So you can use your familar windows tools and mix it with Linux tools.

1
bonfire_processor•

Maybe in addition to my I can give you the following link:

https://www.sifive.com/blog/all-aboard-part-1-compiler-args

It is a part of a series of blog posts which cover compiling and linking RISC-V code. I think many people using compilers like gcc just "use" "as is" on a platform that works, without needing to understand what happens inside. In many cases you can just enter "gcc -o foo foo.c " or something similar, and it works. Don't worry about ABI, memory models, linker scripts, etc.

With RISC-V this could work exactly the same way, in case somebody provided a toolchain with the right defaults for the platform. But in when this is not the case (because you build a custom core in an FPGA with maybe a custom memory map) it is required to understand the details to give the right command line switches to gcc. It has nothing to do with Linux or Windows, it is just gcc.

​

1