examples

command
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Example main.go demonstrating VM initialization, syscall registration, file loading, and execution.

This program accepts a RISC-V binary filename as a command-line argument, sets up a simple print syscall (code 1), loads the binary into the VM’s memory, and runs it. It prints usage instructions and exits with code 1 if no filename is provided, or an error message if loading fails.

Usage:

go run main.go <riscv-binary>

Breakdown:

  1. Argument Check: Ensures a filename argument is passed; otherwise, prints usage and exits.
  2. VM Creation: Instantiates a new RisbeeVm and initializes its state (memory, PC, syscalls).
  3. Syscall Registration: Registers syscall code 1 to print a null-terminated string from VM memory. - Retrieves string pointer via GetPointerParam(0), reads string with GetStringPointer, prints it.
  4. File Loading: Uses LoadFile to read the binary into VM memory at offset 0x1000; on failure, prints an error and exits.
  5. Execution: Calls Run(), entering the fetch-execute loop until the program calls exit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL