7.9.4. Linux Process Initialization
The stack pointer,
sp
, points to the argument count on the stack.
Table 89.
Stack Initial State at User Process Start
Purpose
Start Address
Length
Unspecified
High addresses
Referenced strings
Varies
Unspecified
Null auxilliary vector entry
4 bytes
Auxilliary vector entries
8 bytes each
NULL terminator for envp
4 bytes
Environment pointers
sp
+ 8 + 4 × argc
4 bytes each
NULL terminator for argv
sp
+ 4 + 4 × argc
4 bytes
Argument pointers
sp
+ 4
4 bytes each
Argument count
sp
4 bytes
Unspecified
Low addresses
If the application should register a destructor function with
atexit
, the pointer is
placed in
r4
. Otherwise
r4
is zero.
The contents of all other registers are unspecified. User code should set
fp
to zero to
mark the end of the frame chain.
The auxiliary vector is a series of pairs of 32-bit tag and 32-bit value, terminated by
an
AT_NULL
tag.
7.9.5. Linux Position-Independent Code
Every position-independent code (PIC) function which uses global data or global
functions must load the value of the GOT pointer into a register. Any available register
may be used. If a caller-saved register is used the function must save and restore it
around calls. If a callee-saved register is used it must be saved and restored around
the current function. Examples in this document use
r22
for the GOT pointer.
The GOT pointer is loaded using a PC-relative offset to the
_gp_got
symbol, as
shown below.
Example 15. Loading the GOT Pointer
nextpc r22
1:
orhi r1, %hiadj(_gp_got - 1b) # R_NIOS2_PCREL_HA _gp_got
addi r1, r1, %lo(_gp_got - 1b) # R_NIOS2_PCREL_LO _gp_got - 4
add r22, r22, r1
# GOT pointer in r22
Data may be accessed by loading its location from the GOT. A single word GOT entry is
generated for each referenced symbol.
7. Application Binary Interface
NII-PRG | 2018.04.18
Nios II Processor Reference Guide
162