RISC V Intro For Hackathon
RISC V Intro For Hackathon
A First Introduction
Dr. Adam Teman
Udi Kra
3 November 2019
Who and why?
• The EnICS Labs Impact Center at Bar-Ilan University.
• Focal point of the GenPro Consortium, developing the Israeli RISC-V Platform.
• Developing the PULPEnIX SoC Platform, available for use in the Hackathon.
What are
Embedded Systems ?
Embedded Systems
• When we discuss computers, we usually think of desktops, laptops, tablets…
• But there’s another far more common type of computing system:
• The Embedded System.
• A computing system embedded within an electronic device.
• An embedded system is a special-purpose computer system
designed to perform one or more dedicated functions often in real-time
• Embedded Controller:
• No operating system (“Bare Metal”), small operating system (e.g.,
FreeRTOS), or perhaps full blown Linux-compatible.
• Can code in high-level language (e.g., C) and compile, write
directly in Assembler, or add task-specific hardware (accelerators).
Source: Embedded Systems Design:
A Unified Hardware/Software Introduction © Adam Teman, 2019
Embedded System Example – Digital Camera
• Single-functioned
• Always a digital camera
• Tightly-constrained
• Low cost
• Low power
• Small
• Fast
• Reactive and real-time
• Only to a small extent
• Memory
• Input/Output (I/O) circuitry
• Buses
• Address bus
• Data bus
• Control bus
• Essentially, this is an entire
system integrated on a single
chip:
A System-on-Chip (SoC)
7 Source: Farahmand, Sonoma State © Adam Teman, 2019
Memory Mapped I/O
Just an important concept that is sometimes missed by undergrad students…
• Basically everything in an SoC is a memory address:
• Data is, of course, stored in memory.
• Instructions are stored in the same memory
space as data in a “Von Neumann Architecture”
• And any peripheral or bus connection is
just a memory address.
• This is known as “Memory Mapping”
or “Memory Mapped I/O” https://softwareengineering.stackexchange.com
RISC-V Basics
13
ISA Overview
• The RISC-V Base Integer ISA:
• Two options: RV32I (32-bit) and RV64I (64-bit)
• Must be present in any implementations.
• RV32E is a small microcontroller subset and RV128I is a future 128-bit ISA.
• Standard Instruction Set Extensions:
• M: integer multiply, divide, remainder
• A: atomic memory operations
• F: single-precision floating point
• D: double-precision floating point
• G: All of the above (“IMAFD”)
• C: compressed instructions
• 16-bit encoding for frequently used instructions
14 © Adam Teman, 2019
RISC-V Registers
• Unlike HLL like C or Java, assembly
cannot use variables
• Assembly Operands are registers
• limited number of special locations built
directly into the hardware
• operations can only be performed on these!
• RISC-V has 32 Registers of 32-bits each
• 32-bits is a word in RV32, 64-bits in RV64
• Registers are called x0-x31
• With the ABI, we’ll give them more comprehensible names
• Floating Point adds 32 floating point registers: f0, f1, … f31
Source:
P&H, Ch. 2
22
Steps in Compiling and Running a C Program
gcc -O2 -S -c foo.c foo.c C program: foo.c
• Compiler
Compiler
• Input: High-Level Language Code (foo.c)
• Output: Assembly Language Code (foo.s) foo.s Assembly program: foo.s
Object: foo.o
Linker
Executable: a.out
Loader
Memory
• Compiler
Compiler
• Input: High-Level Language Code (foo.c)
• Output: Assembly Language Code (foo.s) foo.s Assembly program: foo.s
• Assembler
foo.o Object: foo.o
• Input: Assembly Language Code (foo.s)
• Output: Object Code, information tables (foo.o) Linker
• Linker
Compiler
• Input: Object code files, information tables
(e.g., foo.o,libc.o) foo.s Assembly program: foo.s
• Output: Executable code (a.out)
• Combines several.o files into a single executable Assembler
• Loader
a.out Executable: a.out
• Input: Executable Code (a.out)
• Output: Code is loaded into memory Loader
Introduction to PulpEnIX
29
PulpEniX
• PulpEnIX (nickname for PULP-Enics) is EnICS SoC/RISC-V research platform.
Forked from open-source PULP platform https://www.pulp-platform.org/
Boot ROM
& Accelerators Instr. RI5CY
Data
Bridge
Bridge
based
TCM Core TCM
debug
AXI Interconnect
Direct access GPP SOC IO Region
General SOC
Functional Event/Intrpt
Timers Misc. DEBUG BRIDGE
Control/Debug
Purpose Unit
Accelerators Port
Control
Remote Access
APB
Flash device
© Adam Teman, 2019
The RI5CY Core
• RI5CY is a 4-stage, in-order 32b RISC-V processor core.
• The ISA of RI5CY was extended to support additional instructions including:
• Hardware loops
• Post-increment load
and store instructions
• And additional ALU
instructions that are
not part of the standard
RISC-V ISA.
Direct access
Functional
Accelerators
FPGA/ASIC GPP
SMART REMOTE General Purpose Port
python shell
TERMINAL
IOSIM SPI/UART
Emulated SLAVE
Simple Host Interface
Terminal Interface
File interface
DEBUG BRIDGE
Handle GDB commands
TCP socket Access memory space
And Core debug port over AXI
GDB
C/C++
Source GCC 7.1 official
ELF
Code image ECLIPSE
RI5CY GCC
+ debug info
extensions support
UART JTAG
GATEWAY
(HW)
Bridge
(SW)
• Good Luck!