Skip to content

Commit

Permalink
Add a special script for debugging and make changes Hanna recommended.
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkinsw committed Jan 15, 2021
1 parent f6dbc1e commit dbb9a60
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ learning, I want the source code commentary to be as educational as possible.

Special thanks to [Georg Sauthoff](https://gms.tf/riscv-vector.html) whose writing really helped me begin this exercise!

Special thanks also to [Hanna Kruppe](https://github.com/hanna-kruppe) who took the time to read through the source code and counsel me on the RISC-V ISA vector extension.

## Running

As of this writing, the Vector ISA is not standardized so you will need an
Expand All @@ -36,6 +38,10 @@ Execute the `build-caesar.sh` script.

Execute the `run-caesar.sh` script.

## Debugging

Execute the `debug-caesar.sh` script.

## Comments/Issues

Please submit comments and bug reports using Github Issues. Remember, this
Expand Down
15 changes: 10 additions & 5 deletions caesar.S
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,19 @@ main:
# 4. Set t0 to min(a1, VLEN/SEW).
vsetvli t0, a1, e8, m1

# load t0 bytes (bytes are SEW bits in this case) of plaintext into v0
# At this point t0 and vl are equal. vl is the control register that
# tells the vector processor how many elements are in each vector
# register.

# load vl (aka t0) bytes (bytes are SEW bits in this case) of plaintext
# into v0
vlbu.v v0, (a4)
# load t0 bytes of key into 1th vector. This is safe because there are
# 4 bytes of key and t0 is never more than 4.
# load vl (aka t0) bytes of key into 1th vector. This is safe because
# there are 4 bytes of key and t0 is never more than 4.
vlbu.v v1, (a5)
# encrypt t0 bytes
# encrypt vl (aka t0) bytes
vadd.vv v0, v0, v1
# store t0 bytes of encrypted text into memory
# store vl (aka t0) bytes of encrypted text into memory
vsb.v v0, (a3)

# plaintext -= slurped_amt
Expand Down
9 changes: 9 additions & 0 deletions debug-caesar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

source directories.sh

# Debug the Caesar Cipher application using Spike and PK
$SPIKE_INSTALL_DIR/bin/spike -d --isa=RV64gcV $PK_INSTALL_DIR/riscv64-unknown-elf/bin/pk caesar.out

# Debug Spike as it emulates PK running the Caesar Cipher application
#gdb --args $SPIKE_INSTALL_DIR/bin/spike -d --isa=RV64gcV $PK_INSTALL_DIR/riscv64-unknown-elf/bin/pk caesar.out
6 changes: 0 additions & 6 deletions run-caesar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ source directories.sh

# Emulate the Caesar Cipher application using Spike and PK
$SPIKE_INSTALL_DIR/bin/spike --isa=RV64gcV $PK_INSTALL_DIR/riscv64-unknown-elf/bin/pk caesar.out

# Debug the Caesar Cipher application using Spike and PK
#$SPIKE_INSTALL_DIR/bin/spike -d --isa=RV64gcV $PK_INSTALL_DIR/riscv64-unknown-elf/bin/pk caesar.out

# Debug Spike as it emulates PK running the Caesar Cipher application
#gdb --args $SPIKE_INSTALL_DIR/bin/spike -d --isa=RV64gcV $PK_INSTALL_DIR/riscv64-unknown-elf/bin/pk caesar.out

0 comments on commit dbb9a60

Please sign in to comment.