Commit graph

171 commits

Author SHA1 Message Date
Pirmin Vogel
e1a7dcf37f ID stage: rework CSR-related pipeline flushes
This commit clarifies why CSR-related pipeline flushes are needed
(e.g. when enabling interrupts), only introduces them when doing the
critical modifications (write/set bits in `mstatus` and `mie` CSRs
for enabling interrupts, reads and clears are uncritical for these
CSRs), and makes sure the controller is actually able to start
handling interrupts while doing a CSR-related pipeline flush.

This resolves lowrisc/ibex#6.
2019-08-16 13:28:52 +01:00
Tom Roberts
44b033cf8b [rtl] Add support for instruction fetch errors
- Add required signals to top-level
- Propagate error through fetch stages
- Add new exception type
- Update documentation for new exception type
- Resolves issue #109
2019-08-09 10:44:37 +01:00
Pirmin Vogel
ca97cfb58e CSRs: add irq_ prefix to Interrupts_t members
This commit adds a prefix to the members of the `Interrupts_t` struct
to avoid linting errors in AMS mode.
2019-08-09 09:45:22 +01:00
Ivan Ribeiro
19ffe9ac1d Make BASE field of mtvec CSR writeable
This commit makes the BASE field of the `mtvec` CSR writable to
allow changing the trap-vector base address at runtime without
changing the boot address input. Similar to the boot address,
the trap-vector base address must always be aligned to 256 bytes.
At bootup, the trap-vector base address is initialized to the boot
address.

This commit resolves lowrisc/ibex#118.

Most of this work has been done by @ivanmgribeiro as part of
lowrisc/ibex#193.
2019-08-08 10:50:34 +01:00
Pirmin Vogel
bf78a88e9e Fix linting warning 2019-08-08 09:21:30 +01:00
Pirmin Vogel
ea0296d74a Fix IF stalls preventing deassertion of regfile write enable (#222)
* ID stage: make single-cycle instr clear `instr_multicycle_done_q`

Previously, this signal was only cleared when starting the next
multi-cycle instruction.

* ID stage: only eval `instr_multicycle_done_q` for multi-cycle instr

This signal should only be evaluated if the ID/EX stage currently
executes a multi-cycle instruction. Without this commit, the signal
is also evaluated for single-cycle instructions and can for example
cause the register file write enable to not be de-asserted in case of
stalls in the IF stage.

This bug was repored by @udinator. This resolves lowrisc/ibex#216.
2019-08-06 09:04:57 -07:00
Pirmin Vogel
cee2e9396f Remove csr_restore_dret_i signal
This signal was used to restore `mstatus` when executing DRET.
But this is not needed as `mstatus` is not modified when entering
debug mode.
2019-07-29 15:55:48 +01:00
Pirmin Vogel
964e62afee CSRs: remove `define for mstatus CSR handling 2019-07-29 15:55:48 +01:00
Pirmin Vogel
a7f344b02a Avoid linting errors 2019-07-29 15:52:42 +01:00
Pirmin Vogel
6d72aebc16 Correct cause number for illegal instruction exception
This bug has beed reported by @taoliug. This resolves #195.
2019-07-26 11:38:09 +01:00
Pirmin Vogel
1aa276dbc0 RVFI: re-add accidentally removed rvfi_intr signal
This signal is now set during the first instruction after the PC has
been set to enter a trap handler.
2019-07-26 09:30:45 +01:00
Pirmin Vogel
0dee0ff1ec Adapt interrupt IF for Arty example, tracer and TB 2019-07-24 18:58:26 +01:00
Pirmin Vogel
72c77f855d Remove legacy interrupt controller
This removal got partially lost while rebasing for PR #149.
2019-07-24 15:57:36 +01:00
Pirmin Vogel
be975eaa9d Add mstack CSRs for recoverable NMIs
To enable recoverable non-maskeable interrupts (NMIs), an additional
set of registers is needed to backup `mstatus.MPP/MPIE` as well as
`mepc` and `mcause`. This is currently not part of the RISC-V Priv
Spec (v1.11). This commit adds these registers called `mstack` CSRs
according to the following proposal:
https://github.com/riscv/riscv-isa-manual/issues/261

These CSRs are only accessed by the hardware and not accessible to
software running on the core.
2019-07-24 14:22:00 +01:00
Pirmin Vogel
327d836281 Add non-maskeable interrupt (NMI) 2019-07-24 14:22:00 +01:00
Pirmin Vogel
71a33e1ca1 Add local fast interrupts, remove legacy interrupts
This commit adds 15 local fast interrupt lines managed through
the `mie` and `mip` CSRs directly, and removes the old legacy
interrupts including the internal controller.
2019-07-24 14:22:00 +01:00
Pirmin Vogel
c2fffe0440 Add mip and mie CSRs + interrupts
This commit adds the `mip` and `mie` CSRs as well as the software,
timer and external interrupts.

Currently these interrupts are overlapped with some of the legacy
interrupts, i.e., the core will jump to the same address for different
interrupts. For example, the software interrupt has the same ID as
legacy interrupt #3. Thus, the handler must read the `mip` register
to find out whether the interrupt routine has been entered because of
the software interrupt or the legacy interrupt.

Eventually, the number of legacy interrupts will be reduced to avoid
this overlapping, and they will be connected to the `mie` and `mip`
CSRs directly.
2019-07-24 14:22:00 +01:00
Philipp Wagner
1a487c4626 ibex_tracer: Move imports into module 2019-07-23 19:45:48 +01:00
Philipp Wagner
bcaead3ea6 ibex_tracer: Remove Verilator gating
We want people to get an error when compiling the tracer with Verilator:
this file should not be used with Verilator. An error is better than
silently getting the wrong result.
2019-07-23 19:45:48 +01:00
Philipp Wagner
62f3573f2b Rework how tracer is instantiated and called
This change is slighly painful, but a necessary cleanup around the
tracer.

- We now provide a separate core file for the tracer, called
  "ibex_tracer.core" (in line with "ibex_tracer.sv"). The core is called
  "lowrisc:ibex:ibex_tracer".
- The toplevel wrapper with tracing enabled got renamed to
  "ibex_core_tracing.sv", and the core file is correspondingly called
  "ibex_core_tracing.core. The core in it is called
  "lowrisc:ibex:ibex_core_tracing".
- Finally to keep symmetry, the toplevel of Ibex itself got renamed in
  the core file from "lowrisc:ibex:ibex" to "lowrisc:ibex:ibex_core".
  This ensures that we have the same name for the core file, the source
  entry point, and the core name.

IMPORTANT NOTE:
If you apply this change and use fusesoc, you need to adjust the name of
the core dependency from "lowrisc:ibex:ibex" to
"lowrisc:ibex:ibex_core".
2019-07-23 19:45:48 +01:00
Philipp Wagner
428d057c4a Rename ibex_[tracer_]define to ibex_[tracer_]pkg
This file doesn't contain defines any more, but a normal SV package.

The diff is best viewed without whitespace changes, as the reindents
cause a lof of diff noise.

Fixes lowrisc/ibex#173
2019-07-19 11:34:40 +01:00
Philipp Wagner
6d533f07a4 Remove tracer defines from other description files
The ibex_tracer_define.sv file was removed from the FuseSoC core files,
but not from the src_files.yml (for Bender) and the .f file.

This is in line with the changes made in
f12b94c2a2.
2019-07-19 11:34:40 +01:00
Pirmin Vogel
e4383589eb Decoder: remove reg-reg load, make LWU illegal
The custom reg-reg load instruction was added in the original design but
is no longer needed. This commit removes it. Also, load instructions
with `instr[14:12] == 3'b110` are now decoded as illegal.

This resolves #25.
2019-07-19 11:29:33 +01:00
Pirmin Vogel
04f4cd44f6 Decoder: avoid setting PC upon illegal JALR instructions
Without this commit, the PC is still set to a possible wrong jump
target on illegal JALR instructions ultimately causing the wrong PC
being saved to `mepc` during the illegal instruction exception.

This bug has been reported by @taoliug. This commit resolves #170.
2019-07-18 15:52:26 +01:00
Pirmin Vogel
63702b3e75 ID/EX stage: do not write to register file upon load errors
This commit fixes the write back FSM to not store values returned from
memory to the register file when the LSU is reporting a load error.

This bug was reported by @ivanmgribeiro. This commit resolves #162.
2019-07-18 11:28:13 +01:00
Pirmin Vogel
010985a395 Controller: save next PC to dpc CSR upon a halt request
This commit changes the controller to save the PC of the next
instruction to the dpc CSR when entering debug mode upon a halt
request instead of the PC of the current instruction (only valid
for EBREAK instructions).

This bug was reported by @taoliug. This resolves #164.
2019-07-17 11:17:37 +01:00
Pirmin Vogel
5925449848 Decoder: fix signaling and detection of illegal instructions
This commit fixes two bugs in the decoder:

1. For illegal branch condition selections, the illegal instruction
condition must be signaled as long as the instruction is being executed
and not just during the first cycle, as the controller cannot interrupt
multicycle instructions.

2. Illegal instructions should also be signaled when `instr[28]` is set
for register-register ALU operations. Previously, these were not
signaled as the original design used `instr[28]` to encode custom bit-
manipulation instructions.

These bugs were discovered by @taoliug. This resolves issue #163.
2019-07-17 11:04:15 +01:00
Tobias Wölfel
ff50ac8c59 Uncompressed instructions for tracer (#154)
The tracer does not support the decoding of compressed instructions.
Forward the internally used decoded instruction and use it for tracer.
2019-07-16 12:43:38 +02:00
Tobias Wölfel
d059979af6 RVFI based on core state (#151, fix #147)
The RVFI implementation make use of signals from the decoder and
controller to detect the state of the processor.
Especially the signal for a new and retired instruction.
2019-07-16 12:43:38 +02:00
Tobias Wölfel
b8e1f552b4 Cleanup unused define 2019-07-16 12:43:38 +02:00
Pirmin Vogel
a38389e3a2 Remove linting errors for RVFI-related signals 2019-07-16 10:12:01 +01:00
Pirmin Vogel
a775abd967 Fix dpc CSR not updated (#157)
* Controller: remove impossible condition for `DBG_TAKEN_IF`

There is no way to jump into `DBG_TAKEN_IF` because of an EBREAK
instruction. Thus, this case also does not need to be checked.

* Controller: do not enter debug when `debug_req_i` goes low

With this commit, the core is prevented from entering debug mode when
the debug request signal is deasserted during that procedure.
Previously, the core would still enter debug mode but not updating the
debug CSR.

This resolves #153 reported by @taoliug.

* Update ibex_controller.sv
2019-07-15 10:37:33 -07:00
Pirmin Vogel
c437008310 CSRs: replace _n suffix of register signals by _d 2019-07-15 15:33:29 +01:00
Pirmin Vogel
b1df836940 Controller FSM: simplify debug_mode_q-related control
The FSM now uses input signals for interrupt and debug request handling
that depend on whether the core is in debug mode. This avoids the need
for many `debug_mode_q` guards and somewhat simplifies the FSM.

If in debug mode, the core shall not handle interrupts according to the
spec anyway.
2019-07-15 15:33:29 +01:00
Pirmin Vogel
0dafd51b97 Generate instr_ret/compressed inside ID stage
This commit moves the generation of these signals into the ID stage
to generate it with more accurate timing. More precisely, an
instruction is now considered as retired once it has been completely
executed and not once the next instruction is pushed into the IF-ID
pipeline register.

Also, it no longer depends on whether the instruction was valid or
illegal. For RVFI and the tracer, also illegal instructions must be
considered.
2019-07-15 13:20:26 +01:00
Pirmin Vogel
c1bceb2f89 ID stage: remove unneeded branch_in_id signal 2019-07-11 17:35:12 +01:00
Pirmin Vogel
2319e1ec87 Use decoder regfile write enable for non-LSU/mult/div ops
Previsouly, the regfile write enable output of the decoder was always
fed through the WB FSM which is unnecessary except for stores and
mult/div operations.
2019-07-11 17:35:12 +01:00
Pirmin Vogel
5b0e81ecd2 Move store/load_err_i into separate exc_req_lsu signal 2019-07-11 17:35:12 +01:00
Pirmin Vogel
795b5bd651 Cleanup performance monitor signals 2019-07-11 17:35:12 +01:00
Pirmin Vogel
6b5d26bae2 Cleanup interplay of IF and ID stage (controller)
Once the core is executing, the IF stage now only gets two signals
from the controller: One to clear the instruction valid output and one
to prevent the IF stage from pushing new instructions.

The former `if_valid_o` of the IF stage has been renamed to clarify
that this is not a valid bit but just the write enable for the
pipeline register.
2019-07-11 17:35:12 +01:00
Pirmin Vogel
1456e8e0da Rework register file write enable mux
The register file shall not be written upon illegal CSR operations
and when the core is idle (waiting for new instructions). Otherwise
the write enable signal from the WB FSM/decoder is used.
2019-07-11 17:35:12 +01:00
Pirmin Vogel
e47b500c50 Remove obsolete signals between controller and ID stage 2019-07-11 17:35:12 +01:00
Pirmin Vogel
45dadcd5bd Cleanup controller 2019-07-11 17:35:12 +01:00
Pirmin Vogel
35a5a737a7 Do not set PC when setting exceptions registers in single stepping
In the next state, the PC is set to jump into debug anyway.
2019-07-11 17:35:12 +01:00
Pirmin Vogel
3e1c8df311 Correctly prioritize exceptions in controller 2019-07-11 17:35:12 +01:00
Pirmin Vogel
95c0dc0556 Fix handling of single stepping
Single stepping should execute exactly one more instruction, not abort
any running (multicycle) instructions, and only enter debug mode after
the current instruction is finished. In case the current instruction
leads to an exception, the exception registers must be set accordingly,
but the core must jump into debug mode instead of the exception
handler.

Previous to this commit, single stepping would immediately jump into
debug mode and ignore any exceptions.
2019-07-11 17:35:12 +01:00
Pirmin Vogel
9ef3c13f87 Fix control for interrupts, debug request and multicycle instr
This commit makes sure that interrupts and debug requests do not
interrupt currently running multicycle instructions. Priority is
given 1) to the currently running instruction, possible exceptions
caused by this instruction, 2) debug requests, 3) interrupt
requests.

Previously, currently running instructions were aborted upon
incoming debug and interrupt requests, which could corrupt the
processor state and lead to exceptions being ignored.

This commit resolves #108 and #121.
2019-07-11 17:35:12 +01:00
Pirmin Vogel
fd6426f52c Replace pipe_flush signal by wfi_insn
This signal is triggered iff a `wfi` instruction is decoded.
2019-07-11 17:35:12 +01:00
Tobias Wölfel
1df87f4400 Add fence instruction to tracer (#134) 2019-07-11 13:25:18 +01:00
Tobias Wölfel
014c753dde Tracer rewrite
Instantiate tracer module in a separate core file and use only RVFI
signals.
2019-07-11 13:25:18 +01:00