Nuclei-Software / nuclei-sdk

Nuclei RISC-V Software Development Kit
https://doc.nucleisys.com/nuclei_sdk
Apache License 2.0
117 stars 50 forks source link

intexc_gd32vf103.S uses unsupported extension zicsr on architecture rv32imac #51

Closed starnight closed 1 year ago

starnight commented 1 year ago

When I build the example application with upstream RISC-V toolchain (12.2.0) for Longan Nano equipped with GD32VF103C8T6, it will show the error:

Assembling :  ../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S: Assembler messages:
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:162: Error: unrecognized opcode `csrrwi x0,0x7EE,11', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:162: Error: unrecognized opcode `csrrwi x0,0x7EF,12', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:162: Error: unrecognized opcode `csrrwi x0,0x7EB,13', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:169: Error: unrecognized opcode `csrr a0,mcause', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:179: Error: unrecognized opcode `csrw 0x7C4,x5', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:179: Error: unrecognized opcode `csrw 0x341,x5', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:179: Error: unrecognized opcode `csrw 0x342,x5', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:206: Error: unrecognized opcode `csrrwi x0,0x7EE,11', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:206: Error: unrecognized opcode `csrrwi x0,0x7EF,12', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:206: Error: unrecognized opcode `csrrwi x0,0x7EB,13', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:213: Error: unrecognized opcode `csrrw ra,0x7ED,ra', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:216: Error: unrecognized opcode `csrc 0x300,0x00000008', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:219: Error: unrecognized opcode `csrw 0x7C4,x5', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:219: Error: unrecognized opcode `csrw 0x341,x5', extension `zicsr' required
../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S:219: Error: unrecognized opcode `csrw 0x342,x5', extension `zicsr' required
make: *** [../../../Build/Makefile.rules:100: ../../../SoC/gd32vf103/Common/Source/GCC/intexc_gd32vf103.S.o] Error 1
starnight commented 1 year ago

I use riscv64-elf-gcc as the compiler, which is built from the upstream source.

Here lists the supported architectures:

$ riscv64-elf-gcc --print-multi-lib
.;
rv32i/ilp32;@march=rv32i@mabi=ilp32
rv32im/ilp32;@march=rv32im@mabi=ilp32
rv32iac/ilp32;@march=rv32iac@mabi=ilp32
rv32imac/ilp32;@march=rv32imac@mabi=ilp32
rv32imafc/ilp32f;@march=rv32imafc@mabi=ilp32f
rv64imac/lp64;@march=rv64imac@mabi=lp64
rv64imafdc/lp64d;@march=rv64imafdc@mabi=lp64d
fanghuaqi commented 1 year ago

You need to set default isa spec to 2.2, see here https://github.com/riscv-collab/riscv-gnu-toolchain#set-default-isa-spec-version

or add -misa-spec=2.2 when compile application, you can add it here https://github.com/Nuclei-Software/nuclei-sdk/blob/56f4572b80325980f0faa16e76c608243a1fd36f/Build/Makefile.conf#L203

COMMON_FLAGS += -g -misa-spec=2.2

This will only for gcc12 and later version, will not be compatiable with previous gcc10

starnight commented 1 year ago

Thanks for @fanghuaqi's reply! It solves the issue.