From b8fcdddcbb192fc367ff04bbd753b9deb69b09f3 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sat, 28 May 2016 18:12:58 +0200 Subject: nios2: sync support with glibc Only static linking is supported for now. More debugging and analyzing for ld.so, TLS and NPTL is required. But at least you can bootup a static root fileystem in Qemu. --- extra/Configs/Config.in | 1 - extra/Configs/Config.nios2 | 2 - include/elf.h | 97 +++---- ldso/ldso/nios2/dl-debug.h | 18 ++ ldso/ldso/nios2/dl-inlines.h | 12 + ldso/ldso/nios2/dl-startup.h | 34 +++ ldso/ldso/nios2/dl-syscalls.h | 1 + ldso/ldso/nios2/dl-sysdep.h | 74 +++++ ldso/ldso/nios2/elfinterp.c | 297 +++++++++++++++++++++ ldso/ldso/nios2/resolve.S | 73 +++++ libc/sysdeps/linux/nios2/Makefile.arch | 11 +- libc/sysdeps/linux/nios2/__longjmp.S | 71 +++-- libc/sysdeps/linux/nios2/__syscall_error.c | 18 ++ libc/sysdeps/linux/nios2/bits/fcntl.h | 6 +- libc/sysdeps/linux/nios2/bits/kernel_stat.h | 50 ---- libc/sysdeps/linux/nios2/bits/kernel_types.h | 6 +- libc/sysdeps/linux/nios2/bits/setjmp.h | 30 +-- libc/sysdeps/linux/nios2/bits/stat.h | 167 ------------ libc/sysdeps/linux/nios2/bits/syscalls.h | 173 ++++++------ libc/sysdeps/linux/nios2/bsd-_setjmp.S | 44 --- libc/sysdeps/linux/nios2/bsd-setjmp.S | 51 ---- libc/sysdeps/linux/nios2/clone.S | 152 ++++++----- libc/sysdeps/linux/nios2/clone.c | 50 ---- libc/sysdeps/linux/nios2/crt1.S | 147 ++++++---- libc/sysdeps/linux/nios2/fpu_control.h | 98 ------- libc/sysdeps/linux/nios2/jmpbuf-offsets.h | 16 +- libc/sysdeps/linux/nios2/jmpbuf-unwind.h | 39 ++- libc/sysdeps/linux/nios2/setjmp.S | 101 +++---- libc/sysdeps/linux/nios2/syscall.c | 47 ---- libc/sysdeps/linux/nios2/sysdep.h | 34 +++ libc/sysdeps/linux/nios2/vfork.S | 100 +++---- libpthread/nptl/pthread_create.c | 2 +- libpthread/nptl/sysdeps/nios2/Makefile.arch | 4 + libpthread/nptl/sysdeps/nios2/dl-tls.h | 48 ++++ libpthread/nptl/sysdeps/nios2/libc-tls.c | 32 +++ libpthread/nptl/sysdeps/nios2/pthread_spin_lock.c | 66 +++++ .../nptl/sysdeps/nios2/pthread_spin_trylock.c | 27 ++ libpthread/nptl/sysdeps/nios2/pthreaddef.h | 36 +++ libpthread/nptl/sysdeps/nios2/tcb-offsets.sym | 14 + libpthread/nptl/sysdeps/nios2/tls.h | 178 ++++++++++++ .../nptl/sysdeps/unix/sysv/linux/nios2/Makefile | 9 + .../sysdeps/unix/sysv/linux/nios2/Makefile.arch | 9 + .../unix/sysv/linux/nios2/bits/pthreadtypes.h | 189 +++++++++++++ .../sysdeps/unix/sysv/linux/nios2/bits/semaphore.h | 32 +++ .../nptl/sysdeps/unix/sysv/linux/nios2/clone.S | 3 + .../sysdeps/unix/sysv/linux/nios2/createthread.c | 22 ++ .../nptl/sysdeps/unix/sysv/linux/nios2/fork.c | 30 +++ .../sysdeps/unix/sysv/linux/nios2/lowlevellock.h | 281 +++++++++++++++++++ .../unix/sysv/linux/nios2/pt-gettimeofday.c | 5 + .../sysdeps/unix/sysv/linux/nios2/pthread_once.c | 99 +++++++ .../sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h | 140 ++++++++++ .../nptl/sysdeps/unix/sysv/linux/nios2/vfork.S | 38 +++ utils/ldd.c | 5 + 53 files changed, 2337 insertions(+), 952 deletions(-) create mode 100644 ldso/ldso/nios2/dl-debug.h create mode 100644 ldso/ldso/nios2/dl-inlines.h create mode 100644 ldso/ldso/nios2/dl-startup.h create mode 100644 ldso/ldso/nios2/dl-syscalls.h create mode 100644 ldso/ldso/nios2/dl-sysdep.h create mode 100644 ldso/ldso/nios2/elfinterp.c create mode 100644 ldso/ldso/nios2/resolve.S create mode 100644 libc/sysdeps/linux/nios2/__syscall_error.c delete mode 100644 libc/sysdeps/linux/nios2/bits/kernel_stat.h delete mode 100644 libc/sysdeps/linux/nios2/bits/stat.h delete mode 100644 libc/sysdeps/linux/nios2/bsd-_setjmp.S delete mode 100644 libc/sysdeps/linux/nios2/bsd-setjmp.S delete mode 100644 libc/sysdeps/linux/nios2/clone.c delete mode 100644 libc/sysdeps/linux/nios2/fpu_control.h delete mode 100644 libc/sysdeps/linux/nios2/syscall.c create mode 100644 libc/sysdeps/linux/nios2/sysdep.h create mode 100644 libpthread/nptl/sysdeps/nios2/Makefile.arch create mode 100644 libpthread/nptl/sysdeps/nios2/dl-tls.h create mode 100644 libpthread/nptl/sysdeps/nios2/libc-tls.c create mode 100644 libpthread/nptl/sysdeps/nios2/pthread_spin_lock.c create mode 100644 libpthread/nptl/sysdeps/nios2/pthread_spin_trylock.c create mode 100644 libpthread/nptl/sysdeps/nios2/pthreaddef.h create mode 100644 libpthread/nptl/sysdeps/nios2/tcb-offsets.sym create mode 100644 libpthread/nptl/sysdeps/nios2/tls.h create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/Makefile create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/Makefile.arch create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/bits/pthreadtypes.h create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/bits/semaphore.h create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/clone.S create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/createthread.c create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/fork.c create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/lowlevellock.h create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/pt-gettimeofday.c create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/pthread_once.c create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h create mode 100644 libpthread/nptl/sysdeps/unix/sysv/linux/nios2/vfork.S diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index cb2d4d1a2..719218fd8 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -522,7 +522,6 @@ config UCLIBC_HAS_THREADS_NATIVE !TARGET_ia64 && \ !TARGET_m68k && \ !TARGET_nds32 && \ - !TARGET_nios2 && \ !TARGET_or1k && \ ARCH_USE_MMU help diff --git a/extra/Configs/Config.nios2 b/extra/Configs/Config.nios2 index 2310a46c0..958607cb3 100644 --- a/extra/Configs/Config.nios2 +++ b/extra/Configs/Config.nios2 @@ -11,6 +11,4 @@ config FORCE_OPTIONS_FOR_ARCH bool default y select ARCH_LITTLE_ENDIAN - select ARCH_HAS_NO_MMU select ARCH_HAS_NO_LDSO - select HAVE_NO_PIC diff --git a/include/elf.h b/include/elf.h index cca3d3832..e0937b732 100644 --- a/include/elf.h +++ b/include/elf.h @@ -3081,53 +3081,56 @@ typedef Elf32_Addr Elf32_Conflict; /* Andes ELF Version 1.3 and after */ #define E_NDS32_ELF_VER_1_3 0x1 -/* NIOS relocations. */ -#define R_NIOS_NONE 0 -#define R_NIOS_32 1 /* A 32 bit absolute relocation.*/ -#define R_NIOS_LO16_LO5 2 /* A LO-16 5 bit absolute relocation. */ -#define R_NIOS_LO16_HI11 3 /* A LO-16 top 11 bit absolute relocation. */ -#define R_NIOS_HI16_LO5 4 /* A HI-16 5 bit absolute relocation. */ -#define R_NIOS_HI16_HI11 5 /* A HI-16 top 11 bit absolute relocation. */ -#define R_NIOS_PCREL6 6 /* A 6 bit relative relocation. */ -#define R_NIOS_PCREL8 7 /* An 8 bit relative relocation. */ -#define R_NIOS_PCREL11 8 /* An 11 bit relative relocation. */ -#define R_NIOS_16 9 /* A 16 bit absolute relocation. */ -#define R_NIOS_H_LO5 10 /* Low 5-bits of absolute relocation in halfwords. */ -#define R_NIOS_H_HI11 11 /* Top 11 bits of 16-bit absolute relocation in halfwords. */ -#define R_NIOS_H_XLO5 12 /* Low 5 bits of top 16-bits of 32-bit absolute relocation in halfwords. */ -#define R_NIOS_H_XHI11 13 /* Top 11 bits of top 16-bits of 32-bit absolute relocation in halfwords. */ -#define R_NIOS_H_16 14 /* Half-word @h value */ -#define R_NIOS_H_32 15 /* Word @h value */ -#define R_NIOS_GNU_VTINHERIT 200 /* GNU extension to record C++ vtable hierarchy */ -#define R_NIOS_GNU_VTENTRY 201 /* GNU extension to record C++ vtable member usage */ -/* Keep this the last entry. */ -#define R_NIOS_NUM 202 - -/* NIOS II relocations */ -#define R_NIOS2_NONE 0 -#define R_NIOS2_S16 1 -#define R_NIOS2_U16 2 -#define R_NIOS2_PCREL16 3 -#define R_NIOS2_CALL26 4 -#define R_NIOS2_IMM5 5 -#define R_NIOS2_CACHE_OPX 6 -#define R_NIOS2_IMM6 7 -#define R_NIOS2_IMM8 8 -#define R_NIOS2_HI16 9 -#define R_NIOS2_LO16 10 -#define R_NIOS2_HIADJ16 11 -#define R_NIOS2_BFD_RELOC_32 12 -#define R_NIOS2_BFD_RELOC_16 13 -#define R_NIOS2_BFD_RELOC_8 14 -#define R_NIOS2_GPREL 15 -#define R_NIOS2_GNU_VTINHERIT 16 -#define R_NIOS2_GNU_VTENTRY 17 -#define R_NIOS2_UJMP 18 -#define R_NIOS2_CJMP 19 -#define R_NIOS2_CALLR 20 -#define R_NIOS2_ALIGN 21 -/* Keep this the last entry. */ -#define R_NIOS2_NUM 22 +/* Legal values for d_tag (dynamic entry type). */ +#define DT_NIOS2_GP 0x70000002 /* Address of _gp. */ + +/* Nios II relocations. */ +#define R_NIOS2_NONE 0 /* No reloc. */ +#define R_NIOS2_S16 1 /* Direct signed 16 bit. */ +#define R_NIOS2_U16 2 /* Direct unsigned 16 bit. */ +#define R_NIOS2_PCREL16 3 /* PC relative 16 bit. */ +#define R_NIOS2_CALL26 4 /* Direct call. */ +#define R_NIOS2_IMM5 5 /* 5 bit constant expression. */ +#define R_NIOS2_CACHE_OPX 6 /* 5 bit expression, shift 22. */ +#define R_NIOS2_IMM6 7 /* 6 bit constant expression. */ +#define R_NIOS2_IMM8 8 /* 8 bit constant expression. */ +#define R_NIOS2_HI16 9 /* High 16 bit. */ +#define R_NIOS2_LO16 10 /* Low 16 bit. */ +#define R_NIOS2_HIADJ16 11 /* High 16 bit, adjusted. */ +#define R_NIOS2_BFD_RELOC_32 12 /* 32 bit symbol value + addend. */ +#define R_NIOS2_BFD_RELOC_16 13 /* 16 bit symbol value + addend. */ +#define R_NIOS2_BFD_RELOC_8 14 /* 8 bit symbol value + addend. */ +#define R_NIOS2_GPREL 15 /* 16 bit GP pointer offset. */ +#define R_NIOS2_GNU_VTINHERIT 16 /* GNU C++ vtable hierarchy. */ +#define R_NIOS2_GNU_VTENTRY 17 /* GNU C++ vtable member usage. */ +#define R_NIOS2_UJMP 18 /* Unconditional branch. */ +#define R_NIOS2_CJMP 19 /* Conditional branch. */ +#define R_NIOS2_CALLR 20 /* Indirect call through register. */ +#define R_NIOS2_ALIGN 21 /* Alignment requirement for linker relaxation. */ +#define R_NIOS2_GOT16 22 /* 16 bit GOT entry. */ +#define R_NIOS2_CALL16 23 /* 16 bit GOT entry for function. */ +#define R_NIOS2_GOTOFF_LO 24 /* %lo of offset to GOT pointer. */ +#define R_NIOS2_GOTOFF_HA 25 /* %hiadj of offset to GOT pointer. */ +#define R_NIOS2_PCREL_LO 26 /* %lo of PC relative offset. */ +#define R_NIOS2_PCREL_HA 27 /* %hiadj of PC relative offset. */ +#define R_NIOS2_TLS_GD16 28 /* 16 bit GOT offset for TLS GD. */ +#define R_NIOS2_TLS_LDM16 29 /* 16 bit GOT offset for TLS LDM. */ +#define R_NIOS2_TLS_LDO16 30 /* 16 bit module relative offset. */ +#define R_NIOS2_TLS_IE16 31 /* 16 bit GOT offset for TLS IE. */ +#define R_NIOS2_TLS_LE16 32 /* 16 bit LE TP-relative offset. */ +#define R_NIOS2_TLS_DTPMOD 33 /* Module number. */ +#define R_NIOS2_TLS_DTPREL 34 /* Module-relative offset. */ +#define R_NIOS2_TLS_TPREL 35 /* TP-relative offset. */ +#define R_NIOS2_COPY 36 /* Copy symbol at runtime. */ +#define R_NIOS2_GLOB_DAT 37 /* Create GOT entry. */ +#define R_NIOS2_JUMP_SLOT 38 /* Create PLT entry. */ +#define R_NIOS2_RELATIVE 39 /* Adjust by program base. */ +#define R_NIOS2_GOTOFF 40 /* 16 bit offset to GOT pointer. */ +#define R_NIOS2_CALL26_NOAT 41 /* Direct call in .noat section. */ +#define R_NIOS2_GOT_LO 42 /* %lo() of GOT entry. */ +#define R_NIOS2_GOT_HA 43 /* %hiadj() of GOT entry. */ +#define R_NIOS2_CALL_LO 44 /* %lo() of function GOT entry. */ +#define R_NIOS2_CALL_HA 45 /* %hiadj() of function GOT entry. */ /* Xtensa-specific declarations */ diff --git a/ldso/ldso/nios2/dl-debug.h b/ldso/ldso/nios2/dl-debug.h new file mode 100644 index 000000000..1fb596ae3 --- /dev/null +++ b/ldso/ldso/nios2/dl-debug.h @@ -0,0 +1,18 @@ +/* nios2 shared library loader suppport */ + +static const char * const _dl_reltypes_tab[] = + { + "R_NIOS2_NONE", + "R_NIOS2_BFD_RELOC_32", + "R_NIOS2_BFD_RELOC_16", + "R_NIOS2_BFD_RELOC_8", + "R_NIOS2_GNU_VTINHERIT", + "R_NIOS2_GNU_VTENTRY", + "R_NIOS2_GOT16", + "R_NIOS2_CALL16", + "R_NIOS2_JUMP_SLOT", + "R_NIOS2_GLOB_DAT", + "R_NIOS2_RELATIVE", + "R_NIOS2_GOTOFF", + "R_NIOS2_COPY", + }; diff --git a/ldso/ldso/nios2/dl-inlines.h b/ldso/ldso/nios2/dl-inlines.h new file mode 100644 index 000000000..7cf7e4afd --- /dev/null +++ b/ldso/ldso/nios2/dl-inlines.h @@ -0,0 +1,12 @@ + +unsigned int +internal_function +_dl_nios2_get_gp_value (struct link_map *main_map) +{ + ElfW(Dyn) *dyn = main_map->l_ld; + for (dyn = main_map->l_ld; dyn->d_tag != DT_NULL; ++dyn) + if (dyn->d_tag == DT_NIOS2_GP) + return (unsigned int)(dyn->d_un.d_ptr); + return 0; +} + diff --git a/ldso/ldso/nios2/dl-startup.h b/ldso/ldso/nios2/dl-startup.h new file mode 100644 index 000000000..982e55532 --- /dev/null +++ b/ldso/ldso/nios2/dl-startup.h @@ -0,0 +1,34 @@ +__asm__ ("\ + .text\n\ + .globl _start\n\ + .type _start, %function\n\ +_start:\n\ + mov r4, sp\n\ + br _dl_start\n\ + mov r16, r4\n\ + jmp r16\n\ +"); + +/* + * Get a pointer to the argv array. On many platforms this can be just + * the address of the first argument, on other platforms we need to + * do something a little more subtle here. + */ +#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1) + +/* The ld.so library requires relocations */ +#define ARCH_NEEDS_BOOTSTRAP_RELOCS + +static __always_inline +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, + unsigned long symbol_addr, unsigned long load_addr, attribute_unused Elf32_Sym *symtab) +{ + switch (ELF_R_TYPE(rpnt->r_info)) { + case R_NIOS2_RELATIVE: + *reloc_addr = load_addr + rpnt->r_addend; + break; + default: + _dl_exit(1); + break; + } +} diff --git a/ldso/ldso/nios2/dl-syscalls.h b/ldso/ldso/nios2/dl-syscalls.h new file mode 100644 index 000000000..f40c4fd31 --- /dev/null +++ b/ldso/ldso/nios2/dl-syscalls.h @@ -0,0 +1 @@ +/* stub for arch-specific syscall issues */ diff --git a/ldso/ldso/nios2/dl-sysdep.h b/ldso/ldso/nios2/dl-sysdep.h new file mode 100644 index 000000000..5ae3ce311 --- /dev/null +++ b/ldso/ldso/nios2/dl-sysdep.h @@ -0,0 +1,74 @@ +/* Use reloca */ +#define ELF_USES_RELOCA + +#include + +/* Initialise the GOT */ +#define INIT_GOT(GOT_BASE,MODULE) \ +do { \ + GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \ + GOT_BASE[1] = (unsigned long) MODULE; \ +} while(0) + +/* Here we define the magic numbers that this dynamic loader should accept */ + +#define MAGIC1 EM_ALTERA_NIOS2 +#undef MAGIC2 +/* Used for error messages */ +#define ELF_TARGET "nios2" + +struct elf_resolve; +unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry); + +/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so + PLT entries should not be allowed to define the value. + ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one + of the main executable's symbols, as for a COPY reloc. */ +#define elf_machine_type_class(type) \ + ((((type) == R_NIOS2_JUMP_SLOT \ + || (type) == R_NIOS2_TLS_DTPMOD \ + || (type) == R_NIOS2_TLS_DTPREL \ + || (type) == R_NIOS2_TLS_TPREL) * ELF_RTYPE_CLASS_PLT) \ + | (((type) == R_NIOS2_COPY) * ELF_RTYPE_CLASS_COPY)) + +/* Return the link-time address of _DYNAMIC. Conveniently, this is the + first element of the GOT. */ +static inline Elf32_Addr +elf_machine_dynamic (void) +{ + Elf32_Addr *dynamic; + int tmp; + __asm__ ("nextpc\t%0\n\t" + "1: movhi\t%1, %%hiadj(_GLOBAL_OFFSET_TABLE_ - 1b)\n\t" + "addi\t%1, %1, %%lo(_GLOBAL_OFFSET_TABLE_ - 1b)\n\t" + "add\t%0, %0, %1\n" + : "=r" (dynamic), "=r" (tmp)); + return *dynamic; +} + +/* Return the run-time load address of the shared object. */ +static inline Elf32_Addr +elf_machine_load_address (void) +{ + Elf32_Addr result; + int tmp; + __asm__ ("nextpc\t%0\n\t" + "1: movhi\t%1, %%hiadj(1b)\n\t" + "addi\t%1, %1, %%lo(1b)\n\t" + "sub\t%0, %0, %1\n" + : "=r" (result), "=r" (tmp)); + return result; +} + +static __always_inline void +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr, + Elf32_Word relative_count) +{ + Elf32_Rel * rpnt = (void *) rel_addr; + do { + Elf32_Addr *const reloc_addr = (void *) (load_off + (rpnt)->r_offset); + + *reloc_addr += load_off; + } while (--relative_count); +} + diff --git a/ldso/ldso/nios2/elfinterp.c b/ldso/ldso/nios2/elfinterp.c new file mode 100644 index 000000000..bdbaa3383 --- /dev/null +++ b/ldso/ldso/nios2/elfinterp.c @@ -0,0 +1,297 @@ +/* nios2 ELF shared library loader suppport + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2004 Erik Andersen + * + * 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. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE 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 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 "ldso.h" + +/* Program to load an ELF binary on a linux system, and run it. + References to symbols in sharable libraries can be resolved by either + an ELF sharable library or a linux style of shared library. */ + +extern int _dl_linux_resolve(void); + +unsigned long +_dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) +{ + ELF_RELOC *this_reloc; + char *strtab; + ElfW(Sym) *symtab; + int symtab_index; + char *rel_addr; + char *new_addr; + char **got_addr; + ElfW(Addr) instr_addr; + char *symname; + + rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL]; + this_reloc = (ELF_RELOC *)(rel_addr + reloc_entry); + symtab_index = ELF_R_SYM(this_reloc->r_info); + + symtab = (ElfW(Sym) *)tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + symname = strtab + symtab[symtab_index].st_name; + + /* Address of the jump instruction to fix up. */ + instr_addr = (this_reloc->r_offset + tpnt->loadaddr); + got_addr = (char **)instr_addr; + + /* Get the address of the GOT entry. */ + new_addr = _dl_find_hash(symname, &_dl_loaded_modules->symbol_scope, tpnt, ELF_RTYPE_CLASS_PLT, NULL); + if (unlikely(!new_addr)) { + _dl_dprintf(2, "%s: Can't resolve symbol '%s'\n", _dl_progname, symname); + _dl_exit(1); + } + +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_bindings) { + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname); + if (_dl_debug_detail) + _dl_dprintf(_dl_debug_file, + "\tpatched: %x ==> %x @ %x\n", + *got_addr, new_addr, got_addr); + } + if (!_dl_debug_nofixups) +#endif + *got_addr = new_addr; + + return (unsigned long)new_addr; +} + +static int +_dl_parse(struct elf_resolve *tpnt, struct r_scope_elem *scope, + unsigned long rel_addr, unsigned long rel_size, + int (*reloc_fnc)(struct elf_resolve *tpnt, struct r_scope_elem *scope, + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab)) +{ + unsigned int i; + char *strtab; + ElfW(Sym) *symtab; + ELF_RELOC *rpnt; + int symtab_index; + + /* Parse the relocation information. */ + rpnt = (ELF_RELOC *)rel_addr; + rel_size /= sizeof(ELF_RELOC); + + symtab = (ElfW(Sym) *)tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + + for (i = 0; i < rel_size; i++, rpnt++) { + int res; + + symtab_index = ELF_R_SYM(rpnt->r_info); + + debug_sym(symtab, strtab, symtab_index); + debug_reloc(symtab, strtab, rpnt); + + res = reloc_fnc(tpnt, scope, rpnt, symtab, strtab); + + if (res == 0) + continue; + + _dl_dprintf(2, "\n%s: ", _dl_progname); + + if (symtab_index) + _dl_dprintf(2, "symbol '%s': ", + strtab + symtab[symtab_index].st_name); + + if (unlikely(res < 0)) { + int reloc_type = ELF_R_TYPE(rpnt->r_info); + + _dl_dprintf(2, "can't handle reloc type " +#if defined (__SUPPORT_LD_DEBUG__) + "%s\n", _dl_reltypes(reloc_type)); +#else + "%x\n", reloc_type); +#endif + _dl_exit(-res); + } else if (unlikely(res > 0)) { + _dl_dprintf(2, "can't resolve symbol\n"); + return res; + } + } + + return 0; +} + +static int +_dl_do_reloc(struct elf_resolve *tpnt, struct r_scope_elem *scope, + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab) +{ + int reloc_type; + int symtab_index; + char *symname; +#if defined USE_TLS && USE_TLS + struct elf_resolve *tls_tpnt = NULL; +#endif + struct symbol_ref sym_ref; + ElfW(Addr) *reloc_addr; + ElfW(Addr) symbol_addr; +#if defined (__SUPPORT_LD_DEBUG__) + ElfW(Addr) old_val; +#endif + + reloc_addr = (ElfW(Addr)*)(tpnt->loadaddr + (unsigned long)rpnt->r_offset); + reloc_type = ELF_R_TYPE(rpnt->r_info); + symtab_index = ELF_R_SYM(rpnt->r_info); + sym_ref.sym = &symtab[symtab_index]; + sym_ref.tpnt = NULL; + symbol_addr = 0; + symname = strtab + sym_ref.sym->st_name; + + if (symtab_index) { + symbol_addr = (ElfW(Addr))_dl_find_hash(symname, scope, tpnt, + elf_machine_type_class(reloc_type), &sym_ref); + /* + * We want to allow undefined references to weak symbols - this + * might have been intentional. We should not be linking local + * symbols here, so all bases should be covered. + */ + if (unlikely(!symbol_addr && (ELF_ST_TYPE(sym_ref.sym->st_info) != STT_TLS) + && (ELF_ST_BIND(sym_ref.sym->st_info) != STB_WEAK))) { + /* This may be non-fatal if called from dlopen. */ + return 1; + } +#if defined USE_TLS && USE_TLS + tls_tpnt = sym_ref.tpnt; +#endif + } else { + /* Relocs against STN_UNDEF are usually treated as using a + * symbol value of zero, and using the module containing the + * reloc itself. */ + symbol_addr = sym_ref.sym->st_value; +#if defined USE_TLS && USE_TLS + tls_tpnt = tpnt; +#endif + } + + +#if defined (__SUPPORT_LD_DEBUG__) + if (reloc_addr) { + old_val = *reloc_addr; + } else { + old_val = 0; + } +#endif + + switch (reloc_type) { + case R_NIOS2_NONE: + break; + + case R_NIOS2_BFD_RELOC_32: + case R_NIOS2_GLOB_DAT: + case R_NIOS2_JUMP_SLOT: + *reloc_addr = symbol_addr + rpnt->r_addend; + break; + + case R_NIOS2_RELATIVE: + *reloc_addr = (unsigned long)tpnt->loadaddr + rpnt->r_addend; + break; + + case R_NIOS2_COPY: + if (symbol_addr) { +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_move) + _dl_dprintf(_dl_debug_file, + "\t%s move %d bytes from %x to %x\n", + symname, sym_ref.sym->st_size, + symbol_addr, reloc_addr); +#endif + + _dl_memcpy((char *)reloc_addr, + (char *)symbol_addr, + sym_ref.sym->st_size); + } + break; + + default: + return -1; /* Calls _dl_exit(1). */ + } + +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n", + old_val, *reloc_addr, reloc_addr); +#endif + + return 0; +} + +static int +_dl_do_lazy_reloc(struct elf_resolve *tpnt, struct r_scope_elem *scope, + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab) +{ + int reloc_type; + ElfW(Addr) *reloc_addr; +#if defined (__SUPPORT_LD_DEBUG__) + ElfW(Addr) old_val; +#endif + + (void)scope; + (void)strtab; + + reloc_addr = (ElfW(Addr)*)(tpnt->loadaddr + rpnt->r_offset); + reloc_type = ELF_R_TYPE(rpnt->r_info); + +#if defined (__SUPPORT_LD_DEBUG__) + old_val = *reloc_addr; +#endif + + switch (reloc_type) { + case R_NIOS2_NONE: + break; + case R_NIOS2_JUMP_SLOT: + *reloc_addr += (unsigned long)tpnt->loadaddr; + break; + default: + _dl_exit(1); + } + +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatched_lazy: %x ==> %x @ %x\n", + old_val, *reloc_addr, reloc_addr); +#endif + + return 0; +} + +void +_dl_parse_lazy_relocation_information(struct dyn_elf *rpnt, + unsigned long rel_addr, unsigned long rel_size) +{ + (void)_dl_parse(rpnt->dyn, NULL, rel_addr, rel_size, _dl_do_lazy_reloc); +} + +int +_dl_parse_relocation_information(struct dyn_elf *rpnt, + struct r_scope_elem *scope, unsigned long rel_addr, unsigned long rel_size) +{ + return _dl_parse(rpnt->dyn, scope, rel_addr, rel_size, _dl_do_reloc); +} diff --git a/ldso/ldso/nios2/resolve.S b/ldso/ldso/nios2/resolve.S new file mode 100644 index 000000000..a71839e17 --- /dev/null +++ b/ldso/ldso/nios2/resolve.S @@ -0,0 +1,73 @@ +/* PLT trampolines. Nios II version. + Copyright (C) 2005-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +/* This code is used in dl-runtime.c to call the `fixup' function + and then redirect to the address it returns. */ + + .text + .align 4 + .globl _dl_linux_resolver + .globl _dl_linux_resolve + .type _dl_linux_resolve,@function + +_dl_linux_resolve: +/* The runtime resolver receives the original function arguments in r4 + through r7, the shared library identifier from GOT[1]? in r14, and the + relocation index times four in r15. It updates the corresponding PLT GOT + entry so that the PLT entry will transfer control directly to the target + in the future, and then transfers control to the target. */ + /* Save arguments and return address. */ + subi sp, sp, 28 + stw r22, 24(sp) + stw r8, 20(sp) /* save r8, because this might be a call to mcount */ + stw r7, 16(sp) + stw r6, 12(sp) + stw r5, 8(sp) + stw r4, 4(sp) + stw ra, 0(sp) + + /* Get pointer to linker struct. */ + mov r4, r14 + + /* Get the relocation offset. We're given a multiple of 4 and + need a multiple of 12, so multiply by 3. */ + slli r5, r15, 1 + add r5, r5, r15 + + /* Call the fixup routine. */ + nextpc r22 +1: movhi r2, %hiadj(_gp_got - 1b) + addi r2, r2, %lo(_gp_got - 1b) + add r22, r22, r2 + ldw r2, %call(_dl_linux_resolver)(r22) + callr r2 + + /* Restore the arguments and return address. */ + ldw ra, 0(sp) + ldw r4, 4(sp) + ldw r5, 8(sp) + ldw r6, 12(sp) + ldw r7, 16(sp) + ldw r8, 20(sp) + ldw r22, 24(sp) + addi sp, sp, 28 + + /* Jump to the newly found address. */ + jmp r2 + + .size _dl_linux_resolve, . - _dl_linux_resolve diff --git a/libc/sysdeps/linux/nios2/Makefile.arch b/libc/sysdeps/linux/nios2/Makefile.arch index e36e06b52..887ce5aa4 100644 --- a/libc/sysdeps/linux/nios2/Makefile.arch +++ b/libc/sysdeps/linux/nios2/Makefile.arch @@ -1,12 +1,5 @@ # Makefile for uClibc -# -# Copyright (C) 2000-2005 Erik Andersen -# # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. -# -CSRC-y := brk.c syscall.c - -SSRC-y := \ - __longjmp.S bsd-_setjmp.S bsd-setjmp.S setjmp.S \ - vfork.S clone.S +CSRC-y := __syscall_error.c +SSRC-y := __longjmp.S setjmp.S vfork.S clone.S diff --git a/libc/sysdeps/linux/nios2/__longjmp.S b/libc/sysdeps/linux/nios2/__longjmp.S index 7df599768..3f112f15f 100644 --- a/libc/sysdeps/linux/nios2/__longjmp.S +++ b/libc/sysdeps/linux/nios2/__longjmp.S @@ -1,48 +1,39 @@ -/* - * libc/sysdeps/linux/nios2/__longjmp.S - * - * Copyright (C) 2004,05,06 Microtronix Datacom Ltd - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License. See the file COPYING.LIB in the main - * directory of this archive for more details. - * - * Written by Wentao Xu - * - */ +/* longjmp for Nios II. + Copyright (C) 2015-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. -#include -#include + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ -.globl __longjmp -.type __longjmp,@function -.balign 4 +#include +#include -__longjmp: - /* return value is in r5*/ +ENTRY (__longjmp) mov r2, r5 - - /* jmp_buf in r4, restore regs. */ - ldw r16, (JB_REGS+ 0)(r4) - ldw r17, (JB_REGS+ 4)(r4) - ldw r18, (JB_REGS+ 8)(r4) - ldw r19, (JB_REGS+12)(r4) - ldw r20, (JB_REGS+16)(r4) - ldw r21, (JB_REGS+20)(r4) - ldw r22, (JB_REGS+24)(r4) - ldw r23, (JB_REGS+28)(r4) - - ldw ra, JB_PC(r4) - ldw fp, JB_FP(r4) - ldw gp, JB_GP(r4) - ldw sp, JB_SP(r4) - -#ifdef __UCLIBC_HAS_FPU__ - RESTORE_FPU r4 JB_FPREGS -#endif - /* return to saved RA */ + ldw r16, (JB_R16*4)(r4) + ldw r17, (JB_R17*4)(r4) + ldw r18, (JB_R18*4)(r4) + ldw r19, (JB_R19*4)(r4) + ldw r20, (JB_R20*4)(r4) + ldw r21, (JB_R21*4)(r4) + ldw r22, (JB_R22*4)(r4) + ldw fp, (JB_FP*4)(r4) + ldw ra, (JB_RA*4)(r4) + ldw sp, (JB_SP*4)(r4) + ret -.size __longjmp,.-__longjmp +END (__longjmp) libc_hidden_def(__longjmp) diff --git a/libc/sysdeps/linux/nios2/__syscall_error.c b/libc/sysdeps/linux/nios2/__syscall_error.c new file mode 100644 index 000000000..2b642e816 --- /dev/null +++ b/libc/sysdeps/linux/nios2/__syscall_error.c @@ -0,0 +1,18 @@ +/* Wrapper for setting errno. + * + * Copyright (C) 2000-2006 Erik Andersen + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#include +#include + +/* This routine is jumped to by all the syscall handlers, to stash + * an error number into errno. */ +int __syscall_error(int err_no) attribute_hidden; +int __syscall_error(int err_no) +{ + __set_errno(-err_no); + return -1; +} diff --git a/libc/sysdeps/linux/nios2/bits/fcntl.h b/libc/sysdeps/linux/nios2/bits/fcntl.h index d8386d65c..4fe1ee396 100644 --- a/libc/sysdeps/linux/nios2/bits/fcntl.h +++ b/libc/sysdeps/linux/nios2/bits/fcntl.h @@ -44,9 +44,9 @@ #define O_ASYNC 020000 #ifdef __USE_GNU -# define O_DIRECTORY 040000 /* Must be a directory. */ -# define O_NOFOLLOW 0100000 /* Do not follow links. */ -# define O_DIRECT 0200000 /* Direct disk access. */ +# define O_DIRECTORY 0200000 /* Must be a directory. */ +# define O_NOFOLLOW 0400000 /* Do not follow links. */ +# define O_DIRECT 040000 /* Direct disk access. */ # define O_NOATIME 01000000 /* Do not set atime. */ # define O_CLOEXEC 02000000 /* set close_on_exec */ # define O_PATH 010000000 /* Resolve pathname but do not open file. */ diff --git a/libc/sysdeps/linux/nios2/bits/kernel_stat.h b/libc/sysdeps/linux/nios2/bits/kernel_stat.h deleted file mode 100644 index 99a6cba97..000000000 --- a/libc/sysdeps/linux/nios2/bits/kernel_stat.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _BITS_STAT_STRUCT_H -#define _BITS_STAT_STRUCT_H - -/* This file provides whatever this particular arch's kernel thinks - * struct kernel_stat should look like... It turns out each arch has a - * different opinion on the subject... */ - -struct kernel_stat { - unsigned short st_dev; - unsigned short __pad1; - unsigned long st_ino; - unsigned short st_mode; - unsigned short st_nlink; - unsigned short st_uid; - unsigned short st_gid; - unsigned short st_rdev; - unsigned short __pad2; - unsigned long st_size; - unsigned long st_blksize; - unsigned long st_blocks; - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - unsigned long __unused4; - unsigned long __unused5; -}; - -struct kernel_stat64 { - unsigned short st_dev; - unsigned char __pad0[10]; -#define _HAVE_STAT64___ST_INO - unsigned long __st_ino; - unsigned int st_mode; - unsigned int st_nlink; - unsigned long st_uid; - unsigned long st_gid; - unsigned short st_rdev; - unsigned char __pad3[10]; - long long st_size; - unsigned long st_blksize; - unsigned long st_blocks; /* Number 512-byte blocks allocated. */ - unsigned long __pad4; /* future possible st_blocks high bits */ - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - unsigned long long st_ino; -}; - -#endif /* _BITS_STAT_STRUCT_H */ - diff --git a/libc/sysdeps/linux/nios2/bits/kernel_types.h b/libc/sysdeps/linux/nios2/bits/kernel_types.h index 004f9c746..5c122b5b1 100644 --- a/libc/sysdeps/linux/nios2/bits/kernel_types.h +++ b/libc/sysdeps/linux/nios2/bits/kernel_types.h @@ -10,10 +10,10 @@ typedef unsigned long __kernel_dev_t; typedef unsigned long __kernel_ino_t; typedef unsigned short __kernel_mode_t; -typedef unsigned short __kernel_nlink_t; +typedef unsigned long __kernel_nlink_t; typedef long __kernel_off_t; typedef int __kernel_pid_t; -typedef unsigned short __kernel_ipc_pid_t; +typedef int __kernel_ipc_pid_t; typedef unsigned int __kernel_uid_t; typedef unsigned int __kernel_gid_t; typedef unsigned int __kernel_size_t; @@ -22,6 +22,8 @@ typedef int __kernel_ptrdiff_t; typedef long __kernel_time_t; typedef long __kernel_suseconds_t; typedef long __kernel_clock_t; +typedef int __kernel_timer_t; +typedef int __kernel_clockid_t; typedef int __kernel_daddr_t; typedef char * __kernel_caddr_t; typedef unsigned short __kernel_uid16_t; diff --git a/libc/sysdeps/linux/nios2/bits/setjmp.h b/libc/sysdeps/linux/nios2/bits/setjmp.h index bc6f30848..2fbb39562 100644 --- a/libc/sysdeps/linux/nios2/bits/setjmp.h +++ b/libc/sysdeps/linux/nios2/bits/setjmp.h @@ -1,5 +1,5 @@ -/* Define the machine-dependent type `jmp_buf'. Nios2 version. - Copyright (C) 1992,93,95,97,2000 Free Software Foundation, Inc. +/* Define the machine-dependent type `jmp_buf'. Nios II version. + Copyright (C) 1992-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -13,7 +13,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see + License along with the GNU C Library. If not, see . */ #ifndef _BITS_SETJMP_H @@ -23,27 +23,9 @@ # error "Never include directly; use instead." #endif -typedef struct -{ - /* Callee-saved registers r16 through r23. */ - unsigned long __regs[8]; +/* Saves r16-r22 (callee-saved, including GOT pointer), fp (frame pointer), + ra (return address), and sp (stack pointer). */ - /* Program counter. */ - unsigned long __pc; - - /* Stack pointer. */ - unsigned long __sp; - - /* The frame pointer. */ - unsigned long __fp; - - /* The global pointer. */ - unsigned long __gp; - - /* floating point regs, if any */ -#ifdef __UCLIBC_HAS_FPU__ - unsigned long __fpregs[64]; -#endif -} __jmp_buf[1]; +typedef int __jmp_buf[10]; #endif /* bits/setjmp.h */ diff --git a/libc/sysdeps/linux/nios2/bits/stat.h b/libc/sysdeps/linux/nios2/bits/stat.h deleted file mode 100644 index 6e3b0198c..000000000 --- a/libc/sysdeps/linux/nios2/bits/stat.h +++ /dev/null @@ -1,167 +0,0 @@ -/* Copyright (C) 1992,95,96,97,98,99,2000,2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _SYS_STAT_H -# error "Never include directly; use instead." -#endif - -/* Versions of the `struct stat' data structure. */ -#define _STAT_VER_LINUX_OLD 1 -#define _STAT_VER_KERNEL 1 -#define _STAT_VER_SVR4 2 -#define _STAT_VER_LINUX 3 -#define _STAT_VER _STAT_VER_LINUX /* The one defined below. */ - -/* Versions of the `xmknod' interface. */ -#define _MKNOD_VER_LINUX 1 -#define _MKNOD_VER_SVR4 2 -#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */ - - -struct stat - { - __dev_t st_dev; /* Device. */ - unsigned short int __pad1; -#ifndef __USE_FILE_OFFSET64 - __ino_t st_ino; /* File serial number. */ -#else - __ino_t __st_ino; /* 32bit file serial number. */ -#endif - __mode_t st_mode; /* File mode. */ - __nlink_t st_nlink; /* Link count. */ - __uid_t st_uid; /* User ID of the file's owner. */ - __gid_t st_gid; /* Group ID of the file's group.*/ - __dev_t st_rdev; /* Device number, if device. */ - unsigned short int __pad2; -#ifndef __USE_FILE_OFFSET64 - __off_t st_size; /* Size of file, in bytes. */ -#else - __off64_t st_size; /* Size of file, in bytes. */ -#endif - __blksize_t st_blksize; /* Optimal block size for I/O. */ - -#ifndef __USE_FILE_OFFSET64 - __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */ -#else - __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */ -#endif -#ifdef __USE_MISC - /* Nanosecond resolution timestamps are stored in a format - equivalent to 'struct timespec'. This is the type used - whenever possible but the Unix namespace rules do not allow the - identifier 'timespec' to appear in the header. - Therefore we have to handle the use of this header in strictly - standard-compliant sources special. */ - struct timespec st_atim; /* Time of last access. */ - struct timespec st_mtim; /* Time of last modification. */ - struct timespec st_ctim; /* Time of last status change. */ -# define st_atime st_atim.tv_sec /* Backward compatibility. */ -# define st_mtime st_mtim.tv_sec -# define st_ctime st_ctim.tv_sec -#else - __time_t st_atime; /* Time of last access. */ - unsigned long int st_atimensec; /* Nscecs of last access. */ - __time_t st_mtime; /* Time of last modification. */ - unsigned long int st_mtimensec; /* Nsecs of last modification. */ - __time_t st_ctime; /* Time of last status change. */ - unsigned long int st_ctimensec; /* Nsecs of last status change. */ -#endif -#ifndef __USE_FILE_OFFSET64 - unsigned long int __unused4; - unsigned long int __unused5; -#else - __ino64_t st_ino; /* File serial number. */ -#endif - }; - -#ifdef __USE_LARGEFILE64 -struct stat64 - { - __dev_t st_dev; /* Device. */ - unsigned int __pad1; - - __ino_t __st_ino; /* 32bit file serial number. */ - __mode_t st_mode; /* File mode. */ - __nlink_t st_nlink; /* Link count. */ - __uid_t st_uid; /* User ID of the file's owner. */ - __gid_t st_gid; /* Group ID of the file's group.*/ - __dev_t st_rdev; /* Device number, if device. */ - unsigned int __pad2; - __off64_t st_size; /* Size of file, in bytes. */ - __blksize_t st_blksize; /* Optimal block size for I/O. */ - - __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */ -#ifdef __USE_MISC - /* Nanosecond resolution timestamps are stored in a format - equivalent to 'struct timespec'. This is the type used - whenever possible but the Unix namespace rules do not allow the - identifier 'timespec' to appear in the header. - Therefore we have to handle the use of this header in strictly - standard-compliant sources special. */ - struct timespec st_atim; /* Time of last access. */ - struct timespec st_mtim; /* Time of last modification. */ - struct timespec st_ctim; /* Time of last status change. */ -#else - __time_t st_atime; /* Time of last access. */ - unsigned long int st_atimensec; /* Nscecs of last access. */ - __time_t st_mtime; /* Time of last modification. */ - unsigned long int st_mtimensec; /* Nsecs of last modification. */ - __time_t st_ctime; /* Time of last status change. */ - unsigned long int st_ctimensec; /* Nsecs of last status change. */ -#endif - __ino64_t st_ino; /* File serial number. */ - }; -#endif - -/* Tell code we have these members. */ -#define _STATBUF_ST_BLKSIZE -#define _STATBUF_ST_RDEV -/* Nanosecond resolution time values are supported. */ -#define _STATBUF_ST_NSEC - -/* Encoding of the file mode. */ - -#define __S_IFMT 0170000 /* These bits determine file type. */ - -/* File types. */ -#define __S_IFDIR 0040000 /* Directory. */ -#define __S_IFCHR 0020000 /* Character device. */ -#define __S_IFBLK 0060000 /* Block device. */ -#define __S_IFREG 0100000 /* Regular file. */ -#define __S_IFIFO 0010000 /* FIFO. */ -#define __S_IFLNK 0120000 /* Symbolic link. */ -#define __S_IFSOCK 0140000 /* Socket. */ - -/* POSIX.1b objects. Note that these macros always evaluate to zero. But - they do it by enforcing the correct use of the macros. */ -#define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode) -#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode) -#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode) - -/* Protection bits. */ - -#define __S_ISUID 04000 /* Set user ID on execution. */ -#define __S_ISGID 02000 /* Set group ID on execution. */ -#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */ -#define __S_IREAD 0400 /* Read by owner. */ -#define __S_IWRITE 0200 /* Write by owner. */ -#define __S_IEXEC 0100 /* Execute by owner. */ - -#ifdef __USE_ATFILE -# define UTIME_NOW ((1l << 30) - 1l) -# define UTIME_OMIT ((1l << 30) - 2l) -#endif diff --git a/libc/sysdeps/linux/nios2/bits/syscalls.h b/libc/sysdeps/linux/nios2/bits/syscalls.h index 5be5d4d86..2b12343a6 100644 --- a/libc/sysdeps/linux/nios2/bits/syscalls.h +++ b/libc/sysdeps/linux/nios2/bits/syscalls.h @@ -4,106 +4,97 @@ # error "Never use directly; include instead." #endif -#define TRAP_ID_SYSCALL 0 +#ifdef __ASSEMBLER__ -#ifndef __ASSEMBLER__ +#undef DO_CALL +#define DO_CALL(syscall_name, args) \ + DOARGS_##args \ + movi r2, SYS_ify(syscall_name); \ + trap; -#include - -#define __syscall_return(type, res) \ - do { \ - if (unlikely(INTERNAL_SYSCALL_ERROR_P(res, ))) { \ - __set_errno(INTERNAL_SYSCALL_ERRNO(res, )); \ - res = (unsigned long) -1; \ - } \ - return (type) (res); \ - } while (0) +#define DOARGS_0 /* nothing */ +#define DOARGS_1 /* nothing */ +#define DOARGS_2 /* nothing */ +#define DOARGS_3 /* nothing */ +#define DOARGS_4 /* nothing */ +#define DOARGS_5 ldw r8, 0(sp); +#define DOARGS_6 ldw r9, 4(sp); ldw r8, 0(sp); -#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \ -(__extension__ \ - ({ \ - long __res; \ - __asm__ __volatile__ ( \ - "movi r2, %2\n\t" /* TRAP_ID_SYSCALL */ \ - "movi r3, %1\n\t" /* __NR_##name */ \ - ASM_ARGS_##nr \ - "trap\n\t" \ - "mov %0, r2\n\t" /* syscall return */ \ - : "=r" (__res) /* %0 */ \ - : "i" (name) /* %1 */ \ - , "i" (TRAP_ID_SYSCALL) /* %2 */ \ - MAP_ARGS_##nr (args) /* %3-%8 */ \ - : "r2" \ - , "r3" \ - CLOB_ARGS_##nr /* Clobbered */ \ - ); \ - __res; \ - }) \ -) +#else -#define INTERNAL_SYSCALL_ERROR_P(val, err) \ - ((unsigned long)(val) >= (unsigned long)(-125)) - -#define ASM_ARGS_0 -#define MAP_ARGS_0() -#define CLOB_ARGS_0 - -#define ASM_ARGS_1 \ - "mov r4, %3\n\t" -#define MAP_ARGS_1(a) \ - , "r" ((long) a) -#define CLOB_ARGS_1 \ - , "r4" +#include -#define ASM_ARGS_2 \ - ASM_ARGS_1 \ - "mov r5, %4\n\t" -#define MAP_ARGS_2(a, b) \ - MAP_ARGS_1(a) \ - , "r" ((long) b) -#define CLOB_ARGS_2 \ - CLOB_ARGS_1 \ - , "r5" +#undef INTERNAL_SYSCALL_DECL +#define INTERNAL_SYSCALL_DECL(err) unsigned int err __attribute__((unused)) -#define ASM_ARGS_3 \ - ASM_ARGS_2 \ - "mov r6, %5\n\t" -#define MAP_ARGS_3(a, b, c) \ - MAP_ARGS_2(a, b) \ - , "r" ((long) c) -#define CLOB_ARGS_3 \ - CLOB_ARGS_2 \ - , "r6" +#undef INTERNAL_SYSCALL_ERROR_P +#define INTERNAL_SYSCALL_ERROR_P(val, err) ((void) (val), (unsigned int) (err)) -#define ASM_ARGS_4 \ - ASM_ARGS_3 \ - "mov r7, %6\n\t" -#define MAP_ARGS_4(a, b, c, d) \ - MAP_ARGS_3(a, b, c) \ - , "r" ((long) d) -#define CLOB_ARGS_4 \ - CLOB_ARGS_3 \ - , "r7" +#undef INTERNAL_SYSCALL_ERRNO +#define INTERNAL_SYSCALL_ERRNO(val, err) ((void) (err), val) -#define ASM_ARGS_5 \ - ASM_ARGS_4 \ - "mov r8, %7\n\t" -#define MAP_ARGS_5(a, b, c, d, e) \ - MAP_ARGS_4(a, b, c, d) \ - , "r" ((long) e) -#define CLOB_ARGS_5 \ - CLOB_ARGS_4 \ - , "r8" +#undef INTERNAL_SYSCALL_NCS +#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \ + ({ unsigned int _sys_result; \ + { \ + LOAD_ARGS_##nr (args) \ + LOAD_REGS_##nr \ + register int _r2 __asm__ ("r2") = (int)(name); \ + register int _sys_err __asm__ ("r7"); \ + __asm__ volatile ("trap" \ + : "+r" (_r2), "=r" (_sys_err) \ + : ASM_ARGS_##nr \ + : "memory"); \ + _sys_result = _r2; \ + err = _sys_err; \ + } \ + (int) _sys_result; }) -#define ASM_ARGS_6 \ - ASM_ARGS_5 \ - "mov r9, %8\n\t" -#define MAP_ARGS_6(a, b, c, d, e, f) \ - MAP_ARGS_5(a, b, c, d, e) \ - , "r" ((long) f) -#define CLOB_ARGS_6 \ - CLOB_ARGS_5 \ - , "r9" +#define LOAD_ARGS_0() +#define LOAD_REGS_0 +#define ASM_ARGS_0 +#define LOAD_ARGS_1(a1) \ + LOAD_ARGS_0 () \ + int __arg1 = (int) (a1); +#define LOAD_REGS_1 \ + register int _r4 __asm__ ("r4") = __arg1; \ + LOAD_REGS_0 +#define ASM_ARGS_1 "r" (_r4) +#define LOAD_ARGS_2(a1, a2) \ + LOAD_ARGS_1 (a1) \ + int __arg2 = (int) (a2); +#define LOAD_REGS_2 \ + register int _r5 __asm__ ("r5") = __arg2; \ + LOAD_REGS_1 +#define ASM_ARGS_2 ASM_ARGS_1, "r" (_r5) +#define LOAD_ARGS_3(a1, a2, a3) \ + LOAD_ARGS_2 (a1, a2) \ + int __arg3 = (int) (a3); +#define LOAD_REGS_3 \ + register int _r6 __asm__ ("r6") = __arg3; \ + LOAD_REGS_2 +#define ASM_ARGS_3 ASM_ARGS_2, "r" (_r6) +#define LOAD_ARGS_4(a1, a2, a3, a4) \ + LOAD_ARGS_3 (a1, a2, a3) \ + int __arg4 = (int) (a4); +#define LOAD_REGS_4 \ + register int _r7 __asm__ ("r7") = __arg4; \ + LOAD_REGS_3 +#define ASM_ARGS_4 ASM_ARGS_3, "r" (_r7) +#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \ + LOAD_ARGS_4 (a1, a2, a3, a4) \ + int __arg5 = (int) (a5); +#define LOAD_REGS_5 \ + register int _r8 __asm__ ("r8") = __arg5; \ + LOAD_REGS_4 +#define ASM_ARGS_5 ASM_ARGS_4, "r" (_r8) +#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \ + LOAD_ARGS_5 (a1, a2, a3, a4, a5) \ + int __arg6 = (int) (a6); +#define LOAD_REGS_6 \ + register int _r9 __asm__ ("r9") = __arg6; \ + LOAD_REGS_5 +#define ASM_ARGS_6 ASM_ARGS_5, "r" (_r9) #endif /* __ASSEMBLER__ */ #endif /* _BITS_SYSCALLS_H */ diff --git a/libc/sysdeps/linux/nios2/bsd-_setjmp.S b/libc/sysdeps/linux/nios2/bsd-_setjmp.S deleted file mode 100644 index e1350f55e..000000000 --- a/libc/sysdeps/linux/nios2/bsd-_setjmp.S +++ /dev/null @@ -1,44 +0,0 @@ -/* - * libc/sysdeps/linux/nios2/bsd-_setjmp.S - * - * Copyright (C) 2004,05,06 Microtronix Datacom Ltd - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License. See the file COPYING.LIB in the main - * directory of this archive for more details. - * - * Written by Wentao Xu - * - */ - -#include -#include - - .globl _setjmp - .type _setjmp,@function - .balign 4 - -_setjmp: - stw r16, (JB_REGS+ 0)(r4) - stw r17, (JB_REGS+ 4)(r4) - stw r18, (JB_REGS+ 8)(r4) - stw r19, (JB_REGS+12)(r4) - stw r20, (JB_REGS+16)(r4) - stw r21, (JB_REGS+20)(r4) - stw r22, (JB_REGS+24)(r4) - stw r23, (JB_REGS+28)(r4) - - stw ra, JB_PC(r4) - stw sp, JB_SP(r4) - stw fp, JB_FP(r4) - stw gp, JB_GP(r4) - -#ifdef __UCLIBC_HAS_FPU__ - SAVE_FPU r4 JB_FPREGS -#endif - stw r0, JB_SIZE(r4) /* signal mask is not saved */ - mov r2, zero - ret - - - diff --git a/libc/sysdeps/linux/nios2/bsd-setjmp.S b/libc/sysdeps/linux/nios2/bsd-setjmp.S deleted file mode 100644 index f533754dc..000000000 --- a/libc/sysdeps/linux/nios2/bsd-setjmp.S +++ /dev/null @@ -1,51 +0,0 @@ -/* - * libc/sysdeps/linux/nios2/bsd-setjmp.S - * - * Copyright (C) 2004,05,06 Microtronix Datacom Ltd - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License. See the file COPYING.LIB in the main - * directory of this archive for more details. - * - * Written by Wentao Xu - * - */ - - -#include -#include - - .globl setjmp - .type setjmp,@function - .balign 4 - -setjmp: - stw r16, (JB_REGS+ 0)(r4) - stw r17, (JB_REGS+ 4)(r4) - stw r18, (JB_REGS+ 8)(r4) - stw r19, (JB_REGS+12)(r4) - stw r20, (JB_REGS+16)(r4) - stw r21, (JB_REGS+20)(r4) - stw r22, (JB_REGS+24)(r4) - stw r23, (JB_REGS+28)(r4) - - stw ra, JB_PC(r4) - stw sp, JB_SP(r4) - stw fp, JB_FP(r4) - stw gp, JB_GP(r4) - -#ifdef __UCLIBC_HAS_FPU__ - SAVE_FPU r4 JB_FPREGS -#endif - - movui r5, 1 -#ifdef __PIC__ - /* just pray 16 bit offset is enough */ - br __sigjmp_save -#else - movhi r8, %hi(__sigjmp_save) - ori r8, r8, %lo(__sigjmp_save) - jmp r8 -#endif - - diff --git a/libc/sysdeps/linux/nios2/clone.S b/libc/sysdeps/linux/nios2/clone.S index 4afcb7d75..0626d8aa2 100644 --- a/libc/sysdeps/linux/nios2/clone.S +++ b/libc/sysdeps/linux/nios2/clone.S @@ -1,70 +1,94 @@ -/* - * libc/sysdeps/linux/nios2/clone.S -- `clone' syscall for linux/nios2 - * - * Copyright (C) 2004 Microtronix Datacom Ltd - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License. See the file COPYING.LIB in the main - * directory of this archive for more details. - * - * Written by Wentao Xu - */ - -#define _ERRNO_H +/* clone() implementation for Nios II. + Copyright (C) 2008-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andrew Jenner , 2008. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* clone() is even more special than fork() as it mucks with stacks + and invokes a function in the right context after its all over. */ + +#include +#define _ERRNO_H 1 #include -#include - -#ifdef __NR_clone -/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */ - -.text -.global clone -.type clone,%function -.align 4 -clone: - addi sp,sp,-8 - mov r8,r4 - stw ra,4(sp) - stw r16,0(sp) - - mov r4,r6 - movi r2,-EINVAL - - /* sanity check */ - beq r8,zero,CLONE_ERROR_LABEL - beq r5,zero,CLONE_ERROR_LABEL - - /* system call */ - movi r2,TRAP_ID_SYSCALL - movi r3,__NR_clone - trap - - /* child call the function */ - mov r4,r7 - bne r2,zero,CLONE_ERROR_LABEL - callr r8 - - /* exit if it returns */ - mov r4,r2 - movi r3,__NR_exit + +#ifdef __UCLIBC_HAS_THREADS_NATIVE__ +#include +#endif + +#define CLONE_VM 0x00000100 + +/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg, + void *parent_tidptr, void *tls, void *child_tidptr) */ + + .text +ENTRY(__clone) + /* Sanity check arguments. */ + movi r2, EINVAL + + subi r5, r5, 8 /* Reserve argument save space. */ + stw r4, 4(r5) /* Save function pointer. */ + stw r7, 0(r5) /* Save argument pointer. */ + + /* Load arguments. */ + mov r4, r6 + ldw r6, 0(sp) + ldw r7, 8(sp) + ldw r8, 4(sp) + + /* Do the system call. */ + movi r2, SYS_ify (clone) + trap - -CLONE_ERROR_LABEL: - movi r3,-4096 - sub r16,zero,r2 - bgeu r3,r2,CLONE_OK - - /* store errno */ - call __errno_location - stw r16,0(r2) - movi r2,-1 - -CLONE_OK: - ldw ra,4(sp) - ldw r16,0(sp) - addi sp,sp,8 + + /* See if we're on the newly created thread. */ + beq r2, zero, thread_start + /* Successful return from the parent */ ret -.size clone,.-clone +thread_start: + /* We expect the argument registers to be preserved across system + calls and across task cloning, so flags should be in r4 here. */ + andi r2, r4, CLONE_VM + bne r2, zero, 2f + DO_CALL (getpid, 0) +#ifdef RESET_PID + stw r2, PID_OFFSET(r23) + stw r2, TID_OFFSET(r23) +#endif +2: + ldw r5, 4(sp) /* Function pointer. */ + ldw r4, 0(sp) /* Argument pointer. */ + addi sp, sp, 8 + + /* Call the user's function. */ + callr r5 + /* _exit with the result. */ + mov r4, r2 +#ifdef __PIC__ + nextpc r22 +1: movhi r8, %hiadj(_gp_got - 1b) + addi r8, r8, %lo(_gp_got - 1b) + add r22, r22, r8 + ldw r8, %call(HIDDEN_JUMPTARGET(_exit))(r22) + jmp r8 +#else + jmpi _exit #endif + +END(__clone) +libc_hidden_def (__clone) +weak_alias (__clone, clone) diff --git a/libc/sysdeps/linux/nios2/clone.c b/libc/sysdeps/linux/nios2/clone.c deleted file mode 100644 index eec9f42ff..000000000 --- a/libc/sysdeps/linux/nios2/clone.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * libc/sysdeps/linux/nios2/clone.c -- `clone' syscall for linux/nios2 - * Copyright (C) 2000-2006 Erik Andersen - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - * - * - * Copyright (C) 2004,05 Microtronix Datacom Ltd - * Copyright (C) 2002,03 NEC Electronics Corporation - * Copyright (C) 2002,03 Miles Bader - * - * Written by Miles Bader - * Nios2 port by Wentao Xu - */ - -#include -#include -#include - -int clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg, ...) -{ - register unsigned long rval __asm__ ("r2") = -EINVAL; - - if (fn && child_stack) { - register unsigned long syscall __asm__ ("r3"); - register unsigned long arg0 __asm__ ("r4"); - register unsigned long arg1 __asm__ ("r5"); - - /* Clone this thread. */ - rval = TRAP_ID_SYSCALL; - syscall = __NR_clone; - arg0 = flags; - arg1 = (unsigned long)child_stack; - __asm__ __volatile__ ("trap " - : "=r" (rval), "=r" (syscall) - : "0" (rval),"1" (syscall), "r" (arg0), "r" (arg1) - ); - - if (rval == 0) { - /* In child thread, call fn and exit. */ - arg0 = (*fn) (arg); - syscall = __NR_exit; - __asm__ __volatile__ ("trap " - : "=r" (rval), "=r" (syscall) - : "1" (syscall), "r" (arg0)); - } - } - - __syscall_return (int, rval); -} diff --git a/libc/sysdeps/linux/nios2/crt1.S b/libc/sysdeps/linux/nios2/crt1.S index c178452ae..e13d59599 100644 --- a/libc/sysdeps/linux/nios2/crt1.S +++ b/libc/sysdeps/linux/nios2/crt1.S @@ -1,20 +1,40 @@ -/* - * libc/sysdeps/linux/nios2/crt0.S -- entry point for linux/nios2 - * - * Copyright (C) 2004,05,06 Microtronix Datacom Ltd - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License. See the file COPYING.LIB in the main - * directory of this archive for more details. - * - * Written by Wentao Xu - * Updated by Thomas Chou for crt1.S - * - */ +/* Startup code for Nios II + Copyright (C) 1995-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file with other + programs, and to distribute those programs without any restriction + coming from the use of this file. (The GNU Lesser General Public + License restrictions do apply in other respects; for example, they + cover modification of the file, and distribution when not linked + into another program.) + + Note that people who make modified versions of this file are not + obligated to grant this special exception for their modified + versions; it is their choice whether to do so. The GNU Lesser + General Public License gives permission to release a modified + version without this exception; this exception also makes it + possible to release a modified version which carries forward this + exception. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ #include #include -#define TRAP_ID_SYSCALL 0 .global _start .type _start,@function @@ -27,45 +47,64 @@ .type main,@function .type __uClibc_main,@function .text - .balign 4 + _start: - nop - br 0f -0: - /* load gp */ - movhi gp, %hiadj(_gp) - addi gp, gp, %lo(_gp) - - /* load main, argc, argv from stack */ - movhi r4, %hi(main) - ori r4, r4, %lo(main) /* main */ - ldw r5, 0(sp) /* argc */ - ldw r6, 4(sp) /* argv */ - - /* load the 4th arg */ - movhi r7, %hi(_init) - ori r7, r7, %lo(_init) - - /* Allocate space on the stack for 6-7th arg, reuse 5th space */ - addi sp,sp,-8 - /* push 5-7th args on stack */ - movhi r8, %hi(_fini) - ori r8, r8, %lo(_fini) - stw r8, 0(sp) - - stw r2, 4(sp) /* rtld_fini */ - stw sp, 8(sp) /* stack_end */ - - /* call uClibc_main, shouldn't return */ -#ifdef __PIC__ - /* just pray 16 bit offset is enough */ - br __uClibc_main -#else - call __uClibc_main -#endif + /* Set up the global pointer. */ + movhi gp, %hiadj(_gp) + addi gp, gp, %lo(_gp) + + /* Save the stack pointer. */ + mov r2, sp + + /* Create room on the stack for the fini, rtld_fini and stack_end args + to __uClibc_main. */ + subi sp, sp, 12 + + /* Push stack_end */ + stw r2, 8(sp) + + /* Push rtld_fini */ + stw r4, 4(sp) + + /* Set up the GOT pointer. */ + nextpc r22 +1: movhi r2, %hiadj(_gp_got - 1b) + addi r2, r2, %lo(_gp_got - 1b) + add r22, r22, r2 + + /* r6 == argv */ + addi r6, sp, 16 + + /* r5 == argc */ + ldw r5, 12(sp) + + /* r4 == main */ + movhi r4, %call_hiadj(main) + addi r4, r4, %call_lo(main) + add r4, r4, r22 + ldw r4, 0(r4) + + /* fp == 0 */ + mov fp, zero + + /* Let the libc call main and exit with its return code. */ + movhi r2, %call_hiadj(__uClibc_main) + addi r2, r2, %call_lo(__uClibc_main) + add r2, r2, r22 + ldw r2, 0(r2) + callr r2 + + /* should never get here....*/ + movhi r2, %call_hiadj(abort) + addi r2, r2, %call_lo(abort) + add r2, r2, r22 + ldw r2, 0(r2) + callr r2 - /* crash in the event of return */ -__exit: - movui r2, TRAP_ID_SYSCALL - movui r3, __NR_exit - trap +/* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start diff --git a/libc/sysdeps/linux/nios2/fpu_control.h b/libc/sysdeps/linux/nios2/fpu_control.h deleted file mode 100644 index 4ba51b5eb..000000000 --- a/libc/sysdeps/linux/nios2/fpu_control.h +++ /dev/null @@ -1,98 +0,0 @@ -/* FPU control word bits. Nios2 version. - Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _FPU_CONTROL_H -#define _FPU_CONTROL_H - -/* MIPS FPU floating point control register bits. - * - * 31-25 -> floating point conditions code bits 7-1. These bits are only - * available in MIPS IV. - * 24 -> flush denormalized results to zero instead of - * causing unimplemented operation exception. This bit is only - * available for MIPS III and newer. - * 23 -> Condition bit - * 22-18 -> reserved (read as 0, write with 0) - * 17 -> cause bit for unimplemented operation - * 16 -> cause bit for invalid exception - * 15 -> cause bit for division by zero exception - * 14 -> cause bit for overflow exception - * 13 -> cause bit for underflow exception - * 12 -> cause bit for inexact exception - * 11 -> enable exception for invalid exception - * 10 -> enable exception for division by zero exception