5 ms·
Related - M1 ARM assembly examples by Alex von Below: https://github.com/below/HelloSilicon https://github.com/below/HelloSilicon
by johndoe0815 5y ago
Related - M1 ARM assembly examples by Alex von Below: https://github.com/below/HelloSilicon https://github.com/below/HelloSilicon
- tyingq 5y ago"Apple reserves X18 for its own use. Do not use this register." Interesting. I wonder why that particular one. It's not exactly in the middle of the range. Maybe they searched for typical existing use and decided that was the least likely to have some conflict?
- monocasa 5y agox16, x17, and x18 are all different env pointers not really available for general use per se in the main ABI. x16 and x17 are used for plt linkage there, x18 is reserved for the system to make use of as it sees fit, at it's leisure. x18's use there seems to have survived into Apple's slightly modified ABI.
- comex 5y agoFor more context, look at the standard ARM ABI spec. Apple’s ABI diverges from the standard one in some places, IIRC, but in this case it’s complying with it: the spec says that X18 (which it calls r18) can be reserved by platforms for platform-specific use. The spec also shows how the registers are divided into several categories, which helps explain the choice of X18: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#general-purpose-registers https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aap...
- regularfry 5y ago"All these registers are yours - except X18. Attempt no MOVing there."
- saagarjha 5y agox18 is the standard platform register. On Darwin 20 and higher Apple pins the Rosetta context to it. When not used, it gets zeroed out on return to userspace in what I assume is a subtle prod to avoid its use.
- nonameiguess 5y agoWould have posted exactly this if you hadn't already. So many pitfalls with M1 in the way Apple subtly veers from normal ARM64 conventions and the published spec. This guy has already figured them out for you. Also helpful to look at the XNU source code to see how they implement syscalls.
- comex 5y agoFor the record, Apple does publish its own documentation describing how Apple’s ABI diverges from the ARM standard one: https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms https://developer.apple.com/documentation/xcode/writing-arm6...
- saagarjha 5y agoThis is not true, Apple sticks pretty closely to AAPCS except for a handful of cases.