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

Add support for RISC-V #33

Open
Arun-42 opened this issue Nov 4, 2022 · 2 comments
Open

Add support for RISC-V #33

Arun-42 opened this issue Nov 4, 2022 · 2 comments

Comments

@Arun-42
Copy link

Arun-42 commented Nov 4, 2022

I am trying to cross-compile ROS2 to RISCV64, and Mimick is a dependency. Could you please add support for RISCV64? Or if you could provide pointers as how to do it, I could work on it.

@Snaipe
Copy link
Owner

Snaipe commented Nov 4, 2022

You would need to add a new trampoline for the architecture here: https://github.com/Snaipe/Mimick/tree/master/src/asm

The trampoline must be written with position-independent instructions, as it gets copied to multiple locations. It also must not clobber any of the ABI registers and stack, as its main role is to prepare some state before long-jumping to the stub function. This is why you'll see most trampolines backing up the state of some registers before restoring said state later on.

The general memory layout of a trampoline is as follows:

--------------------
 struct mmk_stub *    context pointer of stub  (8 bytes)
--------------------
      plt_fn *        function pointer of stub (8 bytes)
--------------------
   mmk_trampoline     trampoline opcodes       (N bytes)
        ...
 mmk_trampoline_end
--------------------

You can get inspiration from other architectures, but the general gist is that the higher-level behavior of the trampoline is:

  • Load mmk_stub pointer
  • Call mmk_stub->ctx_set
  • Call mmk_stub->ctx_asked
  • If ctx_asked returned 0, this is a stub trampoline jump, perform a long jump to the stub function pointer
  • Otherwise, this is mimick trying to retrieve the trampoline context, call mmk_stub->ctx_get and return its result.

When this is done, add the CMake config to handle the architecture here: https://github.com/Snaipe/Mimick/blob/master/CMakeLists.txt#L50

@ziyao233
Copy link

Thanks for Snaipe's guide, I have ported Mimick to RISCV64.
#34

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

3 participants