查看: 902|回复: 0
收起左侧

riscv-isa-sim的使用

[复制链接]

  离线 

  • TA的每日心情
    奋斗
    2021-1-15 13:53
  • 签到天数: 26 天

    [LV.4]

    发表于 2020-8-18 23:20:43 | 显示全部楼层 |阅读模式

    有人预言,RISC-V或将是继Intel和Arm之后的第三大主流处理器体系。欢迎访问全球首家只专注于RISC-V单片机行业应用的中文网站

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    本帖最后由 新ちゃん 于 2020-8-20 22:35 编辑

    3.3 riscv-isa-sim的使用

    主要资料来源:
    https://github.com/riscv/riscv-isa-sim/tree/d48f107dba6a96fb827cb47fdf290261feadeb35


    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.


    添加新指令:Rocket之添加指令


    交互的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-tools/tree/2faac3398af956cea9f1cbdc64b0575f807fc6a8#linuxman



    本篇完,感谢关注:RISC-V单片机中文网





    上一篇:rocket-chip项目的具体内容
    下一篇:Rocket之添加指令
    RISCV作者优文
    全球首家只专注于RISC-V单片机行业应用的中文网站
    回复

    使用道具 举报

    高级模式
    B Color Image Link Quote Code Smilies

    本版积分规则

    关闭

    RISC-V单片机中文网上一条 /2 下一条



    版权及免责声明|RISC-V单片机中文网 |网站地图

    GMT+8, 2024-4-25 23:04 , Processed in 0.502137 second(s), 46 queries .

    快速回复 返回顶部 返回列表