Commit graph

373 commits

Author SHA1 Message Date
Yuichi Sugiyama
505c9daec1 [rtl] Fix Gift cipher lint errors
- Import::* may pollute global namespace
- Signal width is different
- Signal is not used
- Signal unoptimizable: Feedback to clock or circular logic
2020-07-15 17:02:42 +02:00
Yuichi Sugiyama
719801b938 [rtl] Hook up real Gift cipher core 2020-07-15 17:02:42 +02:00
Flavien Solt
6ae4d3a376 Improved Gift package 2020-07-15 17:02:42 +02:00
Yuichi Sugiyama
6bc3022cc2 [rtl/sw] Add PAC and AUT counters 2020-07-15 17:02:42 +02:00
Yuichi Sugiyama
089016eb74 [rtl] Update tracer for PAC and AUT 2020-07-15 17:02:42 +02:00
Yuichi Sugiyama
efcb049839 [rtl] Fix instr_id_done_o for PAC instruction
PAC instruction writes to the register file twice,
so when not taking stall_pa into consideration,
instr_id_done_o is activated twice during the execution of an PAC.
Unfortunately it interferes with the implementation of counters and
tracers for PAC, so now we are using stall_pa to calculate instr_id_done_o.
2020-07-15 17:02:42 +02:00
Yuichi Sugiyama
46bef34dee [rtl] Fix hazard detection issues for Pointer Authentication
With the writeback stage enabled we execute the PAC/AUT instruction
before the required data is written to the register file.
For example, when the load instruction precedes AUT instruction,
AUT instruction is started before the loaded data is written
to the register file. It is a problem that the hazard detection
(stall_ld_hz) using rf_ren_a/b_o was not active for PAC/AUT instruction.
Also, I change codes not to activate pa_pac_en or pa_aut_en
when load hazard occurs.
2020-07-15 17:02:42 +02:00
Yuichi Sugiyama
47be986b74 [rtl] Fix Pointer Authentication lint errors
- Bits of signal are not used
- Case values incompletely covered
- Signal unoptimizable: Feedback to clock or circular logic
2020-07-15 17:02:42 +02:00
Yuichi Sugiyama
f13ac7b8b9 [rtl] Add Pointer Authentication 2020-07-15 17:02:42 +02:00
Flavien Solt
b1ff52dc67 Input signal injection 2020-07-15 16:38:31 +02:00
Flavien Solt
3a738a2a15 Added Gift cipher for pointer authentication 2020-07-15 16:38:31 +02:00
Tom Roberts
c542edbb1a [rtl] Add register-file ECC checking
- Add SECDED ECC checking to the register file when SecureIbex is
  enabled
- No correction is attempted, but an alert is raised for the system to
  intervene

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-07-15 09:50:23 +01:00
Tom Roberts
aae437d75b [rtl] Add alert outputs
- Add a major and minor alert output which can be used by the system to
  react to fault injection attacks

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-07-15 09:50:23 +01:00
Philipp Wagner
4223803d22 Lint: Fix some line length warnings
AscentLint complains about lines longer than 100 characters, as seen in
the nightly lint reports. Fix some (all?) of them.
2020-07-09 13:42:33 +01:00
Philipp Wagner
d0923fa5d1 ibex_counter: Use always_ff
Fix a lint error reported by AscentLint:

```
E   ALWAYS_SPEC:   ibex_counter.sv:59   Edge triggered block may be more accurately modeled as always_ff                 New
```
2020-07-09 13:42:33 +01:00
Pirmin Vogel
414ff7eeb0 [doc] Fix spelling of CoreMark
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2020-07-06 12:30:02 +02:00
Philipp Wagner
bf5dd7ec15 Icache: It's not a draft any more
The Icache might not be fully perfect, but it's certainly not a draft
any more.
2020-07-03 14:39:48 +01:00
Philipp Wagner
67e7417749 Fix Verible lint issues
Fix all remaining issues reported by Verible lint.

It turns out that #965 undid some of the fixes in `ibex_alu.sv`
that were done in #980 around the `SHUFFLE_*`/`FLIP_*` signals.
2020-07-03 12:20:32 +01:00
Rupert Swarbrick
49c9113d03 Formal protocol checking for icache <-> core interface
This turns out to be quite complicated, because the icache has a lot
of different counters that all track addresses or fill buffer state.
For an inductive proof to go through, you need to make the relations
between them explicit, which takes lots of assertions.

All of the signals defined in the formal_tb are prefixed with 'f_'.
This isn't strictly necessary, but it makes it much easier to see what
came from the design (since we are "bound in", our ports don't have _o
or _i suffixes).

We add a couple of protocol assumptions:

ICache <-> Core:

  - Branch target addresses are half-word aligned
  - The branch_spec signal is driven if branch is

ICache <-> Memory:

  - The bus doesn't respond unless there is an outstanding request
  - The bus doesn't grant more than 4 billion outstanding requests(!)

There's also some protocol state tracking:

  - f_addr_valid tracks whether the ICache currently has an
    architectural address. It goes high with branch_i (which gives the
    cache an address) and goes low when the cache completes a
    transaction with err_o set (since the data is bad, there's no
    notion of a "next address").

  - f_reqs_on_bus tracks the number of requests currently outstanding
    on the bus. This is used for the ICache <-> Memory assumptions
    above. We have some internal assertions that check this equals the
    sum of the "ext" counters minus the sum of the "rvd" counters.

With these assumptions, we can prove:

  - Once asserted, valid_o stays high until a transaction is completed
    by ready_i or until branch_i is asserted (which cancels the
    transaction).

  - While the transaction is pending, addr_o remains stable.

  - While the transaction is pending, err_o remains stable and, if
    err_o is asserted, so does err_plus2_o.

  - While the transaction is pending, if err_o and err_plus2_o are
    high then bottom 16 bits of the returned instruction data imply an
    uncompressed instruction.

  - While the transaction is pending, if err_o is low then the bottom
    16 bits of the returned instruction remain stable.

  - While the transaction is pending, if err_o is low and the bottom
    16 bits of the returned instruction imply an uncompressed
    instruction then the top 16 bits of the returned instruction
    remain stable.
2020-07-02 15:19:11 +01:00
Rupert Swarbrick
ee1ca61fe4 A simple formal flow for the ICache based on SymbiYosys
To get this working, you need a corresponding patch in Edalize, which
adds SymbiYosys as an EDA tool.

At the moment, this proves a couple of simple bus assertions. Later
patches will add more.

There are currently some rough edges to this flow:

  (1) We use a hacky pre_build hook to run sv2v and edit the files in
      the work tree. Among other problems, this means that the any
      failure messages that come out of sby have bogus line numbers.

  (2) Since we haven't yet got bind support in Yosys, we have to
      include a fragment from the design itself.
2020-07-02 15:19:11 +01:00
ganoam
1aa4d5a32b [bitmanip] Optimizations and Parametrization
This commit contains some final optimizations regarding the bit
manipulation extension as well as the parametrization into a balanced
version and a full performance version.

Balanced Version:
        * Supports ZBB, ZBS, ZBF and ZBT extensions
        * Dual cycle instructions:
          ror[i], rol, cmov, cmix fsl, fsr[i]
        * Everything else completes in a single cycle.

Full Version:
        * Supports all 32b sub extensions.
        * Dual cycle instructions:
          ror[i], rol, cmov, cmix fsl, fsr[i], crc32[c], bext, bdep
        * Everything else completes in a single cycle.

Notable Changes:
        * bext/bdep are now multi-cycle: Sharing additional register
          with multiplier module
        * grev/gorc instructions are implemented in separate structures
          rather than sharing the shifter or butterfly network.
        * Speed up decision on using rs1 or rs3 for alu_operand_a by
          introducing single-bit register, to identify ternary
          instructions in their first cycle.
        * Introduce enumerated parameter to chose bit manipulation
          implementation

Signed-off-by: ganoam <gnoam@live.com>
2020-06-26 14:43:24 +02:00
Tom Roberts
71b3474781 [rtl] Fix icache xprop issue
- invalidate all ways on a tag error to prevent xprop from the data
  error signal and reduce the likelyhood of multi-way allocations

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-25 09:46:35 +01:00
Xiang Wang
684d4205bf Prevent writing CSR_SECURESEED to get the seed of dummy instruction
Although CSR_SECURESEED is unreadable, an attacker can write a new seed,
which brings convenience to the attack. This patch is used to XOR the
historical seed, so that even if the attacker writes a new value to
CSR_SECURESEED , he cannot know the value of the seed.

Signed-off-by: Xiang Wang <merle@hardenedlinux.org>
2020-06-23 11:48:33 +01:00
Michael Schaffner
ae547c8d30 [top_pkg] Fix style lint warnings
Signed-off-by: Michael Schaffner <msf@google.com>
2020-06-22 20:52:15 +01:00
Bert Pieters
fdfdcc0467 [rtl] disable clock between reset and fetch_enable_i
Fixes lowRISC#957

Signed-off-by: Bert Pieters <bert.pieters@gmail.com>
2020-06-22 13:25:39 +02:00
Rupert Swarbrick
a247cd45e9 Add some basic protocol checking to the icache's RAM interface
Since we are binding in an interface anyway, we can add some SV
assertions to make sure nothing too strange is happening.

Note that they aren't as strong as you might expect: we don't check
that rdata isn't X, for example. This is because the cache makes
speculative reads, which it (hopefully) ignores if the data is
invalid.
2020-06-22 10:37:34 +01:00
Bert Pieters
4eece98875 [rtl] Remove use of `define in decoder
Fixes #30

Signed-off-by: Bert Pieters <bert.pieters@gmail.com>
2020-06-18 15:38:05 +01:00
Tom Roberts
d79eb58ae5 [rtl] Simplify I$ ECC error handling
- Remove the timing optimisations that delay the factoring-in of ecc
  errors into valid_o.
- Optimisations are probably unnecessary here due to the minimal logic
  hanging off valid_o, and the optimisations cause protocol checker
  violations.

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-12 14:04:30 +01:00
Greg Chadwick
066b91a076 [rtl] Use outer generate loop for latch RF
This matches the style used in the FF based register file. It gives each
register its own always block with a single enable rather than having
multiple registers with enables in a single always block.

Signed-off-by: Greg Chadwick <gac@lowrisc.org>
2020-06-12 12:05:48 +01:00
Greg Chadwick
3c55a72d08 [rtl] Use gated clock for wb_stage and rf
Corrects a typo, ibex_wb_stage and ibex_register_file were being
supplied with the ungated clk.
2020-06-12 10:45:51 +01:00
Greg Chadwick
207cac3ced [rtl] Use generate loop in FF register file
By giving each register its own always_ff block clock gating is more
obvious to synthesis tools.

This also includes some minor naming tweaks to make use of the _q
convention for flops.
2020-06-12 10:31:54 +01:00
Tom Roberts
5ecaa11c63 [rtl] Fix writeback stage interrupt issue
- If an interrupt arrives at the same time as a load/store instruction
  is in ID stage, the interrupt must wait until load/store completes.
  Without the WB stage this happens naturally as the core stalls. With
  the WB stage, we need to allow the load/store to progress to the WB
  stage (and clear the ID stage) then hold back the interrupt until it
  completes.
- Also cleaned up some lsu related stalling terms and signal naming.

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-10 15:13:32 +01:00
Tom Roberts
78e8fb639d [rtl] Remove incorrect LSU assertion
- Protocol-wise data_err_i is notionally X when !data_rvalid_i
- In addition, the design does not appear to rely on the asserted
  behaviour
- Removing as it is firing in chip-level OT simulations

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-10 15:13:32 +01:00
Tom Roberts
bfa531c039 [rtl] Move some assertions around
- Prevents errors due to empty generate blocks when passed through sv2v

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-08 11:20:09 +01:00
Tom Roberts
8332f7de9d [rtl] Rewrite perf counters to be Yosys compatible
- Yosys doesn't like unpacked array partial slicing
- Instantiate counters individually instead

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-08 11:20:09 +01:00
Eunchan Kim
3c35e44301 Fix Writeback stage lint errors
- unpacked array decending order
- unspecified generate block

Signed-off-by: Eunchan Kim <eunchan@opentitan.org>
2020-06-04 23:33:04 +01:00
Greg Chadwick
c0ae8ffb99 [rtl] Fix issue with ID/EX exceptions
When a potential exception occurs in ID/EX controller must wait for any
outstanding instruction in WB to complete before resolving it. The
instruction in WB may also have an exception which takes priority over
ID/EX.

Signed-off-by: Greg Chadwick <gac@lowrisc.org>
2020-06-02 13:45:46 +01:00
Greg Chadwick
833bdefe33 [rtl] Fix exception priority for writeback stage
With the writeback stage enabled the controller can see a load or store
error from the writeback stage whilst seeing some other fault/exception
from ID/EX (e.g. an instruction fetch error). The writeback stage fault
must take priority, however without the writeback stage the
priortisation changes.

This introduces more explicit prioritisation logic for faults/exceptions
and gives the correct prioritisation for configurations both with and
without a writeback stage.

Fixes #912

Signed-off-by: Greg Chadwick <gac@lowrisc.org>
2020-06-02 13:45:46 +01:00
Tom Roberts
ff5375db5c [rtl] Make speculative branch optional
- The speculative branch behaviour causes a performance degradation of
  around 3% in the max config. This change enables that behaviour only
  the maximum PMP config, which is where it is most needed for timing
  closure.

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-02 13:41:29 +01:00
Tom Roberts
f190e3abe4 [rtl] Fix PMP NA4 address matching
- Split out address matching into less than, greater than and equals to
  correctly match NAPOT, NA4 and TOR modes.
- Relates to #902

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-02 13:41:03 +01:00
Tom Roberts
4b01580a7b [rtl] prefetch buffer performance fix
- The prefetch buffer needs to know when space is available in the fetch
  FIFO to accept a new external request.
- This change updates that logic to look at what is in the FIFO and what
  is outstanding on the bus to decide when space is available rather
  than always assuming the maximum number of requests are outstanding.
- This improves the usage efficiency of the FIFO and fixes #574

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-06-01 08:59:51 +01:00
Philipp Wagner
dd39ec0c91 Optimize use of RAM primitive in icache
The RAM primitive provides a way to specify the granularity of the write
mask (wmask) signal, which can be used to select an appropriate
implementation (e.g. a SRAM with only byte selects, or no subselects at
all).
2020-05-27 11:38:33 +01:00
Philipp Wagner
8b42024cd5 Use vendored-in primitives from OpenTitan
Instead of using copies of primitives from OpenTitan, vendor the files
in directly from OpenTitan, and use them.

Benefits:

- Less potential for diverging code between OpenTitan and Ibex, causing
  problems when importing Ibex into OT.

- Use of the abstract primitives instead of the generic ones. The
  abstract primitives are replaced during synthesis time with
  target-dependent implementations. For simulation, nothing changes. For
  synthesis for a given target technology (e.g. a specific ASIC or FPGA
  technology), the primitives system can be instructed to choose
  optimized versions (if available).

  This is most relevant for the icache, which hard-coded the generic
  SRAM primitive before. This primitive is always implemented as
  registers. By using the abstract primitive (prim_ram_1p) instead, the
  RAMs can be replaced with memory-compiler-generated ones if necessary.

There are no real draw-backs, but a couple points to be aware of:

- Our ram_1p and ram_2p implementations are kept as wrapper around the
  primitives, since their interface deviates slightly from the one in
  prim_ram*. This also includes a rather unfortunate naming confusion
  around rvalid, which means "read data valid" in the OpenTitan advanced
  RAM primitives (prim_ram_1p_adv for example), but means "ack" in
  PULP-derived IP and in our bus implementation.

- The core_ibex UVM DV doesn't use FuseSoC to generate its file list,
  but uses a hard-coded list in `ibex_files.f` instead. Since the
  dynamic primitives system requires the use of FuseSoC we need to
  provide a stop-gap until this file is removed. Issue #893 tracks
  progress on that.

- Dynamic primitives depend no a not-yet-merged feature of FuseSoC
  (https://github.com/olofk/fusesoc/pull/391). We depend on the same
  functionality in OpenTitan and have instructed users to use a patched
  branch of FuseSoC for a long time through `python-requirements.txt`,
  so no action is needed for users which are either successfully
  interacting with the OpenTitan source code, or have followed our
  instructions. All other users will see a reasonably descriptive error
  message during a FuseSoC run.

- This commit is massive, but there are no good ways to split it into
  bisectable, yet small, chunks. I'm sorry. Reviewers can safely ignore
  all code in `vendor/lowrisc_ip`, it's an import from OpenTitan.

- The check_tool_requirements tooling isn't easily vendor-able from
  OpenTitan at the moment. I've filed
  https://github.com/lowRISC/opentitan/issues/2309 to get that sorted.

- The LFSR primitive doesn't have a own core file, forcing us to include
  the catch-all `lowrisc:prim:all` core. I've filed
  https://github.com/lowRISC/opentitan/issues/2310 to get that sorted.
2020-05-27 10:23:15 +01:00
Tom Roberts
12b39476c0 [rtl] Add speculative branch signal
- Drive a speculative version of the branch signal into the IF stage to
  drive address muxing
- The speculative signal is the same as the regular branch signal but
  assumes all conditional branches are taken
- This breaks the timing path from branch condition calculation into
  address muxing (and therefore PMP error calculation)
- When the branch is not taken, any external request we might otherwise
  have made is suppressed
- This has a minor performance cost (0.8% without I$, ~0% with I$)

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-05-26 09:41:37 +01:00
Tom Roberts
b4d952e297 [assertions] Tweak xprop assertion qualifiers
- Tighten up enable conditions to stop properties firing when there is
  an instruction fetch error

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-05-26 09:33:50 +01:00
Tom Roberts
99c740e504 [rtl] Prevent xprop from fetch fifo
- data can be X when an error is output
- prevent X getting into the valid and address signals

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-05-26 09:33:50 +01:00
Tom Roberts
344279906f [rtl] Fix PMP address matching
- For TOR matching, match should be range_low <= addr < range_high
- Adapt masking so TOR matching can still be reused for NAPOT matching
- Relates to #864

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-05-26 09:33:50 +01:00
Tom Roberts
84c5373c27 [rtl] Various small icache bugfixes
- Remove any ready -> valid dependency by allowing the skid buffer to
  accept data when the core is not ready
- Tighten-up behaviour around invalidations and cache enable/disable
- Remove xprop through output_compressed from invalid data when driving errors
- Make behaviour more consistent where speculative requests return
  different data/error conditions to existing cache hit

Signed-off-by: Tom Roberts <tomroberts@lowrisc.org>
2020-05-26 09:29:36 +01:00
Tobias Wölfel
46fab41f5b [rtl] Remove redundant assignment 2020-05-25 16:47:25 +01:00
Tobias Wölfel
d1854e8cb5 [rtl] Update RVFI order
Use the stage value which contains the last value.
2020-05-25 16:47:25 +01:00