ibex/dv/formal/check/spec_instance.sv
Louis-Emile c0636dcbde [dv,formal] Add flow for formal equivalence checking with Sail
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>
2025-04-30 13:30:45 +00:00

70 lines
2 KiB
Systemverilog

// 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
/*
The following instantiates the specification via the spec api. It also chooses the mode for the spec to run in (see main.sail
for more on that).
It just wires up the pre_* state to the spec_post* state.
*/
t_MainMode main_mode;
always_comb begin
if (wbexc_handling_irq) main_mode = MAIN_IRQ;
else if (`ID.instr_fetch_err_i) main_mode = MAIN_IFERR;
else main_mode = MAIN_IDEX;
end
spec_api #(
.NREGS(32)
) spec_api_i (
.int_err_o(spec_int_err),
.main_mode(main_mode),
.insn_bits(ex_compressed_instr),
.rx_a_en_o(spec_rx_a_en),
.rx_a_addr_o(spec_rx_a_addr),
.rx_a_i(spec_rx_a),
.rx_b_en_o(spec_rx_b_en),
.rx_b_addr_o(spec_rx_b_addr),
.rx_b_i(spec_rx_b),
.wx_o(spec_post_wX),
.wx_addr_o(spec_post_wX_addr),
.wx_en_o(spec_post_wX_en),
.mvendor_id_i(CSR_MVENDORID_VALUE),
.march_id_i(CSR_MARCHID_VALUE),
.mimp_id_i(CSR_MIMPID_VALUE),
.mhart_id_i(hart_id_i),
.mconfigptr_i(CSR_MCONFIGPTR_VALUE),
.misa_i(`CSR.MISA_VALUE),
.mip_i(pre_mip),
.nextpc_i(pre_nextpc),
`define X(n) .n``_i(pre_``n), .n``_o(spec_post_``n),
`X_EACH_CSR
`undef X
.mem_read_o(spec_mem_read),
.mem_read_snd_gran_o(spec_mem_read_snd),
.mem_read_fst_addr_o(spec_mem_read_fst_addr),
.mem_read_snd_addr_o(spec_mem_read_snd_addr),
.mem_read_fst_rdata_i(spec_mem_read_fst_rdata),
.mem_read_snd_rdata_i(spec_mem_read_snd_rdata),
.mem_write_o(spec_mem_write),
.mem_write_snd_gran_o(spec_mem_write_snd),
.mem_write_fst_addr_o(spec_mem_write_fst_addr),
.mem_write_snd_addr_o(spec_mem_write_snd_addr),
.mem_write_fst_wdata_o(spec_mem_write_fst_wdata),
.mem_write_snd_wdata_o(spec_mem_write_snd_wdata),
.mem_write_fst_be_o(spec_mem_write_fst_be),
.mem_write_snd_be_o(spec_mem_write_snd_be)
);