|
Packit Service |
82fcde |
/* Startup code compliant to the ELF Mips ABI.
|
|
Packit Service |
82fcde |
Copyright (C) 1995-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
In addition to the permissions in the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License, the Free Software Foundation gives you unlimited
|
|
Packit Service |
82fcde |
permission to link the compiled version of this file with other
|
|
Packit Service |
82fcde |
programs, and to distribute those programs without any restriction
|
|
Packit Service |
82fcde |
coming from the use of this file. (The GNU Lesser General Public
|
|
Packit Service |
82fcde |
License restrictions do apply in other respects; for example, they
|
|
Packit Service |
82fcde |
cover modification of the file, and distribution when not linked
|
|
Packit Service |
82fcde |
into another program.)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
Note that people who make modified versions of this file are not
|
|
Packit Service |
82fcde |
obligated to grant this special exception for their modified
|
|
Packit Service |
82fcde |
versions; it is their choice whether to do so. The GNU Lesser
|
|
Packit Service |
82fcde |
General Public License gives permission to release a modified
|
|
Packit Service |
82fcde |
version without this exception; this exception also makes it
|
|
Packit Service |
82fcde |
possible to release a modified version which carries forward this
|
|
Packit Service |
82fcde |
exception.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library. If not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __ASSEMBLY__ 1
|
|
Packit Service |
82fcde |
#include <entry.h>
|
|
Packit Service |
82fcde |
#include <sgidefs.h>
|
|
Packit Service |
82fcde |
#include <sys/asm.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#ifndef ENTRY_POINT
|
|
Packit Service |
82fcde |
#error ENTRY_POINT needs to be defined for start.S on MIPS/ELF.
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* This is the canonical entry point, usually the first thing in the text
|
|
Packit Service |
82fcde |
segment. The SVR4/Mips ABI (pages 3-31, 3-32) says that when the entry
|
|
Packit Service |
82fcde |
point runs, most registers' values are unspecified, except for:
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
v0 ($2) Contains a function pointer to be registered with `atexit'.
|
|
Packit Service |
82fcde |
This is how the dynamic linker arranges to have DT_FINI
|
|
Packit Service |
82fcde |
functions called for shared libraries that have been loaded
|
|
Packit Service |
82fcde |
before this code runs.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
sp ($29) The stack contains the arguments and environment:
|
|
Packit Service |
82fcde |
0(%esp) argc
|
|
Packit Service |
82fcde |
4(%esp) argv[0]
|
|
Packit Service |
82fcde |
...
|
|
Packit Service |
82fcde |
(4*argc)(%esp) NULL
|
|
Packit Service |
82fcde |
(4*(argc+1))(%esp) envp[0]
|
|
Packit Service |
82fcde |
...
|
|
Packit Service |
82fcde |
NULL
|
|
Packit Service |
82fcde |
ra ($31) The return address register is set to zero so that programs
|
|
Packit Service |
82fcde |
that search backword through stack frames recognize the last
|
|
Packit Service |
82fcde |
stack frame.
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* We need to call:
|
|
Packit Service |
82fcde |
__libc_start_main (int (*main) (int, char **, char **), int argc,
|
|
Packit Service |
82fcde |
char **argv, void (*init) (void), void (*fini) (void),
|
|
Packit Service |
82fcde |
void (*rtld_fini) (void), void *stack_end)
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
.text
|
|
Packit Service |
82fcde |
.globl ENTRY_POINT
|
|
Packit Service |
82fcde |
.type ENTRY_POINT,@function
|
|
Packit Service |
82fcde |
#ifndef __mips16
|
|
Packit Service |
82fcde |
ENTRY_POINT:
|
|
Packit Service |
82fcde |
# ifdef __PIC__
|
|
Packit Service |
82fcde |
SETUP_GPX($0)
|
|
Packit Service |
82fcde |
SETUP_GPX64($25,$0)
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
PTR_LA $28, _gp /* Setup GP correctly if we're non-PIC. */
|
|
Packit Service |
82fcde |
move $31, $0
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
PTR_LA $4, main /* main */
|
|
Packit Service |
82fcde |
PTR_L $5, 0($29) /* argc */
|
|
Packit Service |
82fcde |
PTR_ADDIU $6, $29, PTRSIZE /* argv */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Allocate space on the stack for seven arguments (o32 only)
|
|
Packit Service |
82fcde |
and make sure the stack is aligned to double words (8 bytes)
|
|
Packit Service |
82fcde |
on o32 and quad words (16 bytes) on n32 and n64. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
and $29, -2 * SZREG
|
|
Packit Service |
82fcde |
# if _MIPS_SIM == _ABIO32
|
|
Packit Service |
82fcde |
PTR_SUBIU $29, 32
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
PTR_LA $7, __libc_csu_init /* init */
|
|
Packit Service |
82fcde |
PTR_LA $8, __libc_csu_fini
|
|
Packit Service |
82fcde |
# if _MIPS_SIM == _ABIO32
|
|
Packit Service |
82fcde |
PTR_S $8, 16($29) /* fini */
|
|
Packit Service |
82fcde |
PTR_S $2, 20($29) /* rtld_fini */
|
|
Packit Service |
82fcde |
PTR_S $29, 24($29) /* stack_end */
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
move $9, $2 /* rtld_fini */
|
|
Packit Service |
82fcde |
move $10, $29 /* stack_end */
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
PTR_LA $25, __libc_start_main
|
|
Packit Service |
82fcde |
jalr $25
|
|
Packit Service |
82fcde |
hlt: b hlt /* Crash if somehow it does return. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#elif _MIPS_SIM == _ABIO32 /* __mips16 */
|
|
Packit Service |
82fcde |
/* MIPS16 entry point. */
|
|
Packit Service |
82fcde |
.set mips16
|
|
Packit Service |
82fcde |
ENTRY_POINT:
|
|
Packit Service |
82fcde |
# ifdef __PIC__
|
|
Packit Service |
82fcde |
li $3, %hi(_gp_disp)
|
|
Packit Service |
82fcde |
addiu $4, $pc, %lo(_gp_disp)
|
|
Packit Service |
82fcde |
sll $3, 16
|
|
Packit Service |
82fcde |
addu $3, $4
|
|
Packit Service |
82fcde |
move $gp, $3
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
li $3, %hi(_gp)
|
|
Packit Service |
82fcde |
sll $3, 16
|
|
Packit Service |
82fcde |
addiu $3, %lo(_gp)
|
|
Packit Service |
82fcde |
move $gp, $3
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
/* Tie end of stack frames. */
|
|
Packit Service |
82fcde |
li $4, 0
|
|
Packit Service |
82fcde |
move $31, $4
|
|
Packit Service |
82fcde |
/* Create new SP value in $7, including alignment. */
|
|
Packit Service |
82fcde |
li $4, 2 * SZREG
|
|
Packit Service |
82fcde |
neg $4, $4
|
|
Packit Service |
82fcde |
move $7, $sp
|
|
Packit Service |
82fcde |
and $7, $4
|
|
Packit Service |
82fcde |
addiu $7, -32
|
|
Packit Service |
82fcde |
/* Load arguments with original SP. */
|
|
Packit Service |
82fcde |
lw $5, 0($sp)
|
|
Packit Service |
82fcde |
addiu $6, $sp, PTRSIZE
|
|
Packit Service |
82fcde |
/* Update SP. */
|
|
Packit Service |
82fcde |
move $sp, $7
|
|
Packit Service |
82fcde |
/* Lay out last arguments, and call __libc_start_main(). */
|
|
Packit Service |
82fcde |
# ifdef __PIC__
|
|
Packit Service |
82fcde |
sw $7, 24($sp) /* stack_end */
|
|
Packit Service |
82fcde |
lw $4, %got(__libc_csu_fini)($3)
|
|
Packit Service |
82fcde |
lw $7, %got(__libc_csu_init)($3) /* init */
|
|
Packit Service |
82fcde |
sw $4, 16($sp) /* fini */
|
|
Packit Service |
82fcde |
lw $4, %got(main)($3) /* main */
|
|
Packit Service |
82fcde |
lw $3, %call16(__libc_start_main)($3)
|
|
Packit Service |
82fcde |
sw $2, 20($sp) /* rtld_fini */
|
|
Packit Service |
82fcde |
move $25, $3
|
|
Packit Service |
82fcde |
jalr $3
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
lw $4, 1f
|
|
Packit Service |
82fcde |
sw $7, 24($sp) /* stack_end */
|
|
Packit Service |
82fcde |
lw $7, 2f /* init */
|
|
Packit Service |
82fcde |
sw $4, 16($sp) /* fini */
|
|
Packit Service |
82fcde |
lw $4, 3f /* main */
|
|
Packit Service |
82fcde |
sw $2, 20($sp) /* rtld_fini */
|
|
Packit Service |
82fcde |
/* Load and call __libc_start_main(). */
|
|
Packit Service |
82fcde |
lw $3, 4f
|
|
Packit Service |
82fcde |
jalr $3
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
hlt: b hlt /* Crash if somehow it does return. */
|
|
Packit Service |
82fcde |
# ifndef __PIC__
|
|
Packit Service |
82fcde |
.align 2
|
|
Packit Service |
82fcde |
1: .word __libc_csu_fini
|
|
Packit Service |
82fcde |
2: .word __libc_csu_init
|
|
Packit Service |
82fcde |
3: .word main
|
|
Packit Service |
82fcde |
4: .word __libc_start_main
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#else /* __mips16 && _MIPS_SIM != _ABIO32 */
|
|
Packit Service |
82fcde |
# error "MIPS16 support for N32/N64 not implemented"
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#endif /* __mips16 */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Define a symbol for the first piece of initialized data. */
|
|
Packit Service |
82fcde |
.data
|
|
Packit Service |
82fcde |
.globl __data_start
|
|
Packit Service |
82fcde |
__data_start:
|
|
Packit Service |
82fcde |
.long 0
|
|
Packit Service |
82fcde |
.weak data_start
|
|
Packit Service |
82fcde |
data_start = __data_start
|