diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc new file mode 100644 index 0000000..bf7ffbb --- /dev/null +++ b/lib/csu/Makefile.inc @@ -0,0 +1,9 @@ +# $FreeBSD: releng/11.1/lib/csu/Makefile.inc 288074 2015-09-21 18:39:13Z bdrewery $ + +SSP_CFLAGS= + +SED_FIX_NOTE = -i "" -e '/\.note\.tag/s/progbits/note/' + +NO_WMISSING_VARIABLE_DECLARATIONS= + +.include "../Makefile.inc" diff --git a/lib/csu/aarch64/Makefile b/lib/csu/aarch64/Makefile new file mode 100644 index 0000000..9a3de28 --- /dev/null +++ b/lib/csu/aarch64/Makefile @@ -0,0 +1,46 @@ +# $FreeBSD: releng/11.1/lib/csu/aarch64/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} +CLEANFILES+= crt1.s gcrt1.s Scrt1.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not +# directly compiled to .o files. + +crt1.s: crt1.c + ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1.o: crt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s + +gcrt1.s: crt1.c + ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1.o: gcrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s + +Scrt1.s: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1.o: Scrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s + +.include diff --git a/lib/csu/aarch64/crt1.c b/lib/csu/aarch64/crt1.c new file mode 100644 index 0000000..efe790a --- /dev/null +++ b/lib/csu/aarch64/crt1.c @@ -0,0 +1,85 @@ +/* LINTLIBRARY */ +/*- + * Copyright 1996-1998 John D. Polstra. + * Copyright 2014 Andrew Turner. + * Copyright 2014-2015 The FreeBSD Foundation. + * All rights reserved. + * + * Portions of this software were developed by Andrew Turner + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/aarch64/crt1.c 300406 2016-05-22 08:20:30Z andrew $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +extern long * _end; + +void __start(int, char **, char **, void (*)(void)); + +/* The entry function. */ +__asm(" .text \n" +" .align 0 \n" +" .globl _start \n" +" _start: \n" +" mov x3, x2 \n" /* cleanup */ +" add x1, x0, #8 \n" /* load argv */ +" ldr x0, [x0] \n" /* load argc */ +" add x2, x1, x0, lsl #3 \n" /* env is after argv */ +" add x2, x2, #8 \n" /* argv is null terminated */ +" b __start "); + + +/* The entry function. */ +void +__start(int argc, char *argv[], char *env[], void (*cleanup)(void)) +{ + + handle_argv(argc, argv, env); + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +__asm__("eprol:"); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} diff --git a/lib/csu/aarch64/crti.S b/lib/csu/aarch64/crti.S new file mode 100644 index 0000000..7c1253b --- /dev/null +++ b/lib/csu/aarch64/crti.S @@ -0,0 +1,48 @@ +/*- + * Copyright 2001 David E. O'Brien + * Copyright 2014 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by Andrew Turner + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/aarch64/crti.S 280259 2015-03-19 13:53:47Z andrew $"); + + .section .init,"ax",@progbits + .align 4 + .globl _init + .type _init,@function +_init: + sub sp, sp, #16 + str lr, [sp] + + .section .fini,"ax",@progbits + .align 4 + .globl _fini + .type _fini,@function +_fini: + sub sp, sp, #16 + str lr, [sp] + diff --git a/lib/csu/aarch64/crtn.S b/lib/csu/aarch64/crtn.S new file mode 100644 index 0000000..62c4851 --- /dev/null +++ b/lib/csu/aarch64/crtn.S @@ -0,0 +1,44 @@ +/*- + * Copyright 2001 David E. O'Brien + * Copyright 2014 The FreeBSD Foundation + * All rights reserved. + * + * Portions of this software were developed by Andrew Turner + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/aarch64/crtn.S 280259 2015-03-19 13:53:47Z andrew $"); + + .section .init,"ax",@progbits + ldr lr, [sp] + add sp, sp, #16 + ret + + + .section .fini,"ax",@progbits + ldr lr, [sp] + add sp, sp, #16 + ret + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile new file mode 100644 index 0000000..43dbf56 --- /dev/null +++ b/lib/csu/amd64/Makefile @@ -0,0 +1,47 @@ +# $FreeBSD: releng/11.1/lib/csu/amd64/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include +CFLAGS+= -fno-omit-frame-pointer + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} +CLEANFILES+= crt1.s gcrt1.s Scrt1.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not +# directly compiled to .o files. + +crt1.s: crt1.c + ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1.o: crt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s + +gcrt1.s: crt1.c + ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1.o: gcrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s + +Scrt1.s: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1.o: Scrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s + +.include diff --git a/lib/csu/amd64/Makefile.depend b/lib/csu/amd64/Makefile.depend new file mode 100644 index 0000000..85f3253 --- /dev/null +++ b/lib/csu/amd64/Makefile.depend @@ -0,0 +1,12 @@ +# $FreeBSD: releng/11.1/lib/csu/amd64/Makefile.depend 284345 2015-06-13 19:20:56Z sjg $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/amd64/crt1.c b/lib/csu/amd64/crt1.c new file mode 100644 index 0000000..611a11e --- /dev/null +++ b/lib/csu/amd64/crt1.c @@ -0,0 +1,73 @@ +/* LINTLIBRARY */ +/*- + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/amd64/crt1.c 292000 2015-12-08 19:32:58Z emaste $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +typedef void (*fptr)(void); + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +void _start(char **, void (*)(void)); + +/* The entry function. */ +void +_start(char **ap, void (*cleanup)(void)) +{ + int argc; + char **argv; + char **env; + + argc = *(long *)(void *)ap; + argv = ap + 1; + env = ap + 2 + argc; + handle_argv(argc, argv, env); + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +__asm__("eprol:"); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} diff --git a/lib/csu/amd64/crti.S b/lib/csu/amd64/crti.S new file mode 100644 index 0000000..a66927b --- /dev/null +++ b/lib/csu/amd64/crti.S @@ -0,0 +1,43 @@ +/*- + * Copyright 1996, 1997, 1998, 2000 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/amd64/crti.S 217105 2011-01-07 16:07:51Z kib $"); + + .section .init,"ax",@progbits + .align 4 + .globl _init + .type _init,@function +_init: + subq $8,%rsp + + .section .fini,"ax",@progbits + .align 4 + .globl _fini + .type _fini,@function +_fini: + subq $8,%rsp + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/amd64/crtn.S b/lib/csu/amd64/crtn.S new file mode 100644 index 0000000..838ea32 --- /dev/null +++ b/lib/csu/amd64/crtn.S @@ -0,0 +1,37 @@ +/*- + * Copyright 1996, 1997, 1998, 2000 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/amd64/crtn.S 217105 2011-01-07 16:07:51Z kib $"); + + .section .init,"ax",@progbits + addq $8,%rsp + ret + + .section .fini,"ax",@progbits + addq $8,%rsp + ret + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/arm/Makefile b/lib/csu/arm/Makefile new file mode 100644 index 0000000..8b10663 --- /dev/null +++ b/lib/csu/arm/Makefile @@ -0,0 +1,47 @@ +# $FreeBSD: releng/11.1/lib/csu/arm/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include +STATIC_CFLAGS+= -mlong-calls + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} +CLEANFILES+= crt1.s gcrt1.s Scrt1.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not +# directly compiled to .o files. + +crt1.s: crt1.c + ${CC} ${CFLAGS} ${STATIC_CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1.o: crt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s + +gcrt1.s: crt1.c + ${CC} ${CFLAGS} ${STATIC_CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1.o: gcrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s + +Scrt1.s: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1.o: Scrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s + +.include diff --git a/lib/csu/arm/Makefile.depend b/lib/csu/arm/Makefile.depend new file mode 100644 index 0000000..6274e19 --- /dev/null +++ b/lib/csu/arm/Makefile.depend @@ -0,0 +1,12 @@ +# $FreeBSD: releng/11.1/lib/csu/arm/Makefile.depend 288228 2015-09-25 19:44:01Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/arm/crt1.c b/lib/csu/arm/crt1.c new file mode 100644 index 0000000..caf28a0 --- /dev/null +++ b/lib/csu/arm/crt1.c @@ -0,0 +1,130 @@ +/* LINTLIBRARY */ +/*- + * Copyright 2001 David E. O'Brien. + * All rights reserved. + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * Copyright (c) 1997 Jason R. Thorpe. + * Copyright (c) 1995 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the + * FreeBSD Project. See http://www.freebsd.org/ for + * information about FreeBSD. + * This product includes software developed for the + * NetBSD Project. See http://www.netbsd.org/ for + * information about NetBSD. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/arm/crt1.c 292000 2015-12-08 19:32:58Z emaste $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +struct Struct_Obj_Entry; +struct ps_strings; + +extern void _start(int, char **, char **, const struct Struct_Obj_Entry *, + void (*)(void), struct ps_strings *); + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +struct ps_strings *__ps_strings; + +void __start(int, char **, char **, struct ps_strings *, + const struct Struct_Obj_Entry *, void (*)(void)); + +/* The entry function. */ +__asm(" .text \n" +" .align 0 \n" +" .globl _start \n" +" _start: \n" +" mov r5, r2 /* cleanup */ \n" +" mov r4, r1 /* obj_main */ \n" +" mov r3, r0 /* ps_strings */ \n" +" /* Get argc, argv, and envp from stack */ \n" +" ldr r0, [sp, #0x0000] \n" +" add r1, sp, #0x0004 \n" +" add r2, r1, r0, lsl #2 \n" +" add r2, r2, #0x0004 \n" +" /* Ensure the stack is properly aligned before calling C code. */\n" +" bic sp, sp, #7 \n" +" sub sp, sp, #8 \n" +" str r5, [sp, #4] \n" +" str r4, [sp, #0] \n" +"\n" +" b __start "); +/* ARGSUSED */ +void +__start(int argc, char **argv, char **env, struct ps_strings *ps_strings, + const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void)) +{ + + handle_argv(argc, argv, env); + + if (ps_strings != (struct ps_strings *)0) + __ps_strings = ps_strings; + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +#endif + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} + +static const struct { + int32_t namesz; + int32_t descsz; + int32_t type; + char name[sizeof(NOTE_FREEBSD_VENDOR)]; + char desc[sizeof(MACHINE_ARCH)]; +} archtag __attribute__ ((section (NOTE_SECTION), aligned(4))) __used = { + .namesz = sizeof(NOTE_FREEBSD_VENDOR), + .descsz = sizeof(MACHINE_ARCH), + .type = ARCH_NOTETYPE, + .name = NOTE_FREEBSD_VENDOR, + .desc = MACHINE_ARCH +}; + +#ifdef GCRT +__asm__(".text"); +__asm__("eprol:"); +__asm__(".previous"); +#endif diff --git a/lib/csu/arm/crti.S b/lib/csu/arm/crti.S new file mode 100644 index 0000000..faaa18b --- /dev/null +++ b/lib/csu/arm/crti.S @@ -0,0 +1,22 @@ +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/arm/crti.S 288373 2015-09-29 16:09:58Z kib $"); + + .section .init,"ax",%progbits + .align 4 + .globl _init + .type _init,%function +_init: + mov ip, sp + stmdb sp!, {fp, ip, lr, pc} + sub fp, ip, #4 + + .section .fini,"ax",%progbits + .align 4 + .globl _fini + .type _fini,%function +_fini: + mov ip, sp + stmdb sp!, {fp, ip, lr, pc} + sub fp, ip, #4 + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/arm/crtn.S b/lib/csu/arm/crtn.S new file mode 100644 index 0000000..7426a06 --- /dev/null +++ b/lib/csu/arm/crtn.S @@ -0,0 +1,12 @@ +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/arm/crtn.S 288373 2015-09-29 16:09:58Z kib $"); + + .section .init,"ax",%progbits + ldmea fp, {fp, sp, pc} + mov pc, lr + + .section .fini,"ax",%progbits + ldmea fp, {fp, sp, pc} + mov pc, lr + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/common/crtbrand.c b/lib/csu/common/crtbrand.c new file mode 100644 index 0000000..df7af67 --- /dev/null +++ b/lib/csu/common/crtbrand.c @@ -0,0 +1,66 @@ +/*- + * Copyright 2000 David E. O'Brien, John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/common/crtbrand.c 321309 2017-07-20 23:39:50Z gjb $"); + +#include +#include "notes.h" + +/* + * Special ".note" entry specifying the ABI version. See + * http://www.netbsd.org/Documentation/kernel/elf-notes.html + * for more information. + * + * For all arches except sparc, gcc emits the section directive for the + * following struct with a PROGBITS type. However, newer versions of binutils + * (after 2.16.90) require the section to be of NOTE type, to guarantee that the + * .note.ABI-tag section correctly ends up in the first page of the final + * executable. + * + * Unfortunately, there is no clean way to tell gcc to use another section type, + * so this C file (or the C file that includes it) must be compiled in multiple + * steps: + * + * - Compile the .c file to a .s file. + * - Edit the .s file to change the 'progbits' type to 'note', for the section + * directive that defines the .note.ABI-tag section. + * - Compile the .s file to an object file. + * + * These steps are done in the invididual Makefiles for each applicable arch. + */ +static const struct { + int32_t namesz; + int32_t descsz; + int32_t type; + char name[sizeof(NOTE_FREEBSD_VENDOR)]; + int32_t desc; +} abitag __attribute__ ((section (NOTE_SECTION), aligned(4))) __used = { + .namesz = sizeof(NOTE_FREEBSD_VENDOR), + .descsz = sizeof(int32_t), + .type = ABI_NOTETYPE, + .name = NOTE_FREEBSD_VENDOR, + .desc = 1101001 +}; diff --git a/lib/csu/common/ignore_init.c b/lib/csu/common/ignore_init.c new file mode 100644 index 0000000..85a2726 --- /dev/null +++ b/lib/csu/common/ignore_init.c @@ -0,0 +1,118 @@ +/*- + * Copyright 2012 Konstantin Belousov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/common/ignore_init.c 245133 2013-01-07 17:58:27Z kib $"); + +#include "notes.h" + +extern int main(int, char **, char **); + +extern void (*__preinit_array_start[])(int, char **, char **) __hidden; +extern void (*__preinit_array_end[])(int, char **, char **) __hidden; +extern void (*__init_array_start[])(int, char **, char **) __hidden; +extern void (*__init_array_end[])(int, char **, char **) __hidden; +extern void (*__fini_array_start[])(void) __hidden; +extern void (*__fini_array_end[])(void) __hidden; +extern void _fini(void) __hidden; +extern void _init(void) __hidden; + +extern int _DYNAMIC; +#pragma weak _DYNAMIC + +char **environ; +const char *__progname = ""; + +static void +finalizer(void) +{ + void (*fn)(void); + size_t array_size, n; + + array_size = __fini_array_end - __fini_array_start; + for (n = array_size; n > 0; n--) { + fn = __fini_array_start[n - 1]; + if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1) + (fn)(); + } + _fini(); +} + +static inline void +handle_static_init(int argc, char **argv, char **env) +{ + void (*fn)(int, char **, char **); + size_t array_size, n; + + if (&_DYNAMIC != NULL) + return; + + atexit(finalizer); + + array_size = __preinit_array_end - __preinit_array_start; + for (n = 0; n < array_size; n++) { + fn = __preinit_array_start[n]; + if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1) + fn(argc, argv, env); + } + _init(); + array_size = __init_array_end - __init_array_start; + for (n = 0; n < array_size; n++) { + fn = __init_array_start[n]; + if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1) + fn(argc, argv, env); + } +} + +static inline void +handle_argv(int argc, char *argv[], char **env) +{ + const char *s; + + if (environ == NULL) + environ = env; + if (argc > 0 && argv[0] != NULL) { + __progname = argv[0]; + for (s = __progname; *s != '\0'; s++) { + if (*s == '/') + __progname = s + 1; + } + } +} + +static const struct { + int32_t namesz; + int32_t descsz; + int32_t type; + char name[sizeof(NOTE_FREEBSD_VENDOR)]; + uint32_t desc; +} crt_noinit_tag __attribute__ ((section (NOTE_SECTION), + aligned(4))) __used = { + .namesz = sizeof(NOTE_FREEBSD_VENDOR), + .descsz = sizeof(uint32_t), + .type = CRT_NOINIT_NOTETYPE, + .name = NOTE_FREEBSD_VENDOR, + .desc = 0 +}; diff --git a/lib/csu/common/notes.h b/lib/csu/common/notes.h new file mode 100644 index 0000000..72c176c --- /dev/null +++ b/lib/csu/common/notes.h @@ -0,0 +1,39 @@ +/*- + * Copyright 2012 Konstantin Belousov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: releng/11.1/lib/csu/common/notes.h 255874 2013-09-26 07:53:18Z andrew $ + */ + +#ifndef CSU_COMMON_NOTES_H +#define CSU_COMMON_NOTES_H + +#define NOTE_FREEBSD_VENDOR "FreeBSD" + +#define NOTE_SECTION ".note.tag" + +#define ABI_NOTETYPE 1 +#define CRT_NOINIT_NOTETYPE 2 +#define ARCH_NOTETYPE 3 + +#endif diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile new file mode 100644 index 0000000..b9b5313 --- /dev/null +++ b/lib/csu/i386/Makefile @@ -0,0 +1,57 @@ +# $FreeBSD: releng/11.1/lib/csu/i386/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= gcrt1.o crt1.o Scrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o +CLEANFILES+= crt1_c.s gcrt1_c.s Scrt1_c.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1_c.c is not +# directly compiled to .o files. + +gcrt1_c.s: crt1_c.c + ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1_c.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1_c.o: gcrt1_c.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1_c.s + +gcrt1.o: gcrt1_c.o crt1_s.o + ${LD} ${_LDFLAGS} -o gcrt1.o -r crt1_s.o gcrt1_c.o + +crt1_c.s: crt1_c.c + ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1_c.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1_c.o: crt1_c.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1_c.s + +crt1.o: crt1_c.o crt1_s.o + ${LD} ${_LDFLAGS} -o crt1.o -r crt1_s.o crt1_c.o + ${OBJCOPY} --localize-symbol _start1 crt1.o + +Scrt1_c.s: crt1_c.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1_c.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1_c.o: Scrt1_c.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1_c.s + +Scrt1.o: Scrt1_c.o crt1_s.o + ${LD} ${_LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o + ${OBJCOPY} --localize-symbol _start1 Scrt1.o + +.include diff --git a/lib/csu/i386/Makefile.depend b/lib/csu/i386/Makefile.depend new file mode 100644 index 0000000..62680bb --- /dev/null +++ b/lib/csu/i386/Makefile.depend @@ -0,0 +1,12 @@ +# $FreeBSD: releng/11.1/lib/csu/i386/Makefile.depend 288226 2015-09-25 19:26:08Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/i386/crt1_c.c b/lib/csu/i386/crt1_c.c new file mode 100644 index 0000000..73dd67f --- /dev/null +++ b/lib/csu/i386/crt1_c.c @@ -0,0 +1,74 @@ +/* LINTLIBRARY */ +/*- + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: releng/11.1/lib/csu/i386/crt1_c.c 292000 2015-12-08 19:32:58Z emaste $ + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/i386/crt1_c.c 292000 2015-12-08 19:32:58Z emaste $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +typedef void (*fptr)(void); + +extern void _start(char *, ...); + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +void _start1(fptr, int, char *[]) __dead2; + +/* The entry function, C part. */ +void +_start1(fptr cleanup, int argc, char *argv[]) +{ + char **env; + + env = argv + argc + 1; + handle_argv(argc, argv, env); + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +__asm__("eprol:"); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} + +__asm(".hidden _start1"); diff --git a/lib/csu/i386/crt1_s.S b/lib/csu/i386/crt1_s.S new file mode 100644 index 0000000..c680e49 --- /dev/null +++ b/lib/csu/i386/crt1_s.S @@ -0,0 +1,54 @@ +/*- + * Copyright 2009 Konstantin Belousov. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: releng/11.1/lib/csu/i386/crt1_s.S 217383 2011-01-13 23:00:22Z kib $ + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/i386/crt1_s.S 217383 2011-01-13 23:00:22Z kib $"); + + .text + .align 4 + .globl _start + .type _start, @function +_start: + .cfi_startproc + xorl %ebp,%ebp + pushl %ebp + .cfi_def_cfa_offset 4 + movl %esp,%ebp + .cfi_offset %ebp,-8 + .cfi_def_cfa_register %ebp + andl $0xfffffff0,%esp # align stack + leal 8(%ebp),%eax + subl $4,%esp + pushl %eax # argv + pushl 4(%ebp) # argc + pushl %edx # rtld cleanup + call _start1 + int3 + .cfi_endproc + .size _start, . - _start + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/i386/crti.S b/lib/csu/i386/crti.S new file mode 100644 index 0000000..7d29c75 --- /dev/null +++ b/lib/csu/i386/crti.S @@ -0,0 +1,43 @@ +/*- + * Copyright 1996, 1997, 1998, 2000 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/i386/crti.S 217105 2011-01-07 16:07:51Z kib $"); + + .section .init,"ax",@progbits + .align 4 + .globl _init + .type _init,@function +_init: + sub $12,%esp /* re-align stack pointer */ + + .section .fini,"ax",@progbits + .align 4 + .globl _fini + .type _fini,@function +_fini: + sub $12,%esp /* re-align stack pointer */ + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/i386/crtn.S b/lib/csu/i386/crtn.S new file mode 100644 index 0000000..b9c7d2d --- /dev/null +++ b/lib/csu/i386/crtn.S @@ -0,0 +1,37 @@ +/*- + * Copyright 1996, 1997, 1998, 2000 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/i386/crtn.S 217105 2011-01-07 16:07:51Z kib $"); + + .section .init,"ax",@progbits + add $12,%esp + ret + + .section .fini,"ax",@progbits + add $12,%esp + ret + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/mips/Makefile b/lib/csu/mips/Makefile new file mode 100644 index 0000000..18d1e51 --- /dev/null +++ b/lib/csu/mips/Makefile @@ -0,0 +1,46 @@ +# $FreeBSD: releng/11.1/lib/csu/mips/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} +CLEANFILES+= crt1.s gcrt1.s Scrt1.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not +# directly compiled to .o files. + +crt1.s: crt1.c + ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1.o: crt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s + +gcrt1.s: crt1.c + ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1.o: gcrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s + +Scrt1.s: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1.o: Scrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s + +.include diff --git a/lib/csu/mips/Makefile.depend b/lib/csu/mips/Makefile.depend new file mode 100644 index 0000000..9bf2062 --- /dev/null +++ b/lib/csu/mips/Makefile.depend @@ -0,0 +1,12 @@ +# $FreeBSD: releng/11.1/lib/csu/mips/Makefile.depend 288228 2015-09-25 19:44:01Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/mips/crt1.c b/lib/csu/mips/crt1.c new file mode 100644 index 0000000..330b7e0 --- /dev/null +++ b/lib/csu/mips/crt1.c @@ -0,0 +1,90 @@ +/*- + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * Copyright (c) 1995 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: releng/11.1/lib/csu/mips/crt1.c 292000 2015-12-08 19:32:58Z emaste $ + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/mips/crt1.c 292000 2015-12-08 19:32:58Z emaste $"); + +#include +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +struct Struct_Obj_Entry; +struct ps_strings; + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +void __start(char **, void (*)(void), struct Struct_Obj_Entry *, struct ps_strings *); + +/* The entry function. */ +void +__start(char **ap, + void (*cleanup)(void), /* from shared loader */ + struct Struct_Obj_Entry *obj __unused, /* from shared loader */ + struct ps_strings *ps_strings __unused) +{ + int argc; + char **argv; + char **env; + + argc = * (long *) ap; + argv = ap + 1; + env = ap + 2 + argc; + handle_argv(argc, argv, env); + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} + +#ifdef GCRT +__asm__(".text"); +__asm__("eprol:"); +__asm__(".previous"); +#endif diff --git a/lib/csu/mips/crti.S b/lib/csu/mips/crti.S new file mode 100644 index 0000000..8df4311 --- /dev/null +++ b/lib/csu/mips/crti.S @@ -0,0 +1,50 @@ +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/mips/crti.S 205112 2010-03-13 02:10:20Z jmallett $"); + + .section .init,"ax",%progbits + .align 4 + .globl _init + .type _init,%function +_init: + .set noreorder +#if defined(__ABICALLS__) && (defined(__mips_o32) || defined(__mips_o64)) + SETUP_GP +#endif + PTR_ADDU sp, sp, -CALLFRAME_SIZ + REG_S ra, CALLFRAME_RA(sp) +#if defined(__ABICALLS__) +#if defined(__mips_o32) || defined(__mips_o64) + SAVE_GP(CALLFRAME_GP) +#else + SETUP_GP64(CALLFRAME_GP, _init) +#endif +#else /* __ABICALLS__ */ +#if defined(__mips_n32) || defined(__mips_n64) + REG_S gp, CALLFRAME_GP(sp) +#endif +#endif + .set reorder + + .section .fini,"ax",%progbits + .align 4 + .globl _fini + .type _fini,%function +_fini: + .set noreorder +#if defined(__ABICALLS__) && (defined(__mips_o32) || defined(__mips_o64)) + SETUP_GP +#endif + PTR_ADDU sp, sp, -CALLFRAME_SIZ + REG_S ra, CALLFRAME_RA(sp) +#if defined(__ABICALLS__) +#if defined(__mips_o32) || defined(__mips_o64) + SAVE_GP(CALLFRAME_GP) +#else + SETUP_GP64(CALLFRAME_GP, _fini) +#endif +#else /* __ABICALLS__ */ +#if defined(__mips_n32) || defined(__mips_n64) + REG_S gp, CALLFRAME_GP(sp) +#endif +#endif + .set reorder diff --git a/lib/csu/mips/crtn.S b/lib/csu/mips/crtn.S new file mode 100644 index 0000000..e058862 --- /dev/null +++ b/lib/csu/mips/crtn.S @@ -0,0 +1,24 @@ +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/mips/crtn.S 204674 2010-03-03 21:59:23Z imp $"); + + .section .init,"ax",%progbits + .align 4 + .set noreorder +#if defined(__ABICALLS__) && (defined(__mips_n32) || defined(__mips_n64)) + REG_L gp, CALLFRAME_GP(sp) +#endif + REG_L ra, CALLFRAME_RA(sp) + jr ra + PTR_ADDU sp, sp, CALLFRAME_SIZ + .set reorder + + .section .fini,"ax",%progbits + .align 4 + .set noreorder +#if defined(__ABICALLS__) && (defined(__mips_n32) || defined(__mips_n64)) + REG_L gp, CALLFRAME_GP(sp) +#endif + REG_L ra, CALLFRAME_RA(sp) + jr ra + PTR_ADDU sp, sp, CALLFRAME_SIZ + .set reorder diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile new file mode 100644 index 0000000..07a8d24 --- /dev/null +++ b/lib/csu/powerpc/Makefile @@ -0,0 +1,46 @@ +# $FreeBSD: releng/11.1/lib/csu/powerpc/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} +CLEANFILES+= crt1.s gcrt1.s Scrt1.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not +# directly compiled to .o files. + +crt1.s: crt1.c + ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1.o: crt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s + +gcrt1.s: crt1.c + ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1.o: gcrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s + +Scrt1.s: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1.o: Scrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s + +.include diff --git a/lib/csu/powerpc/Makefile.depend b/lib/csu/powerpc/Makefile.depend new file mode 100644 index 0000000..c73e7e9 --- /dev/null +++ b/lib/csu/powerpc/Makefile.depend @@ -0,0 +1,12 @@ +# $FreeBSD: releng/11.1/lib/csu/powerpc/Makefile.depend 288228 2015-09-25 19:44:01Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/powerpc/crt1.c b/lib/csu/powerpc/crt1.c new file mode 100644 index 0000000..4cfb11d --- /dev/null +++ b/lib/csu/powerpc/crt1.c @@ -0,0 +1,102 @@ +/* LINTLIBRARY */ +/*- + * Copyright 2001 David E. O'Brien. + * All rights reserved. + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * Copyright (c) 1997 Jason R. Thorpe. + * Copyright (c) 1995 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the + * FreeBSD Project. See http://www.freebsd.org/ for + * information about FreeBSD. + * This product includes software developed for the + * NetBSD Project. See http://www.netbsd.org/ for + * information about NetBSD. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/powerpc/crt1.c 292000 2015-12-08 19:32:58Z emaste $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +struct Struct_Obj_Entry; +struct ps_strings; + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +struct ps_strings *__ps_strings; + +void _start(int, char **, char **, const struct Struct_Obj_Entry *, + void (*)(void), struct ps_strings *); + +/* The entry function. */ +/* + * First 5 arguments are specified by the PowerPC SVR4 ABI. + * The last argument, ps_strings, is a BSD extension. + */ +/* ARGSUSED */ +void +_start(int argc, char **argv, char **env, + const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void), + struct ps_strings *ps_strings) +{ + + + handle_argv(argc, argv, env); + + if (ps_strings != (struct ps_strings *)0) + __ps_strings = ps_strings; + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} + +#ifdef GCRT +__asm__(".text"); +__asm__("eprol:"); +__asm__(".previous"); +#endif diff --git a/lib/csu/powerpc/crti.S b/lib/csu/powerpc/crti.S new file mode 100644 index 0000000..034e1fb --- /dev/null +++ b/lib/csu/powerpc/crti.S @@ -0,0 +1,51 @@ +/*- + * Copyright 2001 David E. O'Brien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/powerpc/crti.S 217399 2011-01-14 11:34:58Z kib $"); + + .section .init,"ax",@progbits + .align 2 + .globl _init + .type _init,@function +_init: + stwu 1,-16(1) + mflr 0 + stw 31,12(1) + stw 0,20(1) + mr 31,1 + + + .section .fini,"ax",@progbits + .align 2 + .globl _fini +_fini: + stwu 1,-16(1) + mflr 0 + stw 31,12(1) + stw 0,20(1) + mr 31,1 + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/powerpc/crtn.S b/lib/csu/powerpc/crtn.S new file mode 100644 index 0000000..3478ec5 --- /dev/null +++ b/lib/csu/powerpc/crtn.S @@ -0,0 +1,46 @@ +/*- + * Copyright 2001 David E. O'Brien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/powerpc/crtn.S 217399 2011-01-14 11:34:58Z kib $"); + + .section .init,"ax",@progbits + lwz 11,0(1) + lwz 0,4(11) + mtlr 0 + lwz 31,-4(11) + mr 1,11 + blr + + + .section .fini,"ax",@progbits + lwz 11,0(1) + lwz 0,4(11) + mtlr 0 + lwz 31,-4(11) + mr 1,11 + blr + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile new file mode 100644 index 0000000..e272396 --- /dev/null +++ b/lib/csu/powerpc64/Makefile @@ -0,0 +1,47 @@ +# $FreeBSD: releng/11.1/lib/csu/powerpc64/Makefile 316369 2017-04-01 19:27:06Z jhibbits $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include \ + -mlongcall + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} +CLEANFILES+= crt1.s gcrt1.s Scrt1.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not +# directly compiled to .o files. + +crt1.s: crt1.c + ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1.o: crt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s + +gcrt1.s: crt1.c + ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1.o: gcrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s + +Scrt1.s: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1.o: Scrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s + +.include diff --git a/lib/csu/powerpc64/Makefile.depend b/lib/csu/powerpc64/Makefile.depend new file mode 100644 index 0000000..e2dde8d --- /dev/null +++ b/lib/csu/powerpc64/Makefile.depend @@ -0,0 +1,12 @@ +# $FreeBSD: releng/11.1/lib/csu/powerpc64/Makefile.depend 288228 2015-09-25 19:44:01Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/powerpc64/crt1.c b/lib/csu/powerpc64/crt1.c new file mode 100644 index 0000000..62ff083 --- /dev/null +++ b/lib/csu/powerpc64/crt1.c @@ -0,0 +1,101 @@ +/* LINTLIBRARY */ +/*- + * Copyright 2001 David E. O'Brien. + * All rights reserved. + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * Copyright (c) 1997 Jason R. Thorpe. + * Copyright (c) 1995 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the + * FreeBSD Project. See http://www.freebsd.org/ for + * information about FreeBSD. + * This product includes software developed for the + * NetBSD Project. See http://www.netbsd.org/ for + * information about NetBSD. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/powerpc64/crt1.c 292000 2015-12-08 19:32:58Z emaste $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +struct Struct_Obj_Entry; +struct ps_strings; + +extern void _start(int, char **, char **, const struct Struct_Obj_Entry *, + void (*)(void), struct ps_strings *); + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +struct ps_strings *__ps_strings; + +/* The entry function. */ +/* + * First 5 arguments are specified by the PowerPC SVR4 ABI. + * The last argument, ps_strings, is a BSD extension. + */ +/* ARGSUSED */ +void +_start(int argc, char **argv, char **env, + const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void), + struct ps_strings *ps_strings) +{ + + handle_argv(argc, argv, env); + + if (ps_strings != (struct ps_strings *)0) + __ps_strings = ps_strings; + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} + +#ifdef GCRT +__asm__(".text"); +__asm__("eprol:"); +__asm__(".previous"); +#endif diff --git a/lib/csu/powerpc64/crti.S b/lib/csu/powerpc64/crti.S new file mode 100644 index 0000000..dc52ca7 --- /dev/null +++ b/lib/csu/powerpc64/crti.S @@ -0,0 +1,86 @@ +/*- + * Copyright 2001 David E. O'Brien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/powerpc64/crti.S 291668 2015-12-03 00:10:57Z nwhitehorn $"); + +#ifdef _CALL_ELF +.abiversion _CALL_ELF +#endif + + .section .init,"ax",@progbits + .p2align 2 + .globl _init +#if !defined(_CALL_ELF) || _CALL_ELF == 1 + .section ".opd","aw" + .p2align 3 +_init: + .quad .L._init,.TOC.@tocbase,0 + .previous + .type _init,@function + + .p2align 4 +.L._init: +#else + .p2align 4 + .globl _init + .type _init,@function +_init: + addis %r2, %r12, (.TOC.-_init)@ha + addi %r2, %r2, (.TOC.-_init)@l + .localentry _init, .-_init +#endif + stdu 1,-48(1) + mflr 0 + std 0,64(1) + +/* Fini */ + .section .fini,"ax",@progbits + .p2align 2 + .globl _fini +#if !defined(_CALL_ELF) || _CALL_ELF == 1 + .section ".opd","aw" + .p2align 3 +_fini: + .quad .L._fini,.TOC.@tocbase,0 + .previous + .type _fini,@function + + .p2align 4 +.L._fini: +#else + .p2align 4 + .globl _fini + .type _fini,@function +_fini: + addis %r2, %r12, (.TOC.-_fini)@ha + addi %r2, %r2, (.TOC.-_fini)@l + .localentry _fini, .-_fini +#endif + stdu 1,-48(1) + mflr 0 + std 0,64(1) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/powerpc64/crtn.S b/lib/csu/powerpc64/crtn.S new file mode 100644 index 0000000..168d9e7 --- /dev/null +++ b/lib/csu/powerpc64/crtn.S @@ -0,0 +1,42 @@ +/*- + * Copyright 2001 David E. O'Brien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/powerpc64/crtn.S 217399 2011-01-14 11:34:58Z kib $"); + + .section .init,"ax",@progbits + ld %r1,0(%r1) + ld 0,16(%r1) + mtlr 0 + blr + + + .section .fini,"ax",@progbits + ld %r1,0(%r1) + ld 0,16(%r1) + mtlr 0 + blr + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/riscv/Makefile b/lib/csu/riscv/Makefile new file mode 100644 index 0000000..dd66619 --- /dev/null +++ b/lib/csu/riscv/Makefile @@ -0,0 +1,46 @@ +# $FreeBSD: releng/11.1/lib/csu/riscv/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} +CLEANFILES+= crt1.s gcrt1.s Scrt1.s + +# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not +# directly compiled to .o files. + +crt1.s: crt1.c + ${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +crt1.o: crt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s + +gcrt1.s: crt1.c + ${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +gcrt1.o: gcrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s + +Scrt1.s: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c + sed ${SED_FIX_NOTE} ${.TARGET} + +Scrt1.o: Scrt1.s + ${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s + +.include diff --git a/lib/csu/riscv/crt1.c b/lib/csu/riscv/crt1.c new file mode 100644 index 0000000..88b5565 --- /dev/null +++ b/lib/csu/riscv/crt1.c @@ -0,0 +1,89 @@ +/* LINTLIBRARY */ +/*- + * Copyright 1996-1998 John D. Polstra. + * Copyright (c) 2015 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/riscv/crt1.c 292124 2015-12-11 22:55:23Z br $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +typedef void (*fptr)(void); + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +void __start(int argc, char **argv, char **env, void (*cleanup)(void)); + +/* The entry function. */ +__asm(" .text \n" +" .align 0 \n" +" .globl _start \n" +" _start: \n" +" mv a3, a2 \n" /* cleanup */ +" addi a1, a0, 8 \n" /* get argv */ +" ld a0, 0(a0) \n" /* load argc */ +" slli t0, a0, 3 \n" /* mult by arg size */ +" add a2, a1, t0 \n" /* env is after argv */ +" addi a2, a2, 8 \n" /* argv is null terminated */ +" lla gp, _gp \n" /* load global pointer */ +" call __start"); + +void +__start(int argc, char **argv, char **env, void (*cleanup)(void)) +{ + + handle_argv(argc, argv, env); + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +__asm__("eprol:"); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} diff --git a/lib/csu/riscv/crti.S b/lib/csu/riscv/crti.S new file mode 100644 index 0000000..216de98 --- /dev/null +++ b/lib/csu/riscv/crti.S @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2015 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/riscv/crti.S 292124 2015-12-11 22:55:23Z br $"); + +# this puts _gp into .dynsym, so symlook_obj can now find that (see reloc.c) + .weak _gp +_gp: + + .section .init,"ax",@progbits + .align 2 + .globl _init + .type _init,@function +_init: + addi sp, sp, -16 + sd ra, 0(sp) + + .section .fini,"ax",@progbits + .align 2 + .globl _fini + .type _fini,@function +_fini: + addi sp, sp, -16 + sd ra, 0(sp) + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/riscv/crtn.S b/lib/csu/riscv/crtn.S new file mode 100644 index 0000000..f6105c3 --- /dev/null +++ b/lib/csu/riscv/crtn.S @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2015 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/riscv/crtn.S 292124 2015-12-11 22:55:23Z br $"); + + .section .init,"ax",@progbits + ld ra, 0(sp) + addi sp, sp, 16 + ret + + .section .fini,"ax",@progbits + ld ra, 0(sp) + addi sp, sp, 16 + ret + + .section .note.GNU-stack,"",%progbits diff --git a/lib/csu/sparc64/Makefile b/lib/csu/sparc64/Makefile new file mode 100644 index 0000000..b10b47b --- /dev/null +++ b/lib/csu/sparc64/Makefile @@ -0,0 +1,27 @@ +# $FreeBSD: releng/11.1/lib/csu/sparc64/Makefile 313538 2017-02-10 07:32:40Z ngie $ + +.PATH: ${.CURDIR:H}/common + +SRCS= crt1.c crti.S crtn.S +OBJS= ${SRCS:N*.h:R:S/$/.o/g} +OBJS+= Scrt1.o gcrt1.o +CFLAGS+= -I${.CURDIR:H}/common \ + -I${SRCTOP}/lib/libc/include + +FILES= ${OBJS} +FILESMODE= ${LIBMODE} +FILESOWN= ${LIBOWN} +FILESGRP= ${LIBGRP} +FILESDIR= ${LIBDIR} +# These FILES qualify as libraries for the purpose of LIBRARIES_ONLY. +.undef LIBRARIES_ONLY + +CLEANFILES= ${OBJS} + +gcrt1.o: crt1.c + ${CC} ${CFLAGS} -DGCRT -c -o gcrt1.o ${.ALLSRC} + +Scrt1.o: crt1.c + ${CC} ${CFLAGS} -fPIC -DPIC -c -o Scrt1.o ${.ALLSRC} + +.include diff --git a/lib/csu/sparc64/Makefile.depend b/lib/csu/sparc64/Makefile.depend new file mode 100644 index 0000000..cb18ea7 --- /dev/null +++ b/lib/csu/sparc64/Makefile.depend @@ -0,0 +1,12 @@ +# $FreeBSD: releng/11.1/lib/csu/sparc64/Makefile.depend 288228 2015-09-25 19:44:01Z bdrewery $ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/sparc64/crt1.c b/lib/csu/sparc64/crt1.c new file mode 100644 index 0000000..d82a246 --- /dev/null +++ b/lib/csu/sparc64/crt1.c @@ -0,0 +1,103 @@ +/* LINTLIBRARY */ +/*- + * Copyright 2001 David E. O'Brien. + * All rights reserved. + * Copyright (c) 1995, 1998 Berkeley Software Design, Inc. + * All rights reserved. + * Copyright 1996-1998 John D. Polstra. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/sparc64/crt1.c 292000 2015-12-08 19:32:58Z emaste $"); + +#include + +#include "libc_private.h" +#include "crtbrand.c" +#include "ignore_init.c" + +struct Struct_Obj_Entry; +struct ps_strings; + +extern void __sparc_utrap_setup(void); + +#ifdef GCRT +extern void _mcleanup(void); +extern void monstartup(void *, void *); +extern int eprol; +extern int etext; +#endif + +void _start(char **, void (*)(void), struct Struct_Obj_Entry *, + struct ps_strings *); + +/* The entry function. */ +/* + * %o0 holds ps_strings pointer. + * + * Note: kernel may (is not set in stone yet) pass ELF aux vector in %o1, + * but for now we do not use it here. + * + * The SPARC compliance definitions specifies that the kernel pass the + * address of a function to be executed on exit in %g1. We do not make + * use of it as it is quite broken, because gcc can use this register + * as a temporary, so it is not safe from C code. Its even more broken + * for dynamic executables since rtld runs first. + */ +/* ARGSUSED */ +void +_start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused, + struct ps_strings *ps_strings __unused) +{ + int argc; + char **argv; + char **env; + + argc = *(long *)(void *)ap; + argv = ap + 1; + env = ap + 2 + argc; + handle_argv(argc, argv, env); + + if (&_DYNAMIC != NULL) + atexit(cleanup); + else { + __sparc_utrap_setup(); + _init_tls(); + } +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +#endif + + handle_static_init(argc, argv, env); + exit(main(argc, argv, env)); +} + +#ifdef GCRT +__asm__(".text"); +__asm__("eprol:"); +__asm__(".previous"); +#endif diff --git a/lib/csu/sparc64/crti.S b/lib/csu/sparc64/crti.S new file mode 100644 index 0000000..5a3b6d6 --- /dev/null +++ b/lib/csu/sparc64/crti.S @@ -0,0 +1,57 @@ +/*- + * Copyright 2001 David E. O'Brien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of additional contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/sparc64/crti.S 216338 2010-12-09 21:31:21Z dim $"); + + .file "crti.S" + + /* The minimum stack frame size (bytes) is: + * 16 extended words for saving the current register window, + * 1 extended word for "hidden parameter", + * 6 extended words in wihch a callee can store its arguments + * ("The SPARC Architecure Manual" by Weaver & Germond) + * This gives 184 bytes. However we must round up to an extended + * word boundary, thus 192 bytes. + * (if we weren't v9, it would be 96 bytes rather than 192) + */ + + .section .init,"ax",@progbits + .align 4 + .globl _init + .type _init,#function +_init: + save %sp,-192,%sp + + + .section .fini,"ax",@progbits + .globl _fini + .type _fini,#function + .align 4 +_fini: + save %sp,-192,%sp diff --git a/lib/csu/sparc64/crtn.S b/lib/csu/sparc64/crtn.S new file mode 100644 index 0000000..6be6a82 --- /dev/null +++ b/lib/csu/sparc64/crtn.S @@ -0,0 +1,42 @@ +/*- + * Copyright 2001 David E. O'Brien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of additional contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: releng/11.1/lib/csu/sparc64/crtn.S 216338 2010-12-09 21:31:21Z dim $"); + + .file "crtn.S" + + .section .init,"ax",@progbits + .align 4 + ret + restore + + .section .fini,"ax",@progbits + .align 4 + ret + restore