How and what tools and I need to use spike for run on bare metal risc-v?

317 views
Skip to first unread message

JUAN JOSE ROMERO HERNANDEZ

unread,
Aug 3, 2021, 8:19:57 PM8/3/21
to RISC-V SW Dev
I need to make a program that has access in machine mode (M) for use interrupts that reason I need to run it on bare metal (without pk). I have installed the following risc- v tools: riscv-gnu-toolchain, spike.

I tried to follow these steps but got the following error

How can I generate a bare metal binary using riscv64-unknown-elf-gcc and simulate with spike?

Thank you for the time and attention.

Jim Wilson

unread,
Aug 5, 2021, 12:29:35 PM8/5/21
to JUAN JOSE ROMERO HERNANDEZ, RISC-V SW Dev
If you are using a 64-bit target that puts DRAM at 0x80000000, then you need a toolchain that uses the medany code model.  If you aren't using any precompiled libraries, then -mcmodel=medany will work.  But if you need libgcc, libc, etc also compiled using medany code model, then you need to configure a toolchain that uses medany by default.  I do see C library errors, so it looks like you do need a medany toolchain.  You can do this with riscv-gnu-toolchain by using --with-cmodel=medany when configuring the toolchain before building it.

There is an old blog post by Palmer Dabbelt that talks about code models
You might be interested in other parts of this same blog series.  Part 2 talks about the relocation truncated to fit linker error.

Jim

JUAN JOSE ROMERO HERNANDEZ

unread,
Aug 7, 2021, 11:57:08 PM8/7/21
to RISC-V SW Dev, ji...@sifive.com, RISC-V SW Dev
Hi Jim, I was able to understand and solve my problem with this information.

Thanks a lot!
Juan romero
Reply all
Reply to author
Forward
0 new messages