All Projects → edubart → riscvm

edubart / riscvm

Licence: other
Tiny RISC-V virtual machine

Programming Languages

c
50402 projects - #5 most used programming language
lua
6591 projects
Makefile
30231 projects
assembly
5116 projects

Projects that are alternatives of or similar to riscvm

Zelda.RISCV.Emulator
A System Level RISCV32 Emulator Over x86_64: capable of booting RISCV Linux
Stars: ✭ 18 (-30.77%)
Mutual labels:  risc-v, riscv-emulator
riscv em
Simple risc-v emulator, able to run linux, written in C.
Stars: ✭ 51 (+96.15%)
Mutual labels:  risc-v, riscv-emulator
rv32emu
RISC-V RV32I[MAC] emulator with ELF support
Stars: ✭ 61 (+134.62%)
Mutual labels:  risc-v, riscv-emulator
platform-shakti
Shakti: development platform for PlatformIO
Stars: ✭ 26 (+0%)
Mutual labels:  risc-v
CorePartition
Universal Cooperative Multithread Lib with real time Scheduler that was designed to work, virtually, into any modern micro controller or Microchip and, also, for user space applications for modern OS (Mac, Linux, Windows) or on FreeRTOS as well. Supports C and C++
Stars: ✭ 18 (-30.77%)
Mutual labels:  risc-v
stackvm
Virtual Machine with a 240x160 VRAM display.
Stars: ✭ 47 (+80.77%)
Mutual labels:  virtual-machine
wizard-engine
Research WebAssembly Engine
Stars: ✭ 164 (+530.77%)
Mutual labels:  virtual-machine
Never
Never: statically typed, embeddable functional programming language.
Stars: ✭ 248 (+853.85%)
Mutual labels:  virtual-machine
riscv-meta
RISC-V Instruction Set Metadata
Stars: ✭ 33 (+26.92%)
Mutual labels:  risc-v
FPGAmp
720p FPGA Media Player (RISC-V + Motion JPEG + SD + HDMI on an Artix 7)
Stars: ✭ 190 (+630.77%)
Mutual labels:  risc-v
evcloud
EVCloud是一个基于ceph和libvirt的轻量级云主机管理平台,实用稳定,维护简易
Stars: ✭ 44 (+69.23%)
Mutual labels:  virtual-machine
clox
A virtual machine and a tree-walk interpreter for the Lox programming language in C89 🌀
Stars: ✭ 38 (+46.15%)
Mutual labels:  virtual-machine
dd86
No longer maintained. See URL.
Stars: ✭ 36 (+38.46%)
Mutual labels:  virtual-machine
picorv32 Xilinx
A picorv32-riscv Soc with DMAC and Ethernet controller & lwip & Kirtex7@333MHz
Stars: ✭ 49 (+88.46%)
Mutual labels:  risc-v
daintree
ARMv8-A/RISC-V kernel (with UEFI bootloader)
Stars: ✭ 32 (+23.08%)
Mutual labels:  risc-v
Firecracker
Secure and fast microVMs for serverless computing.
Stars: ✭ 16,826 (+64615.38%)
Mutual labels:  virtual-machine
Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: ✭ 101 (+288.46%)
Mutual labels:  virtual-machine
LLVM-JVM
[W.I.P] A Just-In-Time Java Virtual Machine written in Haskell
Stars: ✭ 22 (-15.38%)
Mutual labels:  virtual-machine
core-v-verif
Functional verification project for the CORE-V family of RISC-V cores.
Stars: ✭ 283 (+988.46%)
Mutual labels:  risc-v
convey
Communication through a serial port or named pipe
Stars: ✭ 46 (+76.92%)
Mutual labels:  virtual-machine

Tiny RISC-V virtual machine written in Nelua (and C as consequence).

This is a minimal and simple RISC-V ISA emulator implementing a subset of RV64I instructions.

Only the instructions required to run a minimal userspace virtual machine are implemented.

The emulator allows to run C files compiled with GCC to RISC-V inside a minimal sandboxed virtual machine. The virtual machine is able to call host functions through system calls.

This project has inspired by libriscv.

What is interesting about this?

This is a minimal example on how to interpret C programs inside a sandboxed virtual machine. One may use this concept to run compiled programs with GCC on any system that have the emulator, or to sandbox a C application inside isolated environment, or to do any kind of hot reloading in application on the fly (usually done with scripting languages).

Run examples

Run examples with Nelua:

nelua -r riscvm.nelua examples/fib.bin
nelua -r riscvm.nelua examples/ack.bin
nelua -r riscvm.nelua examples/sieve.bin

The examples were compiled from the respective C files into RV64I binary.

Alternatively if you don't have Nelua:

gcc -O2 -o riscvm riscvm.c
./riscvm examples/fib.bin

Compiling an example

All the examples are already compiled to RV64I, but in case you want to edit or run a new example, then use for example make EXAMPLE=fib.c to compile fib.c into fib.bin, this requires RISC-V elf toolchain.

How it works?

  1. An example is coded in freestanding C code, functionality outside the sandboxed environment such as printing to terminal is implemented through system calls in lib/syscalls.h and minimal libc is implemented in lib/tinyc.c.
  2. The C example is compiled to RISC-V elf binary, using lib/start.s to initialize the properly the virtual machine state, and using special link rules through lib/link.ld to adjust the instruction addresses.
  3. RISC-V bytecode is stripped from the compiled elf binary into a bytecode binary.
  4. The bytecode binary is loaded and run through riscvm, interpreting RV64I instructions.
  5. While interpreting the virtual machine may call the host through system calls.
  6. The application stops once the exit system call is called or if any error occur.

How this was implemented?

This was implemented by reading the RISC-V specification

Benchmarks

Equivalent code was run with the Lua 5.4, riscvm and natively in the same system for some examples, from the experiments the interpreted code can be 10~20x slower than native code:

example lua 5.4 riscvm x86_64
ack 1070ms 1022ms 47ms
sieve 1077ms 716ms 64ms

NOTE: This VM does not do any kind of JIT and has a very simple implementation, there are space for optimizations.

Future improvements

These extensions are not implemented yet and would be useful:

  • M extension - Multiply and division
  • F extension - Floating point with single precision
  • D extension - Floating point with double precision

Also more C functions such as malloc/free/memcpy could be implemented yet as system calls.

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].