Conversation
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.
480253c to
7adf857
Compare
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.
7adf857 to
80a02c0
Compare
|
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? |
|
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. |
|
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. |
|
Apparently on Linux system calls are made by placing the command in |
| pop {{ r0-r4, r12 }} // restore preserved registers, dummy value, and alignment amount | ||
| add sp, r12 // restore SP alignment using R12 | ||
| pop {{ r12 }} // restore SPSR using R12 | ||
| msr spsr_cxsf, r12 // |
There was a problem hiding this comment.
SPSR_cxsf is redundant, because _cxsf covers all the fields (C, X, S and F), and that is the default. Only specify sub-fields of SPSR when writing to a subset of the register.
| pop {{ r0-r3, r12, lr }} // restore alignment amount (in LR) and preserved registers | ||
| add sp, lr // restore SP alignment using LR | ||
| msr cpsr_c, {irq_mode} // switch back to IRQ mode (with IRQ masked) | ||
| ldmia sp!, {{ lr }} // load and restore SPSR using LR |
There was a problem hiding this comment.
Should be POP (which is equivalent).
|
Thought I remembered some generic EABI syscall standard, but I was wrong. The Linux one makes sense: I'd say go ahead an implement that now? Agree that it would be nice to be able to support all the things… |
Includes #99 and #98