mini-rv32ima icon indicating copy to clipboard operation
mini-rv32ima copied to clipboard

Can't compile the baremetal example

Open Buanderie opened this issue 2 years ago • 5 comments

Hi. Nice work there, by the way... But I can't compile the baremetal test. I'm using the buildroot toolchain. Maybe I should use another one ? I get this: make testbare make -C baremetal make[1]: Entering directory '/opt/sandbox/mini-rv32ima/baremetal' ../buildroot/output/host/bin/riscv32-buildroot-linux-uclibc-gcc -o baremetal.elf baremetal.c baremetal.S -fno-stack-protector -static-libgcc -fdata-sections -ffunction-sections -g -Os -march=rv32ima -mabi=ilp32 -static -T flatfile.lds -nostdlib -Wl,--gc-sections baremetal.c: Assembler messages: baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,s1' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,a5' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,a5' baremetal.c:21: Error: unrecognized opcode csrrw x0,0x137,a5' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,a5' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,s1' baremetal.c:31: Error: unrecognized opcode csrr a1,0xC00' baremetal.c:31: Error: unrecognized opcode csrr a5,0xC00' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,a4' baremetal.c:26: Error: unrecognized opcode csrrw x0,0x136,a5' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,a5' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,s0' baremetal.S: Assembler messages: baremetal.S:28: Error: unrecognized opcode csrw 0x138,t0' Makefile:16: recipe for target 'baremetal.elf' failed make[1]: *** [baremetal.elf] Error 1 make[1]: Leaving directory '/opt/sandbox/mini-rv32ima/baremetal' Makefile:25: recipe for target 'testbare' failed make: *** [testbare] Error 2`

Buanderie avatar Dec 06 '22 10:12 Buanderie

Alright, figured it out. Following this

I replaced CFLAGS+=-g -Os -march=rv32ima -mabi=ilp32 -static with CFLAGS+=-g -Os -march=rv32ima_zicsr -mabi=ilp32 -static

And it works now :)

Buanderie avatar Dec 06 '22 20:12 Buanderie

Hmm... I wrote it to use the system rv64 compiler, so you wouldn't need to build the toolchain to compile the example.

That said, that's probably not the best way to do it, now that it's possible to use the buildroot environment in Windows.

I am curious what other people's feelings are. (reopening issue, in case anyone else wants to comment)

cnlohr avatar Dec 06 '22 23:12 cnlohr

What compiler are each of you using? I ran into this issue when building the riscv-pk tool the other day riscv-pk 287. Apparently it's an issue in the newer versions of gcc. Also be aware that it doesn't seem like binutils has caught up with this change, so the linker doesn't accept the _zicsr isa option.

sellicott avatar Dec 07 '22 03:12 sellicott

riscv32-buildroot-linux-uclibc-gcc.br_real (Buildroot -gfc2ef6e2) 12.2.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Buanderie avatar Dec 07 '22 06:12 Buanderie

I use riscv64-unknown-elf-gcc 9.3.0 I think it makes sense to remove zicsr from the line. If anyone's up for making a PR.

cnlohr avatar Dec 08 '22 18:12 cnlohr