Nonstop Pajama Models

    riscv_emu_rust_wasm
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.2 • Public • Published

    riscv_emu_rust_wasm

    npm version

    riscv_emu_rust_wasm is a WebAssembly RISC-V processor and peripheral devices emulator based on riscv-rust.

    How to install

    $ npm install riscv_emu_rust_wasm
    

    How to use

    const riscv = require('riscv_emu_rust_wasm').WasmRiscv.new();
    // Setup program content binary
    riscv.setup_program(new Uint8Array(elfBuffer));
    // Setup filesystem content binary
    riscv.setup_filesystem(new Uint8Array(fsBuffer));
     
    // Emulator needs to break program regularly to handle input/output
    // because the emulator is currenlty designed to run in a single thread.
    // Once `SharedArrayBuffer` lands and becomes stable
    // we would run input/output handler in another thread.
    const runCycles = () => {
      // Run 0x100000 (or certain) cycles, handle input/out,
      // and fire next cycles.
      // Note: Evety instruction is completed in a cycle.
      setTimeout(runCycles, 0);
      riscv.run_cycles(0x100000);
     
      // Output handling
      while (true) {
        const data = riscv.get_output();
        if (data !== 0) {
          // print data
        } else {
          break;
        }
      }
     
      // Input handling. Assuming inputs holds
      // input ascii data.
      while (inputs.length > 0) {
        riscv.put_input(inputs.shift());
      }
    };
    runCycles();

    API

    Refer to the comments in WasmRiscv

    How to build WebAssembly RISC-V emulator locally

    Prerequirements

    $ git clone https://github.com/takahirox/riscv-rust.git
    cd riscv-rust/wasm
    $ bash build.sh

    Install

    npm i riscv_emu_rust_wasm

    DownloadsWeekly Downloads

    0

    Version

    0.2.2

    License

    MIT

    Unpacked Size

    357 kB

    Total Files

    11

    Last publish

    Collaborators

    • takahirox