aw / fiveforths

32-bit RISC-V Forth for microcontrollers
https://fiveforths.a1w.ca
MIT License
66 stars 3 forks source link

Error build with fresh tools: extension `zicsr' required #19

Closed vazhnov closed 1 year ago

vazhnov commented 1 year ago

Hello! Thank you for this great project with opensource license! I don't know Forth, but I'm interesting in pure Assembly code examples for RISC-V boards.

I tried to build the code with the latest Devuan testing, and it failed:

 % make build BOARD=longan-nano
/usr/bin/riscv64-unknown-elf-as -g -march=rv32imac -I src/boards/longan-nano -I src/mcus/gd32vf103 -I src -o fiveforths.o fiveforths.s
src/03-interrupts.s: Assembler messages:
src/03-interrupts.s:15: Error: unrecognized opcode `csrc mstatus,0x08', extension `zicsr' required
src/03-interrupts.s:18: Error: unrecognized opcode `csrs mie,zero', extension `zicsr' required
src/03-interrupts.s:22: Error: unrecognized opcode `csrw mtvec,t0', extension `zicsr' required
make: *** [Makefile:27: fiveforths.o] Error 1

Then I modified Makefile: ARCH ?= rv32imac_zicsr, and the code compiled successfully:

 % make build BOARD=longan-nano
/usr/bin/riscv64-unknown-elf-as -g -march=rv32imac_zicsr -I src/boards/longan-nano -I src/mcus/gd32vf103 -I src -o fiveforths.o fiveforths.s
/usr/bin/riscv64-unknown-elf-ld -m elf32lriscv -T src/boards/longan-nano/linker.ld -o fiveforths.elf fiveforths.o
/usr/bin/riscv64-unknown-elf-objcopy -O binary fiveforths.elf fiveforths.bin
/usr/bin/riscv64-unknown-elf-objcopy -O ihex fiveforths.elf fiveforths.hex
/usr/bin/riscv64-unknown-elf-objdump -D -S fiveforths.elf > fiveforths.dump

Software versions:

 % dpkg -l|grep riscv
ii  binutils-riscv64-unknown-elf          2.39-8+4                                     amd64        GNU assembler, linker and binary utilities for Risc-V processors
ii  gcc-riscv64-unknown-elf               12.1.0-7+11                                  amd64        GCC cross compiler for Risc-V processors

Just FYI.

aw commented 1 year ago

Hi, thanks for the report.

I'll need to run some tests and figure out why this is happening. I'm not sure of the purpose of zicsr so let me research and I'll update the issue later.

aw commented 1 year ago

Then I modified Makefile: ARCH ?= rv32imac_zicsr, and the code compiled successfully:

You can also just type make ARCH=rv32imac_zicsr. That's why I defined the ARCH variable with ?=.

It seems this is caused by a breaking change in gcc/binutils, where zicsr must now be explicitly provided.

I'll fix this and publish a new release after testing it.

Thanks @vazhnov for the detailed bug report and debugging.