Git Product home page Git Product logo

rv32jit's Introduction

RISC-V 32-bit JIT

An assembler for JIT compilation for use on ESP32-C3 (rv32imc)

Setting up the environment

rustup toolchain install nightly
rustup target add riscv32imc-unknown-none-elf
cargo install ldproxy
cargo install cargo-espflash

Building

cargo build --release

To flash and run:

cargo espflash --release --monitor

If you get a certificate error on macOS:

curl "https://ccadb-public.secure.force.com/mozilla/IncludedRootsPEMTxt?TrustBitsInclude=Websites" > IncludedRootsPEM.txt
SSL_CERT_FILE=$(pwd)/IncludedRootsPEM.txt cargo build

To test locally (replace aarch64-apple-darwin with your system's target triple, use rustup target list to find installed targets):

cargo run --example assemble --target aarch64-apple-darwin -- ~/Desktop/test2.bin

The above will write a binary that you can upload in e.g. this disassembler.

Testing

cd rv32assembler
cargo test --target aarch64-apple-darwin

Usage

fn test_jit_simple() {
	let mut f = Fragment::new();
	f.addi(Register::A0, Register::A0, 42);
	f.ret();
	let program = JitFunction::from(&f);
	let s = unsafe { program.call(88) };
	assert_eq!(s, 88 + 42);
}

If you want to use this crate in your own project, be sure to set the following option in sdkconfig.defaults:

# Required to allow JIT
CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=n

References

Useful reference material:

To create a binary file from "[1, 2, 3]" debug output:

const fs = require("fs");
fs.writeFileSync("foo.bin", Buffer.from([1, 2, 3]));

License

MIT

rv32jit's People

Contributors

pixelspark avatar

Stargazers

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