Rust virtual machine.

Overview

EtherVM

A lightweight, efficient virtual machine implementation in Rust, designed for educational purposes and as a foundation for more complex emulation projects.

Features

1. CPU Emulation

  • Basic CPU structure with registers and program counter
  • Instruction fetch-decode-execute cycle
  • Initial instruction set with basic arithmetic operations (ADD, SUB, MUL, DIV)
  • Error handling for unknown opcodes and division by zero
  • Unit tests for arithmetic operations

2. Memory Management Unit

  • Implementation of a Memory Management Unit (MMU)
  • 64KB of emulated memory
  • Byte and word (32-bit) read/write operations
  • Integration of MMU with CPU for instruction fetching and data operations
  • LOAD and STORE instructions for memory access
  • Extended unit tests for memory operations

3. I/O Operations

  • IOController and IODevice trait for managing input/output operations
  • ConsoleDevice implementation for basic console I/O
  • INPUT and OUTPUT instructions added to the CPU
  • MockIOController for testing I/O operations without actual console interaction
  • Flexible architecture allowing easy addition of new I/O devices

4. Expanded Instruction Set

  • Logical operations: AND, OR, XOR, NOT
  • Shift operations: SHL (shift left), SHR (shift right)
  • Comparison operation (CMP) with flags register
  • Control flow instructions:
    • JMP (unconditional jump)
    • JE (jump if equal)
    • JNE (jump if not equal)
    • JG (jump if greater)
    • JL (jump if less)
  • Modified instruction decoding to accommodate the expanded set
  • Comprehensive unit tests for new instructions and operations

Project Structure

  • src/
  • ├── main.rs # Entry point of the application
  • ├── cpu.rs # CPU implementation with instruction set
  • ├── memory.rs # Memory Management Unit implementation
  • └── io.rs # I/O Controller and devices

Usage

  • To build and run the virtual machine:

    • cargo build
    • cargo run
  • To run the tests:

    • cargo test

Future Improvements

  • Implement a simple assembler for easier program input
  • Add more complex I/O devices (e.g., virtual disk, network interface)
  • Implement interrupt handling and system calls
  • Create a debugger interface for step-by-step execution and memory inspection

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Comments
  • Update CodeQL workflow to resolve setup issue

    Update CodeQL workflow to resolve setup issue

    Update CodeQL workflow to resolve setup issue

    • Fixed the issue with 'setup-codeql' action by verifying and updating to the correct version.
    • Ensured correct configuration for CodeQL analysis and database initialization.
    • Workflow now correctly sets up the CodeQL environment, initializes the database, and performs security analysis.
    opened by yezzfusl 0
  • Create the main execution loop for the virtual machine.

    Create the main execution loop for the virtual machine.

    1. In src/main.rs:
    • Added a simple program to demonstrate the VM's functionality.
    • Created instances of IOController and MemoryManagementUnit.
    • Loaded the program into the CPU's memory and started execution.
    1. In src/cpu.rs:
    • Implemented the load_program method to load a program into memory.
    • Created the main run method that executes the fetch-decode-execute cycle until the CPU is halted.
    • Modified the decode_and_execute method to fetch operands for each instruction.
    • Added a halted flag and a HALT instruction to stop execution.
    • Implemented a print_registers method for debugging.
    • Updated all instruction methods to take two operands.
    • Added a comprehensive test that runs a small program in the VM.
    opened by yezzfusl 0
  • Expand the instruction set with advanced operations.

    Expand the instruction set with advanced operations.

    1. Expanded the instruction set with new logical operations: and, or, xor, and not.
    2. Added shift operations: shl (shift left) and shr (shift right).
    3. Implemented a comparison operation cmp that sets flags based on the result.
    4. Added jump instructions: jmp (unconditional jump), je (jump if equal), jne (jump if not equal), jg (jump if greater), and jl (jump if less).
    5. Introduced a flags register to store comparison results.
    6. Modified the decode function to accommodate the expanded instruction set.
    7. Added new unit tests to verify the correctness of the new instructions.
    opened by yezzfusl 0
  • Add basic I/O operations for virtual devices.

    Add basic I/O operations for virtual devices.

    1. A new io.rs file that implements the IOController and IODevice trait.
    2. The ConsoleDevice struct implements basic console I/O operations.
    3. The CPU struct now includes an IOController.
    4. Two new instructions, input and output, have been added to interact with I/O devices.
    5. The main.rs file has been updated to create an IOController and pass it to the CPU.
    6. A MockIOController has been added for testing purposes.
    7. Additional tests have been added to verify the correctness of I/O operations.
    opened by yezzfusl 0
  • Implement memory management unit for allocation and access.

    Implement memory management unit for allocation and access.

    1. A new memory.rs file that implements the MemoryManagementUnit struct.
    2. The MemoryManagementUnit provides methods for reading and writing both bytes and words (32-bit values) to memory.
    3. The CPU struct now uses the MemoryManagementUnit instead of a raw memory array.
    4. Two new instructions, load and store, have been added to interact with memory.
    5. The fetch method now uses the MMU to read instructions from memory.
    6. Additional tests have been added to verify the correctness of memory operations and the new instructions.
    opened by yezzfusl 0
  • Add initial CPU emulator with basic instruction set.

    Add initial CPU emulator with basic instruction set.

    1. We've defined a CPU struct that holds the essential components: registers, program counter, memory, and an instruction set.
    2. The new() function initializes the CPU with default values and sets up the instruction set.
    3. We've implemented a basic fetch-decode-execute cycle in the run() method.
    4. The instruction set includes four basic arithmetic operations: add, subtract, multiply, and divide.
    5. Each instruction operates on two registers, with the result stored in the first register.
    6. We've included a simple opcode format that allows for future expansion.
    7. Error handling is implemented for unknown opcodes and division by zero.
    8. Unit tests are included to verify the correctness of each arithmetic operation.
    opened by yezzfusl 0
Releases(fv)
  • fv(Aug 6, 2024)

    What's Changed

    • Add initial CPU emulator with basic instruction set. by @yezzfusl in https://github.com/yezzfusl/EtherVM/pull/1

    New Contributors

    • @yezzfusl made their first contribution in https://github.com/yezzfusl/EtherVM/pull/1

    Full Changelog: https://github.com/yezzfusl/EtherVM/commits/fv Selection_011

    What's Changed

    • Add initial CPU emulator with basic instruction set. by @yezzfusl in https://github.com/yezzfusl/EtherVM/pull/1

    Full Changelog: https://github.com/yezzfusl/EtherVM/commits/fv

    Source code(tar.gz)
    Source code(zip)
  • final(Aug 6, 2024)

    What's Changed

    • Implement memory management unit for allocation and access. by @yezzfusl in https://github.com/yezzfusl/EtherVM/pull/2
    • Add basic I/O operations for virtual devices. by @yezzfusl in https://github.com/yezzfusl/EtherVM/pull/3
    • Expand the instruction set with advanced operations. by @yezzfusl in https://github.com/yezzfusl/EtherVM/pull/4
    • README UwU 🥺👉👈 by @yezzfusl in https://github.com/yezzfusl/EtherVM/pull/5
    • Create the main execution loop for the virtual machine. by @yezzfusl in https://github.com/yezzfusl/EtherVM/pull/6

    Full Changelog: https://github.com/yezzfusl/EtherVM/compare/fv...final

    Source code(tar.gz)
    Source code(zip)
Owner
Fayssal Chokri
Fayssal Chokri
Rust virtual machine.

EtherVM A lightweight, efficient virtual machine implementation in Rust, designed for educational purposes and as a foundation for more complex emulat

Fayssal Chokri 3 Aug 12, 2024
DeFiChain octopus is a codename research & development for DFIP 2111-B: VOC: Ethereum Virtual Machine (EVM) Support.

DeFiCh/octopus DeFiChain octopus is a codename research & development for DFIP 2111-B: VOC: Ethereum Virtual Machine (EVM) Support . Proposed as a DFI

DeFi Meta Chain 6 Apr 18, 2022
A visual canvas and virtual machine for writing assembly to build cool things. Create machines and connect them together.

Visual Assembly Canvas A highly visual assembly editor, infinite canvas for wiring blocks and machines together, bytecode virtual machine runnable nat

Phoomparin Mano 31 Oct 11, 2023
A visual canvas and virtual machine for writing assembly to build cool things. Create machines and connect them together.

Visual Assembly Canvas A highly visual assembly editor, infinite canvas for wiring blocks and machines together, bytecode virtual machine runnable nat

Phoomparin Mano 32 Oct 11, 2023
A simple made in Rust crack, automatic for Winrar, activated from shared virtual memory, for studies.

Simple Winrar Crack in Rust What does it do ? A simple project that allows you to modify the license check used by WinRaR, "RegKey" from virtual memor

João Vitor 7 Jan 2, 2023
A Windows virtual display driver written in Rust (works with VR, etc)

Virtual Display Driver This is a Windows driver made in Rust which creates a virtual desktop. It has many uses, such as: A private virtual desktop for

Cherry 28 Sep 19, 2023
Nimbus - A virtual, networked filesystem with strong upfront safety guarantees

The Nimbus Filesystem Nimbus is a virtual, networked filesystem that provides upfront safety guarantees to a user, intended for personal use. In parti

Max Fan 3 Jan 10, 2023
Shared execution environment for constructing 3D virtual spaces from the inside.

Hearth Hearth is a shared, always-on execution environment for constructing 3D virtual spaces from the inside. Come join our Discord server! The Histo

null 6 Jan 31, 2023
Log-structured, transactional virtual block device backed by S3

mvps Log-structured, transactional virtual block device compatible with the NBD protocol. mvps stands for "multi-versioned page store". MVPS can store

Heyang Zhou 3 Dec 3, 2023
My solutions for the 2021 edition of the Advent of Code, using Rust and SOM (Simple Object Machine)

Advent of Code 2021 These are my solutions for the 2021 edition of the Advent of Code. The solutions are all implemented using both Rust and SOM (Simp

Nicolas Polomack 1 Dec 23, 2021
SquidVM is a VM made in Rust implementing a Stack-based machine.

What is SquidVM? _____ _ ___ ____ __ / ____| (_) | \ \ / / \/ | | (___ __ _ _ _ _ __| |\ \ / /| \ /

Fragmenta 4 Dec 17, 2023
A command-line downloader for sites archived on the Wayback Machine

This is a small command-line utility I wrote to help with browsing archived websites from the Wayback Machine, which can sometimes be pretty slow.

Jonas Schievink 7 Oct 18, 2022
H2O Open Source Kubernetes operator and a command-line tool to ease deployment (and undeployment) of H2O open-source machine learning platform H2O-3 to Kubernetes.

H2O Kubernetes Repository with official tools to aid the deployment of H2O Machine Learning platform to Kubernetes. There are two essential tools to b

H2O.ai 16 Nov 12, 2022
Sugar is an alternative to the current Metaplex Candy Machine CLI

Sugar: A Candy Machine CLI Sugar is an alternative to the current Metaplex Candy Machine CLI. It has been written from the ground up and includes seve

Metaplex Foundation 152 Dec 23, 2022
By mirroring traffic to and from your machine, mirrord surrounds your local service with a mirror image of its cloud environment.

mirrord lets you easily mirror traffic from your Kubernetes cluster to your development environment. It comes as both Visual Studio Code extension and

MetalBear 2.1k Jan 3, 2023
Shell Of A New Machine: Quickly configure new environments

Shell Of A New Machine soanm is a dead-simple tool for easily configuring new UNIX machines, with almost zero prerequisites on the target machine. All

Ben Weinstein-Raun 41 Dec 22, 2022
batch eval tool for machine code. eval() but for asm.

yaxpeax-eval yaxpeax-eval is the repo providing yaxeval, a tool to execute machine code with preconditions and report state at exit. currently, yaxeva

iximeow 10 Jan 5, 2023
Evaluate performance gains to expect when EVM were to compile hot contracts into machine code

Convert evm bytecode to native machine code and go vroom - just an experiment, probably broken, reach out to [email protected] to contribute / productionize.

Paradigm 105 Aug 1, 2023
Rust-advent - Learning Rust by solving advent of code challenges (Streaming live on Twitch every Monday)

Rust advent ?? ?? Learning Rust by implementing solutions for Advent of Code problems. ?? HEY, we are live-streaming our attempts to solve the exercis

Luciano Mammino 20 Nov 11, 2022