1368860124c34e101f2e9fda71870b5562108357aPete Delaney/* 2368860124c34e101f2e9fda71870b5562108357aPete Delaney * Copyright (C) 2013 The Android Open Source Project 3368860124c34e101f2e9fda71870b5562108357aPete Delaney * All rights reserved. 4368860124c34e101f2e9fda71870b5562108357aPete Delaney * 5368860124c34e101f2e9fda71870b5562108357aPete Delaney * Redistribution and use in source and binary forms, with or without 6368860124c34e101f2e9fda71870b5562108357aPete Delaney * modification, are permitted provided that the following conditions 7368860124c34e101f2e9fda71870b5562108357aPete Delaney * are met: 8368860124c34e101f2e9fda71870b5562108357aPete Delaney * * Redistributions of source code must retain the above copyright 9368860124c34e101f2e9fda71870b5562108357aPete Delaney * notice, this list of conditions and the following disclaimer. 10368860124c34e101f2e9fda71870b5562108357aPete Delaney * * Redistributions in binary form must reproduce the above copyright 11368860124c34e101f2e9fda71870b5562108357aPete Delaney * notice, this list of conditions and the following disclaimer in 12368860124c34e101f2e9fda71870b5562108357aPete Delaney * the documentation and/or other materials provided with the 13368860124c34e101f2e9fda71870b5562108357aPete Delaney * distribution. 14368860124c34e101f2e9fda71870b5562108357aPete Delaney * 15368860124c34e101f2e9fda71870b5562108357aPete Delaney * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16368860124c34e101f2e9fda71870b5562108357aPete Delaney * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17368860124c34e101f2e9fda71870b5562108357aPete Delaney * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18368860124c34e101f2e9fda71870b5562108357aPete Delaney * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19368860124c34e101f2e9fda71870b5562108357aPete Delaney * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20368860124c34e101f2e9fda71870b5562108357aPete Delaney * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21368860124c34e101f2e9fda71870b5562108357aPete Delaney * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22368860124c34e101f2e9fda71870b5562108357aPete Delaney * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23368860124c34e101f2e9fda71870b5562108357aPete Delaney * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24368860124c34e101f2e9fda71870b5562108357aPete Delaney * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25368860124c34e101f2e9fda71870b5562108357aPete Delaney * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26368860124c34e101f2e9fda71870b5562108357aPete Delaney * SUCH DAMAGE. 27368860124c34e101f2e9fda71870b5562108357aPete Delaney */ 28368860124c34e101f2e9fda71870b5562108357aPete Delaney 29368860124c34e101f2e9fda71870b5562108357aPete Delaney#include "../../bionic/libc_init_common.h" 30368860124c34e101f2e9fda71870b5562108357aPete Delaney#include <stddef.h> 31368860124c34e101f2e9fda71870b5562108357aPete Delaney#include <stdint.h> 32368860124c34e101f2e9fda71870b5562108357aPete Delaney 33368860124c34e101f2e9fda71870b5562108357aPete Delaney__attribute__ ((section (".preinit_array"))) 34368860124c34e101f2e9fda71870b5562108357aPete Delaneyvoid (*__PREINIT_ARRAY__)(void) = (void (*)(void)) -1; 35368860124c34e101f2e9fda71870b5562108357aPete Delaney 36368860124c34e101f2e9fda71870b5562108357aPete Delaney__attribute__ ((section (".init_array"))) 37368860124c34e101f2e9fda71870b5562108357aPete Delaneyvoid (*__INIT_ARRAY__)(void) = (void (*)(void)) -1; 38368860124c34e101f2e9fda71870b5562108357aPete Delaney 39368860124c34e101f2e9fda71870b5562108357aPete Delaney__attribute__ ((section (".fini_array"))) 40368860124c34e101f2e9fda71870b5562108357aPete Delaneyvoid (*__FINI_ARRAY__)(void) = (void (*)(void)) -1; 41368860124c34e101f2e9fda71870b5562108357aPete Delaney 42368860124c34e101f2e9fda71870b5562108357aPete Delaney 43368860124c34e101f2e9fda71870b5562108357aPete Delaney__LIBC_HIDDEN__ void do_mips_start(void *raw_args) { 44368860124c34e101f2e9fda71870b5562108357aPete Delaney structors_array_t array; 45368860124c34e101f2e9fda71870b5562108357aPete Delaney array.preinit_array = &__PREINIT_ARRAY__; 46368860124c34e101f2e9fda71870b5562108357aPete Delaney array.init_array = &__INIT_ARRAY__; 47368860124c34e101f2e9fda71870b5562108357aPete Delaney array.fini_array = &__FINI_ARRAY__; 48368860124c34e101f2e9fda71870b5562108357aPete Delaney 49368860124c34e101f2e9fda71870b5562108357aPete Delaney __libc_init(raw_args, NULL, &main, &array); 50368860124c34e101f2e9fda71870b5562108357aPete Delaney} 51368860124c34e101f2e9fda71870b5562108357aPete Delaney 52368860124c34e101f2e9fda71870b5562108357aPete Delaney/* 53368860124c34e101f2e9fda71870b5562108357aPete Delaney * This function prepares the return address with a branch-and-link 54368860124c34e101f2e9fda71870b5562108357aPete Delaney * instruction (bal) and then uses a .cpload to compute the Global 55368860124c34e101f2e9fda71870b5562108357aPete Delaney * Offset Table (GOT) pointer ($gp). The $gp is then used to load 56368860124c34e101f2e9fda71870b5562108357aPete Delaney * the address of _do_start() into $t9 just before calling it. 57368860124c34e101f2e9fda71870b5562108357aPete Delaney * Terminating the stack with a NULL return address. 58368860124c34e101f2e9fda71870b5562108357aPete Delaney */ 59368860124c34e101f2e9fda71870b5562108357aPete Delaney__asm__ ( 60368860124c34e101f2e9fda71870b5562108357aPete Delaney" .set push \n" 61368860124c34e101f2e9fda71870b5562108357aPete Delaney" \n" 62368860124c34e101f2e9fda71870b5562108357aPete Delaney" .text \n" 63368860124c34e101f2e9fda71870b5562108357aPete Delaney" .align 4 \n" 64368860124c34e101f2e9fda71870b5562108357aPete Delaney" .type __start,@function \n" 65368860124c34e101f2e9fda71870b5562108357aPete Delaney" .globl __start \n" 66368860124c34e101f2e9fda71870b5562108357aPete Delaney" .globl _start \n" 67368860124c34e101f2e9fda71870b5562108357aPete Delaney" \n" 68368860124c34e101f2e9fda71870b5562108357aPete Delaney" .ent __start \n" 69368860124c34e101f2e9fda71870b5562108357aPete Delaney"__start: \n" 70368860124c34e101f2e9fda71870b5562108357aPete Delaney" _start: \n" 71368860124c34e101f2e9fda71870b5562108357aPete Delaney" .frame $sp,32,$ra \n" 72368860124c34e101f2e9fda71870b5562108357aPete Delaney" .mask 0x80000000,-4 \n" 73368860124c34e101f2e9fda71870b5562108357aPete Delaney" \n" 74368860124c34e101f2e9fda71870b5562108357aPete Delaney" .set noreorder \n" 75368860124c34e101f2e9fda71870b5562108357aPete Delaney" bal 1f \n" 76368860124c34e101f2e9fda71870b5562108357aPete Delaney" nop \n" 77368860124c34e101f2e9fda71870b5562108357aPete Delaney"1: \n" 78368860124c34e101f2e9fda71870b5562108357aPete Delaney" .cpload $ra \n" 79368860124c34e101f2e9fda71870b5562108357aPete Delaney" .set reorder \n" 80368860124c34e101f2e9fda71870b5562108357aPete Delaney" \n" 81368860124c34e101f2e9fda71870b5562108357aPete Delaney" move $a0, $sp \n" 82368860124c34e101f2e9fda71870b5562108357aPete Delaney" addiu $sp, $sp, (-32) \n" 83368860124c34e101f2e9fda71870b5562108357aPete Delaney" sw $0, 28($sp) \n" 84368860124c34e101f2e9fda71870b5562108357aPete Delaney" la $t9, do_mips_start \n" 85368860124c34e101f2e9fda71870b5562108357aPete Delaney" jalr $t9 \n" 86368860124c34e101f2e9fda71870b5562108357aPete Delaney" \n" 87368860124c34e101f2e9fda71870b5562108357aPete Delaney"2: b 2b \n" 88368860124c34e101f2e9fda71870b5562108357aPete Delaney" .end __start \n" 89368860124c34e101f2e9fda71870b5562108357aPete Delaney" \n" 90368860124c34e101f2e9fda71870b5562108357aPete Delaney" .set pop \n" 91368860124c34e101f2e9fda71870b5562108357aPete Delaney); 92368860124c34e101f2e9fda71870b5562108357aPete Delaney 93eb847bc8666842a3cfc9c06e8458ad1abebebaf0Elliott Hughes#include "../../arch-common/bionic/__dso_handle.h" 94368860124c34e101f2e9fda71870b5562108357aPete Delaney#include "atexit.h" 95