GithubHelp home page GithubHelp logo

cszawisza / riscv-vm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bit-hack/riscv-vm

0.0 0.0 0.0 1.89 MB

A Small RISC-V Virtual Machine

License: MIT License

CMake 0.86% C++ 11.02% C 87.55% Objective-C 0.58%

riscv-vm's Introduction

RISC-V Virtual Machine

This is a RISCV-V Virtual Machine and instruction set emulator implementing a 32 bit RISCV-V processor model. I started this project as a learning exercise to get more familiar with the RISC-V eco system and have increased the scope of the project as it matures. The project itself is still very much in the early stages however.

Features:

  • Support for RV32I and RV32M
  • Partial support for RV32F and RV32A
  • Syscall emulation and host passthrough
  • Emulation using Dynamic Binary Translation
  • It can run Doom, Quake and SmallPT

There are broadly two elements to this project:

  • An ISA emulator core written in C which presents a low level API for interfacing.
  • The VM frontend written in C++ which interfaces the ISA emulator core with the host computer.

Note: The Binary Translation emulator is currently only available when building for x64 Windows. This is due to the generated code being tailored to that ABI, however in time Linux support for the code generator will follow.

See news for a development log and updates.


Build Status

Build Status Build status


Build requirements

  • C++ 14 compatible compiler (VisualStudio 15+, GCC 4.9+)
  • CMake 3.0 or above
  • SDL1.2 (if you want video support)

Compiling the project

mkdir build
cd build
cmake ..
make

Executing a basic program

A simple RISC-V program (i.e. main.c) can be compiled and executed as follows:

riscv64-unknown-elf-gcc -march=rv32im -mabi=ilp32 main.c
riscv_vm a.out

Testing

Please note that while the riscv-vm simulator is provided under the MIT license, any of the materials in the tests folder may not be. These tests were taken from a wide range of places to give the project a reasonable test coverage. If you are the author of any of these tests and are unhappy with its inclusion here then please get in touch and I will remove it from the project and its git history.


Notes

  • Written referencing the 20191214-draft Volume I: Unprivileged ISA document
  • Complete RV32G compliance is the end goal
  • Testing is done currently using a private fork of the compliance test suite
    • As the project develops testing will become a key focus
  • It is enough that it can run doom, see the README

Newlib support

There is rudimentary support for target programs that make use of the newlib library. Currently a number of syscalls have been implemented via the ecall instruction. This is just enough to run a number of simpler programs and do some basic file io operations.

Try the following example program:

#include <stdio.h>

int main(int argc, const char **args) {
  printf("Hello World!\n");
  return 0;
}

Spoiler:

Hello World!

riscv-vm's People

Contributors

bit-hack avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.