Commit graph

548 commits

Author SHA1 Message Date
Greg Chadwick
1851e86113 [rtl] Fix ebreak debug cause
We should only indicate an ebreak debug cause if an ebreak leads to a
debug entry (otherwise when single stepping over an ebreak that traps to
an exception we incorrectly enter debug mode with an ebreak cause).
2022-10-26 12:13:19 +01:00
Pirmin Vogel
28935490c2 [rtl] Protect core_busy_o with a multi-bit encoding
This commit protects the core_busy_o signal using a multi-bit encoding
to reduce the chances of an adversary for glitching this signal to low,
thereby putting the core to sleep and e.g. not handling an alert.

Without this commit, the glitch would only be detected once both the
main core and the shadow core wake up again and the comparison of the
core_busy_o signals continues.

This resolves lowRISC/Ibex#1827.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2022-10-25 12:52:01 +02:00
Greg Chadwick
a0fe5ea3b7 [dv] Fix RVFI stage valid logic
Previously if a dummy instruction entered the pipeline whilst it
wouldn't make RVFI stage 0 valid, it would make RVFI stage 1 valid.

Now stage 1 can only become valid if stage 0 was valid.
2022-10-22 20:30:49 +01:00
Andreas Kurth
ce536ae476 [rtl] Assert that dummy instructions only write R0
Signed-off-by: Andreas Kurth <adk@lowrisc.org>
2022-10-19 10:50:01 +01:00
Greg Chadwick
27907d1d4a [rtl] Immediately stop execution when fetch disabled
Previously `fetch_enable_i` only controlled the request going into the
instruction fetch stage.  Due to buffering in the prefetch queue and
icache when this request is dropped it's possible for multiple
instructions to still be available for the ID/EX stage to consume. So
when `fetch_enable_i` was set to off you would get a 'soft stop'. Some
finite number of instructions may still execute and Ibex would come to
an eventual halt.

Now `fetch_enable_i` also gates the instruction moving between the fetch
stage and the ID/EX stage. This gives a 'hard stop' where once fetch is
disabled Ibex comes to an immediate halt.
2022-10-16 17:17:15 +01:00
Harry Callahan
75a93dbed0 Fixup signal used when checking for ebreak cause 2022-10-14 18:44:02 +01:00
Canberk Topal
f2c1d6dc9d [rtl] Change how we record debug causes
This commit changes when we cath the debug causes. Since debug_cause_o
only gets latched when `csr_save_cause_o` is high, it would work if
we change the cause with a mux that is connected to the input signals.

Resolves #1772

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-10-14 18:44:02 +01:00
Greg Chadwick
298c8789da [rtl/dv] Bring back data integrity check on write responses
Previously Ibex signalled a major alert on an integrity error (where
incoming read data doesn't match its integrity bits) for both read and
write responses. This was removed as the data part of a response to a
write is ignored.

This brings it back in a more measured way. This provides a little extra
fault injection hardening as an attacker glitching the memory bus will
generate an alert on both read and write responses.
2022-10-14 18:22:58 +01:00
Greg Chadwick
48733e23ec [rtl] Ignore MIE bit in U mode 2022-10-13 17:30:05 +01:00
Greg Chadwick
48789dd095 [rtl] Don't take interrupts when single stepping
Fixes #1814
2022-10-13 17:30:05 +01:00
Marno van der Maas
7ab2571bea [if,pmp] Check second bit instead of third for instruction alignment
Signed-off-by: Marno van der Maas <mvdmaas+git@lowrisc.org>
2022-10-06 10:23:01 +01:00
Harry Callahan
836bd67531 Update SCONTEXT address, add MSCONTEXT csr to match riscv_debug 1.0
Observing the spec change:
RISC-V Debug Support Version 1.0.0-STABLE
1.2.1.4 New Features from 0.13 to 1.0
> 8. Move scontext, renaming original to mscontext, and create hcontext. #535

MSCONTEXT is a backwards-compatible alias to SCONTEXT
In Ibex, SCONTEXT is a read-only zero register. Hence MSCONTEXT has the same behaviour.
2022-10-05 16:59:12 +01:00
Greg Chadwick
7b1be3354d [rtl] Don't cache instructions in debug mode
RISC-V debug modules may utilise dynamically changing code. Don't cache
any instructions in debug mode to correctly support this.

Fixes #1472
2022-09-27 10:12:09 +01:00
Greg Chadwick
163ed7ec9b [rtl] Switch FF RF to use unpacked arrays
Previously it had two packed dimensions. In general we prefer the use of
unpacked arrays for this kind of usage. In particular this had an impact
on trace viewing in GTKWave, the two dimensions were flattened into a
single large bus which made determining individual register values
tricky.
2022-09-27 09:59:09 +01:00
Greg Chadwick
70186c57ae [rtl] Add ic_scr_key_valid field to CPUCTRL (renamed CPUCTRLSTS)
The ic_scr_key_valid field indicates whether the ICache scrambling key
is valid.

CPUCTRL is also renamed CPUCTRLSTS as it contains both control and
status bits.
2022-09-22 16:17:31 +01:00
Greg Chadwick
1c5e6b10f5 [rtl] Remove/reword comments referring to specific specifications
Referring to specific parts of a specific version of the specification
can be brittle as all of these references need to be updated when we
shift specification versions. It's also redundant it should be generally
understood Ibex implements the RISC-V specifications and many lines
could have comments that point to the part of the specification they are
implementing. Rather than having a few of these for no particular reason
easier to just remove them all.
2022-09-07 17:31:41 +01:00
Greg Chadwick
423264ce5f [rtl] Clear mprv on mret to non M-mode
This is specification change between the v1.11 and v1.12 privileged
architectures. Previously mprv wasn't altered on mret. Now if returning
to a privilege level other than M mode mprv must be cleared.
2022-09-07 17:31:41 +01:00
Greg Chadwick
1d0344eb89 [rtl, dv] Add new CSRs for latest priviledged spec
This adds the following CSRs to support the v1.12 priviledged spec.

 - MSTATUSH
 - MCONFIGPTR
 - MENVCFG
 - MENVCFGH

MCONFIGPTR is read only and has its value provided by a ibex_pkg
parameter CSR_MCONFIGPTR_VALUE which is set to 0. Implementors can alter
this value if needed.

All the other CSRs ignore writes and read as 0.
2022-09-07 17:31:41 +01:00
Greg Chadwick
cfef9ef7bb [rtl] Integrity errors only relevant to loads
Previously ECC checks would occur on read data seen for both loads and
stores. The data response has no meaning for a write so should be
ignored.
2022-08-30 10:04:38 +01:00
Michael Schaffner
37745c5c72 [lint] Make case statements unique case
Signed-off-by: Michael Schaffner <msf@google.com>
2022-08-24 15:33:38 -07:00
Greg Chadwick
a646737d4d [rtl] Cannot add M mode executable PMP regions when MML = 1
A rule that allows M mode execution (either M mode only or shared M/U
mode) cannot be added when MML is set, unless RLB is also set.

Fixes #1740
2022-08-18 15:45:27 +01:00
Greg Chadwick
db1eced0ee [rtl] Make PMP CSRs illegal in non PMP configurations
The previous behaviour was also acceptable but this matches spike.
2022-08-12 15:13:46 +01:00
Greg Chadwick
8282a0d244 [rtl] Fix MaxOutstandingDSideAccessesCorrect assertion 2022-08-11 15:44:41 +01:00
Greg Chadwick
4acc27b7ab [rtl, icache] Rework invalidation logic
This refactors the invalidation control logic into an explicit state
machine. The top-level icache_invalid_o signal is also removed.
Replaced with an explicit scramble key request instead.

This has all been done to better deal with corner cases around a new
invalidation being requested whilst another is still going on.
Previously there was a bug wher an invalidation request in the final
cycle of an ongoing invalidation didn't restart the invalidation but did
rotate the scrambling key producing an ECC failure and an alert.
2022-08-11 09:21:51 +01:00
Greg Chadwick
e53a02ab31 [rtl] Alter some CSR WARL behaviour to match spike
The following changes are made:

- For unimplemented counters corresponding bits in MCOUNTINHIBIT read as
0 not 1
- For MHPMEVENTx we start at x = 3 with the first bit set (0-2
MHPMEVENTx CSRs do not exist)
- When writing an invalid privilege mode to MSTATUS.MPP/DCSR.PRV default
to U rather than M mode.

These new behaviours remain spec compliant and match spike.
2022-08-09 21:15:09 +01:00
Greg Chadwick
19d12ee3a7 [rtl] Fix MISA
Initially the 'B' bit was going to be used to indicate the presence of
the bit-manipulation extension. Now that has been seperated into
multiple smaller extensions the 'B' MISA bit isn't being used and
remains a reserved bit that should read as 0.

For the RV32B configurations where we implement non ratified
bit-manipulation extensions we must set the 'X' bit.

These changes matche the behaviour of spike.
2022-08-09 21:15:09 +01:00
Michael Schaffner
4975c7fa4b [lint] Minor fixes
Signed-off-by: Michael Schaffner <msf@google.com>
2022-08-05 12:25:36 -07:00
Canberk Topal
46404cf86f [rtl] Flush controller in PMP CSR write ops
As Greg pointed out:

When we have an instruction in ID/EX that writes a PMP register that
update gets written to the CSR the same cycle the next instruction
moves from IF to ID/EX with it's PMP check done with the old value.

The solution is to flush the pipeline when we get a PMP CSR write.

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-08-05 15:50:42 +03:00
Harry Callahan
23806e2ad7 Fix incorrect debug_cause priority against riscv-debug 1.0.0-STABLE
The relevant page [Debug Spec v1.0.0-STABLE, p.53] gives the following
priorities for resolving multiple concurrent reasons for entering debug mode....

DCSR.cause : Explains why Debug Mode was entered.

When there are multiple reasons to enter Debug Mode in a single cycle,
hardware should set cause to the cause with the highest priority.
1: An ebreak instruction was executed.                        (priority 3)
2: A Trigger Module trigger fired with action=1.              (priority 4)
3: The debugger requested entry to Debug Mode using haltreq.  (priority 1)
4: The hart single stepped because step was set.              (priority 0, lowest)
5: The hart halted directly out of reset due to resethaltreq. (priority 2)
   It is also acceptable to report 3 when this happens.
6: The hart halted because it’s part of a halt group.         (priority 5, highest)
   Harts may report 3 for this cause instead.

Other values are reserved for future use.
2022-08-05 12:03:36 +01:00
Canberk Topal
e242ef07ad [rtl] Deny no-match X access in M-Mode while MML=1
In ePMP spec, it specifies as:

```
Executing code with Machine mode privileges is only possible from memory
regions with a matching Mmode-only rule or a locked Shared-Region rule
with executable privileges. Executing code from a region without a
matching rule or with a matching S/U-mode-only rule is denied.
```

This change provides that.

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-08-03 10:59:40 +01:00
Greg Chadwick
6dc0683773 [dv] Fix IbexDataRPayloadX assertion
Some aspects of the memory response are only relevant to reads. This
introduces outstanding request tracking so we know which outstanding
requests are reads and applies X checks appropriately.

Fixes #1645
2022-07-26 16:58:30 +01:00
Canberk Topal
1e613cc7f4 [cosim,dv] Add support to set mcount registers
Extends RVFI connections further to include 30 mhpmcounterX registers.
Sets them up before every cosim step to let Spike know their real values.

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-07-25 08:51:31 +01:00
Canberk Topal
dfca76f386 [dv,fcov] Implement Misaligned Mem Error coverage
Adds some signal to the load store unit to catch when we have the
fetch error signals from both first and second part of the misaligned
load/store access cases.

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-07-21 01:02:15 +03:00
Canberk Topal
5c49fad9a2 [fcov] Adding debug related functional coverage
Includes coverpoints for:

- Hardware trigger point matches
- Debug simple step entrance in controller
- Seeing different insns while single stepping

Also updates on coverage plan to fill up missing mentions of
coverpoints/crosses

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-06-29 16:02:53 +03:00
Timothy Chen
31531f7325 Update crash dump to contain mtval
- mtval is a bit more useful for double fault situations
  as on the second exception we can still "remember" the
  data address and PC of the first exception.

Signed-off-by: Timothy Chen <timothytim@google.com>
2022-06-16 07:58:19 -07:00
Canberk Topal
c253bd76a9 [dv] PMP related functional coverage points
Adding MSECCFG CSR related functionality also some write checks etc.

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-06-01 13:25:09 +01:00
Canberk Topal
51bcae432b [rtl] PMP Logic Refactoring
This makes use of functions in a way that enables us to use `priv_lvl`
dependent logic in the DV environment.

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-05-25 13:37:30 +01:00
Canberk Topal
46f1f69209 [rtl] Remove unused clk/rst_n in PMP module
Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-05-25 13:37:30 +01:00
Canberk Topal
04ce927a74 [fcov] Add various coverage points
Mostly related to WFI, but also double fault and icache enable

Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-05-25 13:37:30 +01:00
Canberk Topal
f21b6545ac [fcov] CSR related coverage points
Signed-off-by: Canberk Topal <ctopal@lowrisc.org>
2022-05-25 13:37:30 +01:00
jamesrbailey
361f2ddedf Update ibex_top.sv
Adding conditional to instantiate non-scrambling instruction cache memories when ICacheScramble parameter is not set.
2022-05-04 14:40:00 +01:00
Michael Schaffner
e1128aa2d4 Add SYNTHESIS ifdef around functional coverage code
This functional code coverage section has hierarchical paths, which will
break certain synthesis and lint flows.

Signed-off-by: Michael Schaffner <msf@google.com>
2022-04-21 09:26:30 -07:00
Michael Schaffner
7fc013c9a4 Break long lines due to lint warnings
Signed-off-by: Michael Schaffner <msf@google.com>
2022-04-21 09:26:30 -07:00
Michael Schaffner
3264fe85c6 Update fetch enable encoding
This is done to match the encoding update done in the OpenTitan repo
here: https://github.com/lowRISC/opentitan/pull/12153

Signed-off-by: Michael Schaffner <msf@google.com>
2022-04-19 15:11:25 +01:00
Michael Schaffner
ccc9bef3ec [regfile] Add countermeasure label
Signed-off-by: Michael Schaffner <msf@google.com>
2022-04-13 14:36:52 -07:00
Michael Schaffner
cfd9b45cfc [regfile] Add spurious write enable check for secure ibex
Signed-off-by: Michael Schaffner <msf@google.com>
2022-04-13 14:36:52 -07:00
Michael Schaffner
6caf82c2b4 [lint] Minor fixes
Signed-off-by: Michael Schaffner <msf@google.com>
2022-04-12 08:38:35 -07:00
mbaykenar
2ae62c145c assign irq_nm_int_cause to all zeros 2022-04-12 15:23:44 +01:00
mbaykenar
eeedeb003a Update ibex_controller.sv
Vivado gives synthesis error complaining about assignment of irq_nm_int_cause to '0 by saying it is an enum type.

Change the assignment to NMI_INT_CAUSE_ECC, which is defined to 5'b0 in ibex_pkg.sv
2022-04-12 15:23:44 +01:00
Rupert Swarbrick
0a9f5ed1da [rtl] Remove "mispredict" ports from icache
These are no longer needed: a previous commit has moved the logic that
handles misprediction into the IF stage and branch_mispredict_i was
dead zero.
2022-04-04 16:56:04 +01:00