From c0a2d0b7edacbc6389574821b0231e07431dabb6 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Fri, 5 Feb 2016 21:07:40 +0100 Subject: frv: resurrect port somehow, totally untested The FR-V port is really broken, and I have no emulator or hardware for this platform. I tried to get some hardware from RedHat, who made the FR-V port initially. Unfortunately Fujitsi didn't agreed to sent me some of their unused spare hardware lying @RedHat. As I invested some time to get stuff compiled, I decided to add the code and may be anytime later I can gain access to some emulator or hardware. GDB simulator for FR-V doesn't support booting Linux AFAIK. --- libc/misc/elf/dl-iterate-phdr.c | 2 +- libc/sysdeps/linux/frv/Makefile | 59 +------ libc/sysdeps/linux/frv/Makefile.arch | 11 ++ libc/sysdeps/linux/frv/bits/fcntl.h | 3 + libc/sysdeps/linux/frv/bits/kernel_types.h | 3 + libc/sysdeps/linux/frv/bits/stat.h | 33 +++- libc/sysdeps/linux/frv/bits/syscalls.h | 181 +++++++-------------- libc/sysdeps/linux/frv/bits/uClibc_arch_features.h | 2 +- libc/sysdeps/linux/frv/crt0.S | 124 -------------- libc/sysdeps/linux/frv/crt1.S | 121 ++++++++++++++ libc/sysdeps/linux/frv/crtreloc.c | 50 +----- libc/sysdeps/linux/frv/jmpbuf-unwind.h | 2 - libc/sysdeps/linux/frv/syscall.c | 2 +- 13 files changed, 244 insertions(+), 349 deletions(-) create mode 100644 libc/sysdeps/linux/frv/Makefile.arch delete mode 100644 libc/sysdeps/linux/frv/crt0.S create mode 100644 libc/sysdeps/linux/frv/crt1.S (limited to 'libc') diff --git a/libc/misc/elf/dl-iterate-phdr.c b/libc/misc/elf/dl-iterate-phdr.c index 5b86db011..27a92544b 100644 --- a/libc/misc/elf/dl-iterate-phdr.c +++ b/libc/misc/elf/dl-iterate-phdr.c @@ -58,7 +58,7 @@ dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, /* This entry describes this statically-linked program itself. */ struct dl_phdr_info info; int ret; -#if defined(__FDPIC__) +#if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) info.dlpi_addr.map = NULL; info.dlpi_addr.got_value = NULL; #elif defined(__DSBT__) diff --git a/libc/sysdeps/linux/frv/Makefile b/libc/sysdeps/linux/frv/Makefile index 7cdb8eca3..3970f6263 100644 --- a/libc/sysdeps/linux/frv/Makefile +++ b/libc/sysdeps/linux/frv/Makefile @@ -1,58 +1,13 @@ # Makefile for uClibc # # Copyright (C) 2000-2006 Erik Andersen -# ported to FR-V by Alexandre Oliva # # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# -TOPDIR=../../../../ -include $(TOPDIR)Rules.mak - -CRT_SRC := crt0.S -CRT_OBJ := crt0.o crt1.o -SCRT_OBJ := $(patsubst %,S%, $(CRT_OBJ)) - -CTOR_TARGETS := crti.o crtn.o - -SSRC := __longjmp.S setjmp.S clone.S vfork.S -SOBJ := $(patsubst %.S,%.o, $(SSRC)) - -CSRC = sysdep.c syscall.c brk.c sbrk.c __init_brk.c dl-iterate-phdr.c -CSRC += xstatconv.c stat.c stat64.c fstat.c fstat64.c lstat.c lstat64.c -COBJ := $(patsubst %.c,%.o, $(CSRC)) - -OBJS := $(SOBJ) $(COBJ) - -OBJ_LIST := ../../../obj.sysdeps.$(TARGET_ARCH) - -all: $(OBJ_LIST) - -$(OBJ_LIST): $(OBJS) $(CRT_OBJ) $(SCRT_OBJ) $(CTOR_TARGETS) - $(STRIPTOOL) -x -R .note -R .comment $^ - $(INSTALL) -d $(TOPDIR)lib/ - cp $(CRT_OBJ) $(SCRT_OBJ) $(CTOR_TARGETS) $(TOPDIR)lib/ - echo $(patsubst %, sysdeps/linux/$(TARGET_ARCH)/%, $(OBJS)) > $@ - -$(CRT_OBJ): $(CRT_SRC) crtreloc.o - $(CC) $(ASFLAGS) -DL_$* -r -nostdlib $^ -o $*.o - -crtreloc.o: crtreloc.c - $(CC) $(CFLAGS) -c $< -o $@ - -$(SCRT_OBJ): $(CRT_SRC) Scrtreloc.o - $(CC) $(ASFLAGS) $(PIEFLAG) -DL_$* -r -nostdlib $^ -o $*.o - -Scrtreloc.o: crtreloc.c - $(CC) $(CFLAGS) $(PIEFLAG) -c $< -o $@ - -$(CTOR_TARGETS): %.o : %.S - $(CC) $(ASFLAGS) $(SSP_DISABLE_FLAGS) -c $< -o $@ - -$(SOBJ): %.o : %.S - $(CC) $(ASFLAGS) -c $< -o $@ - -$(COBJ): %.o : %.c - $(CC) $(CFLAGS) -c $< -o $@ - -clean: - $(RM) *.o *~ core +top_srcdir=../../../../ +top_builddir=../../../../ +all: objs +include $(top_builddir)Rules.mak +include Makefile.arch +include $(top_srcdir)Makerules diff --git a/libc/sysdeps/linux/frv/Makefile.arch b/libc/sysdeps/linux/frv/Makefile.arch new file mode 100644 index 000000000..be48fd007 --- /dev/null +++ b/libc/sysdeps/linux/frv/Makefile.arch @@ -0,0 +1,11 @@ +# Makefile for uClibc +# +# Copyright (C) 2000-2006 Erik Andersen +# ported to FR-V by Alexandre Oliva +# +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + +CSRC-y := sysdep.c syscall.c brk.c sbrk.c __init_brk.c dl-iterate-phdr.c + +SSRC-y := __longjmp.S setjmp.S clone.S vfork.S + diff --git a/libc/sysdeps/linux/frv/bits/fcntl.h b/libc/sysdeps/linux/frv/bits/fcntl.h index 0ef5f29e9..0581f2bf3 100644 --- a/libc/sysdeps/linux/frv/bits/fcntl.h +++ b/libc/sysdeps/linux/frv/bits/fcntl.h @@ -22,6 +22,9 @@ #include +#ifdef __USE_GNU +# include +#endif /* open/fcntl - O_SYNC is only implemented on blocks devices and on files located on an ext2 file system */ diff --git a/libc/sysdeps/linux/frv/bits/kernel_types.h b/libc/sysdeps/linux/frv/bits/kernel_types.h index 8403fd3e8..be4fe224f 100644 --- a/libc/sysdeps/linux/frv/bits/kernel_types.h +++ b/libc/sysdeps/linux/frv/bits/kernel_types.h @@ -31,6 +31,9 @@ typedef unsigned int __kernel_gid32_t; typedef unsigned short __kernel_old_uid_t; typedef unsigned short __kernel_old_gid_t; typedef long long __kernel_loff_t; +typedef __kernel_dev_t __kernel_old_dev_t; +typedef long __kernel_long_t; +typedef unsigned long __kernel_ulong_t; typedef struct { #ifdef __USE_ALL diff --git a/libc/sysdeps/linux/frv/bits/stat.h b/libc/sysdeps/linux/frv/bits/stat.h index 83f5b4726..e6a1944bb 100644 --- a/libc/sysdeps/linux/frv/bits/stat.h +++ b/libc/sysdeps/linux/frv/bits/stat.h @@ -70,6 +70,20 @@ struct stat __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 unsigned long int __unused1; __time_t st_atime; /* Time of last access. */ @@ -78,7 +92,7 @@ struct stat unsigned long int __unused3; __time_t st_ctime; /* Time of last status change. */ - +#endif unsigned long long __unused4; }; @@ -103,7 +117,20 @@ struct stat64 __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. */ +# define st_atime st_atim.tv_sec /* Backward compatibility. */ +# define st_mtime st_mtim.tv_sec +# define st_ctime st_ctim.tv_sec +#else unsigned long int __unused1; __time_t st_atime; /* Time of last access. */ @@ -112,7 +139,7 @@ struct stat64 unsigned long int __unused3; __time_t st_ctime; /* Time of last status change. */ - +#endif unsigned long long __unused4; }; #endif diff --git a/libc/sysdeps/linux/frv/bits/syscalls.h b/libc/sysdeps/linux/frv/bits/syscalls.h index b1f532040..b03e8dbe0 100644 --- a/libc/sysdeps/linux/frv/bits/syscalls.h +++ b/libc/sysdeps/linux/frv/bits/syscalls.h @@ -10,128 +10,71 @@ #define SYS_ify(syscall_name) (__NR_##syscall_name) -/* user-visible error numbers are in the range -1 - -4095: see */ -#if defined _LIBC && !defined __set_errno -# define __syscall_return(type, res) \ -do { \ - unsigned long __sr2 = (res); \ - if (unlikely ((unsigned long)(__sr2) >= (unsigned long)(-4095))) { \ - extern int __syscall_error (int); \ - return (type) __syscall_error (__sr2); \ - } \ - return (type) (__sr2); \ -} while (0) -#else -# define __syscall_return(type, res) \ -do { \ - unsigned long __sr2 = (res); \ - if (unlikely ((unsigned long)(__sr2) >= (unsigned long)(-4095))) { \ - __set_errno (-__sr2); \ - __sr2 = -1; \ - } \ - return (type) (__sr2); \ -} while (0) -#endif - -#ifndef __set_errno -# define __set_errno(val) ((*__errno_location ()) = (val)) -#endif - -/* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */ - -#define _syscall0(type,name) \ -type name(void) \ -{ \ -register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \ -register unsigned long __sc0 __asm__ ("gr8"); \ -__asm__ __volatile__ ("tra gr0,gr0" \ - : "=r" (__sc0) \ - : "r" (__scnum)); \ -__syscall_return(type,__sc0); \ -} - -#define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) \ -{ \ -register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \ -register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \ -__asm__ __volatile__ ("tra gr0,gr0" \ - : "+r" (__sc0) \ - : "r" (__scnum)); \ -__syscall_return(type,__sc0); \ -} - -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1,type2 arg2) \ -{ \ -register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \ -register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \ -register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \ -__asm__ __volatile__ ("tra gr0,gr0" \ - : "+r" (__sc0) \ - : "r" (__scnum), "r" (__sc1)); \ -__syscall_return(type,__sc0); \ -} - -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \ -register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \ -register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \ -register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \ -__asm__ __volatile__ ("tra gr0,gr0" \ - : "+r" (__sc0) \ - : "r" (__scnum), "r" (__sc1), "r" (__sc2)); \ -__syscall_return(type,__sc0); \ -} +#define INLINE_SYSCALL_NCS(name, nr, args...) \ +(__extension__ \ + ({ \ + unsigned int _inline_sys_result = INTERNAL_SYSCALL_NCS (name, , nr, args);\ + if (unlikely (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ))) \ + { \ + __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, )); \ + _inline_sys_result = (unsigned int) -1; \ + } \ + (int) _inline_sys_result; \ + }) \ +) -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \ -register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \ -register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \ -register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \ -register unsigned long __sc3 __asm__ ("gr11") = (unsigned long) arg4; \ -__asm__ __volatile__ ("tra gr0,gr0" \ - : "+r" (__sc0) \ - : "r" (__scnum), "r" (__sc1), "r" (__sc2), "r" (__sc3)); \ -__syscall_return(type,__sc0); \ -} +#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \ +(__extension__ \ + ({unsigned int __internal_sys_result; \ + { \ + register int __a1 __asm__ ("gr8"); \ + register int _nr __asm__ ("gr7"); \ + LOAD_ARGS_##nr (args) \ + _nr = (name); \ + __asm__ __volatile__ ("tra gr0,gr0" \ + : "=r" (__a1) \ + : "r" (_nr) ASM_ARGS_##nr \ + : "memory"); \ + __internal_sys_result = __a1; \ + } \ + (int) __internal_sys_result; }) \ +) -#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ -{ \ -register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \ -register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \ -register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \ -register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \ -register unsigned long __sc3 __asm__ ("gr11") = (unsigned long) arg4; \ -register unsigned long __sc4 __asm__ ("gr12") = (unsigned long) arg5; \ -__asm__ __volatile__ ("tra gr0,gr0" \ - : "+r" (__sc0) \ - : "r" (__scnum), "r" (__sc1), "r" (__sc2), \ - "r" (__sc3), "r" (__sc4)); \ -__syscall_return(type,__sc0); \ -} +#define INTERNAL_SYSCALL_ERROR_P(val, err) \ + ((unsigned int) (val) >= 0xfffff001u) -#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5, type6, arg6) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \ -{ \ -register unsigned long __scnum __asm__ ("gr7") = (__NR_##name); \ -register unsigned long __sc0 __asm__ ("gr8") = (unsigned long) arg1; \ -register unsigned long __sc1 __asm__ ("gr9") = (unsigned long) arg2; \ -register unsigned long __sc2 __asm__ ("gr10") = (unsigned long) arg3; \ -register unsigned long __sc3 __asm__ ("gr11") = (unsigned long) arg4; \ -register unsigned long __sc4 __asm__ ("gr12") = (unsigned long) arg5; \ -register unsigned long __sc5 __asm__ ("gr13") = (unsigned long) arg6; \ -__asm__ __volatile__ ("tra gr0,gr0" \ - : "+r" (__sc0) \ - : "r" (__scnum), "r" (__sc1), "r" (__sc2), \ - "r" (__sc3), "r" (__sc4), "r" (__sc5)); \ -__syscall_return(type,__sc0); \ -} +#define LOAD_ARGS_0() +#define ASM_ARGS_0 +#define LOAD_ARGS_1(a1) \ + int __a1tmp = (int) (a1); \ + LOAD_ARGS_0 () \ + __a1 = __a1tmp; +#define ASM_ARGS_1 ASM_ARGS_0, "r" (__a1) +#define LOAD_ARGS_2(a1, a2) \ + int __a2tmp = (int) (a2); \ + LOAD_ARGS_1 (a1) \ + register int __a2 __asm__ ("gr8") = __a2tmp; +#define ASM_ARGS_2 ASM_ARGS_1, "r" (__a2) +#define LOAD_ARGS_3(a1, a2, a3) \ + int __a3tmp = (int) (a3); \ + LOAD_ARGS_2 (a1, a2) \ + register int __a3 __asm__ ("gr9") = __a3tmp; +#define ASM_ARGS_3 ASM_ARGS_2, "r" (__a3) +#define LOAD_ARGS_4(a1, a2, a3, a4) \ + int __a4tmp = (int) (a4); \ + LOAD_ARGS_3 (a1, a2, a3) \ + register int __a4 __asm__ ("gr10") = __a4tmp; +#define ASM_ARGS_4 ASM_ARGS_3, "r" (__a4) +#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \ + int __v1tmp = (int) (a5); \ + LOAD_ARGS_4 (a1, a2, a3, a4) \ + register int __v1 __asm__ ("gr11") = __v1tmp; +#define ASM_ARGS_5 ASM_ARGS_4, "r" (__v1) +#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \ + int __v2tmp = (int) (a6); \ + LOAD_ARGS_5 (a1, a2, a3, a4, a5) \ + register int __v2 __asm__ ("gr12") = __v2tmp; +#define ASM_ARGS_6 ASM_ARGS_5, "r" (__v2) #endif /* __ASSEMBLER__ */ #endif /* _BITS_SYSCALLS_H */ diff --git a/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h b/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h index 293cc9b00..f660fd223 100644 --- a/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h +++ b/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h @@ -37,6 +37,6 @@ #define __UCLIBC_HAVE_SIGNED_ZERO__ /* only weird assemblers generally need this */ -#undef __UCLIBC_ASM_LINE_SEP__ +#define __UCLIBC_ASM_LINE_SEP__ ! #endif /* _BITS_UCLIBC_ARCH_FEATURES_H */ diff --git a/libc/sysdeps/linux/frv/crt0.S b/libc/sysdeps/linux/frv/crt0.S deleted file mode 100644 index 59f61f94f..000000000 --- a/libc/sysdeps/linux/frv/crt0.S +++ /dev/null @@ -1,124 +0,0 @@ -/* Copyright (C) 1991, 1992, 2003, 2004 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 -Library General Public License for more details. - -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.) - -You should have received a copy of the GNU Lesser General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, see . */ - - -/* Based on ../i386/crt0.S and newlib's libgloss/frv/crt0.S */ - -/* - When we enter this piece of code, the program stack looks like this: - argc argument counter (integer) - argv[0] program name (pointer) - argv[1...N] program args (pointers) - argv[argc-1] end of args (integer) - NULL - env[0...N] environment variables (pointers) - NULL - - Also, GR16 holds a pointer to a memory map. */ - -#include - - .text - .global _start - .type _start,%function -#if defined L_crt0 || defined L_Scrt0 || ! defined __UCLIBC_CTOR_DTOR__ - .type __uClibc_main,%function -#else - .weak _init - .weak _fini - .type __uClibc_start_main,%function -#endif -_start: - /* Make sure the stack pointer is properly aligned. Save the - original value in gr21 such that we can get to arguments and - such from there. */ - mov.p sp, gr21 - andi sp, #-8, sp - /* At program start-up, gr16 contains a pointer to a memory - map, that we use to relocate addresses. */ - call .Lcall -.Lcall: - movsg lr, gr4 - sethi.p #gprelhi(.Lcall), gr5 - setlo #gprello(.Lcall), gr5 - sub.p gr4, gr5, gr4 - /* gr4 now holds the _gp address. */ - - mov gr16, gr8 - sethi.p #gprelhi(__ROFIXUP_LIST__), gr9 - sethi #gprelhi(__ROFIXUP_END__), gr10 - setlo.p #gprello(__ROFIXUP_LIST__), gr9 - setlo #gprello(__ROFIXUP_END__), gr10 - add.p gr9, gr4, gr9 - add gr10, gr4, gr10 - call __self_reloc - mov.p gr8, gr17 - mov gr8, gr15 - /* gr17 now holds the self-relocated _GLOBAL_OFFSET_TABLE_ - address, because the linker added its unrelocated address as - the last entry in the ROFIXUP list, and __self_reloc returns - the last entry, relocated. */ - - /* Prepare arguments for uClibc main. */ - ld @(gr21, gr0), gr8 - slli gr8, #2, gr10 - add gr21, gr10, gr10 - addi.p gr21, #4, gr9 - addi gr10, #8, gr10 - - /* Set up an invalid (NULL return address, NULL frame pointer) - callers stack frame so anybody unrolling the stack knows where - to stop */ - mov gr0, fp - movgs gr0, lr - -#if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__ - /* Pass .init and .fini arguments to __uClibc_start_main(). */ - sethi.p #gotfuncdeschi(_init), gr11 - sethi #gotfuncdeschi(_fini), gr12 - setlo.p #gotfuncdesclo(_init), gr11 - setlo #gotfuncdesclo(_fini), gr12 - ld.p @(gr11, gr17), gr11 - mov gr17, gr15 - ld.p @(gr12, gr17), gr12 - call __uClibc_start_main -#else - mov.p gr17, gr15 - call __uClibc_main -#endif - - /* Crash if somehow `exit' returns anyways. */ - jmpl @(gr0,gr0) -.size _start,.-_start - -/* 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/frv/crt1.S b/libc/sysdeps/linux/frv/crt1.S new file mode 100644 index 000000000..0827feae7 --- /dev/null +++ b/libc/sysdeps/linux/frv/crt1.S @@ -0,0 +1,121 @@ +/* Copyright (C) 1991, 1992, 2003, 2004 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 +Library General Public License for more details. + +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.) + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, see . */ + + +/* Based on ../i386/crt0.S and newlib's libgloss/frv/crt0.S */ + +/* + When we enter this piece of code, the program stack looks like this: + argc argument counter (integer) + argv[0] program name (pointer) + argv[1...N] program args (pointers) + argv[argc-1] end of args (integer) + NULL + env[0...N] environment variables (pointers) + NULL + + Also, GR16 holds a pointer to a memory map. */ + +#include + + .text + .global _start + .type _start,%function + .weak _init + .weak _fini + .type __uClibc_main,%function + +_start: + /* Make sure the stack pointer is properly aligned. Save the + original value in gr21 such that we can get to arguments and + such from there. */ + mov.p sp, gr21 + andi sp, #-8, sp + /* At program start-up, gr16 contains a pointer to a memory + map, that we use to relocate addresses. */ + call .Lcall +.Lcall: + movsg lr, gr4 + sethi.p #gprelhi(.Lcall), gr5 + setlo #gprello(.Lcall), gr5 + sub.p gr4, gr5, gr4 + /* gr4 now holds the _gp address. */ + + mov gr16, gr8 + sethi.p #gprelhi(__ROFIXUP_LIST__), gr9 + sethi #gprelhi(__ROFIXUP_END__), gr10 + setlo.p #gprello(__ROFIXUP_LIST__), gr9 + setlo #gprello(__ROFIXUP_END__), gr10 + add.p gr9, gr4, gr9 + add gr10, gr4, gr10 + call __self_reloc + mov.p gr8, gr17 + mov gr8, gr15 + /* gr17 now holds the self-relocated _GLOBAL_OFFSET_TABLE_ + address, because the linker added its unrelocated address as + the last entry in the ROFIXUP list, and __self_reloc returns + the last entry, relocated. */ + + /* Prepare arguments for uClibc main. */ + ld @(gr21, gr0), gr8 + slli gr8, #2, gr10 + add gr21, gr10, gr10 + addi.p gr21, #4, gr9 + addi gr10, #8, gr10 + + /* Set up an invalid (NULL return address, NULL frame pointer) + callers stack frame so anybody unrolling the stack knows where + to stop */ + mov gr0, fp + movgs gr0, lr + +#if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__ + /* Pass .init and .fini arguments to __uClibc_start_main(). */ + sethi.p #gotfuncdeschi(_init), gr11 + sethi #gotfuncdeschi(_fini), gr12 + setlo.p #gotfuncdesclo(_init), gr11 + setlo #gotfuncdesclo(_fini), gr12 + ld.p @(gr11, gr17), gr11 + mov gr17, gr15 + ld.p @(gr12, gr17), gr12 + call __uClibc_main +#else + mov.p gr17, gr15 + call __uClibc_main +#endif + + /* Crash if somehow `exit' returns anyways. */ + jmpl @(gr0,gr0) +.size _start,.-_start + +/* 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/frv/crtreloc.c b/libc/sysdeps/linux/frv/crtreloc.c index cd07170a8..b1d542395 100644 --- a/libc/sysdeps/linux/frv/crtreloc.c +++ b/libc/sysdeps/linux/frv/crtreloc.c @@ -25,6 +25,8 @@ You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; see the file COPYING.LIB. If not, see . */ +#ifdef __FRV_FDPIC__ + #include #include @@ -61,7 +63,7 @@ reloc_range_indirect (void ***p, void ***e, /* Call __reloc_range_indirect for the given range except for the last entry, whose contents are only relocated. It's expected to hold the GOT value. */ -void* attribute_hidden +attribute_hidden void* __self_reloc (const struct elf32_fdpic_loadmap *map, void ***p, void ***e) { @@ -72,48 +74,4 @@ __self_reloc (const struct elf32_fdpic_loadmap *map, return __reloc_pointer (*p, map); } - -#if 0 -/* These are other functions that might be useful, but that we don't - need. */ - -/* Remap pointers in [p,e). */ -static __always_inline void** -reloc_range (void **p, void **e, - const struct elf32_fdpic_loadmap *map) -{ - while (p < e) - { - *p = __reloc_pointer (*p, map); - p++; - } - return p; -} - -/* Remap p, adjust e by the same offset, then map the pointers in the - range determined by them. */ -void attribute_hidden -__reloc_range (const struct elf32_fdpic_loadmap *map, - void **p, void **e) -{ - void **old = p; - - p = __reloc_pointer (p, map); - e += p - old; - reloc_range (p, e, map); -} - -/* Remap p, adjust e by the same offset, then map pointers referenced - by the (unadjusted) pointers in the range. Return the relocated - value of the last pointer in the range. */ -void* attribute_hidden -__reloc_range_indirect (const struct elf32_fdpic_loadmap *map, - void ***p, void ***e) -{ - void ***old = p; - - p = __reloc_pointer (p, map); - e += p - old; - return reloc_range_indirect (p, e, map); -} -#endif +#endif /* __FRV_FDPIC__ */ diff --git a/libc/sysdeps/linux/frv/jmpbuf-unwind.h b/libc/sysdeps/linux/frv/jmpbuf-unwind.h index b58f3f0e3..c22ab2409 100644 --- a/libc/sysdeps/linux/frv/jmpbuf-unwind.h +++ b/libc/sysdeps/linux/frv/jmpbuf-unwind.h @@ -10,5 +10,3 @@ containing a local variable at ADDRESS. */ #define _JMPBUF_UNWINDS(jmpbuf, address) \ ((void *) (address) < (void *) (jmpbuf)->__sp) - -#endif /* bits/setjmp.h */ diff --git a/libc/sysdeps/linux/frv/syscall.c b/libc/sysdeps/linux/frv/syscall.c index 68fe55696..a98cf3832 100644 --- a/libc/sysdeps/linux/frv/syscall.c +++ b/libc/sysdeps/linux/frv/syscall.c @@ -37,5 +37,5 @@ long syscall(long sysnum, long arg1, long arg2, long arg3, : "+r" (__sc0) : "r" (__scnum), "r" (__sc1), "r" (__sc2), "r" (__sc3), "r" (__sc4), "r" (__sc5)); - __syscall_return(long,__sc0); + return (long) __sc0; } -- cgit v1.2.3