Logic Design 1
Logic Design 1
3 October-December, 2021
Sudong Kang
Department of Information and Communication Engineering, Hanbat National University, Daejeon, 34158, South Korea
sudongkang@gmail.com
Dennis A. N. Gookyi
Department of Information and Communication Engineering, Hanbat National University, Daejeon, 34158, South Korea
dennisgookyi@gmail.com
Guard Kanda
Department of Information and Communication Engineering, Hanbat National University, Daejeon, 34158, South Korea
guardkanda@gmail.com
Kwangki Ryoo*
Department of Information and Communication Engineering, Hanbat National University, Daejeon, 34158, South Korea
kkryoo@gmail.com
855
1. Introduction file, PC, instruction memory, and data memory.
A verification platform is built and loaded onto an
The Central Processing Unit (CPU) is an electronic circuit FPGA board for inputting instruction and observing the data
designed specifically to execute instructions called programs. in the internal architecture of the processor
The CPU executes many forms of instructions such as The rest of this paper is organized as follows: Section 2
arithmetic and logic instructions as well as memory access discusses some related works, Section 3 gives an introduction
instructions. These instructions which are specific to each to the RISC-V ISA, Section 4 illustrates the design and
CPU vendor are collectively known as the ISA. The ISA implementation of the 32-bit single cycle RISC-V ISA,
describes a specific instruction set that can be compiled by Section 5 describe the verification module for testing the
dedicated compilers and translated into machine codes. There processor core, Section 6 present the hardware resource
are many systems in today's society that require very large utilized by the processor core together with the peripheral
computations such as deep learning and image-based modules while the conclusion of the paper is discussed in
processing. Therefore, the demand for embedded systems Section 7.
requiring low power, low cost, and high performance is also
increasing. The paper in [1] gives an example of a system that 2. Related Work
efficiently recognizes vehicle license plate using an
embedded systems and AI. In addition, the usability of IoT is Since the introduction of the RISC-V ISA in the last decade,
gaining popularity and increasing user convenience based on several processor cores have been proposed and implemented
its applicability in real life. Using the Lora module, paper [2] for different reasons. Most the processor cores are meant for
designed a system that broadcasts kindergarten school bus academic use while a few others are commercial. The
location notifications to users on SMS or apps on mobile academic processor cores are designed with interfaces for
devices. Among them, processors are indispensable easy integration into an SoC. This is good for advances
components. But the commercially available ISAs belong to hardware engineers to quickly assemble an SoC but very
companies such as Intel and AMD which include the x86 difficult for beginners to understand the working of the
family of ISAs [3], [4]. These ISAs are patented and cannot processor core. This section therefore explores RISC-V
be used without license that cost a lot of money and thereby processor cores with input/output peripherals that enable a
preventing researchers in academia and hobbyist from using designer to gain understanding of the internal operation of the
them. Moreover, the licenses prevent designers from processor cores.
implementing the ISAs but instead limits them to use the The authors of [11] implemented the RISC-V ISA with
processor cores provided by the companies. This prevents instruction which include environment call, break, status
competition, innovation, and sometimes trust issues as registers, control, branch, memory, and arithmetic logic. A
companies could imbed malicious circuitry in the processor total of 38 instructions were simulated using ModelSim and
for spying [5]. Quartus-II simulators. This work only resulted to functional
The licensing issue associated with commercial processor is simulation without real hardware implementation on an
solved by the design of a new ISA known as RISC-V [6], [7] FPGA board. This makes it difficult to know if the processor
by the computer architecture group in University of will work in the real world.
California, Berkeley. The RISC-V ISA is an open-source ISA The authors of [12] proposed an Integrated Machine Code
available for implementation under the free Berkeley open- Monitor (iMCM) and implemented together with a RISC-V
source license. The RISC-V project started in 2010 and has processor on an FPGA. The iMCM monitors functions
rapidly grown with their board of directors that come from according to the verification method of the RISC-V
companies such as NVIDIA and Google. There are a number processor. A total of 27 compressed RISC-V ISA instructions
of open-source processors that implement the RISC-V ISA were monitored through simulations and FPGA evaluation.
which include Rocket [8], Berkeley Out of Order Machine The verification of the processor instruction is through a
(BOOM) [8], PICORV32 [9] and many more. These terminal to displays only the memory related commands and
processors are complex with pipelined structures that achieve the results of the program trace in hexadecimal values. This
high throughput with low hardware footprint [10]. These makes it difficult to understand the actual internal operations
processors are therefore difficult to understand by researchers of the processor under evaluation.
seeking information about the RISC-V ISA architecture. This The work that comes close to this paper is proposed by [13].
paper therefore implements a 32-bit single cycle RISC-V ISA The author of [13] proposed and implemented a fully
core with peripherals to monitor the internal operations of the synthesizable RISC-V processor core on an FPGA device to
processor. text LCD display port. A user inputs Assembly code which is
The objectives of this paper are as follows converted to machine code and executed by the processor
The paper illustrates design and implementation of with the results displayed on the text LCD. The text LCD
the control and datapath for a 32-bit single cycle RISC-V ISA shown only current PC value and the results of executed
core using Verilog HDL RISC-V instruction. The work of [13] is extended with
Hardware controllers for peripherals such as seven- peripherals such as seven-segment display, LEDs, dot matrix,
segment display, text LCD, dot matrix, LEDs, and keypad are and keypad to form the basis of this paper. The displays show
added to monitor the internal activities of the processor core. the internal content of the processor which include the PC,
This is done to provide an easy way to input instruction and register file, instruction memory, and the data memory. These
observe the internal data of components such as the register displayed values are shown for each RISC-V instruction
856
which makes it easy to understand the internal operation of a RV32/64/128M Extension for Integer Multiplication
typical RISC-V processor core. and Division Instructions
RV32/64/128A Extension for Atomic Instructions
3. RISC-V ISA Technical Specification RV32/64/128F Extension for Single-Precision
Floating-Point Instructions
The RISC-V ISA is a load-store ISA based on the principles RV32/64/128D Extension for Double-Precision
of RISC. The load-store ISA format typically divide Floating-Point Instructions
instructions into two groups which include memory access
(where only store and load instructions have access to There are a total of 32 registers used by the RISC-V ISA out
memory) and ALU operations (where the operands are in of which 31 are general purposed registers (register x1 to x31)
registers). The simplicity of the RISC-V ISA design makes it while one register (register x0) is hardware wired to a
possible execute instructions in just one clock cycle. constant 0. In addition to the 32 registers, a special register is
RISC-V has a base ISA which is referred to as RISC-V 32- used to store the address of the current instruction known as
bit Integer (RV32I) which is compulsory for any the PC register. The width of the registers could be 32-bit, 64-
implementation. The RV32I instructions which include loads, bit, or 128-bit depending on the implementation.
stores, control flow, and integer computations. The RV32I The RISC-V ISA consists of six main instruction formats
instructions can be extended to include multiplication and which include, R-type (register-register instructions), I-type
division (RV32IM), atomic operations (RV32IA), single (loads and jump-and-link instructions), S-type (store
precision floating point (RV32IF), and double precision instructions), B-type (branch instructions), U-type (load-
floating point (RV32ID). These extensions are optional to upper-immediate instructions), and J-type (jump
implement. It must be noted that the RISC-V ISA also allows instructions). Figure 1 illustrates the various instruction
for data widths of 64-bit and 128-bit as shown in Table 1 but format [14], [15] where funct stands for function, opcode
this paper implements a data width of 32-bit. stands for operation code, imm stands for immediate, rd
Table 1: Summary of RISC-V ISAs stands for destination registers, rs1 stands for source register
ISA Description 1, and rs2 stands for source register 2.
RV32/64/128I Base Integer Instruction Set
857
Figure 2. RISC-V RV32I Base Instruction Set
4. RV32I ISA Single Cycle Processor Hardware of this work is to help researchers understand the inner
Architecture workers of the RISC-V processor, the implementation of the
RV32I ISA is simplified. The hardware architecture of the
The hardware architecture for the RV32I ISA was designed RV32I ISA implementation is shown in Figure 3. The
by expanding on an architecture implemented in the RISC-V architecture is a single cycle design which means it is capable
book [15]. The authors of [15] implemented a basic RISC-V of fetching, decoding, and executing the 37 RISC-V
hardware architecture capable of executing a total of seven instructions in just a single cycle using components such as
instructions which include load doubleword (ld), store double the PC, ALU, register file, instruction memory, data memory,
word (sd), add, sub, and, or, and branch if equal (beq). This and some basic logic gates. This section examines each
architecture was expanded to execute a total of 37 instructions component of Figure 3.
and formed the basis of this work. Since the main objective
858
Figure 3. The Hardware Architecture of the RV32I ISA Design
by a factor of 1 to fetch all 32-bit instruction in the instruction
4.1. Program Counter Register memory. When executing B-type (branch), U-type (load-
The PC is a special register inside the processor that stores upper-immediate), and J-type (jump), the PC register stores
the address of the next processor instruction. The PC register the calculated value of the jump addresses. The output of the
in the RV32I ISA is has a data width of 32-bit. The instruction PC register is assigned to the instruction memory, register
is the machine code which is in the instruction memory. file, or the ALU depending on the type of instruction
Generally, in the design of a CPU, the PC is usually increased performed. Figure 4 shows a diagram of the PC register
by 4 during the normal instruction execution. The increased input/output signals.
by a factor 4 is because most CPUs are byte addressable. For
simplicity of the memory design, this work increases the PC
859
Figure 5. ALU Architecture
Two multiplexors with select signals from the instruction are
4.3. Register File Architecture used to route data to selected registers. The internal
The RV32I ISA consist of a total of 32 32-bit registers for architecture of the register file is made up 32x32 memory.
holding data. A register is a memory device that temporarily The value of ina, inb determines the address of the 32-bit
remembers the data that the processor needs to process the output ports outa, outb. The output signals are assigned to the
instruction. The registers are few but are directly connected Data Modification Module which in goes to the PC register
to the ALU which makes the computation and storage of depending on the type of instruction. Figure 6 shows the
intermediate data very fast. The register file implemented in input/output logic of the register file implemented in this
the work consist of five inputs and two outputs. The input work.
labeled ina, inb, and ind each of 5-bit width select the register
to write to or read from depending on the instruction type.
860
Figure 7. Data Modification Module Architecture
be read from the instruction memory. The 32-bit instruction
4.5. Instruction Memory from the output of the instruction memory is assigned to
The instruction memory is responsible for storing 32-bit modules such as the PC, register file, ALU, data memory, and
machine code (instructions). The instruction memory Data Modification Module. The 32-bit output serve as control
implemented in this work is made up of 32-bit data width with signal for activating the values modules depending on the
a depth of 512. This memory is read only and therefore only type of instruction to execute. Figure 8 illustrates the
needs an address port to get access to a particular instruction. input/output signal of the instruction memory.
The PC output port provides the address of an instruction to
861
Figure 9. Data Memory Input/Output
Execution
4.7. General Flow of RISC-V ISA
The typical operation of the RISC-V processor consists of 5. Hardware Verification Module of RISC-V Processor
five steps which include instruction fetch, decode, execute, A verification module is proposed to observe the
memory access, and writeback. Figure 10 shows the flow of functionality of the RISC-V RV32I processor core. This
a typical RISC-V processor operation. In the information module is important because it enables observers to easily
fetch stage, the PC output the address to the instruction understand the RISC-V ISA by observing real internal values
memory which make available the 32-bit instruction or when an instruction is operating. To observe the internal
machine code. The decode stage group the instruction code operation of the processor core, various peripherals are used
and sent to the various modules as control signals. In the to access real-time values from components such as registers,
execute stage, the various modules which the ALU, register PC registers, data memory, and instruction memory during
file, and Data Modification Module are used to perform the normal operation of the processor. Figure 11 shows the
instruction. In the memory access stage, data is read or stored various peripheral used to observe the internal operation of
in the data memory depending on the type of instruction. The the RISC-V processor. The peripherals and with their
writeback stage stores value in the register file depending on functionalities are shown in Table 1.
the type of instruction.
Figure 10. General Flow of RISC-V Instruction Figure 11. RISC-V Processor Verification Peripherals
Table 1: Functionalities of RISC-V Processor Verification Peripherals
Peripheral Functionality
USER SW1 button is used to increment of the PC by 1 while USER SW2 button is used
(a) Push Button
to increment the address of the instruction memory.
First row 2-4 displays status. First row 8-15 display user value entered. The second row
(b) Text LCD 2-5 display the current instruction. Second row 7-14 displays the current value in the
instruction memory.
(c) LEDs Eight LEDs are used to display the current PC value.
(d) 7-Segment Display The last two segments display the address of the instruction memory
The Dot matrix is used to display data stored in the instruction memory, data memory
(e) Dot Matrix
and register file.
The del button is used to delete an entered value. The ins button is used to insert an
(f) Keypad
entered value. Button 1 to 9 are used for entering the machine code.
(g) Dip Switch The first five are used to set the register and data memory address.
862
Figure 12. Connections of Peripheral to the FPGA Device
instruction code. By entering all the values of the instruction
Figure 13 shows the flow chart for checking RISC-V code, it is stored in FPGA instruction memory at the address
processor instructions on the FPGA board. When the FPGA previously specified. The USER SW1 button is used to
is powered up, all registers and memory locations are manually increase the value of the PC which is shown on the
initialized to zero. The user uses the keypad to insert a LED. The dip switch is used to display values from the
instruction that starts with the Operation Code (OPCODE). register file, instruction memory, and data memory on the dot
The USER SW2 button is used to set the instruction address matrix. Figure 14 illustrates the output of ADD UPPER
shown in seven segments before entering the instruction data. IMMEDIATE TO PC (AUIPC) instruction on the FPGA
The desired number of buttons are used to insert the board.
863
Figure 14. Display of AUIPC RISC-V Instruction of an
FPGA Board
864
15. David AP, John LH. Computer organization and
design: The hardware/software interface, RISC-V 5th edn,
Elsevier, 2017.
865