Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the iPhone ARM64 calling convention, what is in register $x1?

I'm having a hard time making sense of the Apple ARM64 Function Calling Conventions doc and ARM Procedure Call Standard.

When a function is called, I understand that $r0 is self, and $r2 appears to be the first function argument.

What is in $x1?

Does the stack pointer refer to the first argument beyond four?

like image 442
bcattle Avatar asked Jan 08 '15 02:01

bcattle


1 Answers

You want to read the "The Base Procedure Call Standard" chapter of the AAPCS64, section 'Subroutine Calls'; their register naming convention uses "r0..r30" where lldb uses "x0..x30". x1 is the second argument register. x0 is the first. The arm64 iOS ABI's biggest difference from AAPCS64 is in how variadic functions (printf etc) are called. The apple doc you linked to details the exact difference.

lldb provides register alias names for armv7/arm64/x86_64, $argi, to refer to the ith argument. $arg1, $arg2, etc. (Arguments are passed on the stack on i386 so the aliases aren't defined there) I'd recommend using these convenience names and not worrying about the details of the architecture, if possible.

NB these argument passing register contents are only valid at the start of the function. They're usually saved on the stack or copied into other registers -- the registers will be reused/overwritten as soon as another function call is made.

like image 131
Jason Molenda Avatar answered Oct 05 '22 23:10

Jason Molenda