Giter Site home page Giter Site logo

picovm's Introduction

picoVM

This is a toy assembly compiler and virutal machine that can build and run 32-bit executables.

Usage

asm

To compile assembly code into an output binary, use the 'asm' command. picovm asm OUTPUT TYPE FORMAT INPUT

  • OUTPUT - resulting .elf output file
  • TYPE - elf32 and elf64 is the only supported package types
  • FORMAT - pico is the only supported code/text format
  • INPUT- source .asm assembly file

inspect

To inspect a binary, similar to the GNU 'readelf' command, use the 'inspect' command. picovm inspect EXECUTABLE

  • EXECUTABLE - file to parse

run

To run a binary in the virtual machine, use the 'run' command. picovm run EXECUTABLE

  • EXECUTABLE - file to run in the virtual machine

asmrun

To compile and immediately run a binary in one command, use 'asmrun'. picovm asmrun OUTPUT TYPE FORMAT INPUT (Same parameters as asm)

Project summary

The project is currently a single Main() function which performs the following steps:

  1. Reads in a .asm file
  2. Assembles the assembly code to bytecode
  3. Writes out an a.out file (experimental, in the future will be divided into workflow tools)
  4. Loads the bytecode into a virtual machine
  5. Executes the code

Project layout

First, source code is processed by the BytecodeCompiler class, which serves as a lexer, parser, and bytecode compiler all in one. This produces a CompilationResult which, if successful, contains a text section and a data section.

A primative loader allocates a byte array and copies the text and data segments, and allocates an Agent, which serves as the virtual machine. The executing instruction pointer within the Agent begins at 0x00000000 and runs one bytecode command per Tick() method call.

A rudimentary *nix syscall table is implemented to handle interrupts. The sys_write syscall, for instance, provides the Hello World program the ability to load a string and write it to Console.Out.

A small set of unit tests are included in the picovm.Tests directory

Project maturity

  • ☑️ .asm file parsed into bytecode
  • ☑️ 32/16/8-bit registers and MOV instruction handled
  • ☑️ Data segment with directives DB and EQU
  • ☑️ Constant value inline expansion
  • ☑️ Interrupt vectors, initial sys_write syscall
  • ☑️ BSS segment, initial sys_read syscall
  • ☑️ Separate compliation and loader
  • ☑️ Output syntactically correct ELF64 binary
  • ☑️ Read ELF64 binary
  • 🔲 x64 support
  • 🔲 Create x64-compatible bytecode
  • 🔲 Floating-point unit (FPU)

picovm's People

Contributors

seanmcelroy avatar

Watchers

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