GithubHelp home page GithubHelp logo

riscv-sim's Introduction

RISC-V Sim

A simulation of a simple RISC-V computer

Getting Started

Installing

This project requires cargo to be installed which can be downloaded from the rust website.

Running

Once rust is installed the library can then be tested using

cargo test

A RISC machine can then be made by providing an already created registry and memory

let mut memory = Memory::default();
memory.set_four_byte(u20::new(0), 100);
let mut registry = Registry::default();
registry.set(rs1, 100);

let mut machine = RISCMachine {
    memory,
    registry,
    program_counter: u20::new(0),
};

or by simply loading the memory into an empty machine

let mut memory = Memory::default();

let mut machine = RISCMachine::default();
machine.load_memory(memory);

The machine currently supports 8 instructions

pub enum CPUInstruction {
    ADD { rd: u5, rs1: u5, rs2: u5 },
    SUB { rd: u5, rs1: u5, rs2: u5 },
    LW { rd: u5, rs1: u5, imm: u32 },
    SW { rs1: u5, rs2: u5, imm: u32 },
    JAL { rd: u5, imm: u32 },
    JALR { rd: u5, rs1: u5, imm: u32 },
    BEQ { rs1: u5, rs2: u5, imm: u32 },
    BNE { rs1: u5, rs2: u5, imm: u32 },
}

A detailed description of each instruction can be found here.

The machine can be ran one tick at a time, or until the program counter reaches a specific value

//Process a single instruction
machine.tick()?;

//Process until the program counter reaches 10
machine.run(&|pc| -> bool { pc == u20::new(10) })?;

Acknowledgments

This simulation took inspiration from the Tiny RISC-V architecture, which is a simple subset of the complete RISC-V specification which can be found here.

riscv-sim's People

Contributors

matt-ord avatar

Watchers

 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.