riscemu
riscemu copied to clipboard
Method to add syscalls?
Could you add a method to add syscalls to the CPU? Thanks!
You can add syscalls by editing the syscalls.py file. I added some instructions at the bottom of docs/syscalls.md.
I'll leave this issue open if you have any further questions!
Oh, I was kind of hoping not to have to modify the files in the distro...
I haven't tested this yet, but you could probably do it like this:
import riscemu.syscall as syscall
from riscemu import UserModeCPU, RV32M, RV32I, RV32A, RunConfig
syscall.SYSCALLS[42] = 'somesyscall'
class MySyscallInterface(syscall.SyscallInterface):
def somesyscall(self, scall: syscall.Syscall):
print(scall)
scall.ret(-1)
cpu = UserModeCPU([RV32M, RV32I, RV32A], RunConfig())
cpu.syscall_int = MySyscallInterface()
# ...
You should keep in mind, that the registers don't work with integers, but with a wrapper around them called Int32 (and UInt32). They behave just like integers, but you must unwrap them if you wish to use "normal" integers to e.g. read memory at an address, or set the CPU pc.
This looks pretty boilerplate heavy though, maybe I should add an easier method to add syscalls at runtime...
Yah -- also just assigning syscall_int wouldn't add the symbols. It's ok to restrict adding syscalls to config time. Once the processor runs, it's probably a bad idea to add syscalls :>