rdcycle rd 指令在纯linux OS中报“非法指令”

Viewed 92
**rdcycle s10**
 vle32.v v0, (a3)
 vrgather.vi v1, v0, 0
 vrgather.vi v2, v0, 1
 vrgather.vi v3, v0, 2
 vrgather.vi v4, v0, 3
 **rdcycle s11**
 sub t0, s11, s10
 sd t0, (a6)

当把rdcycle指令去掉可正常运行;
编译器:Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V3.0.1
编译命令:

Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V3.0.1/bin/riscv64-unknown-linux-gnu-as -march=rv64imafdgcv_zicntr_zihpm_xtheadc_ vrgather.S -o vrgather.o
Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V3.0.1/bin/riscv64-unknown-linux-gnu-gcc vrgather.o  test.c -o correct_test

k230 canmv v1.1板子上的结果:
image.png

这是什么原因呀?怎么解决呢, 感谢!

1 Answers

image.png
用户态默认不允许访问cycle,详见下面寄存器。如果你需要访问,请在uboot或opensbi里面增加enable操作,比如csr_write(CSR_SCOUNTEREN,0x7);