I've been thinking about using dynamic linking for supporting host functions more dynamically. Or at least, a way to support them in libriscv proper. Right now there are all kinds of schemes to define host functions in guests ranging from fully dynamic with hashes to fast pre-built assembly functions using build system code generation.
The thing is, though, that dynamically linked host functions will never be the fastest option. They must fundamentally be loaded somewhere, which is not inside the main execute segment, and then they will invoke system calls (presumably), which leaves out one register for arguments (A7). It's probably OK, as I won't be using this in my games, but it would be nice to have a supported/blessed way to define host functions inside libriscv.
So, how does it (probably) work?
Create a dynamic executable
Define host functions up-front by (globally) registering them with libriscv
Load dynamic executable
During loading, the globally registered host functions will be automatically turned into a shared library
The shared library will be made accessible, so the dynamic linker can open it
When opened, the guest can now access the host functions through the API
I've been thinking about using dynamic linking for supporting host functions more dynamically. Or at least, a way to support them in libriscv proper. Right now there are all kinds of schemes to define host functions in guests ranging from fully dynamic with hashes to fast pre-built assembly functions using build system code generation.
The thing is, though, that dynamically linked host functions will never be the fastest option. They must fundamentally be loaded somewhere, which is not inside the main execute segment, and then they will invoke system calls (presumably), which leaves out one register for arguments (A7). It's probably OK, as I won't be using this in my games, but it would be nice to have a supported/blessed way to define host functions inside libriscv.
So, how does it (probably) work?