天天看點

wujian100_open:基于iverilog的仿真過程記錄

本次仿真在Ubuntu1804環境下進行,仿真工具使用iverilog。仿真過程用到tcsh,該shell需要手動安裝。

準備階段

安裝iverilog、tcsh

sudo apt-get install tcsh iverilog verilator gtkwave           

相關下載下傳

開始仿真前,需要将倉庫clone到本地,并下載下傳官方提供的RISCV交叉編譯工具

wujian100倉庫clone

git clone https://github.com/T-head-Semi/wujian100_open.git           

交叉編譯工具下載下傳

環境配置

1.建立工程目錄

ws@laptop:~$ mkdir ~/wujian_sim
ws@laptop:~$ cd ~/wujian_sim/
ws@laptop:~/wujian_sim$            

2.添加wujian100倉庫到該目錄下

ws@laptop:~/wujian_sim$ cp -r ../wujian/wujian100_open/ ./           

3.配置交叉編譯工具

目前環境下用到的工具為工具包中的riscv64-elf-x86_64-20190731.tar.gz,需要在工程目錄下建立名為riscv_toolchain的目錄,并将該檔案解壓縮至該目錄。

ws@laptop:~/wujian_sim$ mkdir riscv_toolchain
ws@laptop:~/wujian_sim$ cd riscv_toolchain/
ws@laptop:~/wujian_sim/riscv_toolchain$ tar xf ../../wujian/RISC-V\ Toolchain-V1.2.2/riscv64-elf-x86_64-20190731.tar.gz           

ok,完成上述操作之後,就可以開始仿真了

仿真Hello Friend

1.根據倉庫readme描述,進入tools目錄

ws@laptop:~/wujian_sim/riscv_toolchain$ cd ../wujian100_open/tools/
ws@laptop:~/wujian_sim/wujian100_open/tools$           

2.切換tcsh

ws@laptop:~/wujian_sim/wujian100_open/tools$ tcsh 
laptop:~/wujian_sim/wujian100_open/tools>           

3.source環境變量

laptop:~/wujian_sim/wujian100_open/tools> source setup.csh           

4.進入work目錄,仿真走起

laptop:~/wujian_sim/wujian100_open/tools> cd ../workdir/
laptop:~/wujian_sim/wujian100_open/workdir> ../tools/run_case -sim_tool iverilog ../case/timer/timer_test.c           

5.仿真輸出

laptop:~/wujian_sim/wujian100_open/workdir> ../tools/run_case -sim_tool iverilog ../case/timer/timer_test.c
Useless use of not in void context at ../tools/run_case line 204.

Step1 (Remove all things in current 'workdir') is finished!
../case/timer//timer_test.c

Step2 (Process the command line arguments) is finished!
mkdir: cannot create directory ‘../regress/regress_result’: File exists
rm -rf *.o *.pat *.elf *.obj *.hex
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o crt0.o crt0.s
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o __dtostr.o __dtostr.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o __isnan.o __isnan.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o printf.o printf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o vprintf.o vprintf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o sprintf.o sprintf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o snprintf.o snprintf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o fprintf.o fprintf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o vfprintf.o vfprintf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o getchar.o getchar.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o timer_test.o timer_test.c
In file included from timer_test.c:12:
vtimer.h: In function 'get_vtimer':
vtimer.h:14:14: warning: assignment to 'int *' from 'unsigned int' makes pointer from integer without a cast [-Wint-conversion]
   TIMER_ADDR = 0xE0013000;
              ^
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o putc.o putc.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o puts.o puts.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o fputc.o fputc.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o getc.o getc.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o __isinf.o __isinf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o putchar.o putchar.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o vsprintf.o vsprintf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o __v_printf.o __v_printf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o vsnprintf.o vsnprintf.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o __lltostr.o __lltostr.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -c -march=rv32emcxcki -mabi=ilp32e -De902 -Wa,--defsym=e902=1 -O3 -funroll-all-loops -fgcse-sm -finline-limit=500 -fno-schedule-insns -ffunction-sections -fdata-sections -o __ltostr.o __ltostr.c
../../riscv_toolchain/bin/riscv64-unknown-elf-gcc -Tlinker.lcf -nostartfiles -march=rv32emc -mabi=ilp32e -lc -lgcc  crt0.o getchar.o vprintf.o sprintf.o snprintf.o fprintf.o __lltostr.o puts.o __isnan.o timer_test.o getc.o printf.o vsprintf.o __v_printf.o vsnprintf.o __dtostr.o vfprintf.o putc.o fputc.o __isinf.o putchar.o __ltostr.o -o timer_test.elf -lm 
../../riscv_toolchain/bin/riscv64-unknown-elf-objcopy -O srec timer_test.elf timer_test.hex 
rm -f *.pat
#../tools/Srec2vmem.py timer_test.hex test.pat
../tools/Srec2vmem.py -i timer_test.hex -o test.pat
../../riscv_toolchain/bin/riscv64-unknown-elf-objdump -S -Mnumeric timer_test.elf > timer_test.obj
make clean; make all CPU=e902m ENDIAN_MODE=little-endian FILE=timer_test HGPR=

Step3 (Make) is finished!
Use of uninitialized value $had_v in concatenation (.) or string at ../tools/run_case line 241.
warning: Found both default and `timescale based delays. Use
         -Wtimescale to find the module(s) with no `timescale.
######time:                   0, Dump start######
VCD info: dumpfile test.vcd opened for output.
    ******START TO LOAD PROGRAM******


Hello Friend!

timer test successfully
***************************************

*              Test Pass              *

***************************************


Step4 (Run simulation) is finished           

總結

1.Ubuntu預設使用bash shell,仿真環境配置檔案setup.csh需要用tcsh,so 切換的tcsh至關重要;

2.仿真過程需要使用交叉編譯工具,且目錄必須與倉庫所在目錄一緻,注意交叉編譯工具檔案夾的命名。

原文作者:sopho

點選檢視原文