crt1.c revision 330897
1/* LINTLIBRARY */ 2/*- 3 * SPDX-License-Identifier: BSD-4-Clause 4 * 5 * Copyright 2001 David E. O'Brien. 6 * All rights reserved. 7 * Copyright 1996-1998 John D. Polstra. 8 * All rights reserved. 9 * Copyright (c) 1997 Jason R. Thorpe. 10 * Copyright (c) 1995 Christopher G. Demetriou 11 * All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. All advertising materials mentioning features or use of this software 22 * must display the following acknowledgement: 23 * This product includes software developed for the 24 * FreeBSD Project. See http://www.freebsd.org/ for 25 * information about FreeBSD. 26 * This product includes software developed for the 27 * NetBSD Project. See http://www.netbsd.org/ for 28 * information about NetBSD. 29 * 4. The name of the author may not be used to endorse or promote products 30 * derived from this software without specific prior written permission 31 * 32 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 33 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 34 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 35 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 36 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 37 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 41 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 */ 43 44#include <sys/cdefs.h> 45__FBSDID("$FreeBSD: stable/11/lib/csu/arm/crt1.c 330897 2018-03-14 03:19:51Z eadler $"); 46 47#include <stdlib.h> 48 49#include "libc_private.h" 50#include "crtbrand.c" 51#include "ignore_init.c" 52 53struct Struct_Obj_Entry; 54struct ps_strings; 55 56extern void _start(int, char **, char **, const struct Struct_Obj_Entry *, 57 void (*)(void), struct ps_strings *); 58 59#ifdef GCRT 60extern void _mcleanup(void); 61extern void monstartup(void *, void *); 62extern int eprol; 63extern int etext; 64#endif 65 66struct ps_strings *__ps_strings; 67 68void __start(int, char **, char **, struct ps_strings *, 69 const struct Struct_Obj_Entry *, void (*)(void)); 70 71/* The entry function. */ 72__asm(" .text \n" 73" .align 0 \n" 74" .globl _start \n" 75" _start: \n" 76" mov r5, r2 /* cleanup */ \n" 77" mov r4, r1 /* obj_main */ \n" 78" mov r3, r0 /* ps_strings */ \n" 79" /* Get argc, argv, and envp from stack */ \n" 80" ldr r0, [sp, #0x0000] \n" 81" add r1, sp, #0x0004 \n" 82" add r2, r1, r0, lsl #2 \n" 83" add r2, r2, #0x0004 \n" 84" /* Ensure the stack is properly aligned before calling C code. */\n" 85" bic sp, sp, #7 \n" 86" sub sp, sp, #8 \n" 87" str r5, [sp, #4] \n" 88" str r4, [sp, #0] \n" 89"\n" 90" b __start "); 91/* ARGSUSED */ 92void 93__start(int argc, char **argv, char **env, struct ps_strings *ps_strings, 94 const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void)) 95{ 96 97 handle_argv(argc, argv, env); 98 99 if (ps_strings != (struct ps_strings *)0) 100 __ps_strings = ps_strings; 101 102 if (&_DYNAMIC != NULL) 103 atexit(cleanup); 104 else 105 _init_tls(); 106#ifdef GCRT 107 atexit(_mcleanup); 108 monstartup(&eprol, &etext); 109#endif 110 handle_static_init(argc, argv, env); 111 exit(main(argc, argv, env)); 112} 113 114static const struct { 115 int32_t namesz; 116 int32_t descsz; 117 int32_t type; 118 char name[sizeof(NOTE_FREEBSD_VENDOR)]; 119 char desc[sizeof(MACHINE_ARCH)]; 120} archtag __attribute__ ((section (NOTE_SECTION), aligned(4))) __used = { 121 .namesz = sizeof(NOTE_FREEBSD_VENDOR), 122 .descsz = sizeof(MACHINE_ARCH), 123 .type = ARCH_NOTETYPE, 124 .name = NOTE_FREEBSD_VENDOR, 125 .desc = MACHINE_ARCH 126}; 127 128#ifdef GCRT 129__asm__(".text"); 130__asm__("eprol:"); 131__asm__(".previous"); 132#endif 133