Using Spike with Eclipse

597 views
Skip to first unread message

dmi3

unread,
Mar 4, 2018, 4:10:20 AM3/4/18
to RISC-V SW Dev
Hi, everyone!


I use Spike ISA Simulator with Eclipse. I did not found information about this anywhere, so I want to tell how I use it. Might be it will useful for somebody.

To use Spike with Eclipse it's need to connect Spike with OpenOCD and GDB.


0. Preparation. From the manual https://github.com/riscv/riscv-isa-sim#debugging-with-gdb it is clear that it's need to build project with -nostartfiles, so it's need to obviously select entry point by adding ENTRY(main) to ld-script (you can use spike.lds from https://github.com/riscv/riscv-isa-sim#debugging-with-gdb).

1. Create new RISC-V project in Eclipse and set path to the toolchain.

2. File -> Properties -> C/C++ Build -> Settings -> GNU RISCV Cross C++ Linker -> General -> Script files (-T) :
Set path to your ld-script.

3. File -> Properties -> C/C++ Build -> Settings -> GNU RISCV Cross C++ Linker -> General :
Turn on checkbox "-nostartfiles";
Turn off "Remove unused section (-Xlinker --cg-sections)".

4. File -> Properties -> C/C++ Build -> Settings -> GNU RISCV Cross C++ Linker -> Librares -> Library Search Path :
Set path to .../lib/rv64imafdc/lp64d (for example /home/riscv/opt/7.1.1-1-20170702-0625/riscv64-unknown-elf/lib/rv64imafdc/lp64d).

5. Build the project.

6. Select OpenOCD config file for Spike (spike.cfg from https://github.com/riscv/riscv-isa-sim#debugging-with-gdb). Run -> Debug Configuration -> Debugger -> OpenOCD Setup -> Config options:
-f /path/to/spike.cfg

7. Run -> Debug Configurations -> Run -> Debug Configuration -> GDB OpenOCD Debugging -> Startup -> Runtime Options :
Turn on checkbox "Debug in RAM".

8. Initialization the stack pointer. Run -> Debug Configurations -> Run -> Debug Configuration -> GDB OpenOCD Debugging -> Startup -> Run/Restart Commands :
set $sp = 0x10002000

9. Start the Spike:
$ spike --rbb-port=9824 -m0x10000000:0x20000 file.elf (follow the manual https://github.com/riscv/riscv-isa-sim#debugging-with-gdb). It's useful to create bash script with this.



And it works! It is possible to go by C-code, stop at breakpoints and watch registerts and disassembly.


Conclusion
To use Spike with Eclipse it's important to: 
  • Build with -nostartfiles;
  • Set the sp with GDB command "set $sp = 0x10002000";
  • Select the entry point ENTRY(main).


It was tested on:
  • spike-isa-sim (commit: 3a4e89322a8c8dac94185812a238f13789ab392f)
  • GNU MCU Eclipse (from Liviu Ionescu): version v4.1.1-201707111115 and version 4.3.1-201801092051
  • OpenOCD: 0.10.0-3-20170826-1813-dev
  • Toolchain: 7.1.1-1-20170702-0625
  • FreedomStudio (from SiFive)


TODO: It will be great to add to Eclipse buttom for start and restart Spike.

Reply all
Reply to author
Forward
0 new messages