dipl/sections/core/core.tex

76 lines
3.7 KiB
TeX
Raw Permalink Normal View History

2020-03-22 18:54:41 +01:00
\documentclass[../../Diplomschrift.tex]{subfiles}
2020-03-01 17:13:51 +01:00
\begin{document}
2020-03-30 15:20:53 +02:00
\section{The Core}
2020-03-01 17:13:51 +01:00
The core implements the \instrset{} architecture as specified by the RISC-V standard~\cite{riscv-spec-unprivileged}.
2020-03-01 17:13:51 +01:00
2020-03-30 23:38:10 +02:00
\begin{figure}[h]
\includegraphics[width=\textwidth]{core_diagram.png}
\caption{Block diagram of the CPU core}
\label{fig:core-diagram}
\end{figure}
As can be seen in \ref{fig:core-diagram}, it is constructed according to the traditional stages of a RISC pipeline:
2020-03-01 17:13:51 +01:00
\begin{description}
\item[Fetch] fetches the next instruction from memory.
\item[Decode] decodes the instruction into its constituent parts. At the same time, operand values are loaded from any required registers.
\item[Execute] performs the action required by the instruction, such as math performed by the Arithmetic Logic Unit (ALU) or writing to Control and Status Registers (CSRs).
\item[Memory] loads values from or stores values to the system's main memory or interacts with memory-mapped hardware devices.
\item[Writeback] stores a potential result value from Execute or Memory stages to the destination register.
\end{description}
2020-03-30 15:20:53 +02:00
\subsection{Control}
2020-03-01 17:13:51 +01:00
2020-03-27 14:20:22 +01:00
\entityheader{control}
2020-03-01 17:13:51 +01:00
The control unit is responsible for coordinating subcomponents and the data flow between them. Internally, it is based on \icode{instruction\_info\_t} structures, which contain all the information required to pass an instruction along the different pipeline stages. Before the fetch stage, when an instruction is first scheduled, it contains only the instruction's address (because nothing else is known about it). Then, information is added incrementally by the different stages.
2020-03-30 15:20:53 +02:00
\subsection{Decoder}
2020-03-01 17:13:51 +01:00
2020-03-27 14:20:22 +01:00
\entityheader{decoder}
2020-03-01 17:13:51 +01:00
The decoder receives an instruction and interprets it. Among others, it determines
\begin{itemize}
\item The source and destination register addresses
\item The pipeline stages that need to be run for the instruction
\item The ALU operation, if any
\item Whether the instruction should branch, and if so, under what condition
\end{itemize}
2020-03-30 15:20:53 +02:00
\subsection{Registers}
2020-03-01 17:13:51 +01:00
2020-03-27 14:20:22 +01:00
\entityheader{registers}
2020-03-01 17:13:51 +01:00
The registers store the 32 general-purpose values required by \instrset{} (each 32-bit wide). They are accessible through two read ports and one write port. As specified by the RISC-V standard, the first register (\icode{x0}) is hard-wired to 0, and any writes to it are ignored.
2020-03-30 15:20:53 +02:00
\subsection{Arithmetic and Logic Unit (ALU)}
\label{sec:core-alu}
2020-03-01 17:13:51 +01:00
2020-03-27 14:20:22 +01:00
\entityheader{alu}
2020-03-01 17:13:51 +01:00
The ALU contains a math/logic unit as well as a comparator. It is used both explicitly by instructions such as \icode{add} or \icode{shiftl}, as well as to add offsets to base addresses for memory instructions and to decide whether an instructions should branch.
2020-03-30 15:20:53 +02:00
\subsection{Control and Status Registers (CSR)}
2020-03-01 17:13:51 +01:00
2020-03-27 14:20:22 +01:00
\entityheader{csr}
2020-03-01 17:13:51 +01:00
The control and status registers contain configurations relevant to the core itself. For example, they can be used to control interrupts.
2020-03-30 15:20:53 +02:00
\subsection{Memory Arbiter}
2020-03-01 17:13:51 +01:00
2020-03-27 14:20:22 +01:00
\entityheader{memory_arbiter}
2020-03-01 17:13:51 +01:00
Since both fetch and memory stages need to access the same system memory, access to this common resource has to be controlled. The memory arbiter acts as a proxy for both fetch and data memory requests and stalls either until the other one completes.
2020-03-30 15:20:53 +02:00
\subsection{Exception Control}
2020-03-01 17:13:51 +01:00
2020-03-27 14:20:22 +01:00
\entityheader{exception_control}
2020-03-01 17:13:51 +01:00
Several components in the core may raise a synchronous exception when an unexpected error (such as a malformed instruction or an unaligned memory access) occurs. Additionally, asynchronous interrupts (like from a timer or a UART) can be triggered externally. When an exception or an enabled interrupt is registered, program flow is diverted to the trap handler, defined using the machine trap vector (\icode{mtvec}) CSR.
\end{document}