mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Add tests for scause, and improve tests for sepc. Also make improvements to privileged test generator run.sh file
This commit is contained in:
parent
d5f86fadac
commit
fed42ffe19
@ -344,8 +344,7 @@ module testbench();
|
|||||||
string tests64p[] = '{
|
string tests64p[] = '{
|
||||||
"rv64p/WALLY-MCAUSE", "2000",
|
"rv64p/WALLY-MCAUSE", "2000",
|
||||||
"rv64p/WALLY-SCAUSE", "2000",
|
"rv64p/WALLY-SCAUSE", "2000",
|
||||||
"rv64p/WALLY-UCAUSE", "2000",
|
"rv64p/WALLY-MEPC", "5000",
|
||||||
"rv64p/WALLY-MEPC", "4000",
|
|
||||||
"rv64p/WALLY-SEPC", "4000",
|
"rv64p/WALLY-SEPC", "4000",
|
||||||
"rv64p/WALLY-TVAL", "3000",
|
"rv64p/WALLY-TVAL", "3000",
|
||||||
"rv64p/WALLY-MARCHID", "4000",
|
"rv64p/WALLY-MARCHID", "4000",
|
||||||
@ -357,8 +356,7 @@ module testbench();
|
|||||||
string tests32p[] = '{
|
string tests32p[] = '{
|
||||||
"rv32p/WALLY-MCAUSE", "2000",
|
"rv32p/WALLY-MCAUSE", "2000",
|
||||||
"rv32p/WALLY-SCAUSE", "2000",
|
"rv32p/WALLY-SCAUSE", "2000",
|
||||||
"rv32p/WALLY-UCAUSE", "2000",
|
"rv32p/WALLY-MEPC", "5000",
|
||||||
"rv32p/WALLY-MEPC", "4000",
|
|
||||||
"rv32p/WALLY-SEPC", "4000",
|
"rv32p/WALLY-SEPC", "4000",
|
||||||
"rv32p/WALLY-TVAL", "3000",
|
"rv32p/WALLY-TVAL", "3000",
|
||||||
"rv32p/WALLY-MARCHID", "4000",
|
"rv32p/WALLY-MARCHID", "4000",
|
||||||
|
@ -20,3 +20,17 @@ To compile tests without running them in OVPsim, provide -c as the second argume
|
|||||||
```bash
|
```bash
|
||||||
sh run.sh NAME -c
|
sh run.sh NAME -c
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The test generator also has a really nice feature that grabs the location of begin_signature after compiling the tests. For example, running `sh run.sh EPC` will output something like this at the end:
|
||||||
|
|
||||||
|
```verilog
|
||||||
|
rv64p = '{
|
||||||
|
'rv64p/WALLY-MEPC', '5000',
|
||||||
|
'rv64p/WALLY-SEPC', '4000'
|
||||||
|
};
|
||||||
|
|
||||||
|
rv32p = '{
|
||||||
|
'rv32p/WALLY-MEPC', '5000',
|
||||||
|
'rv32p/WALLY-SEPC', '4000'
|
||||||
|
};
|
||||||
|
```
|
@ -1,3 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
#
|
#
|
||||||
# Written 1 Mar 2021 by Domenico Ottolia (dottolia@hmc.edu)
|
# Written 1 Mar 2021 by Domenico Ottolia (dottolia@hmc.edu)
|
||||||
#
|
#
|
||||||
@ -25,6 +27,9 @@ then
|
|||||||
then
|
then
|
||||||
cd ~/riscv-wally/imperas-riscv-tests
|
cd ~/riscv-wally/imperas-riscv-tests
|
||||||
make privileged
|
make privileged
|
||||||
|
|
||||||
|
exe2memfile.pl work/*/*.elf
|
||||||
|
extractFunctionRadix.sh work/rv64p/*.elf.objdump
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -49,3 +54,21 @@ fi
|
|||||||
|
|
||||||
cd ~/riscv-wally/wally-pipelined
|
cd ~/riscv-wally/wally-pipelined
|
||||||
printf "\n\n\n#####\nDone!\n#####\n\n"
|
printf "\n\n\n#####\nDone!\n#####\n\n"
|
||||||
|
|
||||||
|
cd ~/riscv-wally/imperas-riscv-tests/work
|
||||||
|
for isa in "rv64p" "rv32p"; do
|
||||||
|
printf "$isa = '{"
|
||||||
|
COMMA=""
|
||||||
|
for file in "$isa"/*.elf.objdump; do
|
||||||
|
if [[ "$file" == *"$1"* ]]; then
|
||||||
|
RES=$(grep "^\s*0*8000.000 <begin_signature>" $file)
|
||||||
|
RES=$(echo "$RES" | sed -r 's/^0*80+([0-9]+).+?$/\1/g')
|
||||||
|
file=$(echo "$file" | sed -r 's/^(.+?)\.elf\.objdump/\1/g')
|
||||||
|
printf "$COMMA\n '$file', '${RES}'"
|
||||||
|
COMMA=","
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
printf "\n};\n\n"
|
||||||
|
done
|
||||||
|
|
||||||
|
cd ~/riscv-wally/wally-pipelined
|
@ -30,7 +30,7 @@ def randRegs():
|
|||||||
else:
|
else:
|
||||||
return str(reg1), str(reg2), str(reg3)
|
return str(reg1), str(reg2), str(reg3)
|
||||||
|
|
||||||
def writeVectors(storecmd):
|
def writeVectors(storecmd, returningInstruction):
|
||||||
global testnum
|
global testnum
|
||||||
|
|
||||||
# Page 6 of unpriviledged spec
|
# Page 6 of unpriviledged spec
|
||||||
@ -136,6 +136,7 @@ def writeVectors(storecmd):
|
|||||||
""", False, 2)
|
""", False, 2)
|
||||||
|
|
||||||
# Breakpoint
|
# Breakpoint
|
||||||
|
if returningInstruction != "ebreak":
|
||||||
writeTest(storecmd, f, r, f"""
|
writeTest(storecmd, f, r, f"""
|
||||||
ebreak
|
ebreak
|
||||||
""", False, 3)
|
""", False, 3)
|
||||||
@ -156,19 +157,20 @@ def writeVectors(storecmd):
|
|||||||
# writeTest(storecmd, f, r, f"""
|
# writeTest(storecmd, f, r, f"""
|
||||||
# ecall
|
# ecall
|
||||||
# """, False, 8, "u")
|
# """, False, 8, "u")
|
||||||
if testMode == "u":
|
if returningInstruction != "ecall":
|
||||||
|
if fromMode == "u":
|
||||||
writeTest(storecmd, f, r, f"""
|
writeTest(storecmd, f, r, f"""
|
||||||
ecall
|
ecall
|
||||||
""", False, 8, "u")
|
""", False, 8, "u")
|
||||||
|
|
||||||
# Environment call from s-mode
|
# Environment call from s-mode
|
||||||
if testMode == "s":
|
if fromMode == "s":
|
||||||
writeTest(storecmd, f, r, f"""
|
writeTest(storecmd, f, r, f"""
|
||||||
ecall
|
ecall
|
||||||
""", False, 9, "s")
|
""", False, 9, "s")
|
||||||
|
|
||||||
# Environment call from m-mode
|
# Environment call from m-mode
|
||||||
if testMode == "m":
|
if fromMode == "m":
|
||||||
writeTest(storecmd, f, r, f"""
|
writeTest(storecmd, f, r, f"""
|
||||||
ecall
|
ecall
|
||||||
""", False, 11, "m")
|
""", False, 11, "m")
|
||||||
@ -209,7 +211,7 @@ def writeTest(storecmd, f, r, test, interrupt, code, mode = "m", resetHander = "
|
|||||||
trapEnd = f"""j _jend{testnum}"""
|
trapEnd = f"""j _jend{testnum}"""
|
||||||
|
|
||||||
lines = f"""
|
lines = f"""
|
||||||
li x25, 0x7BAD
|
li x25, 0xDEADBEA7
|
||||||
{test}
|
{test}
|
||||||
|
|
||||||
_jend{testnum}:
|
_jend{testnum}:
|
||||||
@ -232,7 +234,7 @@ def writeTest(storecmd, f, r, test, interrupt, code, mode = "m", resetHander = "
|
|||||||
# change these to suite your tests
|
# change these to suite your tests
|
||||||
author = "dottolia@hmc.edu"
|
author = "dottolia@hmc.edu"
|
||||||
xlens = [32, 64]
|
xlens = [32, 64]
|
||||||
numrand = 8;
|
numrand = 4;
|
||||||
|
|
||||||
# setup
|
# setup
|
||||||
seed(0xC365DDEB9173AB42) # make tests reproducible
|
seed(0xC365DDEB9173AB42) # make tests reproducible
|
||||||
@ -249,12 +251,8 @@ for xlen in xlens:
|
|||||||
storecmd = "sd"
|
storecmd = "sd"
|
||||||
wordsize = 8
|
wordsize = 8
|
||||||
|
|
||||||
corners = [
|
for testMode in ["m", "s"]:
|
||||||
0x624B3E976C52DD14 % 2**xlen, 2**(xlen-1)-2, 2**(xlen-1)-1,
|
|
||||||
2**(xlen-1), 2**(xlen-1)+1, 0xC365DDEB9173AB42 % 2**xlen, 2**(xlen)-2, 2**(xlen)-1
|
|
||||||
]
|
|
||||||
|
|
||||||
for testMode in ["m", "s", "u"]:
|
|
||||||
imperaspath = "../../../imperas-riscv-tests/riscv-test-suite/rv" + str(xlen) + "p/"
|
imperaspath = "../../../imperas-riscv-tests/riscv-test-suite/rv" + str(xlen) + "p/"
|
||||||
basename = "WALLY-" + testMode.upper() + "CAUSE"
|
basename = "WALLY-" + testMode.upper() + "CAUSE"
|
||||||
fname = imperaspath + "src/" + basename + ".S"
|
fname = imperaspath + "src/" + basename + ".S"
|
||||||
@ -276,39 +274,100 @@ for xlen in xlens:
|
|||||||
for line in h:
|
for line in h:
|
||||||
f.write(line)
|
f.write(line)
|
||||||
|
|
||||||
|
for returningInstruction in ["ebreak", "ecall"]:
|
||||||
|
|
||||||
|
# All registers used:
|
||||||
|
# x30: set to 1 if we should return to & stay in machine mode after trap, 0 otherwise
|
||||||
|
# ...
|
||||||
|
# x26: expected epc value
|
||||||
|
# x25: value to write to memory
|
||||||
|
# ...
|
||||||
|
# x19: mtvec old value
|
||||||
|
# x18: medeleg old value
|
||||||
|
# x17: sedeleg old value
|
||||||
|
|
||||||
|
|
||||||
lines = f"""
|
lines = f"""
|
||||||
csrr x31, mtvec
|
add x7, x6, x0
|
||||||
li x30, 0
|
csrr x19, mtvec
|
||||||
|
|
||||||
la x1, _j_m_trap
|
|
||||||
csrw mtvec, x1
|
|
||||||
la x1, _j_s_trap
|
|
||||||
csrw stvec, x1
|
|
||||||
j _j_t_begin
|
|
||||||
|
|
||||||
_j_m_trap:
|
|
||||||
csrrs x25, mcause, x0
|
|
||||||
csrrs x1, mepc, x0
|
|
||||||
addi x1, x1, 4
|
|
||||||
csrrw x0, mepc, x1
|
|
||||||
bnez x30, _j_all_end
|
|
||||||
mret
|
|
||||||
|
|
||||||
_j_s_trap:
|
|
||||||
csrrs x25, scause, x0
|
|
||||||
csrrs x1, sepc, x0
|
|
||||||
addi x1, x1, 4
|
|
||||||
csrrw x0, sepc, x1
|
|
||||||
sret
|
|
||||||
|
|
||||||
_j_t_begin:
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if testMode == "s" or testMode == "u":
|
if testMode == "u":
|
||||||
|
lines += f"""
|
||||||
|
csrr x17, sedeleg
|
||||||
|
li x9, {"0b1100000000" if testMode == "u" else "0b0000000000"}
|
||||||
|
csrs sedeleg, x9
|
||||||
|
"""
|
||||||
|
|
||||||
|
lines += f"""
|
||||||
|
li x30, 0
|
||||||
|
|
||||||
|
la x1, _j_m_trap_{returningInstruction}
|
||||||
|
csrw mtvec, x1
|
||||||
|
la x1, _j_s_trap_{returningInstruction}
|
||||||
|
csrw stvec, x1
|
||||||
|
la x1, _j_u_trap_{returningInstruction}
|
||||||
|
csrw utvec, x1
|
||||||
|
j _j_t_begin_{returningInstruction}
|
||||||
|
|
||||||
|
_j_m_trap_{returningInstruction}:
|
||||||
|
csrrs x1, mepc, x0
|
||||||
|
{"csrr x25, mcause" if testMode == "m" else "li x25, 0xBAD00003"}
|
||||||
|
|
||||||
|
addi x1, x1, 4
|
||||||
|
csrrw x0, mepc, x1
|
||||||
|
bnez x30, _j_all_end_{returningInstruction}
|
||||||
|
mret
|
||||||
|
|
||||||
|
_j_s_trap_{returningInstruction}:
|
||||||
|
csrrs x1, sepc, x0
|
||||||
|
{"csrr x25, scause" if testMode == "s" else "li x25, 0xBAD00001"}
|
||||||
|
|
||||||
|
addi x1, x1, 4
|
||||||
|
csrrw x0, sepc, x1
|
||||||
|
bnez x30, _j_goto_machine_mode_{returningInstruction}
|
||||||
|
sret
|
||||||
|
|
||||||
|
_j_u_trap_{returningInstruction}:
|
||||||
|
csrrs x1, uepc, x0
|
||||||
|
{"csrr x25, ucause" if testMode == "u" else "li x25, 0xBAD00000"}
|
||||||
|
|
||||||
|
addi x1, x1, 4
|
||||||
|
csrrw x0, uepc, x1
|
||||||
|
bnez x30, _j_goto_supervisor_mode_{returningInstruction}
|
||||||
|
uret
|
||||||
|
|
||||||
|
_j_goto_supervisor_mode_{returningInstruction}:
|
||||||
|
j _j_goto_machine_mode_{returningInstruction}
|
||||||
|
|
||||||
|
_j_goto_machine_mode_{returningInstruction}:
|
||||||
|
li x30, 1
|
||||||
|
{returningInstruction}
|
||||||
|
|
||||||
|
_j_t_begin_{returningInstruction}:
|
||||||
|
"""
|
||||||
|
|
||||||
|
fromModeOptions = ["m", "s", "u"] if testMode == "m" else (["s", "u"] if testMode == "s" else ["u"])
|
||||||
|
|
||||||
|
medelegMask = "0b1111111111110111" if returningInstruction == "ebreak" else "0b1111000011111111"
|
||||||
|
|
||||||
|
lines += f"""
|
||||||
|
csrr x18, medeleg
|
||||||
|
li x9, {medelegMask if testMode == "s" or testMode == "u" else "0"}
|
||||||
|
csrw medeleg, x9
|
||||||
|
"""
|
||||||
|
|
||||||
|
f.write(lines)
|
||||||
|
|
||||||
|
for fromMode in fromModeOptions:
|
||||||
|
lines = ""
|
||||||
|
|
||||||
|
if fromMode == "s" or fromMode == "u":
|
||||||
lines += f"""
|
lines += f"""
|
||||||
li x1, 0b110000000000
|
li x1, 0b110000000000
|
||||||
csrrc x28, mstatus, x1
|
csrrc x28, mstatus, x1
|
||||||
li x1, 0b{"01" if testMode == "s" else "00"}00000000000
|
li x1, 0b0100000000000
|
||||||
csrrs x28, mstatus, x1
|
csrrs x28, mstatus, x1
|
||||||
|
|
||||||
auipc x1, 0
|
auipc x1, 0
|
||||||
@ -316,25 +375,42 @@ for xlen in xlens:
|
|||||||
csrw mepc, x1
|
csrw mepc, x1
|
||||||
mret
|
mret
|
||||||
|
|
||||||
# We're now in {testMode} mode...
|
# We're now in supervisor mode...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
f.write(lines)
|
if fromMode == "u":
|
||||||
|
lines += f"""
|
||||||
|
|
||||||
|
li x1, 0b110000000000
|
||||||
|
csrrc x28, sstatus, x1
|
||||||
|
|
||||||
|
auipc x1, 0
|
||||||
|
addi x1, x1, 16 # x1 is now right after the sret instruction
|
||||||
|
csrw sepc, x1
|
||||||
|
sret
|
||||||
|
|
||||||
|
# We're now in user mode...
|
||||||
|
"""
|
||||||
|
|
||||||
# print directed and random test vectors
|
# print directed and random test vectors
|
||||||
|
|
||||||
|
f.write(lines)
|
||||||
for i in range(0,numrand):
|
for i in range(0,numrand):
|
||||||
writeVectors(storecmd)
|
writeVectors(storecmd, returningInstruction)
|
||||||
|
|
||||||
|
|
||||||
f.write(f"""
|
f.write(f"""
|
||||||
li x30, 1
|
li x30, 1
|
||||||
ecall
|
{returningInstruction}
|
||||||
_j_all_end:
|
_j_all_end_{returningInstruction}:
|
||||||
|
|
||||||
csrw mtvec, x31
|
csrw mtvec, x19
|
||||||
|
csrw medeleg, x18
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
# if we're in supervisor mode, this leaves the ebreak instruction untested (we need a way to)
|
||||||
|
# get back to machine mode.
|
||||||
|
|
||||||
# print footer
|
# print footer
|
||||||
h = open("../testgen_footer.S", "r")
|
h = open("../testgen_footer.S", "r")
|
||||||
for line in h:
|
for line in h:
|
||||||
@ -349,4 +425,3 @@ for xlen in xlens:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,12 +200,14 @@ for xlen in xlens:
|
|||||||
_j_t_begin:
|
_j_t_begin:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fromModeOptions = ["s", "u"] if testMode == "m" else ["u"]
|
fromModeOptions = ["m", "s", "u"] if testMode == "m" else (["s", "u"] if testMode == "s" else ["u"])
|
||||||
|
|
||||||
f.write(lines)
|
f.write(lines)
|
||||||
|
|
||||||
for fromMode in fromModeOptions:
|
for fromMode in fromModeOptions:
|
||||||
lines = ""
|
lines = ""
|
||||||
|
|
||||||
|
if fromMode == "s" or fromMode == "u":
|
||||||
lines += f"""
|
lines += f"""
|
||||||
li x1, 0b110000000000
|
li x1, 0b110000000000
|
||||||
csrrc x28, mstatus, x1
|
csrrc x28, mstatus, x1
|
||||||
|
Loading…
Reference in New Issue
Block a user