Kenwood HP 9000 Personal Computer User Manual


 
264 Chapter 7
Position-Independent Code
Generating Position-Independent Code
NOP
LDW -24(%sp),%rp ; restore the original rp
LDSID (%rp),%r1
MTSP %r1,%sr0
BE,N 0(%sr0,%rp) ; inter-space return
For More Information:
The remainder of this section describes how compilers generate PIC for
the following addressing situations:
“PIC Requirements for Compilers and Assembly Code”
“Long Calls”
“Long Branches and Switch Tables”
“Assigned GOTO Statements”
“Literal References”
“Global and Static Variable References”
“Procedure Labels”
You can use these guidelines to write assembly language programs that
generate PIC object code. For details on assembly language, refer to the
Assembler Reference Manual and PA-RISC 2.0 Architecture.
PIC Requirements for Compilers and
Assembly Code
The linkage table pointer register, %r19, must be stored at %sp32 by all
PIC routines. This can be done once on procedure entry. %r19 must also
be restored on return from a procedure call. The value should have been
stored in %sp32 (and possibly in a callee-saves register). If the PIC
routine makes several procedure calls, the routine should copy %r19 into
a callee-saves register as well, to avoid a memory reference when
restoring %r19 upon return from each procedure call. Just like %r27
(%dp), the compilers treat %r19 as a reserved register whenever PIC
mode is in effect.
In general, references to code are handled by the linker, and the
compilers act differently only in the few cases where they would have
generated long calls or long branches. References to data, however, need
a new fixup request to identify indirect references through the linkage
table, and the code generated will change slightly.