- Notifications
You must be signed in to change notification settings - Fork19
Fun, portable, minimalistic virtual machine.
License
maximecb/uvm
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
NOTE: this project is very much a work in progress. You're likely to runinto bugs and missing features. I would like to find collaborators who share the visionand want to help me make it happen.
A simple, minimalistic virtual machine designed to run self-contained applications. UVM is intended as a platform to distributeprograms that will not break and to combat code rot. It aims to be conceptually simple, easy to understand, easyto target, fun to work with and approachable to newcomers. It may also be valuable as a teaching tool or as a platformto experiment with. There is a short 4-minuteoverview of UVMon YouTube if you'd like to see a quick survey.
Contents:
- Features
- Build Instructions
- Codebase Organization
- Design and Architecture
- Subsystems and System Calls
- Vision and Motivation
- Planning and Evolution
If you think that UVM is cool, you can support my work viaGitHub Sponsors ❤️
Current features:
- Stack-based bytecode interpreter
- Variable-length instructions for compactness
- Untyped design for simplicity
- Little-endian byte ordering (like x86, ARM & RISC-V)
- 32-bit and 64-bit integer ops, 32-bit floating-point support
- Separate flat, linear address spaces for code and data (Harvard architecture)
- Thread-based parallelism
- Built-in, easy to useassembler with asimple syntax
- Event-driven event execution model compatible with async operations
- Easy to use frame buffer to draw RGB graphics with no boilerplate
- Easy to use audio output API with no boilerplate
Planned future features:
- Simple networking API
- Capability system to safely sandbox apps without granting access to entire computer
- Ability to compile without SDL and without graphics/audio for headless server-side use
- Ability to encode metadata such as author name and app icon into app image files
- Ability to suspend running programs and save them to a new app image file
Dependencies:
Install the SDL2 package:
brew install sdl2
Add this to your~/.zprofile
:
export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib"
Install the Rust toolchain:
curl --proto'=https' --tlsv1.2 -sSf https://sh.rustup.rs| sh
Install the SDL2 package:
sudo apt-get install libsdl2-dev
Install the Rust toolchain:
curl --proto'=https' --tlsv1.2 -sSf https://sh.rustup.rs| sh
Follow the Windows-specific instructions toinstall the Rust toolchain.
GetSDL2.dll
from one ofSDL2 Releases.
CopySDL2.dll
(unzip) to thevm/
folder.
cd vmcargo build
To run anasm file with UVM:
cargo run examples/fizzbuzz.asm
There is also a toy C compiler in thencc
directory, along with manyexample C programs that run on UVM:
cd ncc./build_and_run.sh examples/snake.c
Runcargo test
from thevm
, andncc
directories.
The repository is organized into a 3 different subprojects, each of which is a Rust codebase which can be compiled withcargo
:
/vm
: The implementation of the UVM virtual machine itself/vm/examples/*
: Example assembly programs that can be run by UVM
/ncc
: An implementation of a toy C compiler that outputs UVM assembly/ncc/README.md
: documentation for the NCC compiler./ncc/examples/*
: Example C source files that can be compiled by NCC
/api
: A system to document and automatically export bindings for UVM system calls and constants./api/syscalls.json
: Declarative list of system calls exposed by UVM.
/doc
: Markdown documentation for UVM/doc/syscalls.json
: List of system calls and constants accessible to UVM programs
Thencc
compiler is, at the time of this writing, incomplete in that it lacks some C features and the error messages need improvement. This compilerwas implemented to serve as an example of how to write a compiler that targets UVM, and to write some library code to be used by other programs. Overtime, thencc
compiler will be improved. Despite its limitations, it is still usable to write small programs. Contributions to it are welcome.
Theapi
directory contains JSON files that represent a declarative list of system calls, constants and the permission system that UVM exposesto programs running on it. This is helpful for documentation purposes, or if you want to build a compiler that targets UVM. The directory also containscode that automatically generatesmarkdown documentation, Rust constants andC definitions for system calls.
The code for UVM, NCC and associated tools is shared under theApache-2.0 license.
The examples under thevm/examples
andncc/examples
directories are shared under theCreative Commons CC0 license.
There is a lot of work to be done to get this project going and contributions are welcome.
A good first step is to look at open issues and read the available documentation. Another easy way to contributeis to create new example programs showcasing cool things you can do with UVM, or to open issues to report bugs.If you do report bugs, please provide as much context as possible, and the smallest reproduction you cancome up with.
You can also search the codebase for TODO or FIXME notes:
grep -IRi"todo".
In general, smaller pull requests are easier to review and have a much higher chance of getting merged than largepull requests. If you would like to add a new, complex feature or refactor the design of UVM, I recommend openingan issue or starting a discussion about your proposed change first.
Also please keep in mind that one of the core principles of UVM is to minimize dependencies to keep the VM easyto install and easy to port. Opening a PR that adds dependencies to multiple new packages and libraries isunlikely to get merged. Again, if you have a valid argument in favor of doing so, please open a discussion toshare your point of view.
About
Fun, portable, minimalistic virtual machine.