|
Packit |
6c4009 |
/* Startup code compliant to the ELF s390 ABI.
|
|
Packit |
6c4009 |
Copyright (C) 2000-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
In addition to the permissions in the GNU Lesser General Public
|
|
Packit |
6c4009 |
License, the Free Software Foundation gives you unlimited
|
|
Packit |
6c4009 |
permission to link the compiled version of this file with other
|
|
Packit |
6c4009 |
programs, and to distribute those programs without any restriction
|
|
Packit |
6c4009 |
coming from the use of this file. (The GNU Lesser General Public
|
|
Packit |
6c4009 |
License restrictions do apply in other respects; for example, they
|
|
Packit |
6c4009 |
cover modification of the file, and distribution when not linked
|
|
Packit |
6c4009 |
into another program.)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Note that people who make modified versions of this file are not
|
|
Packit |
6c4009 |
obligated to grant this special exception for their modified
|
|
Packit |
6c4009 |
versions; it is their choice whether to do so. The GNU Lesser
|
|
Packit |
6c4009 |
General Public License gives permission to release a modified
|
|
Packit |
6c4009 |
version without this exception; this exception also makes it
|
|
Packit |
6c4009 |
possible to release a modified version which carries forward this
|
|
Packit |
6c4009 |
exception.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdep.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
This is the canonical entry point, usually the first thing in the text
|
|
Packit |
6c4009 |
segment. Most registers' values are unspecified, except for:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
%r14 Contains a function pointer to be registered with `atexit'.
|
|
Packit |
6c4009 |
This is how the dynamic linker arranges to have DT_FINI
|
|
Packit |
6c4009 |
functions called for shared libraries that have been loaded
|
|
Packit |
6c4009 |
before this code runs.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
%r15 The stack contains the arguments and environment:
|
|
Packit |
6c4009 |
0(%r15) argc
|
|
Packit |
6c4009 |
4(%r15) argv[0]
|
|
Packit |
6c4009 |
...
|
|
Packit |
6c4009 |
(4*argc)(%r15) NULL
|
|
Packit |
6c4009 |
(4*(argc+1))(%r15) envp[0]
|
|
Packit |
6c4009 |
...
|
|
Packit |
6c4009 |
NULL
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
.globl _start
|
|
Packit |
6c4009 |
.type _start,@function
|
|
Packit |
6c4009 |
_start:
|
|
Packit |
6c4009 |
cfi_startproc
|
|
Packit |
6c4009 |
/* Mark r14 as undefined in order to stop unwinding here! */
|
|
Packit |
6c4009 |
cfi_undefined (r14)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check if the kernel provides highgprs facility if needed by
|
|
Packit |
6c4009 |
the binary. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
lr %r6,%r15
|
|
Packit |
6c4009 |
la %r6,4(%r6) /* Skip the argument counter. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.L11: l %r5,0(%r6) /* Skip the argument vector. */
|
|
Packit |
6c4009 |
la %r6,4(%r6)
|
|
Packit |
6c4009 |
ltr %r5,%r5
|
|
Packit |
6c4009 |
jne .L11
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.L12: l %r5,0(%r6) /* Skip the environment vector. */
|
|
Packit |
6c4009 |
la %r6,4(%r6)
|
|
Packit |
6c4009 |
ltr %r5,%r5
|
|
Packit |
6c4009 |
jne .L12
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Usually the auxiliary vector can be expected directly after
|
|
Packit |
6c4009 |
the environment variables. But we have to skip extra zeros
|
|
Packit |
6c4009 |
because the loader might have removed unsecure variables for
|
|
Packit |
6c4009 |
setuid programs. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.L26: l %r5,0(%r6)
|
|
Packit |
6c4009 |
la %r6,4(%r6)
|
|
Packit |
6c4009 |
ltr %r5,%r5
|
|
Packit |
6c4009 |
jz .L26
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ahi %r6,-4
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Obtain the needed values from the auxiliary vector. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
lhi %r7,16 /* AT_HWCAP */
|
|
Packit |
6c4009 |
lhi %r8,3 /* AT_PHDR */
|
|
Packit |
6c4009 |
lhi %r9,5 /* AT_PHNUM */
|
|
Packit |
6c4009 |
lhi %r2,4 /* AT_PHENT */
|
|
Packit |
6c4009 |
.L13: l %r5,0(%r6)
|
|
Packit |
6c4009 |
clr %r5,%r7
|
|
Packit |
6c4009 |
jne .L15
|
|
Packit |
6c4009 |
l %r10,4(%r6) /* r10 = AT_HWCAP value. */
|
|
Packit |
6c4009 |
.L15: clr %r5,%r8
|
|
Packit |
6c4009 |
jne .L16
|
|
Packit |
6c4009 |
l %r11,4(%r6) /* r11 = AT_PHDR value. */
|
|
Packit |
6c4009 |
.L16: clr %r5,%r9
|
|
Packit |
6c4009 |
jne .L17
|
|
Packit |
6c4009 |
l %r12,4(%r6) /* r12 = AT_PHNUM value. */
|
|
Packit |
6c4009 |
.L17: clr %r5,%r2
|
|
Packit |
6c4009 |
jne .L18
|
|
Packit |
6c4009 |
l %r0,4(%r6) /* r0 = AT_PHENT value. */
|
|
Packit |
6c4009 |
.L18: ltr %r5,%r5
|
|
Packit |
6c4009 |
la %r6,8(%r6)
|
|
Packit |
6c4009 |
jnz .L13
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Locate the ELF header by looking for the first PT_LOAD
|
|
Packit |
6c4009 |
segment with a p_offset of zero. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
lr %r4,%r11 /* Backup AT_PHDR. */
|
|
Packit |
6c4009 |
lhi %r7,1 /* PT_LOAD id */
|
|
Packit |
6c4009 |
lhi %r8,0
|
|
Packit |
6c4009 |
.L19: cl %r7,0(%r4) /* p_type == PT_LOAD? */
|
|
Packit |
6c4009 |
jne .L20
|
|
Packit |
6c4009 |
cl %r8,4(%r4) /* p_offset == 0? */
|
|
Packit |
6c4009 |
jne .L20
|
|
Packit |
6c4009 |
l %r9,8(%r4) /* r9 = PT_LOAD.p_vaddr <- ELF header address */
|
|
Packit |
6c4009 |
j .L24
|
|
Packit |
6c4009 |
.L20: alr %r4,%r0 /* r4 += AT_PHENT value */
|
|
Packit |
6c4009 |
brct %r12,.L19
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
j .+2 /* Trap, there must be such a phdr. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.L24: lr %r4,%r11 /* Backup AT_PHDR. */
|
|
Packit |
6c4009 |
lhi %r2,6 /* PT_PHDR id */
|
|
Packit |
6c4009 |
.L23: cl %r2,0(%r4)
|
|
Packit |
6c4009 |
jne .L22
|
|
Packit |
6c4009 |
l %r3,8(%r4) /* r3 = PT_PHDR p_vaddr */
|
|
Packit |
6c4009 |
j .L25
|
|
Packit |
6c4009 |
.L22: alr %r4,%r0 /* r4 += AT_PHENT value */
|
|
Packit |
6c4009 |
brct %r12,.L23
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
j .L14 /* No PT_PHDR found - skip checking. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.L25: slr %r11,%r3 /* AT_PHDR - PT_PHDR.p_vaddr (relocation offset)*/
|
|
Packit |
6c4009 |
alr %r9,%r11 /* PT_LOAD.p_vaddr += relocation offset */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
l %r5,36(%r9) /* Load the e_flags field. */
|
|
Packit |
6c4009 |
tml %r5,1
|
|
Packit |
6c4009 |
jz .L14 /* Binary does not require highgprs facility. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
tml %r10,512 /* Check the AT_HWCAP value. */
|
|
Packit |
6c4009 |
jz 2 /* Trap if no highgprs facility available. */
|
|
Packit |
6c4009 |
.L14:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Setup pointer to literal pool of _start */
|
|
Packit |
6c4009 |
basr %r13,0
|
|
Packit |
6c4009 |
.L0: ahi %r13,.Llit-.L0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* load argc and argv from stack */
|
|
Packit |
6c4009 |
la %r4,4(%r15) # get argv
|
|
Packit |
6c4009 |
l %r3,0(%r15) # get argc
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* align the stack to a double word boundary */
|
|
Packit |
6c4009 |
lhi %r0,-8
|
|
Packit |
6c4009 |
nr %r15,%r0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Setup a stack frame and a parameter area */
|
|
Packit |
6c4009 |
ahi %r15,-104 # make room on stack
|
|
Packit |
6c4009 |
xc 0(4,%r15),0(%r15) # clear back-chain
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* set up arguments for __libc_start_main:
|
|
Packit |
6c4009 |
main, argc, argv, envp, _init, _fini, rtld_fini, stack_end
|
|
Packit |
6c4009 |
Note that envp will be determined later in __libc_start_main
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
stm %r14,%r15,96(%r15) # store rtld_fini/stack_end to parameter area
|
|
Packit |
6c4009 |
la %r7,96(%r15)
|
|
Packit |
6c4009 |
l %r6,.L2-.Llit(%r13) # load pointer to __libc_csu_fini
|
|
Packit |
6c4009 |
l %r5,.L1-.Llit(%r13) # load pointer to __libc_csu_init
|
|
Packit |
6c4009 |
l %r2,.L3-.Llit(%r13) # load pointer to main
|
|
Packit |
6c4009 |
l %r1,.L4-.Llit(%r13) # load pointer to __libc_start_main
|
|
Packit |
6c4009 |
#ifdef PIC
|
|
Packit |
6c4009 |
l %r12,.L5-.Llit(%r13) # load .got pointer
|
|
Packit |
6c4009 |
la %r6,0(%r13,%r6)
|
|
Packit |
6c4009 |
la %r5,0(%r13,%r5)
|
|
Packit |
6c4009 |
la %r12,0(%r13,%r12)
|
|
Packit |
6c4009 |
l %r2,0(%r12,%r2)
|
|
Packit |
6c4009 |
la %r1,0(%r13,%r1)
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* ok, now branch to the libc main routine */
|
|
Packit |
6c4009 |
basr %r14,%r1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* crash if __libc_start_main returns */
|
|
Packit |
6c4009 |
.word 0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cfi_endproc
|
|
Packit |
6c4009 |
.Llit:
|
|
Packit |
6c4009 |
#ifndef PIC
|
|
Packit |
6c4009 |
.L1: .long __libc_csu_init
|
|
Packit |
6c4009 |
.L2: .long __libc_csu_fini
|
|
Packit |
6c4009 |
.L3: .long main
|
|
Packit |
6c4009 |
.L4: .long __libc_start_main
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
.L1: .long __libc_csu_init-.Llit
|
|
Packit |
6c4009 |
.L2: .long __libc_csu_fini-.Llit
|
|
Packit |
6c4009 |
.L3: .long main@GOT
|
|
Packit |
6c4009 |
.L4: .long __libc_start_main@plt-.Llit
|
|
Packit |
6c4009 |
.L5: .long _GLOBAL_OFFSET_TABLE_-.Llit
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Define a symbol for the first piece of initialized data. */
|
|
Packit |
6c4009 |
.data
|
|
Packit |
6c4009 |
.globl __data_start
|
|
Packit |
6c4009 |
__data_start:
|
|
Packit |
6c4009 |
.long 0
|
|
Packit |
6c4009 |
.weak data_start
|
|
Packit |
6c4009 |
data_start = __data_start
|