Skip to content

Add a syscall mechanism#108

Open
thejpster wants to merge 11 commits intorust-embedded:mainfrom
thejpster:syscall-api
Open

Add a syscall mechanism#108
thejpster wants to merge 11 commits intorust-embedded:mainfrom
thejpster:syscall-api

Conversation

@thejpster
Copy link
Contributor

@thejpster thejpster commented Jan 30, 2026

  • Provide r0-r3 to SVC exception handler, for implementing syscalls
  • Re-writes the asm routines for better efficiency
  • Adds svc1!, svc2!, svc3! and svc4! macros for placing syscalls with arguments

Includes #99 and #98

Also relies on all the targets having thumb-interworking enabled.
Thanks, macOS :/
You can't depend on the flags because they vary depending on what the
machine code does.
They were created before I rebased on main, which had changes to the
example programs.
thejpster and others added 6 commits February 1, 2026 15:45
I went with:

* .section
* .arm or .thumb
* .global
* .type
* label
* code

This fixes the smp_test built for thumb mode, which was missing a .arm
directive (and the start-up code doesn't work in thumb mode).
Targets added in rust-lang/rust#150138. Tested with local build of rustc.

Will fail with the versions of nightly rust specified in the CI config. Need to wait for 2025-01-26 to come out.
thumbv6-none-eabi isn't tested because it requires a new compiler-builtins that isn't upstream yet.
This involves stacking the registers in the opposite order, so that
r0-r3 are stacked at the lowest addresses (and that any stack alignment
padding is stored above them).

I also took the opportunity to move the integer register push/pop
code into the asm routines. This meant we could avoid stacking a couple
of registers and speed up the routines. It also meant it was a bit
easier to ensure the frame was stacked after the AAPCS stack padding
and hence in a known location.

This commit also add svc1!, svc2!, svc3! and svc4! macros for passing
arguments to syscall. They have to be macros because the syscall numbe
goes into the instruction as a literal and cannot come from a function
call.
@thejpster
Copy link
Contributor Author

Rebased on latest versions of #98 and #99, so it now includes all the new targets.

@BartMassey
Copy link
Member

Is it worth fully supporting a standard syscall convention such as SMCCC or EABI-32 (or Semihosting, or some subset of these with feature selection)? Or is this far more than we would want to start with?

@thejpster
Copy link
Contributor Author

Semihosting is handled by the semihosting crate so I don’t need to handle that.

I didn’t know there was a specific EABI syscall spec but happy to look at it if you have a link.

@thejpster
Copy link
Contributor Author

https://developer.arm.com/Architectures/Secure%20Monitor%20Calling%20Convention - SMC and HVC would be a good follow-up PR (if they apply on AArch32 systems). I’d love to have a working example of Rust running at all four layers of the stack.

@jonathanpallant
Copy link
Contributor

jonathanpallant commented Feb 4, 2026

Apparently on Linux system calls are made by placing the command in r7 and the arguments in r0-r6 (https://man7.org/linux/man-pages/man2/syscall.2.html). We don't have to follow the Linux syscall model, but now the SVCall exception handler is doing its own integer register stacking, we actually could implement that - we would just push more registers than we strictly need to.

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

Successfully merging this pull request may close these issues.

3 participants