ucb-bar / spike-devices

Collection of device models for spike
7 stars 5 forks source link

Command line for testing output of the plugin device #1

Open xzj478 opened 1 year ago

xzj478 commented 1 year ago

I used the test drive which posted in this repo: "https://github.com/vexingcodes/spike-plugin" to test the output

With this command line: "spike -m1 --extlib=/tmp/riscvtoolchain/lib/libspikedevices.so --device=sifive_uart,0x10000000,argument /tmp/spike-devices/plugin_test"

but it reports: "terminate called after throwing an instance of 'std::runtime_error' what(): Plugin "sifive_uart,0x10000000,argument" not found in loaded extlibs. Aborted (core dumped)"

Could you please show me the right way of testing the output? Thanks.

jerryz123 commented 1 year ago

It should just be --device=sifive_uart.

xzj478 commented 1 year ago

I tried "spike -m1 --extlib=/tmp/riscvtoolchain/lib/libspikedevices.so --device=sifive_uart /tmp/spike-devices/plugin_test", but nothing happened, and if I press Ctrl+C right after, it will be in spike debugging mode (I guess).

It should just be --device=sifive_uart.

xzj478 commented 1 year ago

Okay, after I tried "spike --extlib=/home/zijianxie/riscvtoolchain/lib/libspikedevices.so --device=sifive_uart --isa=RV64GC --dtb /home/zijianxie/spike-devices/test.dtb /home/zijianxie/spike-devices/plugin_test"

it printed "Found uart at 10000000"; which means spike could recognize the mmio device?

Then how could I pass a string argument to the plugin device to test the store/load function? Since the original command of "--device=<P,B,A>; P -- Name of MMIO plugin, B -- Base memory addr. of the device, A -- String arguments to pass to the plugin" is no longer available in spike.cc.

xzj478 commented 1 year ago

All I want to ask is how to access the device with memory load/store? Should I write an assembly file like they did in repo: https://github.com/vexingcodes/spike-plugin?

Or I write a simple function C code to do that(after compilation)?

jerryz123 commented 1 year ago

You should write a test program, whether in C or assembly, and execute it.

xzj478 commented 1 year ago

Any simple example (in C) for that would be appreciated.

xzj478 commented 1 year ago

Ping :-) I am really struggling to put together a working code, could you by any chance provide a c or asm example?

pranjalchanda08 commented 1 month ago

HI @jerryz123, can you please provide a sample test (C) example and a related LD script being used to compile it.

pranjalchanda08 commented 1 month ago

I somehow figured this thing out hence documenting for beginners like me:

  1. We first need to compile the test.dts file to generate a test.dtb file -> dtc -I dts -O dtb test.dts > test.dtb
  2. Make a classic hello_world.c program and compile it using riscv64-unknown-elf-gcc
  3. Test the program using: spike --extlib libspikedevices.so --device sifive_uart --dtb=test.dtb pk hello
  4. We shall see the output as Found uart at 10000000 Hello World.
  5. In above the Hello World which you compiled via printf in step 2 is actually being shown via the syscall done by the uart device.
  6. As a proof you can remove the --device sifive_uart and rerun. You would not be able to see Hello World.
  7. --dtb command would override the pk default compiled dtb and use the sifive_uart as display output driver @xzj478 you can try this if I am not very very very late 😅