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:
- Argument Check: Ensures a filename argument is passed; otherwise, prints usage and exits.
- VM Creation: Instantiates a new RisbeeVm and initializes its state (memory, PC, syscalls).
- 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.
- File Loading: Uses LoadFile to read the binary into VM memory at offset 0x1000; on failure, prints an error and exits.
- Execution: Calls Run(), entering the fetch-execute loop until the program calls exit.
Click to show internal directories.
Click to hide internal directories.