Clemson University -- CPSC 231 -- Fall 2009 ABI - application binary interface - a specification defining requirements for portability of applications at binary level (i.e., executables) - no recompilation or relinking - interoperability (assembly language subroutine can be called from HLL) - usually associated with a particular OS or OS family - thus, an executable compiled according to one ABI will not typically run under a different OS on the same machine - also: allows assembly language routines to be called from HLL routines, and HLL routines to be called from assembly language routines specifications in ABI include: - specific processor or processor family - any required processor features (e.g., SIMD instructions) - data formats - register usage conventions - stack frame format - parameter passing, including fp/structure/union parameters - return value passing, including fp/structure/union return values - specific OS or OS family - object and executable file formats example register conventions - actual parameters - return value(s) - return address - stack pointer - frame pointer - global area pointer - constant pool pointer - temporaries - caller-saved (if caller wants them preserved over call, caller must save and retore) - callee-saved (if called subroutines wants to use them, subroutine must save and retore) SPARC SYSV ABI - http://www.sparc.com/standards/psABI3rd.pdf SPARC register usage conventions %i0-%i5 -- incoming parameters %i6 -- frame pointer %i7 -- address of call instruction (return to %i7 + 8 if save) %l0-%l7 -- all yours %o0 -- all yours, but also used to pass a parameter to and/or return a value from a subroutine %o1-%o5 -- all yours, but also used to pass parameters to a subroutine %o6 -- stack pointer %o7 -- address of call instruction (return to %o7 + 8 if no save) %g0 -- always zero %g1 -- all yours, volatile across calls %g2-%g4 -- "reserved to application" %g5-%g7 -- "reserved to the system" stack frame must be doubleword-aligned for comparison - MIPS register conventions (cf. p. 376) register alt. name - usage -------- --------- ----- r0 $zero - constant 0 (designed into the hardware) r1 $at - reserved for assembler r2-r3 $v0-$v1 - expression evaluation and function return value r4-r7 $a0-$a3 - four arguments r8-r15 $t0-$t7 - eight temporaries (not preserved across calls) r16-r23 $s0-$s7 - eight saved temporaries (preserved across calls) r24-r25 $t8-$t9 - two temporaries (not preserved across calls) r26-r27 $k0-$k1 - reserved for OS kernel r28 $gp - pointer to global area r29 $sp - stack pointer r30 $fp - frame pointer r31 $ra - return address (usage designed into the hardware) have to save registers in absence of full info about caller and subroutine caller-save registers save in caller before call, restore after return opt.: save only those registers that have to be preserved across call callee-save registers save in subroutine prolog, restore in epilog opt.: save only those registers that are actually used in subroutine possible optimization: link-time register allocation (for static linking)