Error when using float or double on GCC-RISC-V port

Hello, I hope everyone is doing well. I was using FreeRTOS-kernel with Cpp and getting errors when using float or double. I have defined my own linker script and startup code which are github(dot)com/illustris/FreeRTOS-RISCV/blob/master/Demo/riscv-spike/arch/boot.S
I can share more info about the riscv64-unknown-elf toolchain also if needed. Can someone help me ?

Are you using the hardware floating point registers? If yes, the likely reason is that we do not store and restore those on context switch. Can you try using software floating point support to confirm that it is the issue?

1 Like

May I ask why the default behavior is not to save/restore FPU registers? I understand that FreeRTOS’s goal is minimal memory/processing footprint, and this can save a few bytes and a few instructions. However, an optimizing compiler will use the FPU registers for multibyte copy/move even if your thread is not doing any floating point math. This causes a very unintuitive problem which is difficult to debug, especially for a developer new to FreeRTOS.

I suggest that the default behavior should be to copy the FPU registers on context switch, with a configuration option to turn this off for systems which are overly resource constrained. In my experience, a few bytes and a few instructions are completely negligible on the VAST majority embedded systems - I have yet to see an embedded system that could not spare a few bytes and a few instructions.

I would like to point out that this exact situation has a precedent: VxWorks used to not save FPU context by default. But this was proving to cause a lot of headache with their customers, so they changed the default to enable FPU.

1 Like

The floating point in the RISC-V ISA is an extension and the current FreeRTOS RISC-V support is the core ISA with provisions for extensions. One of the ports (pulpino-vega) supports the temporary register extension (T0-T6).

Some partner forks have added FPU support and we would welcome a PR that adds FPU extension support for your device.

1 Like