diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1995-10-18 08:53:40 +0000 |
commit | d6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch) | |
tree | ece253b876159b39c620e62b6c9b1174642e070e /lib/csu |
initial import of NetBSD tree
Diffstat (limited to 'lib/csu')
-rw-r--r-- | lib/csu/Makefile | 5 | ||||
-rw-r--r-- | lib/csu/alpha/Makefile | 25 | ||||
-rw-r--r-- | lib/csu/alpha/crt0.s | 107 | ||||
-rw-r--r-- | lib/csu/c++/Makefile | 17 | ||||
-rw-r--r-- | lib/csu/c++/c++rt0.c | 94 | ||||
-rw-r--r-- | lib/csu/common.c | 270 | ||||
-rw-r--r-- | lib/csu/common.h | 113 | ||||
-rw-r--r-- | lib/csu/i386/Makefile | 42 | ||||
-rw-r--r-- | lib/csu/i386/crt0.c | 117 | ||||
-rw-r--r-- | lib/csu/m68k/Makefile | 42 | ||||
-rw-r--r-- | lib/csu/m68k/crt0.c | 114 | ||||
-rw-r--r-- | lib/csu/mips/Makefile | 26 | ||||
-rw-r--r-- | lib/csu/mips/crt0.S | 114 | ||||
-rw-r--r-- | lib/csu/ns32k/Makefile | 42 | ||||
-rw-r--r-- | lib/csu/ns32k/crt0.c | 118 | ||||
-rw-r--r-- | lib/csu/sparc/Makefile | 42 | ||||
-rw-r--r-- | lib/csu/sparc/crt0.c | 186 |
17 files changed, 1474 insertions, 0 deletions
diff --git a/lib/csu/Makefile b/lib/csu/Makefile new file mode 100644 index 00000000000..0c56287c294 --- /dev/null +++ b/lib/csu/Makefile @@ -0,0 +1,5 @@ +# $Id: Makefile,v 1.1 1995/10/18 08:41:17 deraadt Exp $ + +SUBDIR= ${MACHINE_ARCH} c++ + +.include <bsd.subdir.mk> diff --git a/lib/csu/alpha/Makefile b/lib/csu/alpha/Makefile new file mode 100644 index 00000000000..276f37501f0 --- /dev/null +++ b/lib/csu/alpha/Makefile @@ -0,0 +1,25 @@ +# $NetBSD: Makefile,v 1.1 1995/02/10 17:53:00 cgd Exp $ + +CFLAGS= -DLIBC_SCCS +OBJS= crt0.o gcrt0.o +CLEANFILES+= core a.out + +all: ${OBJS} + +crt0.o: crt0.s + ${CPP} -DCRT0 ${CFLAGS} ${.ALLSRC} | ${AS} -o $@ + @${LD} -x -r ${.TARGET} + @mv a.out ${.TARGET} + +gcrt0.o: crt0.s + ${CPP} -DMCRT0 ${CFLAGS} ${.ALLSRC} | ${AS} -o $@ + @${LD} -x -r ${.TARGET} + @mv a.out ${.TARGET} + +install: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +depend lint tags: + +.include <bsd.prog.mk> diff --git a/lib/csu/alpha/crt0.s b/lib/csu/alpha/crt0.s new file mode 100644 index 00000000000..de058c8f24c --- /dev/null +++ b/lib/csu/alpha/crt0.s @@ -0,0 +1,107 @@ +/* $NetBSD: crt0.s,v 1.2 1995/10/09 23:54:37 cgd Exp $ */ + +/* + * Copyright (c) 1994, 1995 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#include <machine/asm.h> + +#define SETGP(pv) ldgp gp,0(pv) + +#define MF_FPCR(x) mf_fpcr x +#define MT_FPCR(x) mt_fpcr x +#define JMP(loc) br zero,loc +#define CONST(c,reg) ldiq reg, c + +/* + * Set up the global variables provided by crt0: + * environ and __progname + */ +BSS(environ, 8) + .data + .align 3 +EXPORT(__progname) + .quad $L1 +$L1: + .quad 0 /* Null string, plus padding. */ + .text + +LEAF(__start, 0) /* XXX */ + .set noreorder + br pv, 1f +1: SETGP(pv) + + ldq s0, 0(sp) /* get argc from stack */ + lda s1, 8(sp) /* get pointer to argv */ + s8addq s0, s1, s2 /* add number of argv pointers */ + addq s2, 8, s2 /* and skip the null pointer */ + stq s2, environ /* save the newly-found env pointer */ + +#ifdef MCRT0 +eprol: + lda a0, eprol + lda a1, _etext + CALL(monstartup) /* monstartup(eprol, etext); */ + lda a0, _mcleanup + CALL(atexit) /* atext(_mcleanup); */ + stl zero, errno +#endif + + ldq a0, 0(s1) /* a0 = argv[0]; */ + beq a0, 2f /* if it's null, then punt */ + CONST(0x2f, a1) /* a1 = '/' */ + CALL(strrchr) + addq v0, 1, a0 /* move past the /, if there was one */ + bne v0, 1f /* if a / found */ + ldq a0, 0(s1) /* a0 = argv[0]; */ +1: + stq a0, __progname /* store the program name */ +2: + /* call main() */ + mov s0, a0 + mov s1, a1 + mov s2, a2 + CALL(main) /* v0 = main(argc, argv, env); */ + + /* on return from main, call exit() with its return value. */ + mov v0, a0 + CALL(exit) /* exit(rv); */ + + /* if that failed, bug out. */ + call_pal 0x81 /* XXX op_bugchk */ + .set reorder +END(__start) + +#ifndef MCRT0 +LEAF(moncontrol, 0) + RET +END(moncontrol) + +LEAF(_mcount, 0) + /* XXX -- dunno what we have to do here! */ + call_pal 0x81 /* XXX op_bugchk */ +END(_mcount) +#endif diff --git a/lib/csu/c++/Makefile b/lib/csu/c++/Makefile new file mode 100644 index 00000000000..9bf86196ed0 --- /dev/null +++ b/lib/csu/c++/Makefile @@ -0,0 +1,17 @@ +# $Id: Makefile,v 1.1 1995/10/18 08:41:17 deraadt Exp $ + +CFLAGS+= -DLIBC_SCCS -fpic +OBJS= c++rt0.o + +all: ${OBJS} + +c++rt0.o: c++rt0.c + ${COMPILE.c} ${.ALLSRC} + @${LD} -x -r ${.TARGET} + @mv a.out ${.TARGET} + +install: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +.include <bsd.prog.mk> diff --git a/lib/csu/c++/c++rt0.c b/lib/csu/c++/c++rt0.c new file mode 100644 index 00000000000..25f22d729da --- /dev/null +++ b/lib/csu/c++/c++rt0.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 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. + * + * $Id: c++rt0.c,v 1.1 1995/10/18 08:41:17 deraadt Exp $ + */ + +/* + * Run-time module for GNU C++ compiled shared libraries. + * + * The linker constructs the following arrays of pointers to global + * constructors and destructors. The first element contains the + * number of pointers in each. + * The tables are also null-terminated. + */ +#include <stdlib.h> + +void (*__CTOR_LIST__[0]) __P((void)); +void (*__DTOR_LIST__[0]) __P((void)); + +static void __dtors __P((void)); +static void __ctors __P((void)); + +static void +__dtors() +{ + unsigned long i = (unsigned long) __DTOR_LIST__[0]; + void (**p)(void) = __DTOR_LIST__ + i; + + while (i--) + (**p--)(); +} + +static void +__ctors() +{ + void (**p)(void) = __CTOR_LIST__ + 1; + + while (*p) + (**p++)(); +} + +extern void __init __P((void)) asm(".init"); +extern void __fini __P((void)) asm(".fini"); + +void +__init() +{ + static int initialized = 0; + + /* + * Call global constructors. + * Arrange to call global destructors at exit. + */ + if (!initialized) { + initialized = 1; + __ctors(); + } + +} + +void +__fini() +{ + /* + * Call global destructors. + */ + __dtors(); +} diff --git a/lib/csu/common.c b/lib/csu/common.c new file mode 100644 index 00000000000..1223faa6087 --- /dev/null +++ b/lib/csu/common.c @@ -0,0 +1,270 @@ +/* $NetBSD: common.c,v 1.4 1995/09/23 22:34:20 pk Exp $ */ +/* + * Copyright (c) 1993,1995 Paul Kranenburg + * 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 Paul Kranenburg. + * 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. + * + */ + +#ifdef DYNAMIC + +typedef int (*rtld_entry_fn) __P((int, struct crt_ldso *)); +static struct ld_entry *ld_entry; + +static void +__load_rtld(dp) + struct _dynamic *dp; +{ + static struct crt_ldso crt; + struct exec hdr; + rtld_entry_fn entry; +#if defined(sun) && defined(DUPZFD) + int dupzfd; +#endif + +#ifdef DEBUG + /* Provision for alternate ld.so - security risk! */ + if ((crt.crt_ldso = _getenv("LDSO")) == NULL) +#endif + crt.crt_ldso = LDSO; + + crt.crt_ldfd = open(crt.crt_ldso, 0, 0); + if (crt.crt_ldfd == -1) { + _FATAL("No ld.so\n"); + } + + /* Read LDSO exec header */ + if (read(crt.crt_ldfd, &hdr, sizeof hdr) < sizeof hdr) { + _FATAL("Failure reading ld.so\n"); + } + if (N_GETMAGIC(hdr) != ZMAGIC && N_GETMAGIC(hdr) != QMAGIC) { + _FATAL("Bad magic: ld.so\n"); + } + +#ifdef sun + /* Get bucket of zeroes */ + crt.crt_dzfd = open("/dev/zero", 0, 0); + if (crt.crt_dzfd == -1) { + _FATAL("No /dev/zero\n"); + } +#endif +#ifdef BSD + /* We use MAP_ANON */ + crt.crt_dzfd = -1; +#endif + +#if defined(sun) && defined(DUPZFD) + if ((dupzfd = dup(crt.crt_dzfd)) < 0) { + _FATAL("Cannot dup /dev/zero\n"); + } +#endif + + /* Map in ld.so */ + crt.crt_ba = mmap(0, hdr.a_text+hdr.a_data+hdr.a_bss, + PROT_READ|PROT_EXEC, + MAP_COPY, + crt.crt_ldfd, N_TXTOFF(hdr)); + if (crt.crt_ba == -1) { + _FATAL("Cannot map ld.so\n"); + } + +#ifdef BSD +/* !!! + * This is gross, ld.so is a ZMAGIC a.out, but has `sizeof(hdr)' for + * an entry point and not at PAGSIZ as the N_*ADDR macros assume. + */ +#undef N_DATADDR +#undef N_BSSADDR +#define N_DATADDR(x) ((x).a_text) +#define N_BSSADDR(x) ((x).a_text + (x).a_data) +#endif + + /* Map in data segment of ld.so writable */ + if (mmap(crt.crt_ba+N_DATADDR(hdr), hdr.a_data, + PROT_READ|PROT_WRITE, + MAP_FIXED|MAP_COPY, + crt.crt_ldfd, N_DATOFF(hdr)) == -1) { + _FATAL("Cannot map ld.so\n"); + } + + /* Map bss segment of ld.so zero */ + if (hdr.a_bss && mmap(crt.crt_ba+N_BSSADDR(hdr), hdr.a_bss, + PROT_READ|PROT_WRITE, + MAP_FIXED|MAP_ANON|MAP_COPY, + crt.crt_dzfd, 0) == -1) { + _FATAL("Cannot map ld.so\n"); + } + + crt.crt_dp = dp; + crt.crt_ep = environ; + crt.crt_bp = (caddr_t)_callmain; + crt.crt_prog = __progname; + +#ifdef sun + /* Call Sun's ld.so entry point: version 1, offset crt */ + __call(CRT_VERSION_SUN, &crt, crt.crt_ba + sizeof hdr); +#else + entry = (rtld_entry_fn)(crt.crt_ba + sizeof hdr); + if ((*entry)(CRT_VERSION_BSD_4, &crt) == -1) { + /* Feeble attempt to deal with out-dated ld.so */ +# define str "crt0: update /usr/libexec/ld.so\n" + (void)write(2, str, sizeof(str)); +# undef str + if ((*entry)(CRT_VERSION_BSD_3, &crt) == -1) { + _FATAL("ld.so failed\n"); + } + ld_entry = dp->d_entry; + return; + } + ld_entry = crt.crt_ldentry; + atexit(ld_entry->dlexit); +#endif + +#if defined(sun) && defined(DUPZFD) + if (dup2(dupzfd, crt.crt_dzfd) < 0) { + _FATAL("Cannot dup2 /dev/zero\n"); + } + (void)close(dupzfd); +#endif + return; +} + +/* + * DL stubs + */ + +void * +dlopen(name, mode) + char *name; + int mode; +{ + if (ld_entry == NULL) + return NULL; + + return (ld_entry->dlopen)(name, mode); +} + +int +dlclose(fd) + void *fd; +{ + if (ld_entry == NULL) + return -1; + + return (ld_entry->dlclose)(fd); +} + +void * +dlsym(fd, name) + void *fd; + char *name; +{ + if (ld_entry == NULL) + return NULL; + + return (ld_entry->dlsym)(fd, name); +} + +int +dlctl(fd, cmd, arg) +void *fd, *arg; +int cmd; +{ + if (ld_entry == NULL) + return -1; + + return (ld_entry->dlctl)(fd, cmd, arg); +} + +char * +dlerror() +{ + int error; + + if (ld_entry == NULL || + (*ld_entry->dlctl)(NULL, DL_GETERRNO, &error) == -1) + return "Service unavailable"; + + return (char *)strerror(error); +} + +/* + * Support routines + */ + +#ifdef DEBUG +static int +_strncmp(s1, s2, n) + register char *s1, *s2; + register int n; +{ + + if (n == 0) + return (0); + do { + if (*s1 != *s2++) + return (*(unsigned char *)s1 - *(unsigned char *)--s2); + if (*s1++ == 0) + break; + } while (--n != 0); + return (0); +} + +static char * +_getenv(name) + register char *name; +{ + extern char **environ; + register int len; + register char **P, *C; + + for (C = name, len = 0; *C && *C != '='; ++C, ++len); + for (P = environ; *P; ++P) + if (!_strncmp(*P, name, len)) + if (*(C = *P + len) == '=') { + return(++C); + } + return (char *)0; +} +#endif + +static char * +_strrchr(p, ch) +register char *p, ch; +{ + register char *save; + + for (save = NULL;; ++p) { + if (*p == ch) + save = (char *)p; + if (!*p) + return(save); + } +/* NOTREACHED */ +} + +#endif /* DYNAMIC */ diff --git a/lib/csu/common.h b/lib/csu/common.h new file mode 100644 index 00000000000..93a1c33a151 --- /dev/null +++ b/lib/csu/common.h @@ -0,0 +1,113 @@ +/* $NetBSD: common.h,v 1.3 1995/06/15 21:41:48 pk Exp $ */ +/* + * Copyright (c) 1993,1995 Paul Kranenburg + * 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 Paul Kranenburg. + * 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 <string.h> + +#ifdef DYNAMIC + +#include <sys/syscall.h> +#include <a.out.h> +#ifndef N_GETMAGIC +#define N_GETMAGIC(x) ((x).a_magic) +#endif +#ifndef N_BSSADDR +#define N_BSSADDR(x) (N_DATADDR(x)+(x).a_data) +#endif + +#include <sys/mman.h> +#ifdef sun +#define MAP_COPY MAP_PRIVATE +#define MAP_ANON 0 +#endif + +#include <link.h> +#include <dlfcn.h> + +extern struct _dynamic _DYNAMIC; +static void __load_rtld __P((struct _dynamic *)); +extern int __syscall __P((int, ...)); +int _callmain __P((void)); +static char *_strrchr __P((char *, char)); +#ifdef DEBUG +static char *_getenv __P((char *)); +static int _strncmp __P((char *, char *, int)); +#endif + +#ifdef sun +#define LDSO "/usr/lib/ld.so" +#endif +#ifdef BSD +#define LDSO "/usr/libexec/ld.so" +#endif + +/* + * We need these system calls, but can't use library stubs + */ +#define _exit(v) __syscall(SYS_exit, (v)) +#define open(name, f, m) __syscall(SYS_open, (name), (f), (m)) +#define close(fd) __syscall(SYS_close, (fd)) +#define read(fd, s, n) __syscall(SYS_read, (fd), (s), (n)) +#define write(fd, s, n) __syscall(SYS_write, (fd), (s), (n)) +#define dup(fd) __syscall(SYS_dup, (fd)) +#define dup2(fd, fdnew) __syscall(SYS_dup2, (fd), (fdnew)) +#ifdef sun +#define mmap(addr, len, prot, flags, fd, off) \ + __syscall(SYS_mmap, (addr), (len), (prot), _MAP_NEW|(flags), (fd), (off)) +#else +#define mmap(addr, len, prot, flags, fd, off) \ + __syscall(SYS___syscall, (quad_t)SYS_mmap, (addr), (len), (prot), (flags), \ + (fd), 0, (off_t)(off)) +#endif + +#define _FATAL(str) \ + write(2, str, sizeof(str)), \ + _exit(1); + +#endif /* DYNAMIC */ + +extern int main __P((int, char **, char **)); +#ifdef MCRT0 +extern void monstartup __P((u_long, u_long)); +extern void _mcleanup __P((void)); +#endif + +char **environ; +int errno; +static char empty[1]; +char *__progname = empty; +#ifndef DYNAMIC +#define _strrchr strrchr +#endif + +extern unsigned char etext; +extern unsigned char eprol asm ("eprol"); + diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile new file mode 100644 index 00000000000..49d269db30d --- /dev/null +++ b/lib/csu/i386/Makefile @@ -0,0 +1,42 @@ +# from: @(#)Makefile 5.5 (Berkeley) 5/21/91 +# $Id: Makefile,v 1.1 1995/10/18 08:41:17 deraadt Exp $ + +CFLAGS+= -DLIBC_SCCS -I${.CURDIR}/.. +OBJS= crt0.o gcrt0.o scrt0.o +SRCS= crt0.c + +all: ${OBJS} + +crt0.o: ${SRCS} + @echo "${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +gcrt0.o: ${SRCS} + @echo "${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +scrt0.o: ${SRCS} + @echo "${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +install: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +.if make(depend) +CPPFLAGS+= -DDYNAMIC +.endif + +afterdepend: .depend + @(TMP=/tmp/_depend$$$$; \ + sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o s\1.o:/' \ + < .depend > $$TMP; \ + mv $$TMP .depend) + +.include <bsd.prog.mk> diff --git a/lib/csu/i386/crt0.c b/lib/csu/i386/crt0.c new file mode 100644 index 00000000000..9ec7585fa74 --- /dev/null +++ b/lib/csu/i386/crt0.c @@ -0,0 +1,117 @@ +/* $NetBSD: crt0.c,v 1.20 1995/06/03 13:16:08 pk Exp $ */ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 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. + * + */ + + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "%W% (Erasmus) %G%"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/param.h> +#include <stdlib.h> + +#include "common.h" + +extern void start __P((void)) asm("start"); + +void +start() +{ + struct kframe { + int kargc; + char *kargv[1]; /* size depends on kargc */ + char kargstr[1]; /* size varies */ + char kenvstr[1]; /* size varies */ + }; + /* + * ALL REGISTER VARIABLES!!! + */ + register struct kframe *kfp; + register char **argv, *ap; + +#ifdef lint + kfp = 0; + initcode = initcode = 0; +#else /* not lint */ + /* just above the saved frame pointer */ + asm ("lea 4(%%ebp), %0" : "=r" (kfp) ); +#endif /* not lint */ + argv = &kfp->kargv[0]; + environ = argv + kfp->kargc + 1; + + if (ap = argv[0]) + if ((__progname = _strrchr(ap, '/')) == NULL) + __progname = ap; + else + ++__progname; + +#ifdef DYNAMIC + /* ld(1) convention: if DYNAMIC = 0 then statically linked */ +#ifdef stupid_gcc + if (&_DYNAMIC) +#else + if ( ({volatile caddr_t x = (caddr_t)&_DYNAMIC; x; }) ) +#endif + __load_rtld(&_DYNAMIC); +#endif /* DYNAMIC */ + +asm("eprol:"); + +#ifdef MCRT0 + atexit(_mcleanup); + monstartup((u_long)&eprol, (u_long)&etext); +#endif MCRT0 + +asm ("__callmain:"); /* Defined for the benefit of debuggers */ + exit(main(kfp->kargc, argv, environ)); +} + +#ifdef DYNAMIC + asm(" ___syscall:"); + asm(" popl %ecx"); + asm(" popl %eax"); + asm(" pushl %ecx"); + asm(" int $0x80"); + asm(" pushl %ecx"); + asm(" jc 1f"); + asm(" ret"); + asm(" 1:"); + asm(" movl $-1,%eax"); + asm(" ret"); + +#endif /* DYNAMIC */ + +#include "common.c" + +#ifdef MCRT0 +asm (" .text"); +asm ("_eprol:"); +#endif diff --git a/lib/csu/m68k/Makefile b/lib/csu/m68k/Makefile new file mode 100644 index 00000000000..c046b296262 --- /dev/null +++ b/lib/csu/m68k/Makefile @@ -0,0 +1,42 @@ +# from: @(#)Makefile 5.5 (Berkeley) 5/21/91 +# $Id: Makefile,v 1.1 1995/10/18 08:41:18 deraadt Exp $ + +CFLAGS+= -DLIBC_SCCS -I${.CURDIR}/.. +OBJS= crt0.o gcrt0.o scrt0.o +SRCS= crt0.c + +all: ${OBJS} + +crt0.o: ${SRCS} + @echo "${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +gcrt0.o: ${SRCS} + @echo "${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +scrt0.o: ${SRCS} + @echo "${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +install: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +.if make(depend) +CPPFLAGS+= -DDYNAMIC +.endif + +afterdepend: .depend + @(TMP=/tmp/_depend$$$$; \ + sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o s\1.o:/' \ + < .depend > $$TMP; \ + mv $$TMP .depend) + +.include <bsd.prog.mk> diff --git a/lib/csu/m68k/crt0.c b/lib/csu/m68k/crt0.c new file mode 100644 index 00000000000..3f08eab70b7 --- /dev/null +++ b/lib/csu/m68k/crt0.c @@ -0,0 +1,114 @@ +/* $NetBSD: crt0.c,v 1.14 1995/06/03 13:16:11 pk Exp $ */ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 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. + * + */ + + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "%W% (Erasmus) %G%"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/param.h> +#include <stdlib.h> + +#include "common.h" + +extern void start __P((void)) asm("start"); + +void +start() +{ + struct kframe { + int kargc; + char *kargv[1]; /* size depends on kargc */ + char kargstr[1]; /* size varies */ + char kenvstr[1]; /* size varies */ + }; + /* + * ALL REGISTER VARIABLES!!! + */ + register struct kframe *kfp; + register char **argv, *ap; + +#ifdef lint + kfp = 0; + initcode = initcode = 0; +#else /* not lint */ + asm("lea a6@(4),%0" : "=r" (kfp)); /* catch it quick */ +#endif /* not lint */ + argv = &kfp->kargv[0]; + environ = argv + kfp->kargc + 1; + + if (ap = argv[0]) + if ((__progname = _strrchr(ap, '/')) == NULL) + __progname = ap; + else + ++__progname; + +#ifdef DYNAMIC + /* ld(1) convention: if DYNAMIC = 0 then statically linked */ +#ifdef stupid_gcc + if (&_DYNAMIC) +#else + if ( ({volatile caddr_t x = (caddr_t)&_DYNAMIC; x; }) ) +#endif + __load_rtld(&_DYNAMIC); +#endif /* DYNAMIC */ + +asm("eprol:"); + +#ifdef MCRT0 + atexit(_mcleanup); + monstartup((u_long)&eprol, (u_long)&etext); +#endif MCRT0 + +asm ("__callmain:"); /* Defined for the benefit of debuggers */ + exit(main(kfp->kargc, argv, environ)); +} + +#ifdef DYNAMIC + asm(" ___syscall:"); + asm(" movel a7@+,a0"); /* return address */ + asm(" movel a7@,d0"); /* syscall number */ + asm(" movel a0,a7@"); + asm(" trap #0"); /* do system call */ + asm(" bcc 1f"); /* check error */ + asm(" moveq #-1,d0"); + asm(" 1: movel a7@,a0"); /* get return address, leave */ + asm(" jmp a0@"); /* correct amount on stack */ + +#endif /* DYNAMIC */ + +#include "common.c" + +#ifdef MCRT0 +asm (" .text"); +asm ("_eprol:"); +#endif diff --git a/lib/csu/mips/Makefile b/lib/csu/mips/Makefile new file mode 100644 index 00000000000..82d031ec445 --- /dev/null +++ b/lib/csu/mips/Makefile @@ -0,0 +1,26 @@ +# from: @(#)Makefile 8.1 (Berkeley) 6/1/93 +# $Id: Makefile,v 1.1 1995/10/18 08:41:18 deraadt Exp $ + +CFLAGS= -DLIBC_SCCS +OBJS= crt0.o gcrt0.o +CLEANFILES+= core a.out + +all: ${OBJS} + +crt0.o: crt0.S + ${COMPILE.S} -DCRT0 ${.ALLSRC} + ${LD} -x -r ${.TARGET} + mv a.out ${.TARGET} + +gcrt0.o: crt0.S + ${COMPILE.S} -DMCRT0 ${.ALLSRC} -o ${.TARGET} + ${LD} -x -r ${.TARGET} + mv a.out ${.TARGET} + +install: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +depend lint tags: + +.include <bsd.prog.mk> diff --git a/lib/csu/mips/crt0.S b/lib/csu/mips/crt0.S new file mode 100644 index 00000000000..a59e49ae140 --- /dev/null +++ b/lib/csu/mips/crt0.S @@ -0,0 +1,114 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * 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 the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)crt0.s 8.2 (Berkeley) 3/21/94 + * $Id: crt0.S,v 1.1 1995/10/18 08:41:18 deraadt Exp $ + */ + +#include <machine/regdef.h> +#include <machine/machAsmDefs.h> + + .comm _C_LABEL(environ), 4 + .comm _C_LABEL(__progname), 4 + .data +$L1: + .word 0 # null string plus padding + .text + +NON_LEAF(__start, 24, ra) + .set noreorder +#ifdef __GP_SUPPORT__ + la gp, _C_LABEL (_gp) +#endif + lw s0, 0(sp) # get argc from stack + addu s1, sp, 4 # get pointer to argv + addu s2, s1, 4 # skip null pointer on stack + sll v0, s0, 2 # add number of argv pointers + addu s2, s2, v0 # final pointer to environment list + sw s2, _C_LABEL(environ) # save environment pointer + subu sp, sp, 24 # allocate standard frame + .mask 0x80000000, -4 + sw zero, 20(sp) # clear return address for debugging +#ifdef MCRT0 +eprol: + la a0, eprol + la a1, etext + jal _C_LABEL(monstartup) # monstartup(eprol, etext); + nop + la a0, _C_LABEL(mcleanup) + jal _C_LABEL(atexit) # atexit(mcleanup); + nop + sw zero, _C_LABEL(errno) +#endif + lw a0, 0(s1) # a0 = argv[0]; + nop + bne a0, zero, 2f # If a0 is NULL, use null string. + nop + la a0, $L1 + nop +2: + move s3, a0 # save argv[0] + jal _C_LABEL(strrchr) + li a1, 0x2f # a1 = '/' + bne v0, zero, 1f # if slash found + addu v0, v0, 1 + move v0, s3 # v0 = argv[0]; +1: + sw v0, _C_LABEL(__progname) + move a0, s0 + move a1, s1 + jal _C_LABEL(main) # v0 = main(argc, argv, env); + move a2, s2 + jal _C_LABEL(exit) # exit(v0); + move a0, v0 + break 0 + .set reorder +END(__start) + +#ifndef MCRT0 +LEAF(moncontrol) + j ra +END(moncontrol) + +LEAF(_mcount) + .set noreorder + .set noat + addu sp, sp, 8 # undo push + j ra + move ra, AT + .set at + .set reorder +END(_mcount) +#endif diff --git a/lib/csu/ns32k/Makefile b/lib/csu/ns32k/Makefile new file mode 100644 index 00000000000..c046b296262 --- /dev/null +++ b/lib/csu/ns32k/Makefile @@ -0,0 +1,42 @@ +# from: @(#)Makefile 5.5 (Berkeley) 5/21/91 +# $Id: Makefile,v 1.1 1995/10/18 08:41:18 deraadt Exp $ + +CFLAGS+= -DLIBC_SCCS -I${.CURDIR}/.. +OBJS= crt0.o gcrt0.o scrt0.o +SRCS= crt0.c + +all: ${OBJS} + +crt0.o: ${SRCS} + @echo "${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +gcrt0.o: ${SRCS} + @echo "${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +scrt0.o: ${SRCS} + @echo "${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +install: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +.if make(depend) +CPPFLAGS+= -DDYNAMIC +.endif + +afterdepend: .depend + @(TMP=/tmp/_depend$$$$; \ + sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o s\1.o:/' \ + < .depend > $$TMP; \ + mv $$TMP .depend) + +.include <bsd.prog.mk> diff --git a/lib/csu/ns32k/crt0.c b/lib/csu/ns32k/crt0.c new file mode 100644 index 00000000000..e4fa31522d3 --- /dev/null +++ b/lib/csu/ns32k/crt0.c @@ -0,0 +1,118 @@ +/* $NetBSD: crt0.c,v 1.7 1995/06/03 13:16:15 pk Exp $ */ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 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. + * + */ + +#if defined(LIBC_SCCS) && !defined(lint) +/*static char sccsid[] = "@(#)crt0.c 5.7 (Berkeley) 7/3/91"; */ +static char rcsid[] = "$Id: crt0.c,v 1.1 1995/10/18 08:41:18 deraadt Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/param.h> +#include <stdlib.h> + +#include "common.h" + +extern void start __P((long)) asm("start"); + +void +start(param) + long param; +{ + struct kframe { + int kargc; + char *kargv[1]; /* size depends on kargc */ + char kargstr[1]; /* size varies */ + char kenvstr[1]; /* size varies */ + }; + /* + * ALL REGISTER VARIABLES!!! + */ + register struct kframe *kfp; + register char **argv, *ap; + + /* just above the saved frame pointer */ + kfp = (struct kframe *) (¶m-1); + argv = &kfp->kargv[0]; + environ = argv + kfp->kargc + 1; + + if (ap = argv[0]) + if ((__progname = _strrchr(ap, '/')) == NULL) + __progname = ap; + else + ++__progname; + +#ifdef DYNAMIC + /* ld(1) convention: if DYNAMIC = 0 then statically linked */ +#ifdef stupid_gcc + if (&_DYNAMIC) +#else + if ( ({volatile caddr_t x = (caddr_t)&_DYNAMIC; x; }) ) +#endif + __load_rtld(&_DYNAMIC); +#endif /* DYNAMIC */ + +asm("eprol:"); + +#ifdef MCRT0 + atexit(_mcleanup); + monstartup((u_long)&eprol, (u_long)&etext); +#endif MCRT0 + +asm ("__callmain:"); /* Defined for the benefit of debuggers */ + exit(main(kfp->kargc, argv, environ)); +} + +#ifdef DYNAMIC + asm(" ___syscall:"); + asm(" movd tos,r1"); /* return address */ + asm(" movd tos,r0"); /* syscall number */ + asm(" movd r1,tos"); + asm(" svc"); /* do system call */ + asm(" bcc 1f"); /* check error */ + asm(" movqd -1,r0"); + asm(" 1: jump 0(0(sp))"); /* return */ + +#ifndef ntohl + asm(" _ntohl: movd 4(sp),r0"); + asm(" rotw 8,r0"); + asm(" rotd 16,r0"); + asm(" rotw 8,r0"); + asm(" ret 0"); +#endif + +#endif /* DYNAMIC */ + +#include "common.c" + +#ifdef MCRT0 +asm (" .text"); +asm ("_eprol:"); +#endif diff --git a/lib/csu/sparc/Makefile b/lib/csu/sparc/Makefile new file mode 100644 index 00000000000..c046b296262 --- /dev/null +++ b/lib/csu/sparc/Makefile @@ -0,0 +1,42 @@ +# from: @(#)Makefile 5.5 (Berkeley) 5/21/91 +# $Id: Makefile,v 1.1 1995/10/18 08:41:18 deraadt Exp $ + +CFLAGS+= -DLIBC_SCCS -I${.CURDIR}/.. +OBJS= crt0.o gcrt0.o scrt0.o +SRCS= crt0.c + +all: ${OBJS} + +crt0.o: ${SRCS} + @echo "${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DCRT0 -DDYNAMIC ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +gcrt0.o: ${SRCS} + @echo "${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DMCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +scrt0.o: ${SRCS} + @echo "${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}" + @${COMPILE.c} -DSCRT0 ${.CURDIR}/${SRCS} -o ${.TARGET}.o + @${LD} -x -r ${.TARGET}.o -o ${.TARGET} + @rm -f ${.TARGET}.o + +install: + install ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +.if make(depend) +CPPFLAGS+= -DDYNAMIC +.endif + +afterdepend: .depend + @(TMP=/tmp/_depend$$$$; \ + sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o s\1.o:/' \ + < .depend > $$TMP; \ + mv $$TMP .depend) + +.include <bsd.prog.mk> diff --git a/lib/csu/sparc/crt0.c b/lib/csu/sparc/crt0.c new file mode 100644 index 00000000000..45dce4e521a --- /dev/null +++ b/lib/csu/sparc/crt0.c @@ -0,0 +1,186 @@ +/* $NetBSD: crt0.c,v 1.15 1995/06/15 21:41:55 pk Exp $ */ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 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. + * + */ + + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "%W% (Erasmus) %G%"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/param.h> +#include <stdlib.h> + +#include "common.h" + +extern unsigned char etext; +extern unsigned char eprol asm ("eprol"); +extern void start __P((void)) asm("start"); + +#if defined(sun) && defined(sparc) +static void __call __P((void)); +#endif + +#ifdef BSD +#undef mmap +#define mmap(addr, len, prot, flags, fd, off) \ + __syscall2((quad_t)SYS_mmap, (addr), (len), (prot), (flags), \ + (fd), 0, (off_t)(off)) +extern int __syscall2 __P((quad_t, ...)); +#endif + +asm (" .global start"); +asm (" .text"); +asm (" start:"); + +/* Set up `argc', `argv', and `envp' into local registers (from GNU Emacs). */ +asm (" mov 0, %fp"); +asm (" ld [%sp + 64], %l0"); /* argc */ +asm (" add %sp, 68, %l1"); /* argv */ +asm (" sll %l0, 2, %l2"); /**/ +asm (" add %l2, 4, %l2"); /* envp = argv + (argc << 2) + 4 */ +asm (" add %l1, %l2, %l2"); /**/ +asm (" sethi %hi(_environ), %l3"); +asm (" st %l2, [%l3+%lo(_environ)]"); /* *environ = l2 */ + +/* Finish diddling with stack. */ +asm (" andn %sp, 7, %sp"); +asm (" sub %sp, 24, %sp"); + +/* + * Set __progname: + * if (argv[0]) + * if ((__progname = _strrchr(argv[0], '/')) == NULL) + * __progname = argv[0]; + * else + * ++__progname; + */ +asm (" ld [%l1], %o0"); +asm (" cmp %o0, 0"); +asm (" mov %o0, %l6"); +asm (" be 1f"); +asm (" sethi %hi(___progname), %l7"); +#ifdef DYNAMIC +asm (" call __strrchr"); +#else +asm (" call _strrchr"); +#endif +asm (" mov 47, %o1"); +asm (" cmp %o0, 0"); +asm (" be,a 1f"); +asm (" st %l6, [%l7+%lo(___progname)]"); +asm (" add %o0, 1, %o0"); +asm (" st %o0, [%l7+%lo(___progname)]"); +asm ("1:"); + +#ifdef DYNAMIC +/* Resolve symbols in dynamic libraries */ +asm (" sethi %hi(__DYNAMIC), %o0"); +asm (" orcc %o0, %lo(__DYNAMIC), %o0"); +asm (" be 1f"); +asm (" nop"); +asm (" call ___load_rtld"); +asm (" nop"); +asm ("1:"); +#endif + +/* From here, all symbols should have been resolved, so we can use libc */ +#ifdef MCRT0 +/* + * atexit(_mcleanup); + * monstartup((u_long)&eprol, (u_long)&etext); + */ +asm (" sethi %hi(__mcleanup), %o0"); +asm (" call _atexit"); +asm (" or %o0, %lo(__mcleanup), %o0"); +asm (" sethi %hi(_eprol), %o0"); +asm (" or %o0, %lo(_eprol), %o0"); +asm (" sethi %hi(_etext), %o1"); +asm (" call _monstartup"); +asm (" or %o1, %lo(_etext), %o1"); +#endif + +#ifdef sun +/* SunOS compatibility */ +asm (" call start_float"); +asm (" nop"); +#endif + +/* Move `argc', `argv', and `envp' from locals to parameters for `main'. */ +asm (" mov %l0,%o0"); +asm (" mov %l1,%o1"); +asm ("__callmain:"); /* Defined for the benefit of debuggers */ +asm (" call _main"); +asm (" mov %l2,%o2"); + +asm (" call _exit"); +asm (" nop"); + +#ifdef DYNAMIC +/* System call entry */ +asm(" .set SYSCALL_G2RFLAG, 0x400"); +asm(" .set SYS___syscall, 198"); +asm("___syscall2:"); +asm(" sethi %hi(SYS___syscall), %g1"); /* `SYS___syscall' */ +asm(" ba 1f"); +asm(" or %g1, %lo(SYS___syscall), %g1"); +asm("___syscall:"); +asm(" clr %g1"); /* `SYS_syscall' */ +asm("1:"); +asm(" or %g1, SYSCALL_G2RFLAG, %g1"); /* Use quick return */ +asm(" add %o7, 8, %g2"); +asm(" ta %g0"); +asm(" mov -0x1, %o0"); /* Note: no `errno' */ +asm(" jmp %o7 + 0x8"); +asm(" mov -0x1, %o1"); +#endif + +#ifdef sun +static +__call() +{ + /* + * adjust the C generated pointer to the crt struct to the + * likings of ld.so, which is an offset relative to its %fp + */ + asm("mov %i0, %o0"); + asm("mov %i1, %o1"); + asm("call %i2"); + asm("sub %o1, %sp, %o1"); + /*NOTREACHED, control is transferred directly to our caller */ +} +#endif + +#include "common.c" + +#ifdef MCRT0 +asm (" .text"); +asm ("_eprol:"); +#endif |