summaryrefslogtreecommitdiff
path: root/assembly/passworddoor/passworddoor.S
diff options
context:
space:
mode:
Diffstat (limited to 'assembly/passworddoor/passworddoor.S')
-rw-r--r--assembly/passworddoor/passworddoor.S42
1 files changed, 32 insertions, 10 deletions
diff --git a/assembly/passworddoor/passworddoor.S b/assembly/passworddoor/passworddoor.S
index 687becf..a808609 100644
--- a/assembly/passworddoor/passworddoor.S
+++ b/assembly/passworddoor/passworddoor.S
@@ -1,9 +1,18 @@
+# Thanks to the Hazard3 reference manual for the macro this is based on
+.macro h3.bextmi rd rs1 shamt nbits
+ .if (\nbits < 1) || (\nbits > 8)
+ .err
+ .endif
+ .if (\shamt < 0) || (\shamt > 31)
+ .err
+ .endif
+ .insn i 0x0b, 0x4, \rd, \rs1, (\shamt & 0x1f) | (((\nbits - 1) & 0x7 ) << 6)
+.endm
+
li gp,0xffff0000
csrw 0x801,gp # Map MMIO
li t0,0xf
sb t0,0(gp) # All four pins -> output
-li t0,0x20 # MBE
-csrs mstatush,t0 # Big-endian here we go!
changepassword:
li a7,4
@@ -215,10 +224,15 @@ randbytenz:
# Returns a random non-zero byte in a0
pause
csrrsi a0,seed,1
-bexti t0,a0,31
-beqz t0,randbytenz # OPST=BIST or WAIT, try again
-bexti t0,a0,30
-bnez t0,rngfail # OPST=DEAD, unrecoverable error
+
+h3.bextmi t0,a0,30,2 # Extract just the OPST field
+beqz t0,randbytenz # BIST, wait and try again
+li t1,1
+beq t0,t1,randbytenz # WAIT, wait and try again
+li t1,3
+beq t0,t1,rngfail # DEAD, fatal error
+# Otherwise ES16, output is OK
+
andi a0,a0,0xff # Trim down to one byte
beqz a0,randbytenz # If it's zero then try again
ret
@@ -240,10 +254,18 @@ mv ra,s0
la t0,inbuf1
la t3,message
-ld t1,0(t0) # Copy input
-sd t1,0(t3) # To hash function input
-ld t1,8(t0)
-sd t1,8(t3)
+lw t1,0(t0) # Copy message to hash function input
+rev8 t1,t1 # Making sure to write it as big-endian
+sw t1,0(t3)
+lw t1,4(t0)
+rev8 t1,t1
+sw t1,4(t3)
+lw t1,8(t0)
+rev8 t1,t1
+sw t1,8(t3)
+lw t1,12(t0)
+rev8 t1,t1
+sw t1,12(t3)
sd x0,0(t0) # Then wipe it
sd x0,8(t0)