Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to add syscalls? #15

Open
RobertBaruch opened this issue Apr 18, 2022 · 5 comments
Open

Method to add syscalls? #15

RobertBaruch opened this issue Apr 18, 2022 · 5 comments

Comments

@RobertBaruch
Copy link

Could you add a method to add syscalls to the CPU? Thanks!

@AntonLydike
Copy link
Owner

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!

@RobertBaruch
Copy link
Author

Oh, I was kind of hoping not to have to modify the files in the distro...

@AntonLydike
Copy link
Owner

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.

@AntonLydike
Copy link
Owner

This looks pretty boilerplate heavy though, maybe I should add an easier method to add syscalls at runtime...

@RobertBaruch
Copy link
Author

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 :>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants