switch to netbsd csu

. file- and functionality-compatible with previous situation
          (FreeBSD csu) (with a crt1.o -> crt0.o symlink in /usr/lib)
        . harmonizes source with netbsd
        . harmonizes linker invocation (e.g. clang) with netbsd
        . helpful to get some arm code in there for the arm port project
This commit is contained in:
Ben Gras 2012-03-31 00:35:32 +02:00
parent b02992f0c1
commit e83f7ba2c9
146 changed files with 17245 additions and 215 deletions

View file

@ -1,4 +1,4 @@
/* $NetBSD: exec_elf.h,v 1.108 2010/12/24 12:41:43 skrll Exp $ */
/* $NetBSD: exec_elf.h,v 1.117 2011/08/03 00:22:05 enami Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@ -169,22 +169,22 @@ typedef struct {
/* e_ident[EI_OSABI] */
#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
#define ELFOSABI_HPUX 1 /* HP-UX operating system */
#define ELFOSABI_NETBSD 2 /* NetBSD */
#define ELFOSABI_LINUX 3 /* GNU/Linux */
#define ELFOSABI_HURD 4 /* GNU/Hurd */
#define ELFOSABI_86OPEN 5 /* 86Open */
#define ELFOSABI_SOLARIS 6 /* Solaris */
#define ELFOSABI_MONTEREY 7 /* Monterey */
#define ELFOSABI_IRIX 8 /* IRIX */
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
#define ELFOSABI_NETBSD 2 /* NetBSD */
#define ELFOSABI_LINUX 3 /* GNU/Linux */
#define ELFOSABI_HURD 4 /* GNU/Hurd */
#define ELFOSABI_86OPEN 5 /* 86Open */
#define ELFOSABI_SOLARIS 6 /* Solaris */
#define ELFOSABI_MONTEREY 7 /* Monterey */
#define ELFOSABI_IRIX 8 /* IRIX */
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
#define ELFOSABI_OPENVMS 13 /* OpenVMS */
#define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */
#define ELFOSABI_AROS 15 /* Amiga Research OS */
/* Unofficial OSABIs follow */
#define ELFOSABI_ARM 97 /* ARM */
#define ELFOSABI_ARM 97 /* ARM */
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
#define ELFOSABI_NONE ELFOSABI_SYSV
@ -344,7 +344,12 @@ typedef struct {
#define PT_NUM 8
#define PT_LOOS 0x60000000 /* OS-specific range */
#define PT_GNU_EH_FRAME 0x6474e550 /* GNU-specific EH frame segment */
/* GNU-specific */
#define PT_GNU_EH_FRAME 0x6474e550 /* EH frame segment */
#define PT_GNU_STACK 0x6474e551 /* Indicate executable stack */
#define PT_GNU_RELRO 0x6474e552 /* Make read-only after relocation */
#define PT_HIOS 0x6fffffff
#define PT_LOPROC 0x70000000 /* Processor-specific range */
#define PT_HIPROC 0x7fffffff
@ -414,11 +419,11 @@ typedef struct {
#define SHT_LOOS 0x60000000 /* Operating system specific range */
#define SHT_SUNW_move 0x6ffffffa
#define SHT_SUNW_syminfo 0x6ffffffc
#define SHT_SUNW_verdef 0x6ffffffd /* Versions defined by file */
#define SHT_SUNW_verdef 0x6ffffffd /* Versions defined by file */
#define SHT_GNU_verdef SHT_SUNW_verdef
#define SHT_SUNW_verneed 0x6ffffffe /* Versions needed by file */
#define SHT_SUNW_verneed 0x6ffffffe /* Versions needed by file */
#define SHT_GNU_verneed SHT_SUNW_verneed
#define SHT_SUNW_versym 0x6fffffff /* Symbol versions */
#define SHT_SUNW_versym 0x6fffffff /* Symbol versions */
#define SHT_GNU_versym SHT_SUNW_versym
#define SHT_HIOS 0x6fffffff
#define SHT_LOPROC 0x70000000 /* Processor-specific range */
@ -459,7 +464,7 @@ typedef struct {
/* Symbol Table index of the undefined symbol */
#define ELF_SYM_UNDEFINED 0
#define STN_UNDEF 0 /* undefined index */
#define STN_UNDEF 0 /* undefined index */
/* st_info: Symbol Bindings */
#define STB_LOCAL 0 /* local symbol */
@ -571,7 +576,7 @@ typedef struct {
} Elf32_Move;
#define ELF32_M_SYM(info) ((info) >> 8)
#define ELF32_M_SIZE(info) (info) & 0xff)
#define ELF32_M_SIZE(info) ((info) & 0xff)
#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
typedef struct {
@ -583,7 +588,7 @@ typedef struct {
} Elf64_Move;
#define ELF64_M_SYM(info) ((info) >> 8)
#define ELF64_M_SIZE(info) (info) & 0xff)
#define ELF64_M_SIZE(info) ((info) & 0xff)
#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
/*
@ -657,12 +662,12 @@ typedef struct {
#define DT_NUM 29
#define DT_LOOS 0x60000000 /* Operating system specific range */
#define DT_VERSYM 0x6ffffff0 /* Symbol versions */
#define DT_VERSYM 0x6ffffff0 /* Symbol versions */
#define DT_FLAGS_1 0x6ffffffb /* ELF dynamic flags */
#define DT_VERDEF 0x6ffffffc /* Versions defined by file */
#define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */
#define DT_VERNEED 0x6ffffffe /* Versions needed by file */
#define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */
#define DT_VERDEF 0x6ffffffc /* Versions defined by file */
#define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */
#define DT_VERNEED 0x6ffffffe /* Versions needed by file */
#define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */
#define DT_HIOS 0x6fffffff
#define DT_LOPROC 0x70000000 /* Processor-specific range */
#define DT_HIPROC 0x7fffffff
@ -741,20 +746,86 @@ typedef struct {
Elf64_Word n_type;
} Elf64_Nhdr;
#define ELF_NOTE_TYPE_ABI_TAG 1
#define ELF_NOTE_GNU_NAMESZ 4
#define ELF_NOTE_GNU_NAME "GNU\0"
/*
* GNU-specific note type: ABI tag
* name: GNU\0
* namesz: 4
* desc:
* word[0]: OS tag
* word[1]: major version
* word[2]: minor version
* word[3]: teeny version
* descsz: 16
*/
/* GNU-specific note name and description sizes */
#define ELF_NOTE_ABI_NAMESZ 4
#define ELF_NOTE_TYPE_ABI_TAG 1
#define ELF_NOTE_ABI_NAME ELF_NOTE_GNU_NAME
#define ELF_NOTE_ABI_NAMESZ ELF_NOTE_GNU_NAMESZ
#define ELF_NOTE_ABI_DESCSZ 16
/* GNU-specific note name */
#define ELF_NOTE_ABI_NAME "GNU\0"
/* GNU-specific OS/version value stuff */
#define ELF_NOTE_ABI_OS_LINUX 0
#define ELF_NOTE_ABI_OS_HURD 1
#define ELF_NOTE_ABI_OS_SOLARIS 2
#define ELF_NOTE_ABI_OS_KFREEBSD 3
#define ELF_NOTE_ABI_OS_KNETBSD 4
/* NetBSD-specific note type: Emulation name. desc is emul name string. */
/*
* GNU-specific note type: Hardware capabilities
* name: GNU\0
* namesz: 4
* desc:
* word[0]: Number of entries
* word[1]: Bitmask of enabled entries
* Followed by a byte id, and a NUL terminated string per entry
* descsz: variable
*/
#define ELF_NOTE_TYPE_GNU_HWCAP 2
/*
* GNU-specific note type: Build ID generated by ld
* name: GNU\0
* desc:
* word[0..4] SHA1 [default]
* or
* word[0..3] md5 or uuid
* descsz: 16 or 20
*/
#define ELF_NOTE_TYPE_GNU_BUILD_ID 3
/* SuSE-specific note type: version
* name: SuSE\0\0\0\0
* namesz: 8
* desc:
* word[0] = VVTTMMmm
*
* V = version of following data
* T = product type: [box, sles, nld, whatever]
* M = product major version
* m = product minor version
* descsz: 8
*/
#define ELF_NOTE_TYPE_SUSE_TAG 0x45537553 /* SuSE in LE */
/* SuSE-specific note name and description sizes */
#define ELF_NOTE_SUSE_NAMESZ 8
#define ELF_NOTE_SUSE_DESCSZ 8
/* SuSE-specific note name */
#define ELF_NOTE_SUSE_NAME "SuSE\0\0\0\0"
/* NetBSD-specific note type: Emulation name.
* name: NetBSD\0\0
* namesz: 8
* desc:
* word[0]: MMmmrrpp00
*
* M = major version
* m = minor version
* r = release ["",A-Z,Z[A-Z] but numeric]
* p = patchlevel
* descsz: 4
*/
#define ELF_NOTE_TYPE_NETBSD_TAG 1
/* NetBSD-specific note name and description sizes */
#define ELF_NOTE_NETBSD_NAMESZ 7
@ -762,26 +833,39 @@ typedef struct {
/* NetBSD-specific note name */
#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
/* NetBSD-specific note type: Checksum. There should be 1 NOTE per PT_LOAD
section. desc is a tuple of <phnum>(16),<chk-type>(16),<chk-value>. */
/* NetBSD-specific note type: Checksum.
* There should be 1 NOTE per PT_LOAD section.
* name: ???
* namesz: ???
* desc:
* a tuple of <phnum>(16),<chk-type>(16),<chk-value>.
* descsz: ???
*/
#define ELF_NOTE_TYPE_CHECKSUM_TAG 2
#define ELF_NOTE_CHECKSUM_CRC32 1
#define ELF_NOTE_CHECKSUM_MD5 2
#define ELF_NOTE_CHECKSUM_SHA1 3
#define ELF_NOTE_CHECKSUM_SHA256 4
/* NetBSD-specific note type: PaX. There should be 1 NOTE per executable.
section. desc is a 32 bit bitmask */
#define ELF_NOTE_TYPE_PAX_TAG 3
/*
* NetBSD-specific note type: PaX.
* There should be 1 NOTE per executable.
* name: PaX\0
* namesz: 4
* desc:
* word[0]: capability bitmask
* descsz: 4
*/
#define ELF_NOTE_TYPE_PAX_TAG 3
#define ELF_NOTE_PAX_MPROTECT 0x01 /* Force enable Mprotect */
#define ELF_NOTE_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
#define ELF_NOTE_PAX_GUARD 0x04 /* Force enable Segvguard */
#define ELF_NOTE_PAX_NOGUARD 0x08 /* Force disable Servguard */
#define ELF_NOTE_PAX_ASLR 0x10 /* Force enable ASLR */
#define ELF_NOTE_PAX_NOASLR 0x20 /* Force disable ASLR */
#define ELF_NOTE_PAX_NAMESZ 4
#define ELF_NOTE_PAX_NAME "PaX\0"
#define ELF_NOTE_PAX_DESCSZ 4
#define ELF_NOTE_PAX_NAMESZ 4
#define ELF_NOTE_PAX_NAME "PaX\0"
#define ELF_NOTE_PAX_DESCSZ 4
/*
* NetBSD-specific core file information.
@ -865,6 +949,11 @@ struct netbsd_elfcore_procinfo {
#define Elf_Off Elf32_Off
#define Elf_SOff Elf32_SOff
#define Elf_Nhdr Elf32_Nhdr
#define Elf_Verdef Elf32_Verdef
#define Elf_Verdaux Elf32_Verdaux
#define Elf_Verneed Elf32_Verneed
#define Elf_Vernaux Elf32_Vernaux
#define Elf_Versym Elf32_Versym
#define ELF_R_SYM ELF32_R_SYM
#define ELF_R_TYPE ELF32_R_TYPE
@ -886,6 +975,11 @@ struct netbsd_elfcore_procinfo {
#define Elf_Off Elf64_Off
#define Elf_SOff Elf64_SOff
#define Elf_Nhdr Elf64_Nhdr
#define Elf_Verdef Elf64_Verdef
#define Elf_Verdaux Elf64_Verdaux
#define Elf_Verneed Elf64_Verneed
#define Elf_Vernaux Elf64_Vernaux
#define Elf_Versym Elf64_Versym
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
@ -944,13 +1038,18 @@ typedef struct {
/*
* These constants are used for Elf32_Verdef struct's version number.
*/
#define VER_DEF_NONE 0
#define VER_DEF_NONE 0
#define VER_DEF_CURRENT 1
/*
* These constants are used for Elf32_Verdef struct's vd_ndx.
*/
#define VER_DEF_IDX(x) VER_NDX(x)
/*
* These constants are used for Elf32_Verdef struct's vd_flags.
*/
#define VER_FLG_BASE 0x1
#define VER_FLG_BASE 0x1
#define VER_FLG_WEAK 0x2
/*
@ -958,6 +1057,7 @@ typedef struct {
*/
#define VER_NDX_LOCAL 0
#define VER_NDX_GLOBAL 1
#define VER_NDX_GIVEN 2
/*
* These constants are used for Elf32_Verneed struct's version number.
@ -966,7 +1066,17 @@ typedef struct {
#define VER_NEED_CURRENT 1
/*
* GNU Extension hidding symb
* These constants are used for Elf32_Vernaux struct's vna_other.
*/
#define VER_NEED_HIDDEN VER_NDX_HIDDEN
#define VER_NEED_IDX(x) VER_NDX(x)
/* index */
#define VER_NDX_HIDDEN 0x8000
#define VER_NDX(x) ((x) & ~VER_NDX_HIDDEN)
/*
* GNU Extension hidding symbol
*/
#define VERSYM_HIDDEN 0x8000
#define VERSYM_VERSION 0x7fff
@ -1019,18 +1129,18 @@ typedef Elf32_Versym Elf64_Versym;
#ifdef _KERNEL
#define ELF_AUX_ENTRIES 14 /* Max size of aux array passed to loader */
#define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
#define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
#define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
#define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
#define ELF_AUX_ENTRIES 14 /* Max size of aux array passed to loader */
#define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
#define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
#define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
#define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
#if defined(ELFSIZE) && (ELFSIZE == 64)
#define ELF_NO_ADDR ELF64_NO_ADDR
#define ELF_LINK_ADDR ELF64_LINK_ADDR
#define ELF_NO_ADDR ELF64_NO_ADDR
#define ELF_LINK_ADDR ELF64_LINK_ADDR
#elif defined(ELFSIZE) && (ELFSIZE == 32)
#define ELF_NO_ADDR ELF32_NO_ADDR
#define ELF_LINK_ADDR ELF32_LINK_ADDR
#define ELF_NO_ADDR ELF32_NO_ADDR
#define ELF_LINK_ADDR ELF32_LINK_ADDR
#endif
#ifndef ELF32_EHDR_FLAGS_OK
@ -1061,6 +1171,8 @@ struct elf_args {
#include "opt_execfmt.h"
#endif
struct ps_strings;
#ifdef EXEC_ELF32
int exec_elf32_makecmds(struct lwp *, struct exec_package *);
int elf32_copyargs(struct lwp *, struct exec_package *,

View file

@ -35,7 +35,7 @@ INCS+= ansi.h atomic.h \
tree.h ttycom.h ttydefaults.h \
types.h \
ucontext.h ucred.h uio.h un.h unistd.h utsname.h uuid.h \
wait.h
wait.h exec.h
INCSYMLINKS=\
sys/fcntl.h ${NETBSDINCSDIR}/fcntl.h \

View file

@ -64,7 +64,7 @@
#define __weak_extern(sym) \
__asm(".weak " _C_LABEL_STRING(#sym));
#if __GNUC_PREREQ__(4, 0) && !defined(__minix)
#if __GNUC_PREREQ__(4, 0)
#define __weak_reference(sym) __attribute__((__weakref__))
#else
#define __weak_reference(sym) ; __asm(".weak " _C_LABEL_STRING(#sym))

298
include/sys/exec.h Normal file
View file

@ -0,0 +1,298 @@
/* $NetBSD: exec.h,v 1.133 2011/03/04 22:25:32 joerg Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* 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 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.
*
* @(#)exec.h 8.4 (Berkeley) 2/19/95
*/
/*-
* Copyright (c) 1993 Theo de Raadt. 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.
*/
/*-
* Copyright (c) 1994 Christopher G. Demetriou
*
* 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.
*
* @(#)exec.h 8.4 (Berkeley) 2/19/95
*/
#ifndef _SYS_EXEC_H_
#define _SYS_EXEC_H_
struct pathbuf; /* from namei.h */
/*
* The following structure is found at the top of the user stack of each
* user process. The ps program uses it to locate argv and environment
* strings. Programs that wish ps to display other information may modify
* it; normally ps_argvstr points to argv[0], and ps_nargvstr is the same
* as the program's argc. The fields ps_envstr and ps_nenvstr are the
* equivalent for the environment.
*/
struct ps_strings {
char **ps_argvstr; /* first of 0 or more argument strings */
int ps_nargvstr; /* the number of argument strings */
char **ps_envstr; /* first of 0 or more environment strings */
int ps_nenvstr; /* the number of environment strings */
};
#ifdef _KERNEL
struct ps_strings32 {
uint32_t ps_argvstr; /* first of 0 or more argument strings */
int32_t ps_nargvstr; /* the number of argument strings */
uint32_t ps_envstr; /* first of 0 or more environment strings */
int32_t ps_nenvstr; /* the number of environment strings */
};
#endif
/*
* the following structures allow execve() to put together processes
* in a more extensible and cleaner way.
*
* the exec_package struct defines an executable being execve()'d.
* it contains the header, the vmspace-building commands, the vnode
* information, and the arguments associated with the newly-execve'd
* process.
*
* the exec_vmcmd struct defines a command description to be used
* in creating the new process's vmspace.
*/
#include <sys/uio.h>
struct lwp;
struct proc;
struct exec_package;
struct vnode;
typedef int (*exec_makecmds_fcn)(struct lwp *, struct exec_package *);
struct execsw {
u_int es_hdrsz; /* size of header for this format */
exec_makecmds_fcn es_makecmds; /* function to setup vmcmds */
union { /* probe function */
int (*elf_probe_func)(struct lwp *,
struct exec_package *, void *, char *, vaddr_t *);
int (*ecoff_probe_func)(struct lwp *, struct exec_package *);
int (*mach_probe_func)(const char **);
} u;
struct emul *es_emul; /* os emulation */
int es_prio; /* entry priority */
int es_arglen; /* Extra argument size in words */
/* Copy arguments on the new stack */
int (*es_copyargs)(struct lwp *, struct exec_package *,
struct ps_strings *, char **, void *);
/* Set registers before execution */
void (*es_setregs)(struct lwp *, struct exec_package *, vaddr_t);
/* Dump core */
int (*es_coredump)(struct lwp *, void *);
int (*es_setup_stack)(struct lwp *, struct exec_package *);
};
#define EXECSW_PRIO_ANY 0x000 /* default, no preference */
#define EXECSW_PRIO_FIRST 0x001 /* this should be among first */
#define EXECSW_PRIO_LAST 0x002 /* this should be among last */
/* exec vmspace-creation command set; see below */
struct exec_vmcmd_set {
u_int evs_cnt;
u_int evs_used;
struct exec_vmcmd *evs_cmds;
};
#define EXEC_DEFAULT_VMCMD_SETSIZE 9 /* # of cmds in set to start */
struct exec_package {
const char *ep_name; /* file's name */
const char *ep_kname; /* kernel-side copy of file's name */
char *ep_resolvedname; /* fully resolved path from namei */
void *ep_hdr; /* file's exec header */
u_int ep_hdrlen; /* length of ep_hdr */
u_int ep_hdrvalid; /* bytes of ep_hdr that are valid */
struct exec_vmcmd_set ep_vmcmds; /* vmcmds used to build vmspace */
struct vnode *ep_vp; /* executable's vnode */
struct vattr *ep_vap; /* executable's attributes */
vaddr_t ep_taddr; /* process's text address */
vsize_t ep_tsize; /* size of process's text */
vaddr_t ep_daddr; /* process's data(+bss) address */
vsize_t ep_dsize; /* size of process's data(+bss) */
vaddr_t ep_maxsaddr; /* proc's max stack addr ("top") */
vaddr_t ep_minsaddr; /* proc's min stack addr ("bottom") */
vsize_t ep_ssize; /* size of process's stack */
vaddr_t ep_entry; /* process's entry point */
vaddr_t ep_vm_minaddr; /* bottom of process address space */
vaddr_t ep_vm_maxaddr; /* top of process address space */
u_int ep_flags; /* flags; see below. */
size_t ep_fa_len; /* byte size of ep_fa */
struct exec_fakearg {
char *fa_arg;
size_t fa_len;
} *ep_fa; /* a fake args vector for scripts */
int ep_fd; /* a file descriptor we're holding */
void *ep_emul_arg; /* emulation argument */
const struct execsw *ep_esch;/* execsw entry */
struct vnode *ep_emul_root; /* base of emulation filesystem */
struct vnode *ep_interp; /* vnode of (elf) interpeter */
uint32_t ep_pax_flags; /* pax flags */
char *ep_path; /* absolute path of executable */
};
#define EXEC_INDIR 0x0001 /* script handling already done */
#define EXEC_HASFD 0x0002 /* holding a shell script */
#define EXEC_HASARGL 0x0004 /* has fake args vector */
#define EXEC_SKIPARG 0x0008 /* don't copy user-supplied argv[0] */
#define EXEC_DESTR 0x0010 /* destructive ops performed */
#define EXEC_32 0x0020 /* 32-bit binary emulation */
#define EXEC_FORCEAUX 0x0040 /* always use ELF AUX vector */
struct exec_vmcmd {
int (*ev_proc)(struct lwp *, struct exec_vmcmd *);
/* procedure to run for region of vmspace */
vsize_t ev_len; /* length of the segment to map */
vaddr_t ev_addr; /* address in the vmspace to place it at */
struct vnode *ev_vp; /* vnode pointer for the file w/the data */
vsize_t ev_offset; /* offset in the file for the data */
u_int ev_prot; /* protections for segment */
int ev_flags;
#define VMCMD_RELATIVE 0x0001 /* ev_addr is relative to base entry */
#define VMCMD_BASE 0x0002 /* marks a base entry */
#define VMCMD_FIXED 0x0004 /* entry must be mapped at ev_addr */
#define VMCMD_STACK 0x0008 /* entry is for a stack */
};
#ifdef _KERNEL
/*
* funtions used either by execve() or the various CPU-dependent execve()
* hooks.
*/
void kill_vmcmd (struct exec_vmcmd **);
int exec_makecmds (struct lwp *, struct exec_package *);
int exec_runcmds (struct lwp *, struct exec_package *);
void vmcmdset_extend (struct exec_vmcmd_set *);
void kill_vmcmds (struct exec_vmcmd_set *);
int vmcmd_map_pagedvn (struct lwp *, struct exec_vmcmd *);
int vmcmd_map_readvn (struct lwp *, struct exec_vmcmd *);
int vmcmd_readvn (struct lwp *, struct exec_vmcmd *);
int vmcmd_map_zero (struct lwp *, struct exec_vmcmd *);
int copyargs (struct lwp *, struct exec_package *,
struct ps_strings *, char **, void *);
int copyin_psstrings (struct proc *, struct ps_strings *);
int copy_procargs (struct proc *, int, size_t *,
int (*)(void *, const void *, size_t, size_t), void *);
void setregs (struct lwp *, struct exec_package *, vaddr_t);
int check_veriexec (struct lwp *, struct vnode *,
struct exec_package *, int);
int check_exec (struct lwp *, struct exec_package *,
struct pathbuf *);
int exec_init (int);
int exec_read_from (struct lwp *, struct vnode *, u_long off,
void *, size_t);
int exec_setup_stack (struct lwp *, struct exec_package *);
int coredump_write (void *, enum uio_seg, const void *, size_t);
/*
* Machine dependent functions
*/
struct core;
struct core32;
int cpu_coredump(struct lwp *, void *, struct core *);
int cpu_coredump32(struct lwp *, void *, struct core32 *);
int exec_add(struct execsw *, int);
int exec_remove(struct execsw *, int);
void new_vmcmd(struct exec_vmcmd_set *,
int (*)(struct lwp *, struct exec_vmcmd *),
vsize_t, vaddr_t, struct vnode *, u_long, u_int, int);
#define NEW_VMCMD(evsp,lwp,len,addr,vp,offset,prot) \
new_vmcmd(evsp,lwp,len,addr,vp,offset,prot,0)
#define NEW_VMCMD2(evsp,lwp,len,addr,vp,offset,prot,flags) \
new_vmcmd(evsp,lwp,len,addr,vp,offset,prot,flags)
typedef int (*execve_fetch_element_t)(char * const *, size_t, char **);
int execve1(struct lwp *, const char *, char * const *, char * const *,
execve_fetch_element_t);
extern int maxexec;
#endif /* _KERNEL */
#endif /* !_SYS_EXEC_H_ */

View file

@ -1,5 +1,33 @@
# $NetBSD: Makefile,v 1.28 2010/11/28 18:40:56 skrll Exp $
.include <bsd.own.mk>
SUBDIR=${ARCH}-elf
CSU_MACHINE_ARCH?= ${MACHINE_ARCH}
.include <bsd.subdir.mk>
.if ${USE_COMPILERCRTSTUFF} != "yes"
ARCHDIR:= ${.PARSEDIR}/arch/${CSU_MACHINE_ARCH}
.PATH: ${ARCHDIR}
. include "${ARCHDIR}/Makefile.inc"
. include "${.PARSEDIR}/common/Makefile.inc"
.else
. if exists(${CSU_MACHINE_ARCH}_elf/Makefile)
SUBDIR= ${CSU_MACHINE_ARCH}_elf
. elif exists(${CSU_MACHINE_ARCH}/Makefile)
SUBDIR= ${CSU_MACHINE_ARCH}
. elif exists(${MACHINE_CPU}_elf/Makefile)
SUBDIR= ${MACHINE_CPU}_elf
. elif exists(${MACHINE_CPU}/Makefile)
SUBDIR= ${MACHINE_CPU}
. else
.BEGIN:
@echo no SUBDIR for ${MACHINE_ARCH}_elf, ${MACHINE_ARCH} nor \
${MACHINE_CPU}
@false
. endif
. include <bsd.subdir.mk>
.endif

63
lib/csu/README Normal file
View file

@ -0,0 +1,63 @@
Overview of the common runtime support
The common runtime support contains two modules, crtbegin and crtend.
crtbegin is linked before all other object files of the program or
dynamic library, crtend after all other object files. They frame the
lists of constructors, destructors, Java types and exception handling frames.
If done correctly, crtend contains no code and is therefore position
independent. crtendS.o is therefore just a link to crtend.o.
crtbegin should be position-independent code. crtbeginT.o doesn't have
to be PIC as it is statically linked. The overhead is generally not
worth the trouble though.
Section types:
.ctor: writeable
.dtor: writeable
.eh_frame: read-only if platform allows mixing read-only and read-write
sections. This is supported by GNU ld.
.jcr: writeable
.init: executable
.fini: executable
Non-local symbols:
Weak references:
- _Jv_RegisterClasses,
- __cxa_finalize (crtbeginS.o)
- __deregister_frame_info
- __register_frame_info
Hidden:
- __dso_handle: pointer to self for crtbeginS.o, NULL otherwise.
- __CTOR_LIST_END__
Initialisation (called from .init):
1. Check that the init code hasn't started already, otherwise bail out.
2. If __register_frame_info is NULL, skip to 4
3. Call __register_frame_info with start of .eh_frame as first argument
and a data object of at least 8 pointers as second argument.
4: If _Jv_RegisterClasses is NULL, skip to 6
5: Call _Jv_RegisterClasses with the first pointer of the .jcr section
as argument.
6: Iterate from the end of the .ctor section to the start. Skip the
terminating NULL and stop when reaching the starting (void *)-1 element.
Call the pointers as void (*)(void) functions.
Deinitialisation (called from .fini):
1. Check if the init code has already started, otherwise bail out.
2. If this is not crtbeginS.o or __cxa_finalize is NULL, skip to 4.
3. Call __cxa_finalize with a pointer into this Dynamic Shared Object (DSO)
as first argument.
4. Iterate from the start of the .dtor section to the send. Skip the
initial (void *)-1 and stop when reaching the terminating NULL element.
Call the pointers as void (*)(void) functions.
5. If __deregister_frame_info is NULL, return.
6. Call __deregister_frame_info with the start of .eh_frame as the argument.

18
lib/csu/alpha/Makefile Normal file
View file

@ -0,0 +1,18 @@
# $NetBSD: Makefile,v 1.24 2008/07/21 15:34:58 lukem Exp $
.include <bsd.own.mk>
ELFSIZE= 64
#Uncomment the next line to enable the new .init fallthru
CPPFLAGS+= -I${.CURDIR}
OBJS+= crtfm.o
.include "${.CURDIR}/../common_elf/Makefile.inc"
crtfm.o: crtfm.c
${_MKTARGET_COMPILE}
${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o

90
lib/csu/alpha/crt0.c Normal file
View file

@ -0,0 +1,90 @@
/* $NetBSD: crt0.c,v 1.24 2003/07/26 19:24:25 salo Exp $ */
/*
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
void __start __P((char **, void (*cleanup) __P((void)), const Obj_Entry *,
struct ps_strings *));
void
__start(sp, cleanup, obj, ps_strings)
char **sp;
void (*cleanup) __P((void)); /* from shared loader */
const Obj_Entry *obj; /* from shared loader */
struct ps_strings *ps_strings;
{
long argc;
char **argv, *namep;
argc = *(long *)sp;
argv = sp + 1;
environ = sp + 2 + argc; /* 2: argc + NULL ending argv */
if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(namep, '/')) == NULL)
__progname = namep;
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0 &&
ps_strings != (struct ps_strings *)0xbabefacedeadbeef)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.24 2003/07/26 19:24:25 salo Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

68
lib/csu/alpha/crtfm.c Normal file
View file

@ -0,0 +1,68 @@
/* $NetBSD: crtfm.c,v 1.2 2002/01/14 01:31:00 thorpej Exp $ */
/*
* Copyright (c) 2002 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
*
* 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 NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
* 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.
*/
/*
* Support for the GCC "-ffast-math" option on the Alpha.
*/
#include <sys/types.h>
#include <machine/fpu.h>
#include <machine/sysarch.h>
/*
* Must provide this wrapper around sysarch(2) so that statically-linked
* programs work properly.
*/
extern void __alpha_sysarch(int, void *);
__asm(".ent __alpha_sysarch 0 ;\n"
"__alpha_sysarch: ;\n"
" ldiq $0, 165 ;\n" /* v0 = SYS_sysarch */
" call_pal 0x0083 ;\n" /* PAL_OSF1_callsys */
" ret $31,($26),1 ;\n"
".end __alpha_sysarch");
static void __attribute__((__constructor__))
__alpha_set_fast_math(void)
{
struct alpha_fp_c_args args;
args.fp_c = IEEE_MAP_DMZ|IEEE_MAP_UMZ;
__alpha_sysarch(ALPHA_SET_FP_C, &args);
}

78
lib/csu/alpha/dot_init.h Normal file
View file

@ -0,0 +1,78 @@
/* $NetBSD: dot_init.h,v 1.8 2008/05/10 15:31:03 martin Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#include <machine/asm.h>
#define ASM_SETUP "sp = $30; gp = $29; pv = $27; ra = $26 \n"
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
ASM_SETUP \
".section "#sect",\"ax\",@progbits \n"\
".global "#entry_pt" \n"\
#entry_pt": \n"\
" ldgp gp, 0(pv) \n"\
" lda sp, -32(sp) \n"\
" stq ra, 0(sp) \n"\
" stq gp, 8(sp) \n"\
" .align 5 \n"\
" /* fall thru */ \n"\
".previous")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
ASM_SETUP \
".section "#sect",\"ax\",@progbits \n"\
" ldq gp, 8(sp) \n"\
" ldq ra, 0(sp) \n"\
" lda sp, 32(sp) \n"\
" RET \n"\
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)
/* We assume we need to reload our GP. */
#define MD_CALL_STATIC_FUNCTION(section, func) \
__asm(".section " #section "\n" \
" br $29, 1f \n" \
"1: ldgp $29, 0($29) \n" \
" unop \n" \
" jsr $26, " #func "\n" \
" .align 3; .previous");

View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:33 joerg Exp $
CPPFLAGS+= -DELFSIZE=32

56
lib/csu/arch/arm/crt0.S Normal file
View file

@ -0,0 +1,56 @@
/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
/*
* Copyright (C) 1997 Mark Brinicombe
* Copyright (C) 1995 Wolfgang Solfrank.
* Copyright (C) 1995 TooLs GmbH.
* 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 TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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 <machine/asm.h>
RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
STRONG_ALIAS(_start,__start)
_ENTRY(__start)
mov r5, r2 /* cleanup */
mov r4, r1 /* obj_main */
mov r3, r0 /* ps_strings */
/* Get argc, argv, and envp from stack */
ldr r0, [sp, #0x0000]
add r1, sp, #0x0004
add r2, r1, r0, lsl #2
add r2, r2, #0x0004
/* Ensure the stack is properly aligned before calling C code. */
bic sp, sp, #7
sub sp, sp, #8
str r5, [sp, #4]
str r4, [sp, #0]
b ___start

56
lib/csu/arch/arm/crti.S Normal file
View file

@ -0,0 +1,56 @@
/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
#include "sysident.S"
.section ".init", "ax", @progbits
.align 0
.globl _init
_init:
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
.section ".fini", "ax", @progbits
.align 0
.globl _fini
_fini:
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4

44
lib/csu/arch/arm/crtn.S Normal file
View file

@ -0,0 +1,44 @@
/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
.section ".init", "ax", @progbits
ldmea fp, {fp, sp, pc}
.section ".fini", "ax", @progbits
ldmea fp, {fp, sp, pc}

View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:33 joerg Exp $
CPPFLAGS+= -DELFSIZE=32

53
lib/csu/arch/i386/crt0.S Normal file
View file

@ -0,0 +1,53 @@
/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include <machine/asm.h>
RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
STRONG_ALIAS(_start,__start)
_ENTRY(__start)
pushl %ebx
pushl %ecx
pushl %edx
movl 12(%esp),%eax
leal 16(%esp),%edx
leal 20(%esp,%eax,4),%ecx
pushl %ecx
pushl %edx
pushl %eax
call ___start

54
lib/csu/arch/i386/crti.S Normal file
View file

@ -0,0 +1,54 @@
/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $")
#include "sysident.S"
.section ".init", "ax", @progbits
.align 16
.globl _init
_init:
pushl %ebp
movl %esp, %ebp
.section ".fini", "ax", @progbits
.align 16
.globl _fini
_fini:
pushl %ebp
movl %esp, %ebp

46
lib/csu/arch/i386/crtn.S Normal file
View file

@ -0,0 +1,46 @@
/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section ".init", "ax", @progbits
leave
ret
.section ".fini", "ax", @progbits
leave
ret

View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:34 joerg Exp $
CPPFLAGS+= -DELFSIZE=32

52
lib/csu/arch/m68k/crt0.S Normal file
View file

@ -0,0 +1,52 @@
#include <machine/asm.h>
/*
* Copyright (c) 1999 Klaus Klein
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
STRONG_ALIAS(_start,__start)
_ENTRY(__start)
movl (%sp),%d0
movl %a2,-(%sp) | ps_strings
movl %a0,-(%sp) | obj
movl %a1,-(%sp) | cleanup
movl %d0,%d1
lsll #2,%d1
pea (16+4)(%sp,%d1.l) | envp = &argv[argc + 1]
pea 20(%sp) | argv
movl %d0,-(%sp) | argc
jsr ___start

50
lib/csu/arch/m68k/crti.S Normal file
View file

@ -0,0 +1,50 @@
/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
#include "sysident.S"
.section ".init", "ax", @progbits
.align 2
.globl _init
_init:
.section ".fini", "ax", @progbits
.align 2
.globl _fini
_fini:

44
lib/csu/arch/m68k/crtn.S Normal file
View file

@ -0,0 +1,44 @@
/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section ".init", "ax", @progbits
rts
.section ".fini", "ax", @progbits
rts

View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:34 joerg Exp $
CPPFLAGS+= -DELFSIZE=32

View file

@ -1,7 +1,10 @@
/*-
* Copyright 1996, 1997, 1998, 2000 John D. Polstra.
/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
* 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:
@ -10,7 +13,14 @@
* 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
* 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.
@ -21,15 +31,17 @@
* 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: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
.section .init,"ax",@progbits
add $12,%esp
ret
#include <machine/asm.h>
.section .fini,"ax",@progbits
add $12,%esp
ret
RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section .rodata
.ascii "$MINIX$\0"
STRONG_ALIAS(_start,__start)
_ENTRY(__start)
mov.l r9,@-r15
bra ___start
mov.l r8,@-r15

56
lib/csu/arch/sh3/crti.S Normal file
View file

@ -0,0 +1,56 @@
/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
#include "sysident.S"
.section ".init", "ax", @progbits
.align 4
.globl _init
_init:
mov.l r14, @-sp
sts.l pr, @-sp
mov sp, r14
.section ".fini", "ax", @progbits
.align 4
.globl _fini
_fini:
mov.l r14, @-sp
sts.l pr, @-sp
mov sp, r14

50
lib/csu/arch/sh3/crtn.S Normal file
View file

@ -0,0 +1,50 @@
/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section ".init", "ax", @progbits
mov r14, sp
lds.l @sp+, pr
rts
mov.l @sp+, r14
.section ".fini", "ax", @progbits
mov r14, sp
lds.l @sp+, pr
rts
mov.l @sp+, r14

View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:34 joerg Exp $
CPPFLAGS+= -DELFSIZE=32

56
lib/csu/arch/sparc/crt0.S Normal file
View file

@ -0,0 +1,56 @@
/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include <machine/asm.h>
RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
STRONG_ALIAS(_start,__start)
_ENTRY(__start)
mov 0, %fp
ld [%sp + 64], %o0 ! get argc
add %sp, 68, %o1 ! get argv
sll %o0, 2, %o2 !
add %o2, 4, %o2 ! envp = argv + (argc << 2) + 4
add %o1, %o2, %o2 !
andn %sp, 7, %sp ! align
sub %sp, 24, %sp ! expand to standard stack frame size
mov %g3, %o3
mov %g2, %o4
call ___start
mov %g1, %o5

78
lib/csu/arch/sparc/crti.S Normal file
View file

@ -0,0 +1,78 @@
/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*
* Copyright (c) 2001 Matthew R. Green
* 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.
*/
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
#include "sysident.S"
.section ".init", "ax", @progbits
.align 4
.globl _init
_init:
save %sp, -96, %sp
.section ".fini", "ax", @progbits
.align 4
.globl _fini
_fini:
save %sp, -96, %sp

74
lib/csu/arch/sparc/crtn.S Normal file
View file

@ -0,0 +1,74 @@
/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*
* Copyright (c) 2001 Matthew R. Green
* 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.
*/
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section ".init", "ax", @progbits
.align 4
ret
restore
.section ".fini", "ax", @progbits
.align 4
ret
restore

View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:34 joerg Exp $
CPPFLAGS+= -DELFSIZE=32

53
lib/csu/arch/vax/crt0.S Normal file
View file

@ -0,0 +1,53 @@
/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*
* Copyright (c) 1999 Matt Thomas
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include <machine/asm.h>
RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
STRONG_ALIAS(_start,__start)
_ENTRY(__start)
.word 0x0101
pushl %r9 /* ps_strings */
pushl %r8 /* obj */
pushl %r7 /* cleanup */
movl (%r6),%r0 /* argc */
pushal 8(%r6)[%r0] /* envp = &argv[argc + 1] */
pushal 4(%r6) /* argv */
pushl %r0 /* argc */
calls $6,___start

52
lib/csu/arch/vax/crti.S Normal file
View file

@ -0,0 +1,52 @@
/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
#include "sysident.S"
.section ".init", "ax", @progbits
.align 1
.globl _init
_init:
.word 0
.section ".fini", "ax", @progbits
.align 1
.globl _fini
_fini:
.word 0

44
lib/csu/arch/vax/crtn.S Normal file
View file

@ -0,0 +1,44 @@
/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section ".init", "ax", @progbits
ret
.section ".fini", "ax", @progbits
ret

View file

@ -0,0 +1,3 @@
# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:34 joerg Exp $
CPPFLAGS+= -DELFSIZE=64

View file

@ -1,7 +1,10 @@
/*-
* Copyright 1996, 1997, 1998, 2000 John D. Polstra.
/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
* 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:
@ -10,7 +13,14 @@
* 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
* 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.
@ -23,19 +33,20 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
.section .init,"ax",@progbits
.align 4
.globl _init
.type _init,@function
_init:
sub $12,%esp /* re-align stack pointer */
#include <machine/asm.h>
.section .fini,"ax",@progbits
.align 4
.globl _fini
.type _fini,@function
_fini:
sub $12,%esp /* re-align stack pointer */
RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section .rodata
.ascii "$MINIX$\0"
STRONG_ALIAS(_start,__start)
_ENTRY(__start)
movq %rbx,%r9
movq %rcx,%r8
movq %rdx,%rcx
movq (%rsp),%rdi
leaq 16(%rsp,%rdi,8),%rdx
leaq 8(%rsp),%rsi
subq $8,%rsp
andq $~15,%rsp
addq $8,%rsp
jmp ___start

View file

@ -0,0 +1,156 @@
/* $NetBSD: crtbegin.S,v 1.2 2010/11/30 18:37:59 joerg Exp $ */
/*-
* Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
* 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDERS 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 <machine/asm.h>
RCSID("$NetBSD: crtbegin.S,v 1.2 2010/11/30 18:37:59 joerg Exp $")
.section .ctors, "aw", @progbits
.align 8
__CTOR_LIST__:
.quad -1
.section .dtors, "aw", @progbits
.align 8
__DTOR_LIST__:
.quad -1
.section .eh_frame, "a", @progbits
.align 8
__EH_FRAME_LIST__:
.section .jcr, "aw", @progbits
.align 8
__JCR_LIST__:
.section .data.rel, "aw", @progbits
.align 8
.type __dso_handle, @object
.size __dso_handle, 8
.globl __dso_handle
.hidden __dso_handle
__dso_handle:
#ifdef SHARED
.quad __dso_handle
#else
.quad 0
#endif
__dwarf_eh_object:
.zero 64
__initialized:
.zero 1
__finished:
.zero 1
.text
.weak __cxa_finalize
.weak __deregister_frame_info
.weak __register_frame_info
.weak _Jv_RegisterClasses
__do_global_dtors_aux:
cmpb $0, __finished(%rip)
je 1f
ret
1:
pushq %rbx
movb $1, __finished(%rip)
#ifdef SHARED
cmpq $0, __cxa_finalize@GOTPCREL(%rip)
je 2f
movq __dso_handle(%rip), %rdi
call __cxa_finalize@PLT
2:
#endif
leaq 8+__DTOR_LIST__(%rip), %rbx
3:
movq (%rbx), %rax
testq %rax, %rax
je 4f
call *%rax
addq $8, %rbx
jmp 3b
4:
cmpq $0, __deregister_frame_info@GOTPCREL(%rip)
je 5f
leaq __EH_FRAME_LIST__(%rip), %rdi
call __deregister_frame_info@PLT
5:
popq %rbx
ret
__do_global_ctors_aux:
cmpb $0, __initialized(%rip)
je 1f
ret
1:
pushq %rbx
movb $1, __initialized(%rip)
cmpq $0, __register_frame_info@GOTPCREL(%rip)
je 2f
leaq __dwarf_eh_object(%rip), %rsi
leaq __EH_FRAME_LIST__(%rip), %rdi
call __register_frame_info@PLT
2:
cmpq $0, _Jv_RegisterClasses@GOTPCREL(%rip)
je 3f
leaq __JCR_LIST__(%rip), %rdi
cmpq $0, (%rdi)
je 3f
call _Jv_RegisterClasses@PLT
3:
leaq -8+__CTOR_LIST_END__(%rip), %rbx
4:
movq (%rbx), %rax
cmpq $-1, %rax
je 5f
call *%rax
subq $8, %rbx
jmp 4b
5:
popq %rbx
ret
.section .init, "ax", @progbits
call __do_global_ctors_aux
.section .fini, "ax", @progbits
call __do_global_dtors_aux

View file

@ -0,0 +1,52 @@
/* $NetBSD: crtend.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */
/*-
* Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
* 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDERS 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 <machine/asm.h>
RCSID("$NetBSD: crtend.S,v 1.1 2010/08/07 18:01:34 joerg Exp $")
.section .ctors, "aw", @progbits
.align 8
.global __CTOR_LIST_END__
.hidden __CTOR_LIST_END__
__CTOR_LIST_END__:
.quad 0
.section .dtors, "aw", @progbits
.align 8
.quad 0
.section .eh_frame, "a", @progbits
.align 8
.quad 0
.section .jcr, "aw", @progbits
.align 8
.quad 0

View file

@ -0,0 +1,52 @@
/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:35 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:35 joerg Exp $")
#include "sysident.S"
.section ".init", "ax", @progbits
.align 16
.globl _init
_init:
subq $8, %rsp
.section ".fini", "ax", @progbits
.align 16
.globl _fini
_fini:
subq $8, %rsp

View file

@ -0,0 +1,46 @@
/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:35 joerg Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:35 joerg Exp $")
.section ".init", "ax", @progbits
addq $8, %rsp
ret
.section ".fini", "ax", @progbits
addq $8, %rsp
ret

8
lib/csu/arm_elf/Makefile Normal file
View file

@ -0,0 +1,8 @@
# $NetBSD: Makefile,v 1.4 2006/05/19 19:11:12 christos Exp $
CPPFLAGS+= -I${.CURDIR}
# Temporary hack to work around ld problems when linking Thumb applications
# where the linker does not correctly insert an interworking veneer.
CFLAGS+=-mlong-calls
.include "${.CURDIR}/../common_elf/Makefile.inc"

109
lib/csu/arm_elf/crt0.c Normal file
View file

@ -0,0 +1,109 @@
/* $NetBSD: crt0.c,v 1.7 2008/06/21 00:52:52 gmcgarry Exp $ */
/*
* Copyright (C) 1997 Mark Brinicombe
* Copyright (C) 1995 Wolfgang Solfrank.
* Copyright (C) 1995 TooLs GmbH.
* 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 TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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 <sys/cdefs.h>
#include <sys/param.h>
#include <machine/asm.h>
#include <stdlib.h>
#include "common.h"
extern void _start(void);
void ___start(int, char *[], char *[], struct ps_strings *,
const Obj_Entry *, void (*)(void));
__asm(" .text \n"
" .align 0 \n"
" .globl _start \n"
" .globl __start \n"
"_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"
"\n"
" /* Ensure the stack is properly aligned before calling C code. */\n"
" bic sp, sp, #" ___STRING(STACKALIGNBYTES) " \n"
" sub sp, sp, #8 \n"
" str r5, [sp, #4] \n"
" str r4, [sp, #0] \n"
"\n"
" b " ___STRING(_C_LABEL(___start)) " ");
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.7 2008/06/21 00:52:52 gmcgarry Exp $");
#endif /* LIBC_SCCS and not lint */
void
___start(int argc, char **argv, char **envp, struct ps_strings *ps_strings,
const Obj_Entry *obj, void (*cleanup)(void))
{
char *ap;
environ = envp;
__ps_strings = ps_strings;
if ((ap = argv[0])) {
if ((__progname = _strrchr(ap, '/')) == NULL)
__progname = ap;
else
++__progname;
}
#ifdef DYNAMIC
/* ld(1) convention: if DYNAMIC = 0 then statically linked */
if (&_DYNAMIC)
_rtld_setup(cleanup, obj);
#endif /* DYNAMIC */
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif /* MCRT0 */
atexit(_fini);
_init();
__asm("__callmain:"); /* Defined for the benefit of debuggers */
exit(main(argc, argv, envp));
}
#include "common.c"

View file

@ -0,0 +1,61 @@
/* $NetBSD: dot_init.h,v 1.6 2008/05/10 15:31:03 martin Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#include <machine/asm.h>
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".section "#sect",\"ax\",%progbits \n"\
".global "#entry_pt" \n"\
" .align 0 \n"\
#entry_pt": \n"\
"mov ip, sp \n"\
"stmfd sp!, {fp, ip, lr, pc} \n"\
"sub fp, ip, #4 \n"\
" /* fall thru */ \n"\
".previous")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".section "#sect",\"ax\",%progbits \n"\
"ldmea fp, {fp, sp, pc} \n"\
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

View file

@ -0,0 +1,87 @@
# $NetBSD: Makefile.inc,v 1.2 2010/12/07 19:51:02 joerg Exp $
.include <bsd.own.mk>
COMMON_DIR:= ${.PARSEDIR}
.PATH: ${COMMON_DIR}
CPPFLAGS+= -I${NETBSDSRCDIR}/libexec/ld.elf_so -I${COMMON_DIR} -I.
OBJS+= crt0.o gcrt0.o crti.o crtn.o
OBJS+= crtbegin.o crtbeginS.o crtend.o
realall: ${OBJS}
crtbegin.o: crtbegin.S
${_MKTARGET_COMPILE}
${COMPILE.S} ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
crtbeginS.o: crtbegin.S
${_MKTARGET_COMPILE}
${COMPILE.S} -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
crtend.o: crtend.S
${_MKTARGET_COMPILE}
${COMPILE.S} ${ARCHDIR}/crtend.S -o ${.TARGET}.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
.if ${MKPIC} != "no"
PICFLAGS= -fPIC
.else
PICFLAGS=
.endif
crt0.o: crt0-common.c crt0.S
${_MKTARGET_COMPILE}
${COMPILE.c} ${PICFLAGS} ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.c.o ${.TARGET}.S.o
rm -f ${.TARGET}.c.o ${.TARGET}.S.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
gcrt0.o: crt0-common.c crt0.S
${_MKTARGET_COMPILE}
${COMPILE.c} ${PICFLAGS} -DMCRT0 ${COMMON_DIR}/crt0-common.c -o ${.TARGET}.c.o
${COMPILE.S} ${ARCHDIR}/crt0.S -o ${.TARGET}.S.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.c.o ${.TARGET}.S.o
rm -f ${.TARGET}.c.o ${.TARGET}.S.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
sysident_assym.h: ${GENASSYM_CONF} ${GENASSYM_EXTRAS}
${_MKTARGET_CREATE}
cat ${COMMON_DIR}/sysident_assym.cf | \
${TOOL_GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
> sysident_assym.h.tmp && \
mv -f sysident_assym.h.tmp sysident_assym.h
CLEANFILES+= sysident_assym.h
crti.o: crti.S sysident_assym.h
crtn.o: crtn.S
FILES=${OBJS}
FILESDIR=${LIBDIR}
CLEANFILES+=${OBJS}
SYMLINKS+= crtbegin.o ${LIBDIR}/crtbeginT.o
SYMLINKS+= crtend.o ${LIBDIR}/crtendS.o
SYMLINKS+= crt0.o ${LIBDIR}/crt1.o
.include <bsd.prog.mk>

View file

@ -0,0 +1,137 @@
/* $NetBSD: crt0-common.c,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: crt0-common.c,v 1.1 2010/08/07 18:01:33 joerg Exp $");
#include <sys/types.h>
#ifndef __minix
#include <sys/syscall.h>
#endif
#include <machine/profile.h>
#include <stdlib.h>
#include <unistd.h>
#include "rtld.h"
extern int main(int, char **, char **);
extern void _init(void);
extern void _fini(void);
/*
* Arrange for _DYNAMIC to be weak and undefined (and therefore to show up
* as being at address zero, unless something else defines it). That way,
* if we happen to be compiling without -static but with without any
* shared libs present, things will still work.
*/
#if __GNUC_PREREQ__(4,2)
static int rtld_DYNAMIC __attribute__((__weakref__, __alias__("_DYNAMIC")));
#define DYNAMIC_SYM rtld_DYNAMIC
#else
extern int _DYNAMIC __weak_reference(_DYNAMIC);
#define DYNAMIC_SYM _DYNAMIC
#endif
#ifdef MCRT0
extern void monstartup(u_long, u_long);
extern void _mcleanup(void);
extern unsigned char __etext, __eprol;
#endif /* MCRT0 */
char **environ;
struct ps_strings *__ps_strings = 0;
static char empty_string[] = "";
char *__progname = empty_string;
void ___start(int, char **, char **, void (*)(void),
const Obj_Entry *, struct ps_strings *);
#ifndef __minix
#define write(fd, s, n) __syscall(SYS_write, (fd), (s), (n))
#else
#define write(fd, s, n) /* NO write() from here on minix */
#endif
#define _FATAL(str) \
do { \
write(2, str, sizeof(str)-1); \
_exit(1); \
} while (0)
void
___start(int argc, char **argv, char **envp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
environ = envp;
if (argv[0] != NULL) {
char *c;
__progname = argv[0];
for (c = argv[0]; *c; ++c) {
if (*c == '/')
__progname = c + 1;
}
} else {
__progname = empty_string;
}
if (ps_strings != NULL)
__ps_strings = ps_strings;
if (&DYNAMIC_SYM != NULL) {
if ((obj == NULL) || (obj->magic != RTLD_MAGIC))
_FATAL("Corrupt Obj_Entry pointer in GOT\n");
if (obj->version != RTLD_VERSION)
_FATAL("Dynamic linker version mismatch\n");
atexit(cleanup);
}
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&__eprol, (u_long)&__etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}

82
lib/csu/common/sysident.S Normal file
View file

@ -0,0 +1,82 @@
/* $NetBSD: sysident.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */
/*
* Copyright (c) 1997 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
/*
* Here we define the NetBSD OS Version in an ELF .note section, structured
* like:
*
* [NOTE HEADER]
* long name size
* long description size
* long note type
*
* [NOTE DATUM]
* string OS name
*
* OSVERSION notes also have:
* long OS version (__NetBSD_Version__ constant from param.h)
*
* The DATUM fields should be padded out such that their actual (not
* declared) sizes % 4 == 0.
*
* These are used by the kernel to determine if this binary is really a
* NetBSD binary, or some other OS's.
*/
#include "sysident_assym.h"
#ifdef __minix
.section .rodata
.ascii "$MINIX$\0"
#else
.section ".note.netbsd.ident", "a"
.align 4
.long ELF_NOTE_NETBSD_NAMESZ
.long ELF_NOTE_NETBSD_DESCSZ
.long ELF_NOTE_TYPE_NETBSD_TAG
.ascii "NetBSD\0\0" /* ELF_NOTE_NETBSD_NAME */
.long __NetBSD_Version__
.section ".note.netbsd.pax", "a"
.align 4
.long ELF_NOTE_PAX_NAMESZ
.long ELF_NOTE_PAX_DESCSZ
.long ELF_NOTE_TYPE_PAX_TAG
.ascii "PaX\0" /* ELF_NOTE_PAX_NAME */
.long 0
#endif

View file

@ -0,0 +1,12 @@
include <sys/param.h>
include <sys/exec_elf.h>
define ELF_NOTE_NETBSD_NAMESZ ELF_NOTE_NETBSD_NAMESZ
define ELF_NOTE_NETBSD_DESCSZ ELF_NOTE_NETBSD_DESCSZ
define ELF_NOTE_TYPE_NETBSD_TAG ELF_NOTE_TYPE_NETBSD_TAG
#define ELF_NOTE_NETBSD_NAME ELF_NOTE_NETBSD_NAME
define __NetBSD_Version__ __NetBSD_Version__
define ELF_NOTE_PAX_NAMESZ ELF_NOTE_PAX_NAMESZ
define ELF_NOTE_PAX_DESCSZ ELF_NOTE_PAX_DESCSZ
define ELF_NOTE_TYPE_PAX_TAG ELF_NOTE_TYPE_PAX_TAG
#define ELF_NOTE_PAX_NAME ELF_NOTE_PAX_NAME

View file

@ -0,0 +1,74 @@
# $NetBSD: Makefile.inc,v 1.32 2009/12/13 08:52:38 mrg Exp $
.if !defined(ELFSIZE)
ELFSIZE=32
.endif
.include "../../Makefile.inc"
CPPFLAGS+= -DLIBC_SCCS -DPIC -DDYNAMIC -DELFSIZE=${ELFSIZE}
CPPFLAGS+= -I${NETBSDSRCDIR}/libexec/ld.elf_so
CPPFLAGS+= -I${.CURDIR}/../common_elf
CPPFLAGS+= -I${NETBSDSRCDIR}/lib/libc/dlfcn
CPPFLAGS+= -DDWARF2_EH
CPPFLAGS+= -DJCR
CPPFLAGS+= -DDSO_HANDLE
.if defined(HAVE_GCC) && ${HAVE_GCC} > 3
CFLAGS+= -fno-unit-at-a-time
.endif
.include <bsd.own.mk>
.PATH: ${.CURDIR}/../common_elf
SRCS+= crt0.c crti.c crtn.c
OBJS+= crt0.o gcrt0.o crti.o crtn.o
.if ${MKPIC} != "no"
COPTS+= -fPIC
.endif
realall: ${OBJS}
crt0.o: crt0.c
${_MKTARGET_COMPILE}
${COMPILE.c} -DCRT0 ${.IMPSRC} -o ${.TARGET}.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
# dependant on crt0.o to pick up header dependencies
gcrt0.o: ${.CURDIR}/crt0.c crt0.o
${_MKTARGET_COMPILE}
${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
${LD} -x -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
crti.o: crti.c
${_MKTARGET_COMPILE}
${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
${LD} -X -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
crtn.o: crtn.c
${_MKTARGET_COMPILE}
${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
${LD} -X -r -o ${.TARGET} ${.TARGET}.o
rm -f ${.TARGET}.o
.if ${MKSTRIPIDENT} != "no"
${OBJCOPY} -R .ident ${.TARGET}
.endif
FILES=${OBJS}
FILESDIR=${LIBDIR}
CLEANFILES=${OBJS}
.include <bsd.prog.mk>

View file

@ -0,0 +1,77 @@
/* $NetBSD: common.c,v 1.17 2005/12/24 22:53:15 perry Exp $ */
/*
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
/*
* NOT A STANDALONE FILE!
*/
static char *
_strrchr(char *p, int ch)
{
char *save;
for (save = NULL;; ++p) {
if (*p == ch)
save = (char *)p;
if (!*p)
return(save);
}
/* NOTREACHED */
}
#ifdef MCRT0
__asm (" .text");
#ifdef EPROL_EXPORT
EPROL_EXPORT;
#endif
__asm ("_eprol:");
#endif
#ifdef DYNAMIC
void
_rtld_setup(void (*cleanup)(void), const Obj_Entry *obj)
{
if ((obj == NULL) || (obj->magic != RTLD_MAGIC))
_FATAL("Corrupt Obj_Entry pointer in GOT\n");
if (obj->version != RTLD_VERSION)
_FATAL("Dynamic linker version mismatch\n");
atexit(cleanup);
}
#endif /* DYNAMIC */

View file

@ -0,0 +1,95 @@
/* $NetBSD: common.h,v 1.13 2009/12/14 01:04:02 matt Exp $ */
/*
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include <sys/types.h>
#include <sys/exec.h>
#ifndef __minix
#include <sys/syscall.h>
#endif
#include <stdlib.h>
#ifdef DYNAMIC
#ifdef __weak_alias
#define dlopen _dlopen
#define dlclose _dlclose
#define dlsym _dlsym
#define dlerror _dlerror
#define dladdr _dladdr
#endif
#include <dlfcn.h>
#include "rtld.h"
#else
typedef void Obj_Entry;
#endif
extern quad_t __syscall(quad_t, ...);
#define _exit(v) __syscall(SYS_exit, (v))
#define write(fd, s, n) __syscall(SYS_write, (fd), (s), (n))
#define _FATAL(str) \
do { \
write(2, str, sizeof(str)-1); \
_exit(1); \
} while (0)
static char *_strrchr(char *, int);
char **environ;
char *__progname = "";
struct ps_strings *__ps_strings = 0;
extern void _init(void);
extern void _fini(void);
#ifdef DYNAMIC
void _rtld_setup(void (*)(void), const Obj_Entry *obj);
/*
* Arrange for _DYNAMIC to be weak and undefined (and therefore to show up
* as being at address zero, unless something else defines it). That way,
* if we happen to be compiling without -static but with without any
* shared libs present, things will still work.
*/
extern int _DYNAMIC __weak_reference(_DYNAMIC);
#endif /* DYNAMIC */
#ifdef MCRT0
extern void monstartup(u_long, u_long);
extern void _mcleanup(void);
extern unsigned char _etext, _eprol;
#endif /* MCRT0 */
int main(int, char **, char **);

40
lib/csu/common_elf/crti.c Normal file
View file

@ -0,0 +1,40 @@
/* $NetBSD: crti.c,v 1.6 2008/04/28 20:22:54 martin Exp $ */
/*-
* Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/param.h> /* sysident.h requires `NetBSD' constant */
#include <sys/exec.h>
#include <sys/exec_elf.h>
#include "sysident.h"
#include <dot_init.h>
MD_INIT_SECTION_PROLOGUE;
MD_FINI_SECTION_PROLOGUE;

35
lib/csu/common_elf/crtn.c Normal file
View file

@ -0,0 +1,35 @@
/* $NetBSD: crtn.c,v 1.3 2008/04/28 20:22:54 martin Exp $ */
/*-
* Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <dot_init.h>
MD_INIT_SECTION_EPILOGUE;
MD_FINI_SECTION_EPILOGUE;

View file

@ -0,0 +1,48 @@
/* $NetBSD: dot_init.h,v 1.3 2008/05/10 15:31:03 martin Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#define INIT_FALLTHRU_DECL
#define FINI_FALLTHRU_DECL
#define INIT_FALLTHRU()
#define FINI_FALLTHRU()
#define MD_INIT_SECTION_PROLOGUE
#define MD_FINI_SECTION_PROLOGUE
#define MD_INIT_SECTION_EPILOGUE
#define MD_FINI_SECTION_EPILOGUE

View file

@ -0,0 +1,70 @@
/* $NetBSD: dwarf2_eh.h,v 1.3 2008/04/28 20:22:54 martin Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Definitions for DWARF2 stack frame unwinding/exception handling.
*/
#ifdef __GNUC__
/*
* We must pass a DWARF2 unwind object to __register_frame_info().
* Since we don't reference any members of this object, but rather
* only provide storage for it, we just declare it in a simple,
* dumb way. We need room for 6 pointers in GCC 2.95.3 and GCC 3.0,
* but declare it with a little slop at the end.
*/
struct dwarf2_eh_object {
void *space[8];
};
/*
* These routines are provided by libgcc to register/unregister
* frame info. Note these prototypes must generate weak references
* (even though the routines in libgcc have strong definitions).
* This is so that we can link with a libgcc that doesn't have these
* routines (e.g. one that uses sjlj exceptions).
*/
/*
* A few platforms (x86_64, s390) have read-only .eh_frame by default,
* so they must have it declared 'const'. These platforms will override
* __EH_FRAME_CONST (which is empty by default) in their CPP flags.
*/
#ifndef __EH_FRAME_CONST
#define __EH_FRAME_CONST
#endif
extern void __register_frame_info(__EH_FRAME_CONST void *,
struct dwarf2_eh_object *) __attribute__((weak));
extern void __deregister_frame_info(__EH_FRAME_CONST void *)
__attribute__((weak));
#endif /* __GNUC__ */

4
lib/csu/hppa/Makefile Normal file
View file

@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.3 2006/05/19 19:11:12 christos Exp $
CPPFLAGS+= -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

158
lib/csu/hppa/crt0.c Normal file
View file

@ -0,0 +1,158 @@
/* $NetBSD: crt0.c,v 1.7 2004/08/26 21:07:14 thorpej Exp $ */
/*
* Copyright (c) 2002 Matt Fredette
* Copyright (c) 1999 Klaus Klein
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
static void ___start(struct ps_strings *,
void (*cleanup)(void), const Obj_Entry *, int)
#ifdef __GNUC__
__attribute__((__used__))
#endif
;
__asm("\n"
" .text \n"
" .align 4 \n"
" .globl _start \n"
" .globl __start \n"
" .type _start,@function \n"
" .type __start,@function \n"
"_start: \n"
"__start: \n"
" .import _GLOBAL_OFFSET_TABLE_ \n"
"\n"
" bl L$lpc, %r27 \n"
" depi 0, 31, 2, %r27 \n"
"L$lpc: addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 8), %r27 \n"
" ldo R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 12)(%r1),%r27 \n"
" copy %r27, %r19 \n"
" b ___start \n"
" copy %r27, %arg3 \n");
static void
___start(struct ps_strings *ps_strings,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
int dp)
{
int argc;
char **argv;
int fini_plabel[2];
argc = ps_strings->ps_nargvstr;
argv = ps_strings->ps_argvstr;
environ = ps_strings->ps_envstr;
if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(__progname, '/')) == NULL)
__progname = argv[0];
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
/*
* XXX fredette - when not compiling PIC, you currently
* can't detect an undefined weak symbol by seeing if
* its address is NULL. The compiler emits code to find
* _DYNAMIC relative to %dp, the assembler notes the
* needed relocations, but when the linker sees that the
* (weak) symbol isn't defined it drops the ball - the
* relocations are never filled, and the binary ends up
* with code that sees an address of %dp plus zero,
* which != NULL.
*
* Arguably the linker could/should distinguish between
* code that is after a weak undefined symbol's contents
* from code that is after its address. In the first case,
* it would warn and/or bail. In the second case, it
* would fix up instructions to give a symbol address
* of NULL.
*
* For now, we take the easy way out and compare &_DYNAMIC
* to %dp, as well as to NULL.
*/
if (&_DYNAMIC != NULL && (int)&_DYNAMIC != dp)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
/*
* Since crt0.o, crtbegin.o, and crtend.o are always
* compiled PIC, they must have %r19 set correctly on
* entry to any function they contain. However, when
* a program is linked statically, the linker does
* not fill a PLABEL relocation with a pointer to a
* true PLABEL, it just fills it with the offset of the
* function. This shows the linker's assumption that
* when linking statically, *all* of the code has *not*
* been compiled PIC. I guess to assume otherwise
* would be a performance hit, as you would end up
* with unnecessary PLABELs for function pointers.
*
* But here, passing the address of the PIC _fini to
* atexit, we must make sure that we pass a PLABEL.
*/
fini_plabel[0] = (int)_fini;
if (fini_plabel[0] & 2)
/* _fini is already a PLABEL. */
atexit(_fini);
else {
fini_plabel[1] = dp;
atexit((void (*)(void))(((int)fini_plabel) | 2));
}
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.7 2004/08/26 21:07:14 thorpej Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

69
lib/csu/hppa/dot_init.h Normal file
View file

@ -0,0 +1,69 @@
/* $NetBSD: dot_init.h,v 1.8 2008/05/10 15:31:04 martin Exp $ */
/*-
* Copyright (c) 2004 Nick Hudson
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".section "#sect",\"ax\",@progbits \n"\
".global "#entry_pt" \n"\
".proc \n"\
".callinfo frame=64, calls, save_rp, save_sp, entry_gr=3\n"\
".entry \n"\
#entry_pt": \n"\
" stw %rp, -20(%sp) \n"\
" copy %r3, %r1 \n"\
" copy %sp, %r3 \n"\
" stw,ma %r1, 64(%sp) \n"\
" /* fall thru */ \n"\
".exit \n"\
".procend \n"\
".previous")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".section "#sect",\"ax\",@progbits \n"\
" ldw -20(%r3) ,%rp \n"\
" ldo 64(%r3), %sp \n"\
" ldw,mb -64(%sp), %r3 \n"\
" bv,n %r0(%rp) \n"\
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

View file

@ -1,29 +0,0 @@
.include <bsd.own.mk>
SRCS= crti.S crtn.S crtbegin.S crtend.S
OBJS= ${SRCS:N*.h:R:S/$/.o/g} gcrt1.o crt1.o Scrt1.o
realall: ${OBJS}
FILES=${OBJS}
FILESDIR=${LIBDIR}
CLEANFILES=${OBJS} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
gcrt1_c.o: crt1_c.c
${CC} ${CFLAGS} -DGCRT -c -o gcrt1_c.o ${.CURDIR}/crt1_c.c
gcrt1.o: gcrt1_c.o crt1_s.o
${LD} ${LDFLAGS} -o gcrt1.o -r crt1_s.o gcrt1_c.o
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.o: crt1_c.c
${CC} ${CFLAGS} -fPIC -DPIC -c -o Scrt1_c.o ${.CURDIR}/crt1_c.c
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 <bsd.prog.mk>

8
lib/csu/ia64/Makefile Normal file
View file

@ -0,0 +1,8 @@
# $NetBSD: Makefile,v 1.2 2006/09/14 23:55:54 cherry Exp $
ELFSIZE= 64
#Uncomment the next line to enable the new .init fallthru
CPPFLAGS+= -I- -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

97
lib/csu/ia64/crt0.c Normal file
View file

@ -0,0 +1,97 @@
/* $NetBSD: crt0.c,v 1.2 2006/09/15 05:29:44 skrll Exp $ */
/*
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
void __start(char **, void (*cleanup)(void), const Obj_Entry *,
struct ps_strings *);
void
__start(char **sp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
long argc;
char **argv, *namep;
__asm __volatile__ ("1: \
{ .mii \
mov r15=@gprel(1b) \n \
mov r16=ip ;; \n \
sub gp=r16,r15 \n \
;; \
} ");
argc = *(long *)sp;
argv = sp + 1;
environ = sp + 2 + argc; /* 2: argc + NULL ending argv */
if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(namep, '/')) == NULL)
__progname = namep;
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0 &&
ps_strings != (struct ps_strings *)0xbabefacedeadbeef) /* XXX: Debug: see machdep.c:setregs() */
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ)); /* XXX: ia64 ABI says 4 parameters. */
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.2 2006/09/15 05:29:44 skrll Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

74
lib/csu/ia64/dot_init.h Normal file
View file

@ -0,0 +1,74 @@
/* $NetBSD: dot_init.h,v 1.6 2009/11/09 14:34:42 skrll Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#include <machine/asm.h>
/*-
* $FreeBSD: src/lib/csu/ia64/crti.S,v 1.3 2001/11/03 06:31:27 peter Exp $
*/
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".section "#sect",\"ax\",@progbits \n" \
".proc "#entry_pt" \n" \
".global "#entry_pt" \n" \
#entry_pt": \n" \
".regstk 0,2,0,0 \n" \
".prologue 12,loc0 \n" \
".save ar.pfs,loc1 \n" \
"alloc loc1=ar.pfs,0,2,0,0 \n" \
"mov loc0=b0 /* Save return addr */ \n" \
".endp "#entry_pt" \n" \
".previous")
/*-
* $FreeBSD: src/lib/csu/ia64/crtn.S,v 1.2 2001/10/29 10:18:58 peter Exp $
*/
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".section "#sect",\"ax\",@progbits \n" \
".regstk 0,2,0,0 \n" \
"mov b0=loc0 /*Recover return addr*/ \n" \
"mov ar.pfs=loc1 \n" \
"br.ret.sptk.many b0 \n" \
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

View file

@ -0,0 +1,6 @@
# $NetBSD: Makefile,v 1.7 2006/05/19 19:11:12 christos Exp $
#Uncomment the next line to enable the new .init fallthru
CPPFLAGS+= -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

100
lib/csu/m68k_elf/crt0.c Normal file
View file

@ -0,0 +1,100 @@
/* $NetBSD: crt0.c,v 1.11 2004/08/26 21:09:52 thorpej Exp $ */
/*
* Copyright (c) 1999 Klaus Klein
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
void __start(int, char **, char **, void (*cleanup)(void),
const Obj_Entry *, struct ps_strings *);
__asm("\n"
" .text \n"
" .align 4 \n"
" .globl _start \n"
"_start: \n"
" movl (%sp),%d0 \n"
" movl %a2,-(%sp) | ps_strings \n"
" movl %a0,-(%sp) | obj \n"
" movl %a1,-(%sp) | cleanup \n"
" movl %d0,%d1 \n"
" lsll #2,%d1 \n"
" pea (16+4)(%sp,%d1.l) | envp = &argv[argc + 1] \n"
" pea 20(%sp) | argv \n"
" movl %d0,-(%sp) | argc \n"
" jsr __start");
void
__start(int argc, char **argv, char **envp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
environ = envp;
if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(__progname, '/')) == NULL)
__progname = argv[0];
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.11 2004/08/26 21:09:52 thorpej Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

View file

@ -0,0 +1,60 @@
/* $NetBSD: dot_init.h,v 1.6 2008/05/10 15:31:04 martin Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#include <machine/asm.h>
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".section "#sect",\"ax\",@progbits \n"\
".global "#entry_pt" \n"\
#entry_pt": \n"\
" .align 2 \n"\
" /* fall thru */ \n"\
".previous")
/* placement of the .align _after_ the label is intentional */
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".section "#sect",\"ax\",@progbits \n"\
" rts \n"\
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

6
lib/csu/mips/Makefile Normal file
View file

@ -0,0 +1,6 @@
# $NetBSD: Makefile,v 1.24 2006/05/19 19:11:12 christos Exp $
#Uncomment the next line to enable the new .init fallthru
CPPFLAGS+= -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

169
lib/csu/mips/crt0.c Normal file
View file

@ -0,0 +1,169 @@
/* $NetBSD: crt0.c,v 1.20 2009/12/14 01:04:02 matt Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
* All rights reserved.
*
* Modifications for NetBSD/mips:
*
* Jonathan Stone
* Jason R. Thorpe, Numerical Aerospace Simulation Facility,
* NASA Ames Research Center
*
* 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.
*/
#include "common.h"
/*
* C start-up. Assumes kernel (or ld.so) passes the
* following parameters to user-space in registers:
*
* a0 stack pointer (0 if setregs didn't fill this in)
* a1 cleanup
* a2 Obj_Entry
* a3 ps_strings
*
* XXX Does this violate the ABI?
* as well as the usual registers (pc, sp, and t9 == pc for ABI).
*/
void __start(u_long, void (*)(void), const Obj_Entry *,
struct ps_strings *);
__asm(".text; .align 4; .globl _start; _start:");
void
__start(u_long sp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
char **ksp;
char **argv, *namep;
int argc;
/*
* Grab the argc, argv, and envp set up by the kernel.
* Layout of stuff on the stack:
*
* [ high ]
* char kenvstr[1]; // size varies
* char kargstr[1]; // size varies
* char *argv[1]; // varies on argc
* int argc;
* [ low ] <--- kernel's SP points here
* .
* .
* .
* [ current stack pointer ]
*
* WARNING! There is an implicit sizeof(int) == sizeof(char *) here!
*/
#ifndef DYNAMIC
#ifdef _LP64
__asm volatile("dla $28,_gp");
#else
__asm volatile("la $28,_gp");
#endif
#endif
ksp = (char**)sp;
#if defined(__mips_n32) || defined(__mips_n64)
if (ksp == 0) {
/*
* Uh, oh. We're running on a old kernel that passed
* us zero in $a0-$a3. Try adjusting the current
* $sp for our own stack-frame size and see what
* we find.
* WARNING! The constants 56 and 64 below were determined
* by examining GCC assembler output of __start to find the
* frame size. If you change the code or compiler,
* you _will_ lose!
*/
#ifndef DYNAMIC
/* XXX 56 is compiler and stackframe dependent */
__asm volatile(" addiu %0,$29,56" : "=r" (ksp));
#else
/* XXX 64 is compiler and stackframe dependent */
__asm volatile(" addiu %0,$29,64" : "=r" (ksp));
#endif
}
#endif
argc = *(int *)ksp;
argv = ksp + 1;
environ = ksp + 2 + argc; /* 2: argc + NULL ending argv */
if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(namep, '/')) == NULL)
__progname = namep;
else
__progname++;
}
/*
* Deal with stuff that is only provided if setregs() did
* did the right thing.
*/
if (sp != 0) {
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
/*
* XXX Old MIPS ld.so didn't do any of this at all.
* XXX If we were loaded by that loader, just abort
* XXX the rtld setup.
*/
if (&_DYNAMIC != NULL && cleanup != NULL && obj != NULL)
_rtld_setup(cleanup, obj);
#endif
}
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* RCSid. Place after __start for programs that assume start of text
* is the entrypoint. (Only needed for old toolchains).
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.20 2009/12/14 01:04:02 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

137
lib/csu/mips/dot_init.h Normal file
View file

@ -0,0 +1,137 @@
/* $NetBSD: dot_init.h,v 1.10 2009/12/14 01:04:02 matt Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* Copyright (c) 2001 Simon Burge
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#define t9 "$25"
/*
* For O32/O64, allocate 8 "slots" for the stack frame. Store GP in the 4th
* (zero-based) slot (since this is where compiler generated code for fallthru
* processing expects it to be), and the RA in seventh (highest address).
*
* For N32/N64, allocate 4 8-byte "slots" for the stack frame. Store GP in the
* 2nd (zero-based) slot (since ...) and the RA in third (highest address).
*/
#ifdef __mips_o32
#define sPTR_ADDU "addu"
#define sREG_L "lw"
#define sREG_S "sw"
#define sRAOFF "28"
#define sFRAMESZ "32"
#define MD_GPRESTORE /* nothing */
#else
#define sPTR_ADDU "daddu"
#define sREG_L "ld"
#define sREG_S "sd"
#if defined(__mips_n32) || defined(__mips_n64)
#define MD_GPRESTORE "ld $gp,8($sp)" "\n\t"
#define sRAOFF "24"
#define sFRAMESZ "32"
#elif defined(__mips_o64)
#define sRAOFF "56"
#define sFRAMESZ "64"
#define MD_GPRESTORE /* nothing */
#endif
#endif
#ifdef __ABICALLS__
#if defined(__mips_o32) || defined(__mips_o64)
#define MD_FUNCTION_PROLOGUE(entry_pt) \
".set noreorder" "\n\t" \
".cpload "t9 "\n\t" \
".set reorder" "\n\t" \
sPTR_ADDU" $sp,$sp,-"sFRAMESZ "\n\t" \
".cprestore 16" "\n\t" \
sREG_S" $ra,"sRAOFF"($sp)" "\n\t"
#elif defined(__mips_n32) || defined(__mips_n64)
#define MD_FUNCTION_PROLOGUE(entry_pt) \
".set noreorder" "\n\t" \
"daddu $sp,$sp,-32" "\n\t" \
".cpsetup "t9", 8, "#entry_pt "\n\t" \
"sd $ra,24($sp)" "\n\t" \
".set reorder" "\n\t"
#else
#error ABI not supported (__ABICALLS)
#endif
#else
#if defined(__mips_o32) || defined(__mips_o64)
#define MD_FUNCTION_PROLOGUE(entry_pt) \
sPTR_ADDU" $sp,$sp,-"sFRAMESZ "\n\t" \
sREG_S" $ra,"sRAOFF"($sp)" "\n\t"
#elif defined(__mips_n32) || defined(__mips_n64)
/*
* On N32/N64, GP is callee-saved.
*/
#define MD_FUNCTION_PROLOGUE(entry_pt) \
"daddu $sp,$sp,-32" "\n\t" \
"sd $gp,8($sp)" "\n\t" \
"sd $ra,24($sp)" "\n\t"
#else
#error ABI not supported (!__ABICALLS)
#endif
#endif /* __ABICALLS */
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".section "#sect",\"ax\",@progbits" "\n\t" \
".align 2" "\n\t" \
".globl "#entry_pt "\n\t" \
#entry_pt":" "\n\t" \
MD_FUNCTION_PROLOGUE(entry_pt) \
" /* fall thru */" "\n\t" \
".previous")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".section "#sect",\"ax\",@progbits" "\n\t" \
sREG_L" $ra,"sRAOFF"($sp)" "\n\t" \
MD_GPRESTORE \
".set noreorder" "\n\t" \
"j $ra" "\n\t" \
sPTR_ADDU" $sp,$sp,"sFRAMESZ "\n\t" \
".set reorder" "\n\t" \
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

5
lib/csu/powerpc/Makefile Normal file
View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.13 2006/05/19 19:11:12 christos Exp $
CPPFLAGS+= -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

107
lib/csu/powerpc/crt0.c Normal file
View file

@ -0,0 +1,107 @@
/* $NetBSD: crt0.c,v 1.26 2006/05/18 17:54:19 christos Exp $ */
/*
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
/*
* Small Data Area designators. If not defined, will show up as being
* at address zero.
*/
extern int _SDA_BASE_[] __weak_reference(_SDA_BASE_);
extern int _SDA2_BASE_[] __weak_reference(_SDA2_BASE_);
/*
* First 5 arguments are specified by the PowerPC SVR4 ABI. The
* last argument, ps_strings, is a NetBSD extension.
*/
void _start(int, char **, char **, const Obj_Entry *,
void (*)(void), struct ps_strings *);
void
_start(int argc, char **argv, char **envp,
const Obj_Entry *obj, /* from shared loader */
void (*cleanup)(void), /* from shared loader */
struct ps_strings *ps_strings) /* NetBSD extension */
{
char *namep;
/*
* Initialize the Small Data Area registers.
* _SDA_BASE is defined in the SVR4 ABI for PPC.
* _SDA2_BASE is defined in the E[mbedded] ABI for PPC.
*/
__asm( "lis %r13,_SDA_BASE_@ha;"
"addi %r13,%r13,_SDA_BASE_@l;"
"lis %r2,_SDA2_BASE_@ha;"
"addi %r2,%r2,_SDA2_BASE_@l" );
if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(namep, '/')) == NULL)
__progname = namep;
else
__progname++;
}
environ = envp;
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.26 2006/05/18 17:54:19 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

View file

@ -0,0 +1,62 @@
/* $NetBSD: dot_init.h,v 1.7 2008/05/10 15:31:04 martin Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".section "#sect",\"ax\",@progbits \n" \
".global "#entry_pt" \n" \
#entry_pt": \n" \
" stwu %r1,-16(%r1) \n" \
" mflr %r0 \n" \
" stw %r0,12(%r1) \n" \
" /* fall thru */ \n" \
".previous")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".section "#sect",\"ax\",@progbits \n" \
" lwz %r0,12(%r1) \n" \
" mtlr %r0 \n" \
" la %r1,16(%r1) \n" \
" blr \n" \
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2006/06/30 22:49:50 ross Exp $
CPPFLAGS+= -I- -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

99
lib/csu/powerpc64/crt0.c Normal file
View file

@ -0,0 +1,99 @@
/* $NetBSD: crt0.c,v 1.2 2006/07/01 01:39:17 ross Exp $ */
/*
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
/*
* Small Data Area designators. If not defined, will show up as being
* at address zero.
*/
extern int _SDA_BASE_[];
__weak_extern(_SDA_BASE_);
extern int _SDA2_BASE_[];
__weak_extern(_SDA2_BASE_);
/*
* First 5 arguments are specified by the PowerPC SVR4 ABI. The
* last argument, ps_strings, is a NetBSD extension.
*/
void _start(int, char **, char **, const Obj_Entry *,
void (*)(void), struct ps_strings *);
void
_start(int argc, char **argv, char **envp,
const Obj_Entry *obj, /* from shared loader */
void (*cleanup)(void), /* from shared loader */
struct ps_strings *ps_strings) /* NetBSD extension */
{
char *namep;
if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(namep, '/')) == NULL)
__progname = namep;
else
__progname++;
}
environ = envp;
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.2 2006/07/01 01:39:17 ross Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

View file

@ -0,0 +1,69 @@
/* $NetBSD: dot_init.h,v 1.7 2008/05/10 15:31:04 martin Exp $ */
/*-
* Copyright (c) 2001, 2006 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".globl " #entry_pt " \n" \
".globl ." #entry_pt " \n" \
".pushsection \".opd\",\"aw\" \n" \
".align 3 \n" \
#entry_pt": .quad ." #entry_pt ",.TOC.@tocbase,0\n" \
".size " #entry_pt ",24 \n" \
".type " #entry_pt ",@function \n" \
".pushsection "#sect",\"ax\",@progbits \n" \
"." #entry_pt": \n" \
" stdu %r1,-48(%r1) \n" \
" mflr %r0 \n" \
" std %r0,16(%r1) \n" \
" /* fall thru */ \n" \
".popsection \n" \
".popsection")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".pushsection "#sect",\"ax\",@progbits \n" \
" ld %r0,16(%r1) \n" \
" mtlr %r0 \n" \
" la %r1,48(%r1) \n" \
" blr \n" \
".popsection")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

5
lib/csu/sh3_elf/Makefile Normal file
View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.3 2006/05/19 19:11:12 christos Exp $
CPPFLAGS+= -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

94
lib/csu/sh3_elf/crt0.c Normal file
View file

@ -0,0 +1,94 @@
/* $NetBSD: crt0.c,v 1.10 2004/08/26 21:16:41 thorpej Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
void ___start(int, char **, char **, void (*cleanup)(void),
const Obj_Entry *, struct ps_strings *);
__asm( " .text \n"
" .align 2 \n"
" .globl _start \n"
" .globl __start \n"
"_start: \n"
"__start: \n"
" mov.l r9,@-r15 \n"
" bra ___start \n"
" mov.l r8,@-r15");
void
___start(int argc, char **argv, char **envp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
environ = envp;
if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(__progname, '/')) == NULL)
__progname = argv[0];
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.10 2004/08/26 21:16:41 thorpej Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

View file

@ -0,0 +1,91 @@
/* $NetBSD: dot_init.h,v 1.7 2008/05/10 15:31:04 martin Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
/*
* Don't use C versions of _init/_fini, they have become just a
* rudimentary indirection to the entry points we would supply with
* MD_SECTION_PROLOGUE.
*/
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)
#define MD_ASM_IN_SECTION(section, content) \
__asm( \
".section " #section ",\"ax\",@progbits\n" \
content "\n" \
".previous")
/*
* Declare the entry point global.
*/
#define MD_SECTION_PROLOGUE(section, entry_pt) \
MD_ASM_IN_SECTION(section, \
" .global "_C_LABEL_STRING(#entry_pt)" \n" \
" .type "_C_LABEL_STRING(#entry_pt)",@function\n" \
_C_LABEL_STRING(#entry_pt)": \n" \
" mov.l r14, @-sp \n" \
" sts.l pr, @-sp \n" \
" mov sp, r14 \n" \
" .p2align 2")
/*
* NOTE 1: Supply the semicolon here because crtbegin.c doesn't.
* NOTE 2: We don't use our crtbegin.c for gcc3 and later,
* we use gcc crtstuff.c via src/gnu/lib/crtstuff*
*/
#define MD_CALL_STATIC_FUNCTION(section, func) \
MD_ASM_IN_SECTION(section, \
" mov.l 1f, r1 \n" \
" mova 2f, r0 \n" \
"0: braf r1 \n" \
" lds r0, pr \n" \
\
" .p2align 2 \n" \
"1: .long "_C_LABEL_STRING(#func)" - (0b+4) \n" \
"2: ");
#define MD_SECTION_EPILOGUE(section) \
MD_ASM_IN_SECTION(section, \
" mov r14, sp \n" \
" lds.l @sp+, pr \n" \
" rts \n" \
" mov.l @sp+, r14")

8
lib/csu/sparc64/Makefile Normal file
View file

@ -0,0 +1,8 @@
# $NetBSD: Makefile,v 1.6 2006/05/19 19:11:12 christos Exp $
#Uncomment the next line to enable the new .init fallthru
CPPFLAGS+= -I${.CURDIR}/../sparc_elf
ELFSIZE=64
.include "${.CURDIR}/../common_elf/Makefile.inc"

119
lib/csu/sparc64/crt0.c Normal file
View file

@ -0,0 +1,119 @@
/* $NetBSD: crt0.c,v 1.24 2005/12/24 21:38:40 perry Exp $ */
/*
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
/*
* __start needs to gather up argc, argv, env_p, ps_strings, the termination
* routine passed in %g1 and call ___start to finish up the startup processing.
*
* NB: We are violating the ELF spec by passing a pointer to the ps strings in
* %g1 instead of a termination routine.
*/
__asm("\n\
.data\n\
__data_start: ! Start of data section\n\
.text\n\
.align 4\n\
.global _start\n\
.global __start\n\
.register %g3,#scratch\n\
.register %g2,#scratch\n\
_start:\n\
__start:\n\
setx __data_start, %o0, %g4 ! Point %g4 to start of data section\n\
clr %g4 ! egcs thinks this is zero. XXX\n\
clr %fp\n\
add %sp, 8*16 + 0x7ff, %o0 ! start of stack\n\
mov %g1, %o1 ! Cleanup routine\n\
mov %g3, %o1 ! XXXX our rtld uses %g3\n\
mov %g2, %o2 ! XXXX obj from rtld.\n\
ba,pt %icc, ___start ! XXXX jump over the retl egcs 2.96 inserts\n\
mov %g1, %o3 ! ps_strings XXXX\n\
");
void ___start(char **, void (*cleanup)(void), const Obj_Entry *,
struct ps_strings *);
void
___start(char **sp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
long argc;
char **argv, *namep;
argc = *(long *)sp;
argv = sp + 1;
environ = sp + 2 + argc; /* 2: argc + NULL ending argv */
if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(namep, '/')) == NULL)
__progname = namep;
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0 &&
ps_strings != (struct ps_strings *)0xbabefacedeadbeef)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ _start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.24 2005/12/24 21:38:40 perry Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

View file

@ -0,0 +1,6 @@
# $NetBSD: Makefile,v 1.6 2006/05/19 19:11:12 christos Exp $
#Uncomment the next line to enable the new .init fallthru
CPPFLAGS+= -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

104
lib/csu/sparc_elf/crt0.c Normal file
View file

@ -0,0 +1,104 @@
/* $NetBSD: crt0.c,v 1.12 2004/08/26 21:18:36 thorpej Exp $ */
/*
* Copyright (c) 1998 Christos Zoulas
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
void ___start(int, char **, char **, void (*cleanup)(void),
const Obj_Entry *, struct ps_strings *);
__asm(" .text\n\
.align 4\n\
.global __start\n\
.global _start\n\
__start:\n\
_start:\n\
mov 0, %fp\n\
ld [%sp + 64], %o0 ! get argc\n\
add %sp, 68, %o1 ! get argv\n\
sll %o0, 2, %o2 !\n\
add %o2, 4, %o2 ! envp = argv + (argc << 2) + 4\n\
add %o1, %o2, %o2 !\n\
andn %sp, 7, %sp ! align\n\
sub %sp, 24, %sp ! expand to standard stack frame size\n\
mov %g3, %o3\n\
mov %g2, %o4\n\
call ___start\n\
mov %g1, %o5\n\
");
void
___start(int argc, char **argv, char **envp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
environ = envp;
if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(__progname, '/')) == NULL)
__progname = argv[0];
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.12 2004/08/26 21:18:36 thorpej Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

View file

@ -0,0 +1,92 @@
/* $NetBSD: dot_init.h,v 1.9 2008/05/29 14:51:25 mrg Exp $ */
/*
* Copyright (c) 2001 Matthew R. Green
* 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.
*/
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#ifdef __sparc64__
#define SAVE " save %sp, -176, %sp \n"
#else
#define SAVE " save %sp, -96, %sp \n"
#endif
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
".section "#sect",\"ax\",@progbits \n"\
" .align 4 \n"\
".global "#entry_pt" \n"\
#entry_pt": \n"\
SAVE \
" /* fall thru */ \n"\
".previous")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
".section "#sect",\"ax\",@progbits \n"\
" .align 4 \n"\
" ret \n"\
" restore \n"\
".previous")
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

4
lib/csu/vax_elf/Makefile Normal file
View file

@ -0,0 +1,4 @@
# $NetBSD: Makefile,v 1.3 2006/05/19 19:11:12 christos Exp $
CPPFLAGS+= -I${.CURDIR}
.include "${.CURDIR}/../common_elf/Makefile.inc"

101
lib/csu/vax_elf/crt0.c Normal file
View file

@ -0,0 +1,101 @@
/* $NetBSD: crt0.c,v 1.10 2004/08/26 21:24:09 thorpej Exp $ */
/*
* Copyright (c) 1999 Matt Thomas
* 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
* 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.
*
* <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
*/
#include "common.h"
void ___start(int, char **, char **, void (*cleanup)(void),
const Obj_Entry *, struct ps_strings *);
__asm(" .text;"
" .align 2;"
" .globl _start;"
" .globl __start;"
"__start:;"
"_start:;"
" .word 0x0101;"
" pushl %r9;" /* ps_strings */
" pushl %r8;" /* obj */
" pushl %r7;" /* cleanup */
" movl (%r6),%r0;" /* argc */
" pushal 8(%r6)[%r0];" /* envp = &argv[argc + 1] */
" pushal 4(%r6);" /* argv */
" pushl %r0;" /* argc */
" calls $6,___start;"
);
void
___start(int argc, char **argv, char **envp,
void (*cleanup)(void), /* from shared loader */
const Obj_Entry *obj, /* from shared loader */
struct ps_strings *ps_strings)
{
environ = envp;
if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */
if ((__progname = _strrchr(__progname, '/')) == NULL)
__progname = argv[0];
else
__progname++;
}
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
#ifdef DYNAMIC
if (&_DYNAMIC != NULL)
_rtld_setup(cleanup, obj);
#endif
#ifdef MCRT0
atexit(_mcleanup);
monstartup((u_long)&_eprol, (u_long)&_etext);
#endif
atexit(_fini);
_init();
exit(main(argc, argv, environ));
}
/*
* NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
*/
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: crt0.c,v 1.10 2004/08/26 21:24:09 thorpej Exp $");
#endif /* LIBC_SCCS and not lint */
#include "common.c"

View file

@ -0,0 +1,66 @@
/* $NetBSD: dot_init.h,v 1.7 2008/05/10 15:31:04 martin Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h> /* RCS ID & Copyright macro defns */
#include <machine/asm.h>
#define MD_SECTION_PROLOGUE(sect, entry_pt) \
__asm ( \
" .section "#sect",\"ax\",@progbits\n" \
" .globl " #entry_pt "\n" \
" .type " #entry_pt "@function\n" \
" .align 1\n" \
#entry_pt":\n" \
" .word 0\n" \
/* fall thru */ \
" .previous")
#define MD_SECTION_EPILOGUE(sect) \
__asm ( \
" .section "#sect",\"ax\",@progbits\n" \
" ret\n" \
" .previous")
#define MD_CALL_STATIC_FUNCTION(sect, func) \
__asm ( \
" .section "#sect",\"ax\",@progbits\n" \
" calls $0,"#func"\n" \
" .previous");
#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, _init)
#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, _fini)
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)

View file

@ -168,17 +168,15 @@ static LIST_HEAD(, _ns_drec) _ns_drec = LIST_HEAD_INITIALIZER(&_ns_drec);
static mutex_t _ns_drec_lock = MUTEX_INITIALIZER;
#endif /* _REENTRANT */
/*
* Runtime determination of whether we are dynamically linked or not.
*/
#ifdef __ELF__
extern int _DYNAMIC __weak_reference(_DYNAMIC);
#define is_dynamic() (&_DYNAMIC != NULL)
#else
#ifndef __ELF__
#define is_dynamic() (0) /* don't bother - switch to ELF! */
#endif /* __ELF__ */
#elif __GNUC_PREREQ__(4,2)
static int rtld_DYNAMIC __attribute__((__weakref__, __alias__("_DYNAMIC")));
#define is_dynamic() (&rtld_DYNAMIC != NULL)
#else
extern int _DYNAMIC __weak_reference(_DYNAMIC);
#define is_dynamic() (&_DYNAMIC != NULL)
#endif
/*
* size of dynamic array chunk for _nsmap and _nsmap[x].srclist (and other

133
libexec/ld.elf_so/Makefile Normal file
View file

@ -0,0 +1,133 @@
# $NetBSD: Makefile,v 1.102 2011/01/16 02:36:05 matt Exp $
#
# NOTE: when changing ld.so, ensure that ldd still compiles.
#
WARNS?=4
# This needs to be before bsd.init.mk
.if defined(BSD_MK_COMPAT_FILE)
.include <${BSD_MK_COMPAT_FILE}>
.endif
# We are not building this with PIE
PIE_CFLAGS=
PIE_LDFLAGS=
.include <bsd.init.mk> # for MKPIC definition
.include <bsd.shlib.mk> # for SHLINKINSTALLDIR definition
.if defined(LDELFSO_MACHINE_CPU) && !empty(LDELFSO_MACHINE_CPU) && \
exists(${.CURDIR}/arch/${LDELFSO_MACHINE_CPU})
ARCHSUBDIR= ${LDELFSO_MACHINE_CPU}
.else
ARCHSUBDIR= ${MACHINE_CPU}
.endif
M= ${.CURDIR}/arch/${ARCHSUBDIR}
.if ((${MACHINE_ARCH} == "alpha") || \
(${MACHINE_CPU} == "arm") || \
(${MACHINE_ARCH} == "hppa") || \
(${MACHINE_ARCH} == "i386") || \
(${MACHINE_ARCH} == "m68k") || \
(${MACHINE_CPU} == "mips") || \
(${MACHINE_ARCH} == "powerpc") || \
(${MACHINE_CPU} == "sh3") || \
(${MACHINE_ARCH} == "sparc") || \
(${MACHINE_ARCH} == "sparc64") || \
(${MACHINE_ARCH} == "x86_64") || \
(${MACHINE_ARCH} == "vax")) && \
${MKPIC} != "no"
LDFLAGS+= -shared -symbolic -nostartfiles
LDFLAGS+= -Wl,-static
LDFLAGS+= -Wl,--warn-shared-textrel
CFLAGS+= -fvisibility=hidden
# Adds SRCS, CPPFLAGS, LDFLAGS, etc. Must go first so MD startup source
# is first.
.if exists($M/Makefile.inc)
.include "$M/Makefile.inc"
.endif
# Support compat ld.elf_so.
.if defined(MLIBDIR)
PROG= ld.elf_so-${MLIBDIR}
CPPFLAGS+= -DRTLD_ARCH_SUBDIR=\"${MLIBDIR}\"
.else
PROG= ld.elf_so
.endif
CLIBOBJ!= cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
SRCS+= rtld.c reloc.c symbol.c xmalloc.c xprintf.c debug.c \
map_object.c load.c search.c headers.c paths.c expand.c
.if ${USE_FORT} == "yes"
.PATH.c: ${NETBSDSRCDIR}/lib/libc/misc
SRCS+= stack_protector.c
.endif
.PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib
SRCS+= exit.c
errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h
${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \
mv -f ${.TARGET}.tmp ${.TARGET}
xprintf.c: errlist_concat.h
CLEANFILES+= errlist_concat.h
BINDIR= ${SHLINKINSTALLDIR}
CPPFLAGS+= -DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
CPPFLAGS+= -I${.CURDIR} -I.
CPPFLAGS+= -DRTLD_LOADER
CPPFLAGS+= -D_RTLD_SOURCE
CPPFLAGS+= -DCOMBRELOC
#CPPFLAGS+= -DDEBUG
#CPPFLAGS+= -DRTLD_DEBUG
#CPPFLAGS+= -DRTLD_DEBUG_RELOC
#DBG= -g
DBG= -O3 -fomit-frame-pointer
.if ${SHLIBDIR} != ${LIBDIR}
CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
.endif
# rtld.c and symbol.c use alloca, so disable SSP warnings.
COPTS.rtld.c+= -Wno-stack-protector
COPTS.symbol.c+=-Wno-stack-protector
LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
.if ${MKPICLIB} != "no"
LDADD+= -lc_pic
.if ${MKPICINSTALL} != "no"
DPADD+= ${LIBC_PIC}
.endif
DPADD+= ${CLIBOBJ}/libc_pic.a
.else
LDADD+= -lc
DPADD+= ${CLIBOBJ}/libc.a
.endif
STRIPFLAG=
.PATH: $M
${PROG}: ${OBJS} ${DPADD}
${_MKMSG_LINK} ${PROG}
${CC} ${LDFLAGS} -o ${PROG} ${OBJS} ${LDADD}
.if ${SHLINKINSTALLDIR} != "/usr/libexec"
SYMLINKS+= ${SHLINKINSTALLDIR}/${PROG} /usr/libexec/${PROG}
.endif
.include <bsd.prog.mk>
.else
MAN= ld.elf_so.1
.include <bsd.man.mk>
.endif

6
libexec/ld.elf_so/README Normal file
View file

@ -0,0 +1,6 @@
$NetBSD: README,v 1.11 2006/11/24 22:52:16 wiz Exp $
TO DO:
* Support for coexistence of 32-bit and 64-bit ELF on platforms that can
do that.

33
libexec/ld.elf_so/TODO Normal file
View file

@ -0,0 +1,33 @@
rtld:
* resolve MIPS binding lossage
binutils/gcc:
* alpha: why are there GLOB_DAT relocs in ld.elf_so?
* alpha: bogus textrels in rtti info
* mips: why are there global GOT relocs in ld.elf_so?
* mips: bogus textrels in .rel.dyn
* powerpc: make sure the .got section is always executable
* powerpc: fix ld scripts so that .rodata is still used for PIC
machine-specific:
* #ifdefs:
headers.c:#ifndef __mips__
headers.c:#ifdef __mips__
reloc.c:#if defined(__hppa__)
rtld.c:#if !defined(__hppa__)
rtld.c:#if !defined(__mips__) && !defined(__hppa__)
rtld.c:#if !defined(__arm__) && !defined(__mips__) && !defined(__sh__)
rtld.c:#ifdef __mips__
rtld.h:#ifdef __mips__
symbol.c:#ifndef __mips__
issues to research:
* sh, x86_64 have different absolute and GLOB_DAT relocs; nothing else does
* sh, vax, x86_64 use addend on PLT; nothing else does
rela: alpha hppa m68k powerpc sh sparc sparc64 vax x86_64
rel: arm i386 mips
- mycroft
2003/09/24

View file

@ -0,0 +1,11 @@
# $NetBSD: Makefile.inc,v 1.12 2005/06/04 16:17:17 lukem Exp $
SRCS+= rtld_start.S alpha_reloc.c
# XXX Should not be in CPPFLAGS!
CPPFLAGS+= -fpic -mno-fp-regs
CPPFLAGS+= -DELFSIZE=64
#CPPFLAGS+= -DRTLD_DEBUG_ALPHA
LDFLAGS+= -Wl,-e,_rtld_start

View file

@ -0,0 +1,503 @@
/* $NetBSD: alpha_reloc.c,v 1.38 2010/09/30 09:11:18 skrll Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
*
* 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 NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
* 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.
*/
/*
* Copyright 1996, 1997, 1998, 1999 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: alpha_reloc.c,v 1.38 2010/09/30 09:11:18 skrll Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <string.h>
#include "rtld.h"
#include "debug.h"
#ifdef RTLD_DEBUG_ALPHA
#define adbg(x) xprintf x
#else
#define adbg(x) /* nothing */
#endif
void _rtld_bind_start(void);
void _rtld_bind_start_old(void);
void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
caddr_t _rtld_bind(const Obj_Entry *, Elf_Addr);
static inline int _rtld_relocate_plt_object(const Obj_Entry *,
const Elf_Rela *, Elf_Addr *);
void
_rtld_setup_pltgot(const Obj_Entry *obj)
{
uint32_t word0;
/*
* The PLTGOT on the Alpha looks like this:
*
* PLT HEADER
* .
* . 32 bytes
* .
* PLT ENTRY #0
* .
* . 12 bytes
* .
* PLT ENTRY #1
* .
* . 12 bytes
* .
* etc.
*
* The old-format entries look like (displacements filled in
* by the linker):
*
* ldah $28, 0($31) # 0x279f0000
* lda $28, 0($28) # 0x239c0000
* br $31, plt0 # 0xc3e00000
*
* The new-format entries look like:
*
* br $28, plt0 # 0xc3800000
* # 0x00000000
* # 0x00000000
*
* What we do is fetch the first PLT entry and check to
* see the first word of it matches the first word of the
* old format. If so, we use a binding routine that can
* handle the old format, otherwise we use a binding routine
* that handles the new format.
*
* Note that this is done on a per-object basis, we can mix
* and match shared objects build with both the old and new
* linker.
*/
word0 = *(uint32_t *)(((char *) obj->pltgot) + 32);
if ((word0 & 0xffff0000) == 0x279f0000) {
/* Old PLT entry format. */
adbg(("ALPHA: object %p has old PLT format\n", obj));
obj->pltgot[2] = (Elf_Addr) &_rtld_bind_start_old;
obj->pltgot[3] = (Elf_Addr) obj;
} else {
/* New PLT entry format. */
adbg(("ALPHA: object %p has new PLT format\n", obj));
obj->pltgot[2] = (Elf_Addr) &_rtld_bind_start;
obj->pltgot[3] = (Elf_Addr) obj;
}
__asm volatile("imb");
}
/*
* It is possible for the compiler to emit relocations for unaligned data.
* We handle this situation with these inlines.
*/
#define RELOC_ALIGNED_P(x) \
(((uintptr_t)(x) & (sizeof(void *) - 1)) == 0)
static inline Elf_Addr
load_ptr(void *where)
{
Elf_Addr res;
memcpy(&res, where, sizeof(res));
return (res);
}
static inline void
store_ptr(void *where, Elf_Addr val)
{
memcpy(where, &val, sizeof(val));
}
void
_rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
{
const Elf_Rela *rela = 0, *relalim;
Elf_Addr relasz = 0;
Elf_Addr *where;
for (; dynp->d_tag != DT_NULL; dynp++) {
switch (dynp->d_tag) {
case DT_RELA:
rela = (const Elf_Rela *)(relocbase + dynp->d_un.d_ptr);
break;
case DT_RELASZ:
relasz = dynp->d_un.d_val;
break;
}
}
relalim = (const Elf_Rela *)((const uint8_t *)rela + relasz);
for (; rela < relalim; rela++) {
where = (Elf_Addr *)(relocbase + rela->r_offset);
/* XXX For some reason I see a few GLOB_DAT relocs here. */
*where += (Elf_Addr)relocbase;
}
}
int
_rtld_relocate_nonplt_objects(Obj_Entry *obj)
{
const Elf_Rela *rela;
Elf_Addr target = -1;
for (rela = obj->rela; rela < obj->relalim; rela++) {
Elf_Addr *where;
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf_Addr tmp;
unsigned long symnum;
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
symnum = ELF_R_SYM(rela->r_info);
switch (ELF_R_TYPE(rela->r_info)) {
case R_TYPE(NONE):
break;
case R_TYPE(REFQUAD):
case R_TYPE(GLOB_DAT):
def = _rtld_find_symdef(symnum, obj, &defobj, false);
if (def == NULL)
return -1;
target = (Elf_Addr)(defobj->relocbase +
def->st_value);
tmp = target + rela->r_addend;
if (__predict_true(RELOC_ALIGNED_P(where))) {
if (*where != tmp)
*where = tmp;
} else {
if (load_ptr(where) != tmp)
store_ptr(where, tmp);
}
rdbg(("REFQUAD/GLOB_DAT %s in %s --> %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)tmp, defobj->path));
break;
case R_TYPE(RELATIVE):
if (__predict_true(RELOC_ALIGNED_P(where)))
*where += (Elf_Addr)obj->relocbase;
else
store_ptr(where,
load_ptr(where) + (Elf_Addr)obj->relocbase);
rdbg(("RELATIVE in %s --> %p", obj->path,
(void *)*where));
break;
case R_TYPE(COPY):
/*
* These are deferred until all other relocations have
* been done. All we do here is make sure that the
* COPY relocation is not in a shared library. They
* are allowed only in executable files.
*/
if (obj->isdynamic) {
_rtld_error(
"%s: Unexpected R_COPY relocation in shared library",
obj->path);
return -1;
}
rdbg(("COPY (avoid in main)"));
break;
default:
rdbg(("sym = %lu, type = %lu, offset = %p, "
"addend = %p, contents = %p, symbol = %s",
symnum, (u_long)ELF_R_TYPE(rela->r_info),
(void *)rela->r_offset, (void *)rela->r_addend,
(void *)load_ptr(where),
obj->strtab + obj->symtab[symnum].st_name));
_rtld_error("%s: Unsupported relocation type %ld "
"in non-PLT relocations",
obj->path, (u_long) ELF_R_TYPE(rela->r_info));
return -1;
}
}
return 0;
}
int
_rtld_relocate_plt_lazy(const Obj_Entry *obj)
{
const Elf_Rela *rela;
if (!obj->relocbase)
return 0;
for (rela = obj->pltrela; rela < obj->pltrelalim; rela++) {
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
assert(ELF_R_TYPE(rela->r_info) == R_TYPE(JMP_SLOT));
/* Just relocate the GOT slots pointing into the PLT */
*where += (Elf_Addr)obj->relocbase;
rdbg(("fixup !main in %s --> %p", obj->path, (void *)*where));
}
return 0;
}
static inline int
_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rela *rela,
Elf_Addr *tp)
{
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
Elf_Addr new_value;
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf_Addr stubaddr;
unsigned long info = rela->r_info;
assert(ELF_R_TYPE(info) == R_TYPE(JMP_SLOT));
def = _rtld_find_plt_symdef(ELF_R_SYM(info), obj, &defobj, tp != NULL);
if (__predict_false(def == NULL))
return -1;
if (__predict_false(def == &_rtld_sym_zero))
return 0;
new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
rdbg(("bind now/fixup in %s --> old=%p new=%p",
defobj->strtab + def->st_name, (void *)*where, (void *)new_value));
if ((stubaddr = *where) != new_value) {
int64_t delta, idisp;
uint32_t insn[3], *stubptr;
int insncnt;
Elf_Addr pc;
/* Point this GOT entry at the target. */
*where = new_value;
/*
* Alpha shared objects may have multiple GOTs, each
* of which may point to this entry in the PLT. But,
* we only have a reference to the first GOT entry which
* points to this PLT entry. In order to avoid having to
* re-bind this call every time a non-first GOT entry is
* used, we will attempt to patch up the PLT entry to
* reference the target, rather than the binder.
*
* When the PLT stub gets control, PV contains the address
* of the PLT entry. Each PLT entry has room for 3 insns.
* If the displacement of the target from PV fits in a signed
* 32-bit integer, we can simply add it to PV. Otherwise,
* we must load the GOT entry itself into PV.
*
* Note if the shared object uses the old PLT format, then
* we cannot patch up the PLT safely, and so we skip it
* in that case[*].
*
* [*] Actually, if we're not doing lazy-binding, then
* we *can* (and do) patch up this PLT entry; the PLTGOT
* thunk won't yet point to any binder entry point, and
* so this test will fail as it would for the new PLT
* entry format.
*/
if (obj->pltgot[2] == (Elf_Addr) &_rtld_bind_start_old) {
rdbg((" old PLT format"));
goto out;
}
delta = new_value - stubaddr;
rdbg((" stubaddr=%p, where-stubaddr=%ld, delta=%ld",
(void *)stubaddr, (long)where - (long)stubaddr,
(long)delta));
insncnt = 0;
if ((int32_t)delta == delta) {
/*
* We can adjust PV with an LDA, LDAH sequence.
*
* First, build an LDA insn to adjust the low 16
* bits.
*/
insn[insncnt++] = 0x08 << 26 | 27 << 21 | 27 << 16 |
(delta & 0xffff);
rdbg((" LDA $27,%d($27)", (int16_t)delta));
/*
* Adjust the delta to account for the effects of
* the LDA, including sign-extension.
*/
delta -= (int16_t)delta;
if (delta != 0) {
/*
* Build an LDAH instruction to adjust the
* high 16 bits.
*/
insn[insncnt++] = 0x09 << 26 | 27 << 21 |
27 << 16 | ((delta >> 16) & 0xffff);
rdbg((" LDAH $27,%d($27)",
(int16_t)(delta >> 16)));
}
} else {
int64_t dhigh;
/* We must load the GOT entry. */
delta = (Elf_Addr)where - stubaddr;
/*
* If the GOT entry is too far away from the PLT
* entry, then we can't patch up the PLT entry.
* This PLT entry will have to be bound for each
* GOT entry except for the first one. This program
* will still run, albeit very slowly. It is very
* unlikely that this case will ever happen in
* practice.
*/
if ((int32_t)delta != delta) {
rdbg((" PLT stub too far from GOT to relocate"));
goto out;
}
dhigh = delta - (int16_t)delta;
if (dhigh != 0) {
/*
* Build an LDAH instruction to adjust the
* high 16 bits.
*/
insn[insncnt++] = 0x09 << 26 | 27 << 21 |
27 << 16 | ((dhigh >> 16) & 0xffff);
rdbg((" LDAH $27,%d($27)",
(int16_t)(dhigh >> 16)));
}
/* Build an LDQ to load the GOT entry. */
insn[insncnt++] = 0x29 << 26 | 27 << 21 |
27 << 16 | (delta & 0xffff);
rdbg((" LDQ $27,%d($27)",
(int16_t)delta));
}
/*
* Now, build a JMP or BR insn to jump to the target. If
* the displacement fits in a sign-extended 21-bit field,
* we can use the more efficient BR insn. Otherwise, we
* have to jump indirect through PV.
*/
pc = stubaddr + (4 * (insncnt + 1));
idisp = (int64_t)(new_value - pc) >> 2;
if (-0x100000 <= idisp && idisp < 0x100000) {
insn[insncnt++] = 0x30 << 26 | 31 << 21 |
(idisp & 0x1fffff);
rdbg((" BR $31,%p", (void *)new_value));
} else {
insn[insncnt++] = 0x1a << 26 | 31 << 21 |
27 << 16 | (idisp & 0x3fff);
rdbg((" JMP $31,($27),%d",
(int)(idisp & 0x3fff)));
}
/*
* Fill in the tail of the PLT entry first, for reentrancy.
* Until we have overwritten the first insn (an unconditional
* branch), the remaining insns have no effect.
*/
stubptr = (uint32_t *)stubaddr;
while (insncnt > 1) {
insncnt--;
stubptr[insncnt] = insn[insncnt];
}
/*
* Commit the tail of the insn sequence to memory
* before overwriting the first insn.
*/
__asm volatile("wmb" ::: "memory");
stubptr[0] = insn[0];
/*
* I-stream will be sync'd when we either return from
* the binder (lazy bind case) or when the PLTGOT thunk
* is patched up (bind-now case).
*/
}
out:
if (tp)
*tp = new_value;
return 0;
}
caddr_t
_rtld_bind(const Obj_Entry *obj, Elf_Addr reloff)
{
const Elf_Rela *rela =
(const Elf_Rela *)((const uint8_t *)obj->pltrela + reloff);
Elf_Addr result = 0; /* XXX gcc */
int err;
err = _rtld_relocate_plt_object(obj, rela, &result);
if (err)
_rtld_die();
return (caddr_t)result;
}
int
_rtld_relocate_plt_objects(const Obj_Entry *obj)
{
const Elf_Rela *rela;
for (rela = obj->pltrela; rela < obj->pltrelalim; rela++)
if (_rtld_relocate_plt_object(obj, rela, NULL) < 0)
return -1;
return 0;
}

View file

@ -0,0 +1,194 @@
/* $NetBSD: rtld_start.S,v 1.16 2004/02/18 23:04:49 enami Exp $ */
/*
* Copyright 1996 Matt Thomas <matt@3am-software.com>
* Portions copyright 2002 Charles M. Hannum <root@ihack.net>
* 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 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 <machine/asm.h>
/*
* Note: we can call ourselves LEAF even though we use callee-saved
* registers because we're the root of the call graph.
*/
LEAF_NOPROFILE(_rtld_start, 0)
.set noreorder
br pv, 1f
1: LDGP(pv)
/*
* Relocate ourself.
*/
br s2, 2f /* get our PC */
2: ldiq s3, 2b /* get where the linker thought we were */
subq s2, s3, a1 /* relocbase */
lda t5, _DYNAMIC
addq a1, t5, a0 /* &_DYNAMIC */
/* Squirrel away ps_strings. */
mov a3, s0
bsr ra, _rtld_relocate_nonplt_self
LDGP(ra)
/*
* Allocate space on the stack for the cleanup and obj_main
* entries that _rtld() will provide for us.
*/
lda sp, -16(sp)
subq s2, s3, a1 /* relocbase */
mov sp, a0 /* sp */
CALL(_rtld) /* v0 = _rtld(sp, relocbase); */
ldq a1, 0(sp) /* cleanup */
ldq a2, 8(sp) /* obj_main */
lda sp, 16(sp) /* pop stack */
mov sp, a0 /* stack pointer */
mov s0, a3 /* ps_strings */
mov v0, pv /* set up PV for entry point */
jsr ra, (v0), 0 /* (*_start)(sp, cleanup, obj, ps_strings); */
ldgp gp, 0(ra)
CALL(exit)
halt
END(_rtld_start)
#define RTLD_BIND_START_PROLOGUE \
/* at_reg already used by PLT code. */ \
.set noat ; \
\
/* \
* Allocate stack frame and preserve all registers that the \
* caller would have normally saved themselves. \
*/ \
lda sp, -168(sp) ; \
stq ra, 0(sp) ; \
stq v0, 8(sp) ; \
stq t0, 16(sp) ; \
stq t1, 24(sp) ; \
stq t2, 32(sp) ; \
stq t3, 40(sp) ; \
stq t4, 48(sp) ; \
stq t5, 56(sp) ; \
stq t6, 64(sp) ; \
stq t7, 72(sp) ; \
stq a0, 80(sp) ; \
stq a1, 88(sp) ; \
stq a2, 96(sp) ; \
stq a3, 104(sp) ; \
stq a4, 112(sp) ; \
stq a5, 120(sp) ; \
stq t8, 128(sp) ; \
stq t9, 136(sp) ; \
stq t10, 144(sp) ; \
stq t11, 152(sp) ; \
stq gp, 160(sp) ; \
\
/* \
* Load our global pointer. Note, can't use pv, since it is \
* already used by the PLT code. \
*/ \
br t0, 1f ; \
1: LDGP(t0)
#define RTLD_BIND_START_EPILOGUE \
/* Move the destination address into position. */ \
mov v0, pv ; \
\
/* Restore program registers. */ \
ldq ra, 0(sp) ; \
ldq v0, 8(sp) ; \
ldq t0, 16(sp) ; \
ldq t1, 24(sp) ; \
ldq t2, 32(sp) ; \
ldq t3, 40(sp) ; \
ldq t4, 48(sp) ; \
ldq t5, 56(sp) ; \
ldq t6, 64(sp) ; \
ldq t7, 72(sp) ; \
ldq a0, 80(sp) ; \
ldq a1, 88(sp) ; \
ldq a2, 96(sp) ; \
ldq a3, 104(sp) ; \
ldq a4, 112(sp) ; \
ldq a5, 120(sp) ; \
ldq t8, 128(sp) ; \
ldq t9, 136(sp) ; \
ldq t10, 144(sp) ; \
ldq t11, 152(sp) ; \
ldq gp, 160(sp) ; \
/* XXX LDGP? */ \
\
/* \
* We've patched the PLT; sync the I-stream. \
*/ \
imb ; \
\
/* Pop the stack frame and turn control to the destination. */ \
lda sp, 168(sp) ; \
jmp zero, (pv)
/*
* Lazy binding entry point, called via PLT.
*/
NESTED_NOPROFILE(_rtld_bind_start, 0, 168, ra, 0, 0)
RTLD_BIND_START_PROLOGUE
/* Set up the arguments for _rtld_bind. */
subq at_reg, pv, a1 /* calculate offset of reloc entry */
ldq a0, 8(pv) /* object structure */
subq a1, 20, a1 /* = (at - pv - 20) / 12 * 24 */
addq a1, a1, a1
CALL(_rtld_bind)
RTLD_BIND_START_EPILOGUE
END(_rtld_bind_start)
/*
* Lazy binding entry point, called via PLT. This version is for the
* old PLT entry format.
*/
NESTED_NOPROFILE(_rtld_bind_start_old, 0, 168, ra, 0, 0)
RTLD_BIND_START_PROLOGUE
/* Set up the arguments for _rtld_bind. */
ldq a0, 8(pv) /* object structure */
mov at_reg, a1 /* offset of reloc entry */
CALL(_rtld_bind)
RTLD_BIND_START_EPILOGUE
END(_rtld_bind_start_old)

View file

@ -0,0 +1,10 @@
# $NetBSD: Makefile.inc,v 1.11 2005/06/04 16:17:17 lukem Exp $
SRCS+= rtld_start.S mdreloc.c
# XXX Should not be in CPPFLAGS!
CPPFLAGS+= -fpic
CPPFLAGS+= -DELFSIZE=32
LDFLAGS+= -Wl,-e,_rtld_start

View file

@ -0,0 +1,276 @@
/* $NetBSD: mdreloc.c,v 1.34 2010/08/06 16:33:17 joerg Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: mdreloc.c,v 1.34 2010/08/06 16:33:17 joerg Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <string.h>
#include "debug.h"
#include "rtld.h"
void _rtld_bind_start(void);
void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
caddr_t _rtld_bind(const Obj_Entry *, Elf_Word);
void
_rtld_setup_pltgot(const Obj_Entry *obj)
{
obj->pltgot[1] = (Elf_Addr) obj;
obj->pltgot[2] = (Elf_Addr) &_rtld_bind_start;
}
void
_rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
{
const Elf_Rel *rel = 0, *rellim;
Elf_Addr relsz = 0;
Elf_Addr *where;
for (; dynp->d_tag != DT_NULL; dynp++) {
switch (dynp->d_tag) {
case DT_REL:
rel = (const Elf_Rel *)(relocbase + dynp->d_un.d_ptr);
break;
case DT_RELSZ:
relsz = dynp->d_un.d_val;
break;
}
}
rellim = (const Elf_Rel *)((const uint8_t *)rel + relsz);
for (; rel < rellim; rel++) {
where = (Elf_Addr *)(relocbase + rel->r_offset);
*where += (Elf_Addr)relocbase;
}
}
/*
* It is possible for the compiler to emit relocations for unaligned data.
* We handle this situation with these inlines.
*/
#define RELOC_ALIGNED_P(x) \
(((uintptr_t)(x) & (sizeof(void *) - 1)) == 0)
static inline Elf_Addr
load_ptr(void *where)
{
Elf_Addr res;
memcpy(&res, where, sizeof(res));
return (res);
}
static inline void
store_ptr(void *where, Elf_Addr val)
{
memcpy(where, &val, sizeof(val));
}
int
_rtld_relocate_nonplt_objects(Obj_Entry *obj)
{
const Elf_Rel *rel;
for (rel = obj->rel; rel < obj->rellim; rel++) {
Elf_Addr *where;
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf_Addr tmp;
unsigned long symnum;
where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
symnum = ELF_R_SYM(rel->r_info);
switch (ELF_R_TYPE(rel->r_info)) {
case R_TYPE(NONE):
break;
#if 1 /* XXX should not occur */
case R_TYPE(PC24): { /* word32 S - P + A */
Elf32_Sword addend;
/*
* Extract addend and sign-extend if needed.
*/
addend = *where;
if (addend & 0x00800000)
addend |= 0xff000000;
def = _rtld_find_symdef(symnum, obj, &defobj, false);
if (def == NULL)
return -1;
tmp = (Elf_Addr)obj->relocbase + def->st_value
- (Elf_Addr)where + (addend << 2);
if ((tmp & 0xfe000000) != 0xfe000000 &&
(tmp & 0xfe000000) != 0) {
_rtld_error(
"%s: R_ARM_PC24 relocation @ %p to %s failed "
"(displacement %ld (%#lx) out of range)",
obj->path, where,
obj->strtab + obj->symtab[symnum].st_name,
(long) tmp, (long) tmp);
return -1;
}
tmp >>= 2;
*where = (*where & 0xff000000) | (tmp & 0x00ffffff);
rdbg(("PC24 %s in %s --> %p @ %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)*where, where, defobj->path));
break;
}
#endif
case R_TYPE(ABS32): /* word32 B + S + A */
case R_TYPE(GLOB_DAT): /* word32 B + S */
def = _rtld_find_symdef(symnum, obj, &defobj, false);
if (def == NULL)
return -1;
if (__predict_true(RELOC_ALIGNED_P(where))) {
tmp = *where + (Elf_Addr)defobj->relocbase +
def->st_value;
/* Set the Thumb bit, if needed. */
if (ELF_ST_TYPE(def->st_info) == STT_ARM_TFUNC)
tmp |= 1;
*where = tmp;
} else {
tmp = load_ptr(where) +
(Elf_Addr)defobj->relocbase +
def->st_value;
/* Set the Thumb bit, if needed. */
if (ELF_ST_TYPE(def->st_info) == STT_ARM_TFUNC)
tmp |= 1;
store_ptr(where, tmp);
}
rdbg(("ABS32/GLOB_DAT %s in %s --> %p @ %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)tmp, where, defobj->path));
break;
case R_TYPE(RELATIVE): /* word32 B + A */
if (__predict_true(RELOC_ALIGNED_P(where))) {
tmp = *where + (Elf_Addr)obj->relocbase;
*where = tmp;
} else {
tmp = load_ptr(where) +
(Elf_Addr)obj->relocbase;
store_ptr(where, tmp);
}
rdbg(("RELATIVE in %s --> %p", obj->path,
(void *)tmp));
break;
case R_TYPE(COPY):
/*
* These are deferred until all other relocations have
* been done. All we do here is make sure that the
* COPY relocation is not in a shared library. They
* are allowed only in executable files.
*/
if (obj->isdynamic) {
_rtld_error(
"%s: Unexpected R_COPY relocation in shared library",
obj->path);
return -1;
}
rdbg(("COPY (avoid in main)"));
break;
default:
rdbg(("sym = %lu, type = %lu, offset = %p, "
"contents = %p, symbol = %s",
symnum, (u_long)ELF_R_TYPE(rel->r_info),
(void *)rel->r_offset, (void *)load_ptr(where),
obj->strtab + obj->symtab[symnum].st_name));
_rtld_error("%s: Unsupported relocation type %ld "
"in non-PLT relocations",
obj->path, (u_long) ELF_R_TYPE(rel->r_info));
return -1;
}
}
return 0;
}
int
_rtld_relocate_plt_lazy(const Obj_Entry *obj)
{
const Elf_Rel *rel;
if (!obj->relocbase)
return 0;
for (rel = obj->pltrel; rel < obj->pltrellim; rel++) {
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JUMP_SLOT));
/* Just relocate the GOT slots pointing into the PLT */
*where += (Elf_Addr)obj->relocbase;
rdbg(("fixup !main in %s --> %p", obj->path, (void *)*where));
}
return 0;
}
static int
_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
Elf_Addr *tp)
{
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
Elf_Addr new_value;
const Elf_Sym *def;
const Obj_Entry *defobj;
unsigned long info = rel->r_info;
assert(ELF_R_TYPE(info) == R_TYPE(JUMP_SLOT));
def = _rtld_find_plt_symdef(ELF_R_SYM(info), obj, &defobj, tp != NULL);
if (__predict_false(def == NULL))
return -1;
if (__predict_false(def == &_rtld_sym_zero))
return 0;
new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
/* Set the Thumb bit, if needed. */
if (ELF_ST_TYPE(def->st_info) == STT_ARM_TFUNC)
new_value |= 1;
rdbg(("bind now/fixup in %s --> old=%p new=%p",
defobj->strtab + def->st_name, (void *)*where, (void *)new_value));
if (*where != new_value)
*where = new_value;
if (tp)
*tp = new_value;
return 0;
}
caddr_t
_rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
{
const Elf_Rel *rel = (const Elf_Rel *)((const uint8_t *)obj->pltrel + reloff);
Elf_Addr new_value = 0; /* XXX gcc */
int err;
err = _rtld_relocate_plt_object(obj, rel, &new_value);
if (err)
_rtld_die();
return (caddr_t)new_value;
}
int
_rtld_relocate_plt_objects(const Obj_Entry *obj)
{
const Elf_Rel *rel;
int err = 0;
for (rel = obj->pltrel; rel < obj->pltrellim; rel++) {
err = _rtld_relocate_plt_object(obj, rel, NULL);
if (err)
break;
}
return err;
}

View file

@ -0,0 +1,104 @@
/* $NetBSD: rtld_start.S,v 1.10 2009/11/11 14:15:41 skrll Exp $ */
/*-
* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas and by Charles M. Hannum.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
RCSID("$NetBSD: rtld_start.S,v 1.10 2009/11/11 14:15:41 skrll Exp $")
.text
.align 0
.globl _rtld_start
.type _rtld_start,%function
_rtld_start:
sub sp, sp, #8 /* make room for obj_main & exit proc */
mov r4, r0 /* save ps_strings */
ldr sl, .L2
ldr r5, .L2+4
ldr r0, .L2+8
.L1:
add sl, pc, sl
ldr r5, [sl, r5]
ldr r0, [sl, r0]
sub r1, sl, r5 /* relocbase */
add r0, r1, r0 /* &_DYNAMIC */
bl _rtld_relocate_nonplt_self
sub r1, sl, r5 /* relocbase */
mov r0, sp /* sp */
bl _rtld /* call the shared loader */
mov r3, r0 /* save entry point */
ldr r2, [sp, #0] /* r2 = cleanup */
ldr r1, [sp, #4] /* r1 = obj_main */
add sp, sp, #8 /* restore stack */
mov r0, r4 /* restore ps_strings */
#ifdef _ARM_ARCH_4T
bx r3 /* jump to the entry point */
#else
mov pc, r3 /* jump to the entry point */
#endif
.L2:
.word _GLOBAL_OFFSET_TABLE_ - (.L1+8)
.word _GLOBAL_OFFSET_TABLE_(GOT)
.word _DYNAMIC(GOT)
.align 0
.globl _rtld_bind_start
.type _rtld_bind_start,%function
/*
* stack[0] = RA
* ip = &GOT[n+3]
* lr = &GOT[2]
*/
_rtld_bind_start:
stmdb sp!,{r0-r4,sl,fp}
sub r1, ip, lr /* r1 = 4 * (n + 1) */
sub r1, r1, #4 /* r1 = 4 * n */
add r1, r1, r1 /* r1 = 8 * n */
ldr r0, [lr, #-4] /* get obj ptr from GOT[1] */
mov r4, ip /* save GOT location */
bl _rtld_bind /* Call the binder */
str r0, [r4] /* save address in GOT */
mov ip, r0 /* save new address */
ldmia sp!,{r0-r4,sl,fp,lr} /* restore the stack */
#ifdef _ARM_ARCH_4T
bx ip /* jump to the new address */
#else
mov pc, ip /* jump to the new address */
#endif

View file

@ -0,0 +1,14 @@
# $NetBSD: Makefile.inc,v 1.8 2009/09/12 07:22:16 skrll Exp $
SRCS+= rtld_start.S hppa_reloc.c
# XXX Should not be in CPPFLAGS!
CPPFLAGS+= -fpic
CPPFLAGS+= -DELFSIZE=32
#CPPFLAGS+= -DDEBUG
#CPPFLAGS+= -DRTLD_DEBUG
#CPPFLAGS+= -DRTLD_DEBUG_RELOC
#CPPFLAGS+= -DRTLD_DEBUG_HPPA
LDFLAGS+= -Wl,-e,'$$rtld_start'

View file

@ -0,0 +1,617 @@
/* $NetBSD: hppa_reloc.c,v 1.34 2010/09/24 11:41:46 skrll Exp $ */
/*-
* Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Fredette and Nick Hudson.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: hppa_reloc.c,v 1.34 2010/09/24 11:41:46 skrll Exp $");
#endif /* not lint */
#include <stdlib.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <string.h>
#include "rtld.h"
#include "debug.h"
#ifdef RTLD_DEBUG_HPPA
#define hdbg(x) xprintf x
#else
#define hdbg(x) /* nothing */
#endif
caddr_t _rtld_bind(const Obj_Entry *, const Elf_Addr);
void _rtld_bind_start(void);
void __rtld_setup_hppa_pltgot(const Obj_Entry *, Elf_Addr *);
/*
* It is possible for the compiler to emit relocations for unaligned data.
* We handle this situation with these inlines.
*/
#define RELOC_ALIGNED_P(x) \
(((uintptr_t)(x) & (sizeof(void *) - 1)) == 0)
static inline Elf_Addr
load_ptr(void *where)
{
if (__predict_true(RELOC_ALIGNED_P(where)))
return *(Elf_Addr *)where;
else {
Elf_Addr res;
(void)memcpy(&res, where, sizeof(res));
return res;
}
}
static inline void
store_ptr(void *where, Elf_Addr val)
{
if (__predict_true(RELOC_ALIGNED_P(where)))
*(Elf_Addr *)where = val;
else
(void)memcpy(where, &val, sizeof(val));
}
/*
* In the runtime architecture (ABI), PLABEL function pointers are
* distinguished from normal function pointers by having the next-least-
* significant bit set. (This bit is referred to as the L field in HP
* documentation). The $$dyncall millicode is aware of this.
*/
#define RTLD_MAKE_PLABEL(plabel) (((Elf_Addr)(plabel)) | (1 << 1))
#define RTLD_IS_PLABEL(addr) (((Elf_Addr)(addr)) & (1 << 1))
#define RTLD_GET_PLABEL(addr) ((hppa_plabel *) (((Elf_Addr)addr) & ~3))
/*
* This is the PLABEL structure. The function PC and
* shared linkage members must come first, as they are
* the actual PLABEL.
*/
typedef struct _hppa_plabel {
Elf_Addr hppa_plabel_pc;
Elf_Addr hppa_plabel_sl;
SLIST_ENTRY(_hppa_plabel) hppa_plabel_next;
} hppa_plabel;
/*
* For now allocated PLABEL structures are tracked on a
* singly linked list. This maybe should be revisited.
*/
static SLIST_HEAD(hppa_plabel_head, _hppa_plabel) hppa_plabel_list
= SLIST_HEAD_INITIALIZER(hppa_plabel_list);
/*
* Because I'm hesitant to use NEW while relocating self,
* this is a small pool of preallocated PLABELs.
*/
#define HPPA_PLABEL_PRE (14)
static hppa_plabel hppa_plabel_pre[HPPA_PLABEL_PRE];
static int hppa_plabel_pre_next = 0;
void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
int _rtld_relocate_plt_objects(const Obj_Entry *);
static inline int _rtld_relocate_plt_object(const Obj_Entry *,
const Elf_Rela *, Elf_Addr *);
/*
* This bootstraps the dynamic linker by relocating its GOT.
* On the hppa, unlike on other architectures, static strings
* are found through the GOT. Static strings are essential
* for RTLD_DEBUG, and I suspect they're used early even when
* !defined(RTLD_DEBUG), making relocating the GOT essential.
*
* It gets worse. Relocating the GOT doesn't mean just walking
* it and adding the relocbase to all of the entries. You must
* find and use the GOT relocations, since those RELA relocations
* have the necessary addends - the GOT comes initialized as
* zeroes.
*/
void
_rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
{
const Elf_Rela *relafirst, *rela, *relalim;
Elf_Addr relasz;
void *where;
Elf_Addr *pltgot;
const Elf_Rela *plabel_relocs[HPPA_PLABEL_PRE];
int nplabel_relocs = 0;
int i;
const Elf_Sym *symtab, *sym;
unsigned long symnum;
hppa_plabel *plabel;
/*
* Process the DYNAMIC section, looking for the non-PLT relocations.
*/
relafirst = NULL;
relasz = 0;
symtab = NULL;
pltgot = NULL;
for (; dynp->d_tag != DT_NULL; ++dynp) {
switch (dynp->d_tag) {
case DT_RELA:
relafirst = (const Elf_Rela *)
(relocbase + dynp->d_un.d_ptr);
break;
case DT_RELASZ:
relasz = dynp->d_un.d_val;
break;
case DT_SYMTAB:
symtab = (const Elf_Sym *)
(relocbase + dynp->d_un.d_ptr);
break;
case DT_PLTGOT:
pltgot = (Elf_Addr *)
(relocbase + dynp->d_un.d_ptr);
break;
}
}
relalim = (const Elf_Rela *)((const char *)relafirst + relasz);
for (rela = relafirst; rela < relalim; rela++) {
symnum = ELF_R_SYM(rela->r_info);
where = (void *)(relocbase + rela->r_offset);
switch (ELF_R_TYPE(rela->r_info)) {
case R_TYPE(DIR32):
if (symnum == 0)
store_ptr(where,
relocbase + rela->r_addend);
else {
sym = symtab + symnum;
store_ptr(where,
relocbase + rela->r_addend + sym->st_value);
}
break;
case R_TYPE(PLABEL32):
/*
* PLABEL32 relocation processing is done in two phases
*
* i) local function relocations (symbol number == 0)
* can be resolved immediately.
*
* ii) external function relocations are deferred until
* we finish all other relocations so that global
* data isn't accessed until all other non-PLT
* relocations have been done.
*/
if (symnum == 0)
*((Elf_Addr *)where) =
relocbase + rela->r_addend;
else
plabel_relocs[nplabel_relocs++] = rela;
break;
default:
break;
}
}
assert(nplabel_relocs < HPPA_PLABEL_PRE);
for (i = 0; i < nplabel_relocs; i++) {
rela = plabel_relocs[i];
where = (void *)(relocbase + rela->r_offset);
sym = symtab + ELF_R_SYM(rela->r_info);
plabel = &hppa_plabel_pre[hppa_plabel_pre_next++];
plabel->hppa_plabel_pc = (Elf_Addr)
(relocbase + sym->st_value + rela->r_addend);
plabel->hppa_plabel_sl = (Elf_Addr)pltgot;
SLIST_INSERT_HEAD(&hppa_plabel_list, plabel, hppa_plabel_next);
*((Elf_Addr *)where) = (Elf_Addr)(RTLD_MAKE_PLABEL(plabel));
}
#if defined(RTLD_DEBUG_HPPA)
for (rela = relafirst; rela < relalim; rela++) {
where = (void *)(relocbase + rela->r_offset);
switch (ELF_R_TYPE(rela->r_info)) {
case R_TYPE(DIR32):
hdbg(("DIR32 rela @%p(%p) -> %p(%p)\n",
(void *)rela->r_offset,
(void *)where,
(void *)rela->r_addend,
(void *)*((Elf_Addr *)where) ));
break;
case R_TYPE(PLABEL32):
symnum = ELF_R_SYM(rela->r_info);
if (symnum == 0) {
hdbg(("PLABEL rela @%p(%p) -> %p(%p)\n",
(void *)rela->r_offset,
(void *)where,
(void *)rela->r_addend,
(void *)*((Elf_Addr *)where) ));
} else {
sym = symtab + symnum;
hdbg(("PLABEL32 rela @%p(%p), symnum=%ld(%p) -> %p(%p)\n",
(void *)rela->r_offset,
(void *)where,
symnum,
(void *)sym->st_value,
(void *)rela->r_addend,
(void *)*((Elf_Addr *)where) ));
}
break;
default:
hdbg(("rela XXX reloc\n"));
break;
}
}
#endif /* RTLD_DEBUG_HPPA */
}
/*
* This allocates a PLABEL. If called with a non-NULL def, the
* plabel is for the function associated with that definition
* in the defining object defobj, plus the given addend. If
* called with a NULL def, the plabel is for the function at
* the (unrelocated) address in addend in the object defobj.
*/
Elf_Addr
_rtld_function_descriptor_alloc(const Obj_Entry *defobj, const Elf_Sym *def,
Elf_Addr addend)
{
Elf_Addr func_pc, func_sl;
hppa_plabel *plabel;
if (def != NULL) {
/*
* We assume that symbols of type STT_NOTYPE
* are undefined. Return NULL for these.
*/
if (ELF_ST_TYPE(def->st_info) == STT_NOTYPE)
return (Elf_Addr)NULL;
/* Otherwise assert that this symbol must be a function. */
assert(ELF_ST_TYPE(def->st_info) == STT_FUNC);
func_pc = (Elf_Addr)(defobj->relocbase + def->st_value +
addend);
} else
func_pc = (Elf_Addr)(defobj->relocbase + addend);
/*
* Search the existing PLABELs for one matching
* this function. If there is one, return it.
*/
func_sl = (Elf_Addr)(defobj->pltgot);
SLIST_FOREACH(plabel, &hppa_plabel_list, hppa_plabel_next)
if (plabel->hppa_plabel_pc == func_pc &&
plabel->hppa_plabel_sl == func_sl)
return RTLD_MAKE_PLABEL(plabel);
/*
* Once we've used up the preallocated set, we start
* using NEW to allocate plabels.
*/
if (hppa_plabel_pre_next < HPPA_PLABEL_PRE)
plabel = &hppa_plabel_pre[hppa_plabel_pre_next++];
else {
plabel = NEW(hppa_plabel);
if (plabel == NULL)
return (Elf_Addr)-1;
}
/* Fill the new entry and insert it on the list. */
plabel->hppa_plabel_pc = func_pc;
plabel->hppa_plabel_sl = func_sl;
SLIST_INSERT_HEAD(&hppa_plabel_list, plabel, hppa_plabel_next);
return RTLD_MAKE_PLABEL(plabel);
}
/*
* If a pointer is a PLABEL, this unwraps it.
*/
const void *
_rtld_function_descriptor_function(const void *addr)
{
return (RTLD_IS_PLABEL(addr) ?
(const void *) RTLD_GET_PLABEL(addr)->hppa_plabel_pc :
addr);
}
/* This sets up an object's GOT. */
void
_rtld_setup_pltgot(const Obj_Entry *obj)
{
__rtld_setup_hppa_pltgot(obj, obj->pltgot);
}
int
_rtld_relocate_nonplt_objects(Obj_Entry *obj)
{
const Elf_Rela *rela;
for (rela = obj->rela; rela < obj->relalim; rela++) {
Elf_Addr *where;
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf_Addr tmp;
unsigned long symnum;
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
symnum = ELF_R_SYM(rela->r_info);
switch (ELF_R_TYPE(rela->r_info)) {
case R_TYPE(NONE):
break;
case R_TYPE(DIR32):
if (symnum) {
/*
* This is either a DIR32 against a symbol
* (def->st_name != 0), or against a local
* section (def->st_name == 0).
*/
def = obj->symtab + symnum;
defobj = obj;
if (def->st_name != 0)
def = _rtld_find_symdef(symnum, obj,
&defobj, false);
if (def == NULL)
return -1;
tmp = (Elf_Addr)(defobj->relocbase +
def->st_value + rela->r_addend);
if (load_ptr(where) != tmp)
store_ptr(where, tmp);
rdbg(("DIR32 %s in %s --> %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)load_ptr(where),
defobj->path));
} else {
tmp = (Elf_Addr)(obj->relocbase +
rela->r_addend);
if (load_ptr(where) != tmp)
store_ptr(where, tmp);
rdbg(("DIR32 in %s --> %p", obj->path,
(void *)load_ptr(where)));
}
break;
case R_TYPE(PLABEL32):
if (symnum) {
def = _rtld_find_symdef(symnum, obj, &defobj,
false);
if (def == NULL)
return -1;
tmp = _rtld_function_descriptor_alloc(defobj,
def, rela->r_addend);
if (tmp == (Elf_Addr)-1)
return -1;
if (*where != tmp)
*where = tmp;
rdbg(("PLABEL32 %s in %s --> %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)*where, defobj->path));
} else {
/*
* This is a PLABEL for a static function, and
* the dynamic linker has both allocated a PLT
* entry for this function and told us where it
* is. We can safely use the PLT entry as the
* PLABEL because there should be no other
* PLABEL reloc referencing this function.
* This object should also have an IPLT
* relocation to initialize the PLT entry.
*
* The dynamic linker should also have ensured
* that the addend has the
* next-least-significant bit set; the
* $$dyncall millicode uses this to distinguish
* a PLABEL pointer from a plain function
* pointer.
*/
tmp = (Elf_Addr)
(obj->relocbase + rela->r_addend);
if (*where != tmp)
*where = tmp;
rdbg(("PLABEL32 in %s --> %p", obj->path,
(void *)*where));
}
break;
case R_TYPE(COPY):
/*
* These are deferred until all other relocations have
* been done. All we do here is make sure that the
* COPY relocation is not in a shared library. They
* are allowed only in executable files.
*/
if (obj->isdynamic) {
_rtld_error(
"%s: Unexpected R_COPY relocation in shared library",
obj->path);
return -1;
}
rdbg(("COPY (avoid in main)"));
break;
default:
rdbg(("sym = %lu, type = %lu, offset = %p, "
"addend = %p, contents = %p, symbol = %s",
symnum, (u_long)ELF_R_TYPE(rela->r_info),
(void *)rela->r_offset, (void *)rela->r_addend,
(void *)load_ptr(where),
obj->strtab + obj->symtab[symnum].st_name));
_rtld_error("%s: Unsupported relocation type %ld "
"in non-PLT relocations",
obj->path, (u_long) ELF_R_TYPE(rela->r_info));
return -1;
}
}
return 0;
}
int
_rtld_relocate_plt_lazy(const Obj_Entry *obj)
{
const Elf_Rela *rela;
for (rela = obj->pltrela; rela < obj->pltrelalim; rela++) {
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
Elf_Addr func_pc, func_sl;
assert(ELF_R_TYPE(rela->r_info) == R_TYPE(IPLT));
/*
* If this is an IPLT reloc for a static function,
* fully resolve the PLT entry now.
*/
if (ELF_R_SYM(rela->r_info) == 0) {
func_pc = (Elf_Addr)(obj->relocbase + rela->r_addend);
func_sl = (Elf_Addr)(obj->pltgot);
}
/*
* Otherwise set up for lazy binding.
*/
else {
/*
* This function pointer points to the PLT
* stub added by the linker, and instead of
* a shared linkage value, we stash this
* relocation's offset. The PLT stub has
* already been set up to transfer to
* _rtld_bind_start.
*/
func_pc = ((Elf_Addr)(obj->pltgot)) - 16;
func_sl = (Elf_Addr)
((const char *)rela - (const char *)(obj->pltrela));
}
rdbg(("lazy bind %s(%p) --> old=(%p,%p) new=(%p,%p)",
obj->path,
(void *)where,
(void *)where[0], (void *)where[1],
(void *)func_pc, (void *)func_sl));
/*
* Fill this PLT entry and return.
*/
where[0] = func_pc;
where[1] = func_sl;
}
return 0;
}
static inline int
_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rela *rela,
Elf_Addr *tp)
{
Elf_Word *where = (Elf_Word *)(obj->relocbase + rela->r_offset);
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf_Addr func_pc, func_sl;
unsigned long info = rela->r_info;
assert(ELF_R_TYPE(info) == R_TYPE(IPLT));
if (ELF_R_SYM(info) == 0) {
func_pc = (Elf_Addr)(obj->relocbase + rela->r_addend);
func_sl = (Elf_Addr)(obj->pltgot);
} else {
def = _rtld_find_plt_symdef(ELF_R_SYM(info), obj, &defobj,
tp != NULL);
if (__predict_false(def == NULL))
return -1;
if (__predict_false(def == &_rtld_sym_zero))
return 0;
func_pc = (Elf_Addr)(defobj->relocbase + def->st_value +
rela->r_addend);
func_sl = (Elf_Addr)(defobj->pltgot);
rdbg(("bind now/fixup in %s --> old=(%p,%p) new=(%p,%p)",
defobj->strtab + def->st_name,
(void *)where[0], (void *)where[1],
(void *)func_pc, (void *)func_sl));
}
/*
* Fill this PLT entry and return.
*/
if (where[0] != func_pc)
where[0] = func_pc;
if (where[1] != func_sl)
where[1] = func_sl;
if (tp)
*tp = (Elf_Addr)where;
return 0;
}
caddr_t
_rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
{
const Elf_Rela *rela;
Elf_Addr new_value = 0; /* XXX gcc */
int err;
rela = (const Elf_Rela *)((const char *)obj->pltrela + reloff);
assert(ELF_R_SYM(rela->r_info) != 0);
err = _rtld_relocate_plt_object(obj, rela, &new_value);
if (err)
_rtld_die();
return (caddr_t)new_value;
}
int
_rtld_relocate_plt_objects(const Obj_Entry *obj)
{
const Elf_Rela *rela = obj->pltrela;
for (; rela < obj->pltrelalim; rela++) {
if (_rtld_relocate_plt_object(obj, rela, NULL) < 0)
return -1;
}
return 0;
}

View file

@ -0,0 +1,231 @@
/* $NetBSD: rtld_start.S,v 1.9 2010/09/30 19:32:40 skrll Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Fredette.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
#include <machine/frame.h>
.import _GLOBAL_OFFSET_TABLE_
ENTRY($rtld_start,HPPA_FRAME_SIZE)
/* Start stack calling convention. */
copy %r3, %r1
copy %sp, %r3
stw,ma %r1, HPPA_FRAME_SIZE(%sp)
/*
* Save our single argument, the ps_strings pointer. We'll need this
* twice later: once to call _rtld, and again to transfer to the
* program's entry point.
*/
stw %arg0, HPPA_FRAME_ARG(0)(%r3)
/*
* We can't move to C until we relocate at least the
* Global Offset Table. Even finding the GOT is tricky
* without inadvertently causing the linker to make
* relocations for this part of the text segment.
*/
bl L$lpc1, %r19
depi 0, 31, 2, %r19
L$lpc1: addil L'_DYNAMIC - ($PIC_pcrel$0 - 8), %r19
ldo R'_DYNAMIC - ($PIC_pcrel$0 - 12)(%r1),%arg0
/*
* Load the absolute address of the beginning of the GOT into %r19, the
* shared library linkage table register, leaving it ready-to-use by
* the dynamic linker C code.
*/
addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 16), %r19
ldo R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 20)(%r1),%r19
/*
* The linker sets the first entry in the GOT to the unrelocated
* address of _DYNAMIC. Subtract this from the absolute address of
* _DYNAMIC to get our relocbase.
*/
ldw 0(%r19), %arg1
sub %arg0, %arg1, %arg1 ; %arg1 = relocbase
bl _rtld_relocate_nonplt_self, %rp
copy %arg1, %r4 ; save for later
/*
* Recover the ps_strings pointer, and take out the
* ps_argvstr member.
*/
ldw HPPA_FRAME_ARG(0)(%r3), %arg0 ; ps_strings
ldw 0(%arg0), %arg0 ; ps_argvstr member first in struct
/*
* ps_argvstr - 4 would get us a pointer to argc, comparable to the
* initial stack pointer on architectures where the stack grows down.
* Subtracting an additional eight creates the storage for obj and
* cleanup that _rtld needs.
*/
ldo -12(%arg0), %arg0
stw %arg0, HPPA_FRAME_ARG(1)(%r3)
/* Call _rtld, copying relocbase into arg1. */
bl _rtld, %rp
copy %r4, %arg1 ; %arg1 = relocbase
/* Prepare the arguments for the entry point. */
ldw HPPA_FRAME_ARG(1)(%r3), %r1
ldw HPPA_FRAME_ARG(0)(%r3), %arg0 ; ps_strings
ldw 0(%r1), %arg1 ; cleanup
ldw 4(%r1), %arg2 ; obj
/* End stack calling convention. */
ldo HPPA_FRAME_SIZE(%r3), %sp
ldw,mb -HPPA_FRAME_SIZE(%sp), %r3
/* Go for it. */
bv %r0(%ret0)
copy %r0, %rp
EXIT($rtld_start)
/*
* This does our setup for an object's GOT. %arg0 is the Obj_Entry * for the
* object, and %arg1 is its GOT pointer.
*/
LEAF_ENTRY(__rtld_setup_hppa_pltgot)
/*
* The second entry of the GOT is reserved for the dynamic linker. We
* put the Obj_Entry * for the object in there.
*/
stw %arg0, 4(%arg1)
/*
* Fill the fixup_func and fixup_ltp members of the PLT stub. This
* stub is inserted by the linker immediately before the GOT. We use
* this stub to enter our binder.
*/
bl L$lpc2, %arg0
depi 0, 31, 2, %arg0
L$lpc2: addil L'_rtld_bind_start - ($PIC_pcrel$0 - 8), %arg0
ldo R'_rtld_bind_start - ($PIC_pcrel$0 - 12)(%r1),%arg0
stw %arg0, -8(%arg1)
bv %r0(%rp)
stw %r19, -4(%arg1)
EXIT(__rtld_hppa_setup_pltgot)
/*
* In order to support lazy binding, this implementation of _rtld_bind_start is
* very closely tied to the shared-library call stub and the PLT stub, both
* inserted by the linker.
*/
/*
* This is a magic branch instruction that is used by GCC's
* __canonicalize_funcptr_for_compare() function to fixup relocations
* in order to do function pointer comparisons.
*/
bl _rtld_bind, %rp
ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE)
/* Start stack calling convention. */
copy %r3, %r1
copy %sp, %r3
stw,ma %r1, HPPA_FRAME_SIZE(%sp)
/*
* We have to save all calling convention registers that are set by the
* caller, because we have to restore them before transferring to the
* bound function. Note that this includes %ret0, %ret1, and %t1.
*
* %ret0 and %ret1 because they can have meaning on entry to a
* function.
*
* %t1 because it's used by libc to pass on errno values to cerror.
*/
stw %rp, HPPA_FRAME_CRP(%r3)
stw %arg0, HPPA_FRAME_ARG(0)(%r3)
stw %arg1, HPPA_FRAME_ARG(1)(%r3)
stw %arg2, HPPA_FRAME_ARG(2)(%r3)
stw %arg3, HPPA_FRAME_ARG(3)(%r3)
/* 0(%r3) is filled with the saved %r3 above */
stw %ret0, 4(%r3)
stw %ret1, 8(%r3)
/*
* The linker PLT stub loads %r20 with (GOT - 8) for the object that
* needs binding done. The second entry of the GOT is reserved for the
* dynamic linker's use, and we previously stashed the object's
* Obj_Entry * there.
*/
ldw 12(%r20), %arg0
/*
* The linker shared-library call stub loads %r19 from the shared
* linkage member of the PLT entry. We previously stashed the reloff
* of the relocation there.
*/
copy %r19, %arg1
/*
* The linker PLT stub loads %r21 with the fixup_ltp word in itself.
* We previously stashed our %r19 value there.
*/
bl _rtld_bind, %rp
copy %r21, %r19
/*
* Our hppa version of _rtld_bind returns to us the address of the PLT
* entry that it fixed up. Load the function address and shared
* linkage for the newly bound function.
*/
ldw 0(%ret0), %r21
ldw 4(%ret0), %r19
/* Restore registers saved above. */
ldw HPPA_FRAME_CRP(%r3), %rp
ldw HPPA_FRAME_ARG(0)(%r3), %arg0
ldw HPPA_FRAME_ARG(1)(%r3), %arg1
ldw HPPA_FRAME_ARG(2)(%r3), %arg2
ldw HPPA_FRAME_ARG(3)(%r3), %arg3
ldw 4(%r3), %ret0
ldw 8(%r3), %ret1
/* End stack calling convention. */
ldo HPPA_FRAME_SIZE(%r3), %sp
ldw,mb -HPPA_FRAME_SIZE(%sp), %r3
/* Transfer to the function. */
bv %r0(%r21)
nop
EXIT(_rtld_bind_start)

View file

@ -0,0 +1,10 @@
# $NetBSD: Makefile.inc,v 1.14 2009/12/13 09:31:47 mrg Exp $
SRCS+= rtld_start.S mdreloc.c
# XXX Should not be in CPPFLAGS!
CPPFLAGS+= -fpic
CPPFLAGS+= -DELFSIZE=32
LDFLAGS+= -Wl,-e,.rtld_start

Some files were not shown because too many files have changed in this diff Show more