All Projects → mariusmm → RISC-V-TLM

mariusmm / RISC-V-TLM

Licence: GPL-3.0 license
RISC-V SystemC-TLM simulator

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
Makefile
30231 projects
assembly
5116 projects
Dockerfile
14818 projects
CMake
9771 projects

Projects that are alternatives of or similar to RISC-V-TLM

Zelda.RISCV.Emulator
A System Level RISCV32 Emulator Over x86_64: capable of booting RISCV Linux
Stars: ✭ 18 (-85.6%)
Mutual labels:  riscv
KyogenRV
The Simple 5-staged pipeline RISC-V written in chisel3 for intel FPGA.
Stars: ✭ 37 (-70.4%)
Mutual labels:  riscv
RiscvSpecFormal
The RiscvSpecKami package provides SiFive's RISC-V processor model. Built using Coq, this processor model can be used for simulation, model checking, and semantics analysis. The RISC-V processor model can be output as Verilog and simulated/synthesized using standard Verilog tools.
Stars: ✭ 69 (-44.8%)
Mutual labels:  riscv
tornado-os
异步内核就像风一样快!
Stars: ✭ 264 (+111.2%)
Mutual labels:  riscv
ravel
A RISC-V simulator
Stars: ✭ 24 (-80.8%)
Mutual labels:  riscv
pulp soc
pulp_soc is the core building component of PULP based SoCs
Stars: ✭ 43 (-65.6%)
Mutual labels:  riscv
jonesforth riscv
Jonesforth RISC-V port.
Stars: ✭ 50 (-60%)
Mutual labels:  riscv
arv
ARV: Asynchronous RISC-V Go High-level Functional Model
Stars: ✭ 18 (-85.6%)
Mutual labels:  riscv
sedna
Sedna - a pure Java RISC-V emulator.
Stars: ✭ 52 (-58.4%)
Mutual labels:  riscv
rv32emu
RISC-V RV32I[MAC] emulator with ELF support
Stars: ✭ 61 (-51.2%)
Mutual labels:  riscv
systemc-compiler
This tool translates synthesizable SystemC code to synthesizable SystemVerilog.
Stars: ✭ 128 (+2.4%)
Mutual labels:  systemc
yarvi
Yet Another RISC-V Implementation
Stars: ✭ 59 (-52.8%)
Mutual labels:  riscv
riscv em
Simple risc-v emulator, able to run linux, written in C.
Stars: ✭ 51 (-59.2%)
Mutual labels:  riscv
yatcpu
Yet another toy CPU.
Stars: ✭ 42 (-66.4%)
Mutual labels:  riscv
GeeOS
The Gee (寂) Operating System, written in YuLang.
Stars: ✭ 22 (-82.4%)
Mutual labels:  riscv
nuclei-sdk
Nuclei RISC-V Software Development Kit
Stars: ✭ 65 (-48%)
Mutual labels:  riscv
vcml
A modeling library with virtual components for SystemC and TLM simulators
Stars: ✭ 44 (-64.8%)
Mutual labels:  systemc
Fuxi
Fuxi (伏羲) is a 32-bit pipelined RISC-V processor written in Chisel3.
Stars: ✭ 68 (-45.6%)
Mutual labels:  riscv
mdepx
MDEPX — A BSD-style RTOS
Stars: ✭ 17 (-86.4%)
Mutual labels:  riscv
rvkrypto-fips
FIPS and higher-level algorithm tests for RISC-V Crypto Extension
Stars: ✭ 18 (-85.6%)
Mutual labels:  riscv

Another RISC-V ISA simulator.

This code is suitable to hard refactor at any time

This is another RISC-V ISA simulator, this is coded in SystemC + TLM-2. It supports RV32IMAC Instruction set by now.

travis Codacy Badge Coverity Scan Build Status license last commit commit activity Docker Twitter URL

Table of Contents

Description

Brief description of the modules:

  • CPU: Top entity that includes all other modules.
  • Memory: Memory highly based on TLM-2 example with read file capability
  • Registers: Implements the register file, PC register & CSR registers
  • Instruction: Decodes instruction type and keeps instruction field
  • BASE_ISA: Executes Base ISA, Zifencei and Zicsr.
    • C_extension: Decodes & Executes Compressed instructions (C extension)
    • M_extension: Decodes & Executes Multiplication and Division instructions (M extension)
    • A_extension: Decodes & Executes Atomic instructions (A extension)
  • Simulator: Top-level entity that builds & starts the simulation
  • BusCtrl: Simple bus manager
  • Trace: Simple trace peripheral
  • Timer: Simple IRQ programable real-time counter peripheral
  • Debug: GDB server for remote debugging (Beta)

Helper classes:

  • Performance: Performance indicators stores here (singleton class)
  • Log: Log class to log them all (singleton class)

Current performance is about 3.000.000 instructions / sec in a Intel Core i5-5200@2.2Ghz and about 4.500.000 instructions / sec in a Intel Core i7-8550U@1.8Ghz.

Trace perihperal creates a xterm window where it prints out all received data.

Structure

Modules' hierarchy

Memory map

Base Module Description
0x40000000 Trace Output data to xterm
0x40004000 Timer LSB Timer
0x40004004 Timer MSB Timer
0x40004008 Timer MSB Timer Comparator
0x4000400C Timer LSB Timer Comparator

TODO

This is a preliminar and incomplete version.

Task to do:

  • Implement all missing instructions (Execute)
  • Implement CSRs (where/how?)
  • Add full support to read file with memory contents (to memory.h)
    • .elf files
    • .hex files (only partial .hex support)
  • Connect some TLM peripherals
    • Debug module similiar to ARM's ITM
    • Some standard UART model
    • ...
  • Implement interrupts
    • implement timer (mtimecmp) & timer interrupt
    • generic IRQ comtroller
  • Test, test, test & test. I'm sure there are a lot of some bugs in the code
    • riscv-test almost complete (see Test)
    • riscv-compliance
  • Improve structure and modules hierarchy
  • Add 64 & 128 bits architecture (RV64I, RV128I)
  • Debug capabilities

Compile

In order to compile the project you need SystemC-2.3.2 installed in your system. Just change SYSTEMC path in Makefile.

$ make

Then, you need to modifiy your LD_LIBRARY_PATH environtment variable to add path systemc library. In my case:

$ export LD_LIBRARY_PATH=/home/marius/Work/RiscV/code/systemc-2.3.2/lib-linux64

And then you can execute the simulator:

$ ./RISCV_TLM asm/BasicLoop.hex

Using cmake

It is possible to use cmake:

mkdir build
cd build
cmake ..
make

note that SystemC must be compiled with cmake:

cd <systemc directory>
mkdir build
cd build
cmake ../ -DCMAKE_CXX_STANDARD=17
make

Arguments

-L loglevel: 3 for detailed (INFO) log, 0 to ERROR log level

-f filename .hex filename to use

-D Enter in Debug mode, simulator starts gdb server (Beta)

Cross-compiler

It is possible to use gcc as risc-v compiler. Follow the instructions (from https://github.com/riscv/riscv-gnu-toolchain):

$ git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
$ cd riscv-gnu-toolchain
$ ./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32
$ make
...
wait for long time ...
...
$ export PATH=$PATH:/opt/riscv/bin

In test/C/long_test/ example there is a Makefile that compiles a project with any .c files and links them against new-lib nano. There is a Helper_functions.c file with defiitions of all missing functions needed by the library (_read(), _close(), _fstat_r(), _lseek_r(), _isatty_r(), _write()). All of them are defined empty except _write() that is written to use the Trace perihperal. The definition of the function _write() allows developer to use printf() as usual and the stdout will be redirected to the Trace perihperal.

Debug

It is possible to debug an application running in RISC-V-TLM simulator. It is tested with riscv32-unknown-elf-gdb version 8.3.0.20190516-git and eclipse. Configure a "C/C++ Remote Application" debug configuration as the figure

Modules' hierarchy

gdbinit.txt file must contain:

set debug remote 1
set arch riscv:rv32

With this configuration, eclipse debuggins is almost normal (I experienced some problems wiith "step-over" and "step-into" commands)

Docker container

There is a Docker container available with the latest release at https://hub.docker.com/r/mariusmm/riscv-tlm. This container has RISCV-TLM already build at /usr/src/riscv64/RISCV-TLM directory.

How to use Docker

$ docker pull mariusmm/riscv-tlm
$ docker run -v <path_to_RISCV-V-TLM>/:/tmp -u $UID -e DISPLAY=$DISPLAY --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw"  -it mariusmm/riscv-tlm /bin/bash

$ ./RISC-V-TLM/build/RISCV_TLM /tmp/<your_hex_file>

or you can call binary inside docker image directly:

$ docker run -v <path_to_RISCV-V-TLM>/:/tmp -u $UID -e DISPLAY=$DISPLAY --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw"  -it mariusmm/riscv-tlm /usr/src/riscv64/RISC-V-TLM/RISCV_TLM /tmp/<your_hex_file>

I'm using docker image zmors/riscv_gcc to have a cross-compiler, I'm using both docker images this way:

console1:
$ docker run -v /tmp:/PRJ -it zmors/riscv_gcc:1  bash

# cd /PRJ/func3
# make

console2:
$ docker run -v /tmp:/tmp -u $UID -e DISPLAY=$DISPLAY --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -it mariusmm/riscv-tlm /bin/bash

# cd /usr/src/riscv64/RISC-V-TLM/ 
# ./RISCV-TLM /tmp/file.hex
...

or

...
console 2:
$  docker run -v /tmp/tmp -it  mariusmm/riscv-tlm /usr/src/riscv64/RISC-V-TLM/RISCV_TLM /tmp/file.hex

Performance is not affected by running the simulator inside the container

Test

See Test page for more information.

In the asm directory there are some basic assembly examples.

I "compile" one file with the follwing command:

$ cd asm
$ riscv32-unknown-elf-as  EternalLoop.asm -o EternalLoop.o
$ riscv32-unknown-elf-ld EternalLoop.o -o EternalLoop.elf
$ riscv32-unknown-elf-objcopy -O ihex EternalLoop.elf EternalLoop.hex
$ cd ..
$ ./RISCV_SCTLM asm/EternalLoop.hex

This example needs that you hit Ctr+C to stop execution.

C code

The C directory contains simple examples in C. Each directory contains an example, to compile it just:

$ make

and then execute the .hex file like the example before.

FreeRTOS

FreeRTOS can run in this simulator!

In test/FreeRTOS/ directory there is portable files (port.c, portmacro.c portasm.S) and main file (freertos_test.c) ported to this RISC-V model.

Documentation

The code is documented using doxygen. In the doc folder there is a Doxygen.cfg file ready to be used.

Contribute

There are several ways to contribute to this project:

  • Test
  • Pull request are welcome (see TODO list)
  • Good documentation
  • RTL-Level simulation

Authors and credits

RISC-V-TLM is managed by Màrius Montón.

If you find this code useful, please consider citing:

@inproceedings{montonriscvtlm2020,
        title = {A {RISC}-{V} {SystemC}-{TLM} simulator},
        booktitle = {Workshop on {Computer} {Architecture} {Research} with {RISC}-{V} ({CARRV 2020}),
        author = {Montón, Màrius},
        year = {2020}
}

Publications

I've published a paper describing the RISC-V simulator in CARRV 2020 conference (pdf).

License

Copyright (C) 2018, 2019, 2020 Màrius Montón (@mariusmonton)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].