查看: 6198|回复: 0

RISC-V指令的仿真器riscv-isa-sim的使用方法

[复制链接]
  • TA的每日心情

    2018-11-20 13:41
  • 签到天数: 3 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2019-3-8 14:34:26 | 显示全部楼层 |阅读模式
    分享到:
    主要资料来源:
    https://github.com/riscv/riscv-i ... 47fdf290261feadeb35

    riscv-isa-sim是一个RISC-V指令的仿真器,riscv-isa-sim的正常运行需要依赖riscv-pk和riscv-fesvr工具。前面有对这些工具的说明。riscv-isa-sim编译后主要用到的工具是spike。其实spike不单单可以仿真RISC-V指令的,还能仿真Linux系统。我主要工作的方面是硬件,因此对于软件的使用没有过多的深入,大家可以在CSDN中查找更多软件方面的使用方法,最后我会贴一些我找到的资料。

    仿真C程序过程:
    Compiling and Running a Simple C Program
    Install spike (see Build Steps), riscv-gnu-toolchain, and riscv-pk.
    Write a short C program and name it hello.c. Then, compile it into a RISC-V ELF binary named hello:
    1. $ riscv64-unknown-elf-gcc -o hello hello.c
    复制代码
    Now you can simulate the program atop the proxy kernel:
    1. $ spike pk hello
    复制代码

    仿真新指令过程(官方说法):
    Simulating a New Instruction
    Adding an instruction to the simulator requires two steps:
    Describe the instruction’s functional behavior in the file riscv/insns/<new_instruction_name>.h. Examine other instructions in that directory as a starting point.
    Add the opcode and opcode mask to riscv/opcodes.h. Alternatively, add it to the riscv-opcodes package, and it will do so for you:
    $ cd ../riscv-opcodes $ vi opcodes // add a line for the new instruction $ make install
    Rebuild the simulator.

    添加新指令:
    https://blog.csdn.net/qq_33096883/article/details/83476656

    交互的debug模式:
    Interactive Debug Mode
    To invoke interactive debug mode, launch spike with -d:

    交互的debug模式:
    Interactive Debug Mode
    To invoke interactive debug mode, launch spike with -d:
    1. $ spike -d pk hello

    2. : reg 0 a0                                        //读core0 a0的值
    3. : mem 0 2020                                        //读core0 地址2020的值
    4. : until pc 0 2020                                   //(stop when pc=2020)                                       
    5. : until mem 2020 50a990                             //(stop when mem[2020]=50a990)
    6. : while mem 2020 50a990                                //当地址2020的值等于50a990
    7. : r                                                //继续运行
    8. : q                                                //退出
    复制代码
    在spike的仿真过程中,大家可以对/riscv-tools/risc-isa-sim/riscv目录下的process.cc文件做一定的修改,第313行,添加以下的语句:
    1. FILE *fp;
    2. fp = fopen("./spike.log","a");       
    3. fprintf(fp, "core %3d: 0x%016" PRIx64 " (0x%08" PRIx64 ") %s\n",
    4.         id, state.pc, bits, disassembler->disassemble(insn).c_str());
    5. fclose(fp);
    复制代码

    这样就可以将spike和pk仿真过程中的信息一一记录下来,方便debug。不过每次重新仿真需要将旧的spike.log删除,不然会一直在后面增加打印,无法准确定位本次仿真的信息。

    利用spike进行Linux系统的仿真比较复杂,而且不是我的主要研究方向,所以我没有花费过多的时间,没有完成一次完整的仿真,如果大家有兴趣可以通过以下的链接进行学习。

    仿真Linux系统:
    https://blog.csdn.net/l919898756/article/details/80987440
    https://blog.csdn.net/l919898756/article/details/80987456
    https://github.com/riscv/riscv-t ... 5f807fc6a8#linuxman
    ---------------------
    作者:a_weiming
    来源:CSDN

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 02:47 , Processed in 0.103420 second(s), 14 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.