Commit graph

585 commits

Author SHA1 Message Date
Greg Chadwick
11749c7e4d [rtl] Implement FENCE.I
Fixes #391
2019-11-27 08:47:26 +00:00
Pirmin Vogel
d117b24a17 [rtl] Do not update CSRs upon exceptions in debug mode
In debug mode, exceptions shall not update any CSRs including `mcause`,
`mepc`, `mtval`, `dpc` and `mstatus`, see Debug Spec v0.13.2, p.39.

This resolves lowRISC/ibex#168.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2019-11-19 15:15:42 +01:00
Philipp Wagner
7465a68615 Fix typo in comment 2019-11-18 10:30:14 +00:00
Pirmin Vogel
aefbcdceb3 [rtl] Add new assertions
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2019-11-15 10:23:03 +01:00
Pirmin Vogel
40e3db5f23 [rtl] Rework assertions
This commit modifies the assertions to not fire as long as the reset
is active. Also, it updates some assertions.

This resolves lowRISC/ibex#274.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2019-11-15 10:23:03 +01:00
Pirmin Vogel
9738b6c703 [rtl] Rework core_busy signals, remove feedback to clk
This commit reworks the generation of the `core_busy` signal used to
control the main clock gate of the core. Without this commit, the
controller generates a separate `first_fetch` signal only asserted in
the FIRST_FETCH state that directly controls `core_busy` and thus the
main clock gate. This is problematic as it introduces a feedback to
from the controller state into the clock.

This commit removes the problematic signal and changes the generation of
`ctrl_busy` in the FIRST_FETCH state of the controller. This signal is
now used to control the main clock gate in all states (previously all
except FIRST_FETCH) but it gets registered, thus it does not introduce
the feedback into the clock.

This resolves lowRISC/ibex#211.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2019-11-14 12:55:16 +01:00
Tom Roberts
0243e08111 [rtl] Switch to M mode on debug entry
- Core should operate as if in M-mode while in debug mode
- Previous priv level is restored from dcsr on DRET
- Fixes #463
2019-11-14 09:37:02 +00:00
Pirmin Vogel
52b03f3637 [rtl/controller] Remove redundant check in EBREAK handling
This commit removes a redundant for `ebrk_insn` in the `DBG_TAKEN_ID`
state. If this signal is not set, the controller does not enter this
state in the first place. This is not changing functional behavior,
but removes a `MISSING_ELSE` coverage hole reported by @udinator.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2019-11-13 13:12:15 +01:00
Pirmin Vogel
6a5ee22395 [rtl/controller] Remove redundant check in execption handling
This commit turns the last case in the exception handling if/else block
from an `else if` to an `else`. This is not changing functional
behavior as the same condition is checked previously, but removes a
`MISSING_ELSE` coverage hole reported by @udinator.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2019-11-13 13:12:15 +01:00
Pirmin Vogel
d538261c78 [rtl] Ignore LSB only for writes to dpc
Without this commit, writes to `dpc` with the LSB set are completely
ignored. This commit changes the implementation to ignore the LSB only.
This is the same behavior as seen required for `mepc`. This resolves
lowRISC/ibex#444.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
2019-11-13 13:11:22 +01:00
Pirmin Vogel
0a1a8514c4 [rtl] Rework access to performance counter CSRs
This commit reworks the code section describing how the performance
counter CSRs are accessed by CSR instructions. Instead of using an
address mask inside the default case, and excluding CSRs in the same
address range previously handled (like `mcycle(h)`, `minstret(h)`,
`mcountinhibit`), all performance counter CSRs are now explicitly
enumerated. This enhances readability of the code and enhances
compatibility with some tools without changing behavior or causing
lint problems.

This commit is based on suggestions from @MarekPikula. It replaces the
proposal in lowRISC/ibex#336.
2019-11-11 19:01:49 +01:00
Pirmin Vogel
275c3310fa [rtl] Remove unused set-less-or-equal-than ALU ops
These operations (ALU_SLET, ALU_SLETU) are remnants of of the original
OpenRISC design. RISC-V just has set-less-than (ALU_SLT, ALU_SLTU).

This resolves lowRISC/ibex#432 reported by @udinator.
2019-11-01 11:51:25 +00:00
Greg Chadwick
5ce6351530 Add performance counter utils for verilator sims 2019-10-30 16:56:55 +00:00
Pascal Cotret
e5cf0c0fcf Error synthesis in Vivado 2019-10-28 20:36:37 +00:00
Pirmin Vogel
36ce999fbb [rtl/lsu] Rework assertion checking response valid
This commit replaces an obsolete assertion with one checking that
response valid is received only if the LSU is ready to handle it.

This resolves lowRISC/ibex#421 reported by @udinator.
2019-10-26 14:51:19 +01:00
Pirmin Vogel
0331ed61b1 [rtl/alu] Remove unused comparison operations
These operations (ALU_GT, ALU_GTU, ALU_LE, ALU_LEU) are remnants of
of the original OpenRISC design. RISC-V does not have these instructions
and instead implements the operations by reversing operands for ALU_LT,
ALU_LTU, ALU_GE, ALU_GEU.

This resolves lowRISC/ibex#420 reported by @udinator.
2019-10-25 13:58:59 +01:00
Marek Pikuła
294849bb18 [RTL] Add MultiplierImplementation parameter in top level 2019-10-24 14:33:24 +01:00
udinator
023b7b6856
[RTL/Tracer] Fix compressed jump RD write (#416) 2019-10-23 10:30:11 -07:00
Philipp Wagner
1c3903e2ce Tracer: Decode an all-zero instruction as c.unimp
Fixes #396
2019-10-17 13:48:29 +01:00
Greg Chadwick
cc94bc8d54 [RTL] Fix single stepping on exceptions
When we single step over an instruction that causes an exception DPC
should be set to point to the exception handler (where we would have
gone were we not single stepping).
2019-10-16 10:23:05 +01:00
Greg Chadwick
b94961402c [RTL] Fix ebreak behaviour in U-mode
Fixes #370

Whether EBREAK enters debug mode is controlled by the
ebreaku and ebreakm dcsr fields. Which is relevant depends upon the
privilege level.
2019-10-16 09:10:34 +01:00
Greg Chadwick
7aa87156d3 [RTL] Fix ebreak and cleanup debug
Fixes #393

When entering debug mode in controller need to ensure ID doesn't get
flushed until the relevant debug state can see the contents of ID and
perform the appropriate actions. ID is flushed at that point.

Also cleaned up some code replication around entering debug mode
(debug_req vs single step look very similar so can use the same code
paths).
2019-10-16 09:10:34 +01:00
Greg Chadwick
2bc785e7d9 [RTL] Prevent CSR write on any illegal CSR reason
Debug register access sets illegal_csr if not in debug mode but CSR
write still went ahead. This modifies the CSR write to ensure that
anything that results in an illegal CSR instruction being signalled will
prevent a CSR write.
2019-10-15 14:43:55 +01:00
Pirmin Vogel
5f0be50473 Remove non-ASCII characters from .sv and .rst files 2019-10-14 09:08:16 +01:00
udinator
566e73c352
[RTL] Enable reading mstatus.tw (#388) 2019-10-10 09:17:14 -07:00
Philipp Wagner
3db46f91e0 Tie off csr_pmp_* signals for all lint tools
Our generic way of marking signals as unused is assigning them to an
unused_* signal. That works for all lint tools and avoids tool-specific
waivers.
2019-10-09 13:35:01 +01:00
Philipp Wagner
90ff45abbd Avoid self-determined bit length of signals
This works around a lint error we get; the old and the new version are
equally wrong or right, but it doesn't seem to be worth fighting with a tool.
2019-10-09 13:35:01 +01:00
Philipp Wagner
cdc8078c0f ibex_cs_registers: Add missing generate name
One condition is missing a generate label.
2019-10-09 13:35:01 +01:00
Tom Roberts
c33525ae80 [RTL LSU] Change unaligned error behaviour
- If an error is signalled in the first part of an unaligned
  transaction, the second part is issued anyway (to avoid a
  timing loop from data_err_i -> data_req_o)
- Previously, the error was signalled and an exception was taken
  as soon as the first transaction completed. This commits makes
  the core wait until both transactions have completed.
- This prevents strange behaviour caused by the lsu and controller
  being out of sync (fixes #374).
2019-10-09 10:07:07 +01:00
Philipp Wagner
ee1098f9af Tracer: Reference Verilator bug for miscompilation
This miscompilation is now reported and fixed, mention it in the code to
refer back to it when we can revert back to the old code (which will
take a couple months until we can require a newer Verilator version).

Fixes #372
2019-10-06 12:55:59 +01:00
Philipp Wagner
d8e4852f76 Include rs1 and rd in trace of c.addi16sp
New output looks like this:

118         55      00000154        6121    c.addi16sp      x2,64     x2:0x00000030  x2=0x00000070

Fixes #322
2019-10-05 18:22:14 +01:00
Philipp Wagner
2acb497d22 Add missing enum cast
Vivado doesn't compile the design without this cast.
2019-10-03 16:56:26 +01:00
Tom Roberts
f35db04b7c [RTL PMP] Fix address matching bugs
- Partial matching not relevant for 32bit only accesses
- Apply region size masking correctly
2019-10-03 10:41:29 +01:00
Tom Roberts
2aacd2b98b [Priv modes] Add support for U-Mode
- General changes to suport U-mode (fixes #88)
- Update documentation
- Add priv mode flops to CSRs module
- Propagate correct priv mode to PMP module
- Implement CSR priv-mode permission checking
- Implement illegal U-mode instruction checking
- Add extra mstatus bits for U-mode (MPRV and TW)
2019-10-03 10:41:29 +01:00
Philipp Wagner
0908817963 Tracer: Fix default file name
We document the default file name to be trace_core_00000000.log, but
actually used trace_core__00000000.log. Fix that.
2019-10-02 20:12:38 +01:00
Philipp Wagner
74780e7e17 Implement Verilator-compatible tracer, and use it
The ibex_tracer module implements an execution tracer, observing the
execution flow and writing a human-readable execution trace. The trace
information is coming from the RVFI signals, as specified at
https://github.com/SymbioticEDA/riscv-formal/blob/master/docs/rvfi.md.

The existing implementation was tailored for use in ModelSim and other
commercial simulators, and used SystemVerilog features which are not
supported in Verilator or Icarus Verilog, such as classes, queues and
non-standard format specifiers (e.g. the `-` specifier for right-aligned
output). Being unable to see an execution trace when using Verilator
significantly reduced productivity and its usefulness.

This commit refactors the tracer to only use SystemVerilog constructs
which are supported in Verilator. While doing so, multiple improvements
were made for correctness and style.

Major changes:

- Improve compatibility with Verilator. Remove many non-synthesizable
  SystemVerilog constructs, such as classes and queues.
  Use casez instead of casex for better Verilator support (Verilator
  doesn't support X).
- Make the decoded output of the tracer match objdump from binutils
  exactly. Doing so is beneficial for two reasons: we can easily
  cross-check the decoded output from the tracer against the disassembly
  produced by objdump (and we did that), and users don't need to get
  used to another slighly different disassembly format.
- A plusarg "+ibex_tracer_file_base=ibex_my_trace" can be used to set a
  different basename for the trace log file.

Smaller cleanups:

- Remove decoding of reg-reg loads, which were leftover from a PULP
  extension.
- Make better use of the data available on the RVFI. Pass all of RVFI
  to the tracer, and use the provided data instead of manually
  recreating it, e.g. to get register data or the jump target.
- Rename all "instr" abbreviations to "insn". "insn" is what RVFI uses
  (and we cannot change that), so for consistency we now always use this
  abbreviation across the file.

All CSR names have been imported from binutils' riscv-opc.h file, available at
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob_plain;f=include/opcode/riscv-opc.h
using this small C program:

  #include <stdio.h>

  #define STR(s) #s

  int main(int argc, char **argv) {
    printf("unique case (csr_addr)\n");
  #define DECLARE_CSR(name, csraddr) \
    printf("  12'd%d: return \"%s\";\n", csraddr, STR(name));
  #include "riscv-opc.h"
    printf("  default: return $sformatf(\"0x%%x\", csr_addr);\n");
    printf("endcase\n");
    return 0;
  }

The RISC-V compliance test suite for the RV32 I, M, and C extensions has
been executed and traced. The disassembly of all traces have been
compared against traces produced by objdump to ensure identical output.

This PR is based on work by Rahul Behl <raulbehl@gmail.com> in #280.
Thank you Rahul for providing a great starting point for this work!
2019-10-02 18:28:26 +01:00
Greg Chadwick
2a947c5e7f [RTL] Fix timing path around exceptions and pc_set
When an exception occurs controller goes into the flush state and then
does a pc_set to go the exception handler.  So there is no need for the
incoming signals that indicate an exception to factor directly into
pc_set_o.  This flops exc_req and illegal_insn to break long timing
paths that were occurring because of this.

Fixes #305
2019-10-02 15:46:26 +01:00
Greg Chadwick
b1155740c2 [RTL] Keep instr in ID valid for FLUSH state
When an instruction that caused an exception occurred the controller
would clear the instr_valid bit but rely on the instruction bits staying
in the ID register so it could still use them in the FLUSH state to
decide what to do. This reworks the control logic slightly so
instr_valid remains asserted when the controller goes into the FLUSH
state so relevant signals can be qualified with the instr_valid bit.

There were no known functional issues caused by the previous behaviour
however this gives a more robust approach.
2019-10-02 15:46:26 +01:00
Marek Pikuła
252874d32d Pull csr_we_int around case in CSR
`if (csr_we_int)` conditional is now outside address `unique case`.

Also add comment about `illegal_csr_*` origin.
2019-10-02 15:37:42 +01:00
Philipp Wagner
51dbfe1575 ibex_core_tracing: Pass through all parameters
The PMP parameters were not passed through on ibex_core_tracing, add
them back.
2019-10-01 10:38:45 +01:00
Philipp Wagner
e2848f2181 ibex_core: Use correct width for param assignments
These parameters are of type bit, we need to assign a value of the
correct width to avoid Verilator lint warnings.
2019-10-01 10:38:45 +01:00
Philipp Wagner
e6b42a1529 Tracer: Update copyright notice to match other files
In this file I missed updating the ETH/UniBo copyright notice to include
a reference to the CREDITS.md. Fixing that for consistency.
2019-10-01 09:18:48 +01:00
Tom Roberts
f2fccaadbc [Prefetch buffer] - various bug fixes
- Fix incorrect address output to mepc on interrupt (fixes #320)
- Fix instruction address changing before grant (fixes #296)
- Suppress requests and reg writes on fetch error (fixes #340)
- Remove excess address flops in fetch_fifo
- Remove restriction on outstanding requests
2019-10-01 08:23:08 +01:00
NilsGraf
4c0ac554a6
[rtl/ibex_core] Added missing parameter assignment (#356)
Added missing parameter assignment for PMPEnable of ibex_cs_registers.
2019-09-30 09:52:07 -07:00
Pirmin Vogel
83d2185c9b Tracing: Wrap fatal error message with $fatal()
The syntax of this statement is not correct without the `$fatal()` SV
construct. This causes errors in some tools even if the error condition
is not met.
2019-09-20 09:35:26 +01:00
Philipp Wagner
fa31484a6a Lint: Fix signal width in tracer
These width warnings are only visible if RVFI is enabled and reported by
Verilator lint.
2019-09-17 13:29:37 +01:00
Tom Roberts
f025236a22 [I-side] - Fix issues found in tracing example
- Fixes #288
- Add missing grant qualification to stop incorrect address updates
- Make RTL robust to spurious rvalid signalling
- Make sure a request is held until granted
- Remove incorrect assertion
2019-09-12 08:47:09 +01:00
Pirmin Vogel
85ae06d054 Controller: fix nmi_mode default assignment
Without this commit, the `nmi_mode` register is continuously cleared and
set again, and the core can never handle the NMI.

This resolves lowRISC/ibex#300 reported by @udinator.
2019-09-11 10:45:26 +01:00
Pirmin Vogel
8d3d87ae53 Controller: Fix exception cause ID of fast interrupts
This commit fixes the generation of the exception cause ID for fast
interrupts. Without this commit, the core tries to handle fast
interrupts using the handlers of other interrupts like external,
software, and timer interrupts.

This commit resolves lowRISC/ibex#290 reported by @udinator.
2019-09-09 13:05:48 +01:00
Tom Roberts
b87ed7c82e [I-side] - Fix assertion error
- Assertion was added in the wrong file
2019-09-09 09:06:31 +01:00