mirror of
https://github.com/lowRISC/ibex.git
synced 2025-06-27 17:00:41 -04:00
Here's a high-level overview of what this commit does: - Compiles Sail into SystemVerilog including patchin compiler bugs - Create a TCL file that tells JasperGold what to prove and assume - Check memory operations modelling the LSU Most of these properties now prove without time-bound on the response from memory due to alternative LSUs - Check memory even with Smepmp errors: Continues on top of https://github.com/riscv/sail-riscv/pull/196 - CSR verification - Checks for instruction types such as B-Type, I-Type, R-Type - Check illegal instructions and WFI instructions - Using psgen language for proof generation - Documentation on how to use the setup - Wrap around proof that proves instructions executed in a row still match the specification. - Liveness proof to guarantee instructions will retire within a upper bound of cycles. All of these proofs make heavy use of the concept of k-induction. All the different properties and steps are necessary to help the tool get the useful properties it needs to prove the next step. The instruction correctness, wrap-around and liveness all give us increased confidence that Ibex is trace-equivalent to Sail. Throughout this process an issue was found in Ibex where the pipeline was not flushing properly on changing PMP registers using clear: #2193 Alternative LSUs: This makes all top level memory properties prove quickly and at a low proof effort (1 or 2-induction). Three 'alternative LSUs' representing three stages of memory instructions: 1. Before the first response is received, in the EX stage 2. After the first response is received, but not the second grant, also in the EX stage 3. Before the last response is received in the WB stage. In each case we ask 'if the response came now, would the result be correct?'. Similar is applied for CSRs/PC though less directly. This is particularly interesting (read: ugly) in the case of a PMP error wbexc_exists makes Wrap properties fast to prove. The bottleneck becomes SpecPastNoWbexcPC, which fails only due to a bug. See the comment in riscv.proof. Co-authored-by: Marno van der Maas <mvdmaas+git@lowrisc.org> Signed-off-by: Louis-Emile Ploix <louis-emile.ploix@lowrisc.org>
113 lines
3.1 KiB
Python
113 lines
3.1 KiB
Python
# Copyright lowRISC contributors.
|
|
# Copyright 2024 University of Oxford, see also CREDITS.md.
|
|
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
|
|
# Original author: Louis-Emile Ploix
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# This script is called from the Makefile.
|
|
# Essentially it is a way to enable and disable instructions from the Sail specification to make proofs easier.
|
|
|
|
import json
|
|
import re
|
|
import sys
|
|
|
|
with open("instrs.json", "r") as f:
|
|
INSTRS = set(json.load(f))
|
|
|
|
class SpecConfig:
|
|
def __init__(self):
|
|
self.instrs = set()
|
|
|
|
def add(self, *instrs):
|
|
for instr in instrs:
|
|
assert instr in INSTRS
|
|
self.instrs.add(instr)
|
|
|
|
def add_all(self):
|
|
self.instrs = INSTRS
|
|
|
|
def add_noncompressed(self):
|
|
self.instrs = {x for x in INSTRS if not x.startswith("C_")}
|
|
|
|
def remove(self, instr):
|
|
assert instr in INSTRS
|
|
self.instrs.discard(instr)
|
|
|
|
def make_sail_unreachables(self):
|
|
return " ".join(f"-sv_unreachable execute_{instr}" for instr in INSTRS.difference(self.instrs))
|
|
|
|
def make_sv_header(self):
|
|
return "\n".join([
|
|
"`ifndef SPEC_INSTRS",
|
|
"`define SPEC_INSTRS",
|
|
"",
|
|
*[f"`define SPEC_{instr.upper()} {int(instr in self.instrs)}" for instr in INSTRS],
|
|
"",
|
|
"`endif"
|
|
])
|
|
|
|
def add_jmps(self):
|
|
self.add("RISCV_JAL", "RISCV_JALR")
|
|
|
|
def add_itype(self):
|
|
self.add("ITYPE")
|
|
self.add("SHIFTIOP")
|
|
|
|
def add_rtype(self):
|
|
self.add("RTYPE")
|
|
|
|
def add_fences(self):
|
|
self.add("FENCE", "FENCEI")
|
|
|
|
def add_loads(self):
|
|
self.add("LOAD")
|
|
|
|
def add_stores(self):
|
|
self.add("STORE")
|
|
|
|
def add_mtypes(self):
|
|
self.add("MUL", "DIV", "REM")
|
|
|
|
def add_illegal(self, extra=True):
|
|
self.add("ILLEGAL", "C_ILLEGAL")
|
|
if extra:
|
|
self.add("CSR")
|
|
self.add("MRET", "WFI")
|
|
|
|
def add_system(self):
|
|
self.add("ECALL", "EBREAK", "MRET", "WFI")
|
|
|
|
def add_csr(self):
|
|
self.add("CSR")
|
|
|
|
def add_utypes(self):
|
|
self.add("UTYPE")
|
|
|
|
def add_btypes(self):
|
|
self.add("BTYPE")
|
|
|
|
conf = SpecConfig()
|
|
conf.add_noncompressed()
|
|
|
|
if len(sys.argv) > 1:
|
|
if sys.argv[1] == "unreachables":
|
|
print(conf.make_sail_unreachables())
|
|
elif sys.argv[1] == "header":
|
|
print(conf.make_sv_header())
|
|
elif sys.argv[1] == "unreachable_loc_hack":
|
|
with open("build/ibexspec.sv", "r") as f:
|
|
c = f.read()
|
|
c = c.replace(
|
|
"sail_reached_unreachable = 1;",
|
|
"begin sail_reached_unreachable = 1; sail_reached_unreachable_loc = `__LINE__; end"
|
|
).replace(
|
|
"sail_reached_unreachable = 0;",
|
|
"begin sail_reached_unreachable = 0; sail_reached_unreachable_loc = -1; end"
|
|
).replace(
|
|
"bit sail_reached_unreachable;",
|
|
"bit sail_reached_unreachable;\n\tlogic [31:0] sail_reached_unreachable_loc;"
|
|
)
|
|
with open("build/ibexspec.sv", "w") as f:
|
|
f.write(c)
|
|
else:
|
|
print("Intended usage is to run make sv")
|