diff options
Diffstat (limited to 'libexec/ld.so/sparc')
-rw-r--r-- | libexec/ld.so/sparc/archdep.h | 72 | ||||
-rw-r--r-- | libexec/ld.so/sparc/ldasm.S | 281 | ||||
-rw-r--r-- | libexec/ld.so/sparc/rtld_machine.c | 82 | ||||
-rw-r--r-- | libexec/ld.so/sparc/syscall.h | 67 |
4 files changed, 502 insertions, 0 deletions
diff --git a/libexec/ld.so/sparc/archdep.h b/libexec/ld.so/sparc/archdep.h new file mode 100644 index 00000000000..86850b86605 --- /dev/null +++ b/libexec/ld.so/sparc/archdep.h @@ -0,0 +1,72 @@ +/* $OpenBSD: archdep.h,v 1.1 2002/07/27 13:19:26 art Exp $ */ + +/* + * Copyright (c) 1998 Per Fogelstrom, Opsycon AB + * + * 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 under OpenBSD by + * Per Fogelstrom, Opsycon AB, Sweden. + * 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. + * + */ + +#ifndef _SPARC64_ARCHDEP_H_ +#define _SPARC64_ARCHDEP_H_ + +#define DL_MALLOC_ALIGN 8 /* Arch constraint or otherwise */ + +#define MACHID EM_SPARC /* ELF e_machine ID value checked */ + +#define RELTYPE Elf32_Rela +#define RELSIZE sizeof(Elf32_Rela) + +#include <elf_abi.h> +#include <machine/exec.h> +#include <machine/reloc.h> +#include <sys/syscall.h> +#include "syscall.h" +#include "util.h" + +static inline void * +_dl_mmap(void *addr, unsigned int len, unsigned int prot, + unsigned int flags, int fd, off_t offset) +{ + return((void *)_dl__syscall((quad_t)SYS_mmap, addr, len, prot, + flags, fd, 0, offset)); +} + +static inline void +RELOC_RELA(Elf_RelA *r, const Elf_Sym *s, Elf_Addr *p, unsigned long v) +{ + if (ELF_R_TYPE(r->r_info) == RELOC_RELATIVE) { + *p = v + r->r_addend; + } else { + /* XXX - printf might not work here, but we give it a shot. */ + _dl_printf("Unknown bootstrap relocation.\n"); + _dl_exit(6); + } +} + +#endif /* _SPARC64_ARCHDEP_H_ */ diff --git a/libexec/ld.so/sparc/ldasm.S b/libexec/ld.so/sparc/ldasm.S new file mode 100644 index 00000000000..ab194027b6e --- /dev/null +++ b/libexec/ld.so/sparc/ldasm.S @@ -0,0 +1,281 @@ +/* $OpenBSD: ldasm.S,v 1.1 2002/07/27 13:19:26 art Exp $ */ + +/* + * Copyright (c) 2001 Jason L. Wright (jason@thought.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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jason L. Wright + * 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. + */ + +/*- + * Copyright (c) 2000 Eduardo Horvath. + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas and Paul Kranenburg. + * + * 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/syscall.h> +#include <machine/trap.h> +#include <machine/asm.h> + +#define DL_DATA_SIZE (16*4) +#define ARGC (16*4) + + .section ".text" + .align 4 + .global _dl_start + .type _dl_start,@function +_dl_start: + mov 0, %fp /* Erect a fence post for ourselves */ + mov %g1, %l1 /* save ps_strings */ + sub %sp, DL_DATA_SIZE, %sp /* make room for dl_data */ + mov %sp, %o3 + + mov %g0, %o2 + call _dl_boot_bind + add %sp, ARGC+DL_DATA_SIZE, %o0 /* &argc - 8 */ + + mov %l3, %o4 + ld [%l0], %l3 ! argc = *sp + sll %l3, 3, %l3 ! argc *= sizeof(long) + add %l0, 8, %o0 ! argv = [sp + argc] + add %l0, 16, %o1 ! envp = sp + 16 + + add %o1, %l3, %o1 ! + argc + + add %o4, (7*8), %l2 + ld [%l2], %o2 ! loff = dl_data[AUX_base]; + + call _dl_boot ! _dl_boot(argv,envp,loff,dynp,dl_data) + mov 0, %o3 ! dynp = 0 + + add %sp, DL_DATA_SIZE, %sp ! restore stack + + jmp %o0 + mov %l1, %g1 ! restore ps_strings + + + .section ".text" + .align 4 + .global _dl_bind_start + .type _dl_bind_start,@function +_dl_bind_start: # (obj, reloff) + save %sp, -96, %sp /* setup standard stack frame */ + ld [%i7 + 8], %o0 /* obj id is in second PLT slot */ + srl %g1, 10, %o1 /* offset is in high 22 bits */ + call _dl_bind /* Call _rtld_bind(obj, offset) */ + sub %o1, 12*4, %o1 /* first 4 `pltrel' entries missing! */ + + mov %o0, %g1 /* return value == function address */ + restore /* get rid of our context */ + jmp %g1 /* and the jmpslot context, then go. */ + restore + + .section ".text" + .align 4 + .global _dl_close + .type _dl_close,@function +_dl_close: + mov SYS_close | SYSCALL_G2RFLAG, %g1 ! call sys_close + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_exit + .type _dl_exit,@function +_dl_exit: + mov SYS_exit | SYSCALL_G2RFLAG, %g1 ! call sys_exit + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_issetugid + .type _dl_issetugid,@function +_dl_issetugid: + mov SYS_issetugid | SYSCALL_G2RFLAG, %g1 + add %o7, 8, %g2 + t ST_SYSCALL + retl + sub %g0, %o0, %o0 + + + .section ".text" + .align 4 + .global _dl__syscall + .type _dl__syscall,@function +_dl__syscall: + mov SYS___syscall | SYSCALL_G2RFLAG, %g1 ! call sys_exit + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_munmap + .type _dl_munmap,@function +_dl_munmap: + mov SYS_munmap | SYSCALL_G2RFLAG, %g1 ! calling sys_mmap + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_mprotect + .type _dl_mprotect,@function +_dl_mprotect: + mov SYS_mprotect | SYSCALL_G2RFLAG, %g1 ! calling sys_mprotect + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_open + .type _dl_open,@function +_dl_open: + mov SYS_open | SYSCALL_G2RFLAG, %g1 ! calling sys_open + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_read + .type _dl_read,@function +_dl_read: + mov SYS_read | SYSCALL_G2RFLAG, %g1 ! calling sys_read + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_write + .type _dl_write,@function +_dl_write: + mov SYS_write | SYSCALL_G2RFLAG, %g1 ! calling sys_write + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .global _dl_stat + .type _dl_stat,@function +_dl_stat: + mov SYS_stat | SYSCALL_G2RFLAG, %g1 ! call sys_stat + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .globl _dl_fstat + .type _dl_fstat,@function +_dl_fstat: + mov SYS_fstat | SYSCALL_G2RFLAG, %g1 ! call sys_fstat + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .globl _dl_fcntl + .type _dl_fcntl,@function +_dl_fcntl: + mov SYS_fcntl | SYSCALL_G2RFLAG, %g1 ! call sys_fstat + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + + + .section ".text" + .align 4 + .globl _dl_getdirentries + .type _dl_getdirentries,@function +_dl_getdirentries: + mov SYS_getdirentries | SYSCALL_G2RFLAG, %g1 ! call sys_fstat + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno + diff --git a/libexec/ld.so/sparc/rtld_machine.c b/libexec/ld.so/sparc/rtld_machine.c new file mode 100644 index 00000000000..546e8c40fe7 --- /dev/null +++ b/libexec/ld.so/sparc/rtld_machine.c @@ -0,0 +1,82 @@ +/* $OpenBSD: rtld_machine.c,v 1.1 2002/07/27 13:19:26 art Exp $ */ + +/* + * Copyright (c) 1999 Dale Rahn + * Copyright (c) 2001 Niklas Hallqvist + * Copyright (c) 2001 Artur Grabowski + * + * 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 under OpenBSD by + * Dale Rahn. + * 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. + */ + +#define _DYN_LOADER + +#include <sys/types.h> +#include <sys/cdefs.h> +#include <sys/mman.h> + +#include <nlist.h> +#include <link.h> + +#include "syscall.h" +#include "archdep.h" +#include "resolve.h" + +void +_dl_bcopy(const void *src, void *dest, int size) +{ + const unsigned char *psrc = src; + unsigned char *pdest = dest; + int i; + + for (i = 0; i < size; i++) + pdest[i] = psrc[i]; +} + +int +_dl_md_reloc(elf_object_t *object, int rel, int relasz) +{ + return (0); +} +/* + * Resolve a symbol at run-time. + */ +void * +_dl_bind(elf_object_t *object, int index) +{ + return (NULL); +} + +void +_dl_install_plt(Elf_Word *pltgot, Elf_Addr proc) +{ +} + +void +_dl_md_reloc_got(elf_object_t *object, int lazy) +{ +} diff --git a/libexec/ld.so/sparc/syscall.h b/libexec/ld.so/sparc/syscall.h new file mode 100644 index 00000000000..3d450ad5e99 --- /dev/null +++ b/libexec/ld.so/sparc/syscall.h @@ -0,0 +1,67 @@ +/* $OpenBSD: syscall.h,v 1.1 2002/07/27 13:19:26 art Exp $ */ + +/* + * Copyright (c) 2001 Niklas Hallqvist + * + * 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 under OpenBSD by + * Niklas Hallqvist. + * 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. + * + */ + +#ifndef __DL_SYSCALL_H__ +#define __DL_SYSCALL_H__ + +#include <sys/syscall.h> +#include <sys/stat.h> + +#ifndef _dl_MAX_ERRNO +#define _dl_MAX_ERRNO 4096 +#endif +#define _dl_check_error(__res) \ + ((int) __res < 0 && (int) __res >= -_dl_MAX_ERRNO) + +int _dl_close(int); +int _dl_exit(int); +int _dl_issetugid(void); +long _dl__syscall(quad_t, ...); +int _dl_mprotect(const void *, int, int); +int _dl_munmap(const void*, unsigned int); +int _dl_open(const char*, unsigned int); +int _dl_read(int, const char*, int); +int _dl_stat(const char *, struct stat *); +int _dl_write(int, const char*, int); +int _dl_fstat(int, struct stat *); +int _dl_fcntl(int, int, ...); +int _dl_getdirentries(int, char*, int, long *); + +static inline off_t +_dl_lseek(int fildes, off_t offset, int whence) +{ + return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); +} + +#endif /*__DL_SYSCALL_H__*/ |