Rv32iCPU 运行时报错
zchliu opened this issue · 3 comments
zchliu commented
我的环境是Ubuntu20.04虚拟机,按照教程说的执行了下面的命令,但是报了两个warning,结果也不对,看上去像是数组越界,问一下具体会是什么原因呢?顺便问一下有没有什么方法能够将写好的C或者C++语言按照文中的Rv32i的指令集转换成.txt格式,我想测试一下自己写的别的程序。期待大神的回答!
$ bsvbuild.sh -bs mkTb TbRv32iCPU.bsv
top module: mkTb
top file : TbRv32iCPU.bsv
bsc -sim -g mkTb -u TbRv32iCPU.bsv
checking package dependencies
compiling ./DFIFOF1.bsv
compiling ./Rv32iCPU.bsv
code generation for mkRv32iCPU starts
Elaborated module file created: mkRv32iCPU.ba
compiling TbRv32iCPU.bsv
code generation for mkTb starts
Elaborated module file created: mkTb.ba
All packages are up to date.
bsc -sim -e mkTb -o sim.out
Bluesim object created: mkTb.{h,o}
Bluesim object created: mkRv32iCPU.{h,o}
Bluesim object created: model_mkTb.{h,o}
Simulation shared library created: sim.out.so
Simulation executable created: sim.out
./sim.out
Warning: file 'benchmark/qsort_instruction.txt' for memory 'instr_ram_memory' has a gap at addresses 175 to 16383.
Warning: BRAM 'top.data_ram_memory' -- Write address on port A is out of bounds: 0x2aaaaaaa
final: cycle= 4917 instructions= 2796 100*cpi= 175 pc/4= 119
DataRAM[00000000] = -9
DataRAM[00000004] = -9
DataRAM[00000008] = -8
DataRAM[0000000c] = -8
DataRAM[00000010] = -7
DataRAM[00000014] = -7
DataRAM[00000018] = -6
DataRAM[0000001c] = -6
DataRAM[00000020] = -5
DataRAM[00000024] = -5
DataRAM[00000028] = -4
DataRAM[0000002c] = -4
DataRAM[00000030] = -3
DataRAM[00000034] = -3
DataRAM[00000038] = -2
DataRAM[0000003c] = -2
DataRAM[00000040] = -1
DataRAM[00000044] = -1
DataRAM[00000048] = 0
DataRAM[0000004c] = 0
DataRAM[00000050] = 1
DataRAM[00000054] = 1
DataRAM[00000058] = 2
DataRAM[0000005c] = 2
DataRAM[00000060] = 3
DataRAM[00000064] = 3
DataRAM[00000068] = 4
DataRAM[0000006c] = 4
DataRAM[00000070] = 5
DataRAM[00000074] = 5
DataRAM[00000078] = 6
DataRAM[0000007c] = 6
DataRAM[00000080] = 7
DataRAM[00000084] = 7
DataRAM[00000088] = 8
DataRAM[0000008c] = 8
DataRAM[00000090] = 9
DataRAM[00000094] = 9
DataRAM[00000098] = -1431655766
DataRAM[0000009c] = -1431655766
zchliu commented
运行的是benchmark/qsort_instruction.txt
WangXuan95 commented
结果是对的,原因:
- 这两个运行时 Warning 不重要,只是因为加载 RAM 时 .txt 文件内的数字的数量少于 Memory 的大小。
- 数组溢出并不重要,因为该快速排序只排序 DataRAM 的前 38个数,而打印却打印了 DataRAM 的前 40 个数,最后两个数 -1431655766 (0xAAAAAAAA) 是仿真时 BRAM 的默认值。只要前 38 个数是从小到大排序的,就说明快速排序正常运行。另外你要明白,这个打印不是 CPU 运行 printf() 所产生的,CPU只负责运行快速排序,然后就停住不动(死循环)了,该打印是 BSV 直接读取 DataRAM 并打印的(详见代码)。
如果你想把 C 语言编译成 RISC-V 指令流,可以前往 RISC-V 官方库下载 RISC-V gcc 编译器: https://github.com/riscv-collab/riscv-gnu-toolchain
如果你想把 RISC-V 汇编语言汇编成 RISC-V 指令流,可以参考我的一个 RISC-V MCU(SoC)设计,里面有一个 GUI 工具可以做到这一点: https://github.com/WangXuan95/USTC-RVSoC
zchliu commented
谢谢前辈,我理解了