cnlohr / mini-rv32ima

A tiny C header-only risc-v emulator.
MIT License
1.69k stars 137 forks source link

Can't compile the baremetal example #8

Open Buanderie opened 1 year ago

Buanderie commented 1 year ago

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 opcodecsrrw x0,0x138,s1' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,a5' baremetal.c:16: Error: unrecognized opcodecsrrw x0,0x138,a5' baremetal.c:21: Error: unrecognized opcode csrrw x0,0x137,a5' baremetal.c:16: Error: unrecognized opcodecsrrw x0,0x138,a5' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,s1' baremetal.c:31: Error: unrecognized opcodecsrr a1,0xC00' baremetal.c:31: Error: unrecognized opcode csrr a5,0xC00' baremetal.c:16: Error: unrecognized opcodecsrrw x0,0x138,a4' baremetal.c:26: Error: unrecognized opcode csrrw x0,0x136,a5' baremetal.c:16: Error: unrecognized opcodecsrrw x0,0x138,a5' baremetal.c:16: Error: unrecognized opcode csrrw x0,0x138,s0' baremetal.S: Assembler messages: baremetal.S:28: Error: unrecognized opcodecsrw 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 commented 1 year ago

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 :)

cnlohr commented 1 year ago

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)

sellicott commented 1 year ago

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.

Buanderie commented 1 year ago

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.

cnlohr commented 1 year ago

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.