I'm trying to design a processor in VHDL. While the base instruction set is done, I'm having trouble building on top of it.
Specifically, I'm implementing control and status registers (CSRs), which allows the system to be controlled to a greater degree.
These CSRs do not need an instruction to be altered, they can change based on the state of the machine. This comes with a set of data hazards that I have been trying to solve. There are not many existing resources that offer solutions to these hazards.
Rules:
All instructions which associate with these registers are atomic instructions which are meant to swap the CSR value with a general purpose value.
Hazard 1: RAW
The register is read from, and the CSR are read from on one clock cycle of the pipeline. On the next clock cycle, the values are written. During this time, the CSR may have changed.
Hazard 2: interrupt WAW Something in the processor triggers an interrupt, And changes a whole bunch of registers at once. In the pipeline, however, there is an instruction which writes to a CSR which has been modified. This corrupts the register.
What are some common ways to remedy these hazards?