SPRAB89A September 2011 – March 2014
The following code sequences illustrate how an exported function changes the DP to point to its data segment by indexing into its caller's DSBT. Any function that changes DP is responsible for restoring it upon return (the DP is callee-save).
Entry Sequence to Setup DP
func:
MV DP,somewhere ;typically the stack
LD *+DP[$DSBT_index(func)],DP ;reloc R_C6000_DSBT_INDEX
; body of function
The expression $DSBT_index(func) evaluates to the unique library index of the current object and generates a special relocation to indicate this. The index will be bound either at static link time or dynamically.
Exit Sequence
MV somewhere, DP
RET
The exit sequence simply restores the caller's DP.
An exported function may choose not to change the DP if it does not use any DP-relative addressing, and it does not call any functions that use DP-relative addressing.