seldridge / rocket-rocc-examples

Tests for example Rocket Custom Coprocessors
Other
69 stars 27 forks source link

Illegal instruction error for accumulator example #7

Closed arkhan91 closed 6 years ago

arkhan91 commented 6 years ago

cd build make mkdir -p bareMetal make -C bareMetal -f /home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/../bareMetal/Makefile abs_top_srcdir=/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/.. XLEN=64 PREFIX=examples-bareMetal src_dir=/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/../bareMetal RISCVTOOLS=/home/abdullah/Workspace/Chisel-practice/rocket-chip/riscv-tools make[1]: Entering directory '/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/bareMetal' make[1]: Nothing to be done for 'default'. make[1]: Leaving directory '/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/bareMetal' mkdir -p pk make -C pk -f /home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/../pk/Makefile abs_top_srcdir=/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/.. XLEN=64 PREFIX=examples-pk src_dir=/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/../pk RISCVTOOLS=/home/abdullah/Workspace/Chisel-practice/rocket-chip/riscv-tools make[1]: Entering directory '/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/pk' make[1]: Nothing to be done for 'default'. make[1]: Leaving directory '/home/abdullah/Workspace/Chisel-practice/rocket-chip/rocket-rocc-examples/build/pk'

spike pk examples-pk-accumulator [INFO] Write R[1] = 0xdead z 0000000000000000 ra 00000000000101e8 sp 000000007f7e9af0 gp 000000000001c910 tp 0000000000000000 t0 0000000000010560 t1 0000000000040000 t2 0000000000000000 s0 000000007f7e9b40 s1 0000000000000000 a0 000000000000001b a1 000000000000dead a2 0000000000000001 a3 0000000000000000 a4 0000000000000000 a5 0000000000000001 a6 000000000000000f a7 0000000000000040 s2 0000000000000000 s3 0000000000000000 s4 0000000000000000 s5 0000000000000000 s6 0000000000000000 s7 0000000000000000 s8 0000000000000000 s9 0000000000000000 sA 0000000000000000 sB 0000000000000000 t3 000000000000000a t4 0000000000000000 t5 0000000000000000 t6 0000000000000000 pc 00000000000101f4 va 0000000000c5f50b insn 00c5f50b sr 8000000200046020 An illegal instruction was executed!

Hi, thanks for providing this git. I was trying to run the example I got this error. is it fault due to
ROCC_INSTRUCTION(XCUSTOM_ACC, y, data, rocc_rd, k_DO_WRITE);

seldridge commented 6 years ago

This is the expected behavior under Spike (it's trying to execute a Custom0 instruction and it has no idea what that is). There is a way to implement custom instructions for Spike, but I'm not aware of examples that align with the example RoCCs that the Rocket Chip repository provides.

This is only expected to work with a rocket chip using the RoccExampleConfig configuration. Bare metal tests should work automatically while Proxy Kernel tests require patching the Proxy Kernel to enable XS bits.

arkhan91 commented 6 years ago

sorry for late response I just stuck at pk. probably I am not following correctly.
here it is, what I am doing. 1) I have installed the riscv-tool chain.
./build.sh 2) make emmulator make CONFIG=RoccExampleConfig

2) then cloned this github : changed the minit.c manually because the patch was not working create the dir inside rocket-rocc-examples mkdir build && cd build ../configure --prefix=$RISCV/riscv64-unknown-elf --host=riscv64-unknown-elf make 4) emulator-freechips.rocketchip.system-RoccExampleConfig pk pk/examples-pk-accumulator i get this error This emulator compiled with JTAG Remote Bitbang client. To enable, use +jtag_rbb_enable=1. Listening on port 32873 emulator-freechips.rocketchip.system-RoccExampleConfig: ../fesvr/elfloader.cc:27: std::map<std::__cxx11::basic_string, long unsigned int> load_elf(const char, memif_t, reg_t*): Assertion `buf != MAP_FAILED' failed.

if i do this for baremetal test , emulator-freechips.rocketchip.system-RoccExampleConfig -c -V bareMetal/examples-bareMetal-p-accumulator Completed after 129348 cycles

Intention:: My intention is to calculate the number of cycles taken by a hardware accelerator than a simple program on riscv.

-- Kind regards

seldridge commented 6 years ago

Thanks for bringing it to my attention that the patch was out of date with the proxy kernel. I've updated that now on the master branch.

As long as the modifications that you put in place are correct, then things should work. The only possible problem that I can see with what you're doing is that you aren't running make install after modifying the proxy kernel. That's fine, but when you then run the emulator, you need to point at the explicit pk binary as opposed to relying on your $RISCV environment variable to find it, e.g., run:

./emulator-freechips.rocketchip.system-RoccExampleConfig ../riscv-tools/riscv-pk/build/pk pk/examples-pk-accumulator

I did incorrectly patch things initially using write_csr as opposed to set_csr (the former will blow away the old value). Making this mistake will result in a hang at the proxy kernel level.

arkhan91 commented 6 years ago

Thanks for updates, I could not see any make install option.I was actually configuring using this command: ../configure --prefix=$RISCV/riscv64-unknown-elf/ --host=riscv64-unknown-elf --with-riscvtools=$Rocket/rocket-chip/riscv-tools

make

since only --prefix generates the warning :

../configure --prefix=$RISCV/riscv64-unknown-elf --host=riscv64-unknown-elf checking for riscv64-unknown-elf-gcc... riscv64-unknown-elf-gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... yes checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether riscv64-unknown-elf-gcc accepts -g... yes checking for riscv64-unknown-elf-gcc option to accept ISO C89... none needed configure: error: "You must specify a path to a riscv-tools repo (--with-riscvtools)"

With simple make, it doesn't also work.

seldridge commented 6 years ago

The make install is related to building the Proxy Kernel. That will install your pk binary in $RISCV/riscv64-unknown-elf/pk. When you run the emulator this is where it's looking to resolve your pk. If you don't run make install to put it there, you'll need to give a full path to the pk binary. Otherwise, you'll be using your old version of pk and not the patched version.

Yes, you do need to specify a --with-riscvtools path as this repository has a dependency on the riscv-test-env repo and I did not want to include that as an explicit submodule here.

arkhan91 commented 6 years ago

Hi, I have tried many times to configure but I could not get make install option. Could you please share your log if it is possible and guide me which files I can manually install to their respective folders.

However, I can run a bare-metal test on emulator and can also able to generate the test.vcd. Thanks for this.!

seldridge commented 6 years ago

I attempted to convey this in the README, but let me know if that's not clear:

cd $RISCV_PK_DIR
git apply $THIS_REPO_DIR/patches/riscv-pk.patch

mkdir build
cd build
../configure --prefix=$RISCV/riscv64-unknown-elf --host=riscv64-unknown-elf
make
make install

This is doing three things: 1) This patches the proxy kernel to enable "extensions" by setting the XS bits 2) This configures the proxy kernel following the instructions provided by the proxy kernel's README 3) This builds and installs the proxy kernel into $RISCV/riscv64-unknown-elf/bin

When you then run the emulator and do not specify a location for pk, it's using this specifically installed version.

If you don't want to do this, you can specify the pk explicitly with a full path, e.g.:

./emulator-freechips.rocketchip.system-RoccExampleConfig $RISCV_PK_DIR/bin/pk pk/examples-pk-accumulator
arkhan91 commented 6 years ago

sorry, I don't know why I'm not getting the make install option. however, I will go without it... Thanks for your cooperation and especially for this git..!

noureddine-as commented 6 years ago

Hello @seldridge I would like, please, to know why doesn't Spike recognize the Custom instructions, since there is a dummy_rocc extension defined there and which is registered? I get the same illegal instruction. I saw that people used normally the command spike --extension=dummy_rocc executable.elf to run the thing.

Thanks a lot! Best regards. Noureddine

seldridge commented 6 years ago

I assume that you're running this through the Proxy Kernel?

I have never tested the dummy_rocc extension with Spike, but that appears to be equivalent to the Rocket accumulator RoCC and I think that this should work with the Proxy Kernel test in this repo.

I expect that this is because the Proxy Kernel does not enable extensions (sets the XS bits of MSTATUS to a non-zero value) by default. A modification to the Proxy Kernel like in this patch will set the XS bits for you.

seldridge commented 6 years ago

The act of establishing the extension should be handling the setting of XS automatically. However, it doesn't appear to be working correctly. This appears to be a more involved issue than I had imagined. This would be better targeted at the Spike repository specifically after doing some digging...

noureddine-as commented 6 years ago

Thanks for the ideas @seldridge . Actually I tested both, with patched pk and with a baremetal version ( here) with MSTATUS_XS bits set.

I posted that here https://github.com/riscv/riscv-isa-sim/issues/214

Best regards. Noureddine.

chenxuhao commented 6 years ago

I have the same problem when running the Proxy Kernel test with the emulator:

$ ./emulator-freechips.rocketchip.system-RoccExampleConfig pk ../rocket-rocc-examples/build/pk/examples-pk-accumulator This emulator compiled with JTAG Remote Bitbang client. To enable, use +jtag_rbb_enable=1. Listening on port 44165 [INFO] Write R[1] = 0xdead z 0000000000000000 ra 00000000000101e8 sp 000000000fee9ad0 gp 000000000001d6a8 tp 0000000000000000 t0 0000000000010560 t1 0000000000040000 t2 0000000000000000 s0 000000000fee9b20 s1 0000000000000000 a0 000000000000001b a1 000000000000dead a2 0000000000000001 a3 0000000000000000 a4 0000000000000000 a5 0000000000000001 a6 000000000000001f a7 0000000000000040 s2 0000000000000000 s3 0000000000000000 s4 0000000000000000 s5 0000000000000000 s6 0000000000000000 s7 0000000000000000 s8 0000000000000000 s9 0000000000000000 sA 0000000000000000 sB 0000000000000000 t3 000000000000000a t4 0000000000000000 t5 0000000000000000 t6 0000000000000000 pc 00000000000101f4 va 0000000000c5f50b insn 00c5f50b sr 8000000200046020 An illegal instruction was executed! FAILED via dtm (code = -1, seed 1531194881) after 3611144 cycles

However, the baremetal test works fine:

./emulator-freechips.rocketchip.system-RoccExampleConfig ../rocket-rocc-examples/build/bareMetal/examples-bareMetal-p-accumulator This emulator compiled with JTAG Remote Bitbang client. To enable, use +jtag_rbb_enable=1. Listening on port 45235

I did apply the patch and rebuild pk (configure, make and make install).

Using spike, I got this:

$ spike ../rocket-rocc-examples/build/bareMetal/examples-bareMetal-p-accumulator FAILED (tohost = 668)

$ spike pk ../rocket-rocc-examples/build/pk/examples-pk-accumulator [INFO] Write R[1] = 0xdead z 0000000000000000 ra 00000000000101e8 sp 000000007f7e9ad0 gp 000000000001d6a8 tp 0000000000000000 t0 0000000000010560 t1 0000000000040000 t2 0000000000000000 s0 000000007f7e9b20 s1 0000000000000000 a0 000000000000001b a1 000000000000dead a2 0000000000000001 a3 0000000000000000 a4 0000000000000000 a5 0000000000000001 a6 000000000000001f a7 0000000000000040 s2 0000000000000000 s3 0000000000000000 s4 0000000000000000 s5 0000000000000000 s6 0000000000000000 s7 0000000000000000 s8 0000000000000000 s9 0000000000000000 sA 0000000000000000 sB 0000000000000000 t3 000000000000000a t4 0000000000000000 t5 0000000000000000 t6 0000000000000000 pc 00000000000101f4 va 0000000000c5f50b insn 00c5f50b sr 8000000200046020 An illegal instruction was executed!

Any ideas?

Best regards, Xuhao