diff options
author | Tobias Anderberg <tobias.anderberg@axis.com> | 2002-09-16 08:08:37 +0000 |
---|---|---|
committer | Tobias Anderberg <tobias.anderberg@axis.com> | 2002-09-16 08:08:37 +0000 |
commit | 35df59db508dbf23437f3253f25147191796e19f (patch) | |
tree | 59047d1c78611a04816d17cb8182666e1ae4b3b1 /libc/sysdeps | |
parent | da6874a62e91b80e39cfd8f20a5b9d36ec28db0b (diff) |
Initial version of the CRIS port.
Diffstat (limited to 'libc/sysdeps')
27 files changed, 1634 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/cris/Makefile b/libc/sysdeps/linux/cris/Makefile new file mode 100644 index 000000000..398139be5 --- /dev/null +++ b/libc/sysdeps/linux/cris/Makefile @@ -0,0 +1,59 @@ +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Library General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) any +# later version. +# +# This program 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. +# +# You should have received a copy of the GNU Library General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +TOPDIR=../../../../ +include $(TOPDIR)Rules.mak +ASFLAGS=$(CFLAGS) + +CRT0=crt0.c +CRT0_OBJ=$(patsubst %.c,%.o, $(CRT0)) + +SSRC= setjmp.S __longjmp.S +ifeq ($(UNIFIED_SYSCALL),true) + SSRC += __uClibc_syscall.S +endif +SOBJS=$(patsubst %.S,%.o, $(SSRC)) + +CSRC= __init_brk.c brk.c sbrk.c vfork.c +COBJS=$(patsubst %.c,%.o, $(CSRC)) + +OBJS=$(SOBJS) $(COBJS) + + +all: $(OBJS) $(LIBC) + +$(LIBC): ar-target + +ar-target: $(OBJS) $(CRT0_OBJ) + $(AR) $(ARFLAGS) $(LIBC) $(OBJS) + cp $(CRT0_OBJ) $(TOPDIR)libc/$(CRT0_OBJ) + +$(CRT0_OBJ): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ + $(STRIPTOOL) -x -R .note -R .comment $*.o + +$(SOBJS): %.o : %.S + $(CC) $(CFLAGS) -c $< -o $@ + $(STRIPTOOL) -x -R .note -R .comment $*.o + +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ + $(STRIPTOOL) -x -R .note -R .comment $*.o + +headers: + @(TOPDIR=$(TOPDIR) CC=$(CC) /bin/sh $(TOPDIR)/extra/scripts/gen_bits_syscall_h.sh > bits/syscall.h ) + +clean: + rm -f *.[oa] *~ core + diff --git a/libc/sysdeps/linux/cris/__init_brk.c b/libc/sysdeps/linux/cris/__init_brk.c new file mode 100644 index 000000000..0f5624b85 --- /dev/null +++ b/libc/sysdeps/linux/cris/__init_brk.c @@ -0,0 +1,32 @@ +/* From libc-5.3.12 */ + +#include <unistd.h> +#include <sys/syscall.h> +#include <errno.h> +#include "sysdep.h" + +void * ___brk_addr = 0; + +int +__init_brk (void) +{ + if (___brk_addr == 0) { + /* Notice that we don't need to save/restore the GOT + * register since that is not call clobbered by the syscall + */ + + asm ("clear.d $r10\n\t" + "movu.w " STR(__NR_brk) ",$r9\n\t" + "break 13\n\t" + "move.d $r10, %0" + : "=r" (___brk_addr) + : + : "r9", "r10"); + + if (___brk_addr == 0) { + __set_errno(ENOMEM); + return -1; + } + } + return 0; +} diff --git a/libc/sysdeps/linux/cris/__longjmp.S b/libc/sysdeps/linux/cris/__longjmp.S new file mode 100644 index 000000000..98472a673 --- /dev/null +++ b/libc/sysdeps/linux/cris/__longjmp.S @@ -0,0 +1,40 @@ +/* longjmp for CRIS. + Copyright (C) 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 Library General Public License as + published by the Free Software Foundation; either version 2 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. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <sysdep.h> +#define _SETJMP_H +#define _ASM +#include <bits/setjmp.h> + +/* Saving and restoring CCR is meaningless, so we don't do it. */ +ENTRY (__longjmp) + /* Note that r10 = jmp_buf, r11 = retval. */ + move [$r10+16*4],$srp + test.d $r11 + beq 0f /* Already a 1 in place. */ + nop + /* Offset for r9, the return value (see setjmp). */ + move.d $r11,[$r10+6*4] +0: + movem [$r10],$pc +END (__longjmp) + + .weak longjmp + longjmp = __longjmp + diff --git a/libc/sysdeps/linux/cris/bits/byteswap.h b/libc/sysdeps/linux/cris/bits/byteswap.h new file mode 100644 index 000000000..60544a0ad --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/byteswap.h @@ -0,0 +1,47 @@ +#define ___swab16(x) \ +({ \ + unsigned short __x = (x); \ + ((unsigned short)( \ + (((unsigned short)(__x) & (unsigned short)0x00ffU) << 8) | \ + (((unsigned short)(__x) & (unsigned short)0xff00U) >> 8) )); \ +}) + +#define ___swab32(x) \ +({ \ + unsigned long __x = (x); \ + ((unsigned long)( \ + (((unsigned long)(__x) & (unsigned long)0x000000ffUL) << 24) | \ + (((unsigned long)(__x) & (unsigned long)0x0000ff00UL) << 8) | \ + (((unsigned long)(__x) & (unsigned long)0x00ff0000UL) >> 8) | \ + (((unsigned long)(__x) & (unsigned long)0xff000000UL) >> 24) )); \ +}) + +/* these are CRIS specific */ + +static inline unsigned short __fswab16(unsigned short x) +{ + __asm__ ("swapb %0" : "=r" (x) : "0" (x)); + + return(x); +} + +static inline unsigned long __fswab32(unsigned long x) +{ + __asm__ ("swapwb %0" : "=r" (x) : "0" (x)); + + return(x); +} + +# define __bswap_16(x) \ +(__builtin_constant_p((unsigned short)(x)) ? \ + ___swab16((x)) : \ + __fswab16((x))) + +# define __bswap_32(x) \ +(__builtin_constant_p((unsigned long)(x)) ? \ + ___swab32((x)) : \ + __fswab32((x))) + + + + diff --git a/libc/sysdeps/linux/cris/bits/endian.h b/libc/sysdeps/linux/cris/bits/endian.h new file mode 100644 index 000000000..90e290b92 --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/endian.h @@ -0,0 +1,7 @@ +/* cris is little-endian. */ + +#ifndef _ENDIAN_H +# error "Never use <bits/endian.h> directly; include <endian.h> instead." +#endif + +#define __BYTE_ORDER __LITTLE_ENDIAN diff --git a/libc/sysdeps/linux/cris/bits/fcntl.h b/libc/sysdeps/linux/cris/bits/fcntl.h new file mode 100644 index 000000000..d47a66191 --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/fcntl.h @@ -0,0 +1,141 @@ +/* O_*, F_*, FD_* bit values for Linux. + Copyright (C) 1995, 1996, 1997, 1998 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 Library General Public License as + published by the Free Software Foundation; either version 2 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. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _FCNTL_H +# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead." +#endif + + +#include <sys/types.h> + +/* open/fcntl - O_SYNC is only implemented on blocks devices and on files + located on an ext2 file system */ +#define O_ACCMODE 0003 +#define O_RDONLY 00 +#define O_WRONLY 01 +#define O_RDWR 02 +#define O_CREAT 0100 /* not fcntl */ +#define O_EXCL 0200 /* not fcntl */ +#define O_NOCTTY 0400 /* not fcntl */ +#define O_TRUNC 01000 /* not fcntl */ +#define O_APPEND 02000 +#define O_NONBLOCK 04000 +#define O_NDELAY O_NONBLOCK +#define O_SYNC 010000 +#define O_FSYNC O_SYNC +#define O_ASYNC 020000 + +#ifdef __USE_GNU +# define O_DIRECT 040000 /* Direct disk access. */ +# define O_DIRECTORY 0200000 /* Must be a directory. */ +# define O_NOFOLLOW 0400000 /* Do not follow links. */ +#endif + +/* For now Linux has synchronisity options for data and read operations. + We define the symbols here but let them do the same as O_SYNC since + this is a superset. */ +#if defined __USE_POSIX199309 || defined __USE_UNIX98 +# define O_DSYNC O_SYNC /* Synchronize data. */ +# define O_RSYNC O_SYNC /* Synchronize read operations. */ +#endif + +#ifdef __USE_LARGEFILE64 +# define O_LARGEFILE 0100000 +#endif + +/* Values for the second argument to `fcntl'. */ +#define F_DUPFD 0 /* Duplicate file descriptor. */ +#define F_GETFD 1 /* Get file descriptor flags. */ +#define F_SETFD 2 /* Set file descriptor flags. */ +#define F_GETFL 3 /* Get file status flags. */ +#define F_SETFL 4 /* Set file status flags. */ +#define F_GETLK 5 /* Get record locking info. */ +#define F_SETLK 6 /* Set record locking info (non-blocking). */ +#define F_SETLKW 7 /* Set record locking info (blocking). */ + +/* XXX missing */ +#define F_GETLK64 5 /* Get record locking info. */ +#define F_SETLK64 6 /* Set record locking info (non-blocking). */ +#define F_SETLKW64 7 /* Set record locking info (blocking). */ + +#ifdef __USE_BSD +# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */ +# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */ +#endif + +#ifdef __USE_GNU +# define F_SETSIG 10 /* Set number of signal to be sent. */ +# define F_GETSIG 11 /* Get number of signal to be sent. */ +#endif + +/* For F_[GET|SET]FL. */ +#define FD_CLOEXEC 1 /* actually anything with low bit set goes */ + +/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */ +#define F_RDLCK 0 /* Read lock. */ +#define F_WRLCK 1 /* Write lock. */ +#define F_UNLCK 2 /* Remove lock. */ + +/* for old implementation of bsd flock () */ +#define F_EXLCK 4 /* or 3 */ +#define F_SHLCK 8 /* or 4 */ + +#ifdef __USE_BSD +/* operations for bsd flock(), also used by the kernel implementation */ +# define LOCK_SH 1 /* shared lock */ +# define LOCK_EX 2 /* exclusive lock */ +# define LOCK_NB 4 /* or'd with one of the above to prevent + blocking */ +# define LOCK_UN 8 /* remove lock */ +#endif + +struct flock + { + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */ +#ifndef __USE_FILE_OFFSET64 + __off_t l_start; /* Offset where the lock begins. */ + __off_t l_len; /* Size of the locked area; zero means until EOF. */ +#else + __off64_t l_start; /* Offset where the lock begins. */ + __off64_t l_len; /* Size of the locked area; zero means until EOF. */ +#endif + __pid_t l_pid; /* Process holding the lock. */ + }; + +#ifdef __USE_LARGEFILE64 +struct flock64 + { + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */ + __off64_t l_start; /* Offset where the lock begins. */ + __off64_t l_len; /* Size of the locked area; zero means until EOF. */ + __pid_t l_pid; /* Process holding the lock. */ + }; +#endif + +/* Define some more compatibility macros to be backward compatible with + BSD systems which did not managed to hide these kernel macros. */ +#ifdef __USE_BSD +# define FAPPEND O_APPEND +# define FFSYNC O_FSYNC +# define FASYNC O_ASYNC +# define FNONBLOCK O_NONBLOCK +# define FNDELAY O_NDELAY +#endif /* Use BSD. */ diff --git a/libc/sysdeps/linux/cris/bits/huge_val.h b/libc/sysdeps/linux/cris/bits/huge_val.h new file mode 100644 index 000000000..43f576d8a --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/huge_val.h @@ -0,0 +1,81 @@ +/* `HUGE_VAL' constants for ix86 (where it is infinity). + Used by <stdlib.h> and <math.h> functions for overflow. + Copyright (C) 1992, 1995, 1996, 1997, 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _MATH_H +# error "Never use <bits/huge_val.h> directly; include <math.h> instead." +#endif + +#include <features.h> + +/* IEEE positive infinity (-HUGE_VAL is negative infinity). */ + +#if __GNUC_PREREQ(2,96) +# define HUGE_VAL (__extension__ 0x1.0p2047) +#else +# define __HUGE_VAL_bytes { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } + +# define __huge_val_t union { unsigned char __c[8]; double __d; } +# ifdef __GNUC__ +# define HUGE_VAL (__extension__ \ + ((__huge_val_t) { __c: __HUGE_VAL_bytes }).__d) +# else /* Not GCC. */ +static __huge_val_t __huge_val = { __HUGE_VAL_bytes }; +# define HUGE_VAL (__huge_val.__d) +# endif /* GCC. */ +#endif /* GCC 2.95 */ + + +/* ISO C99 extensions: (float) HUGE_VALF and (long double) HUGE_VALL. */ + +#ifdef __USE_ISOC99 + +# if __GNUC_PREREQ(2,96) + +# define HUGE_VALF (__extension__ 0x1.0p255f) +# define HUGE_VALL (__extension__ 0x1.0p32767L) + +# else + +# define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f } + +# define __huge_valf_t union { unsigned char __c[4]; float __f; } +# ifdef __GNUC__ +# define HUGE_VALF (__extension__ \ + ((__huge_valf_t) { __c: __HUGE_VALF_bytes }).__f) +# else /* Not GCC. */ +static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes }; +# define HUGE_VALF (__huge_valf.__f) +# endif /* GCC. */ + + +# define __HUGE_VALL_bytes { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0x7f, 0, 0 } + +# define __huge_vall_t union { unsigned char __c[12]; long double __ld; } +# ifdef __GNUC__ +# define HUGE_VALL (__extension__ \ + ((__huge_vall_t) { __c: __HUGE_VALL_bytes }).__ld) +# else /* Not GCC. */ +static __huge_vall_t __huge_vall = { __HUGE_VALL_bytes }; +# define HUGE_VALL (__huge_vall.__ld) +# endif /* GCC. */ + +# endif /* GCC 2.95 */ + +#endif /* __USE_ISOC99. */ diff --git a/libc/sysdeps/linux/cris/bits/kernel_stat.h b/libc/sysdeps/linux/cris/bits/kernel_stat.h new file mode 100644 index 000000000..5f0c0f4fe --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/kernel_stat.h @@ -0,0 +1,80 @@ +/* Taken from linux/include/asm-cris/stat.h */ + +#ifndef _CRIS_STAT_H +#define _CRIS_STAT_H + +struct __old_kernel_stat { + unsigned short st_dev; + unsigned short st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned short st_rdev; + unsigned long st_size; + unsigned long st_atime; + unsigned long st_mtime; + unsigned long st_ctime; +}; + +struct 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; + unsigned long st_atime; + unsigned long __unused1; + unsigned long st_mtime; + unsigned long __unused2; + unsigned long st_ctime; + unsigned long __unused3; + unsigned long __unused4; + unsigned long __unused5; +}; + +/* This matches struct stat64 in glibc2.1, hence the absolutely + * insane amounts of padding around dev_t's. + */ +struct stat64 { + unsigned short st_dev; + unsigned char __pad0[10]; + +#define STAT64_HAS_BROKEN_ST_INO 1 + 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 */ + + unsigned long st_atime; + unsigned long __pad5; + + unsigned long st_mtime; + unsigned long __pad6; + + unsigned long st_ctime; + unsigned long __pad7; /* will be high 32 bits of ctime someday */ + + unsigned long long st_ino; +}; + +#endif diff --git a/libc/sysdeps/linux/cris/bits/kernel_types.h b/libc/sysdeps/linux/cris/bits/kernel_types.h new file mode 100644 index 000000000..e5cdacc7b --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/kernel_types.h @@ -0,0 +1,45 @@ +/* Taken from linux/include/asm-cris/posix_types.h */ + +#ifndef __ARCH_CRIS_POSIX_TYPES_H +#define __ARCH_CRIS_POSIX_TYPES_H + +typedef unsigned short __kernel_dev_t; +typedef unsigned long __kernel_ino_t; +typedef unsigned short __kernel_mode_t; +typedef unsigned short __kernel_nlink_t; +typedef long __kernel_off_t; +typedef int __kernel_pid_t; +typedef unsigned short __kernel_ipc_pid_t; +typedef unsigned short __kernel_uid_t; +typedef unsigned short __kernel_gid_t; +typedef unsigned long __kernel_size_t; +typedef long __kernel_ssize_t; +typedef int __kernel_ptrdiff_t; +typedef long __kernel_time_t; +typedef long __kernel_suseconds_t; +typedef long __kernel_clock_t; +typedef int __kernel_daddr_t; +typedef char * __kernel_caddr_t; +typedef unsigned short __kernel_uid16_t; +typedef unsigned short __kernel_gid16_t; +typedef unsigned int __kernel_uid32_t; +typedef unsigned int __kernel_gid32_t; + +typedef unsigned short __kernel_old_uid_t; +typedef unsigned short __kernel_old_gid_t; + +#ifdef __GNUC__ +typedef long long __kernel_loff_t; +#endif + +typedef struct { +#if defined(__USE_ALL) + int val[2]; +#else + int __val[2]; +#endif +} __kernel_fsid_t; + +/* should this ifdef be here ? */ + +#endif /* __ARCH_CRIS_POSIX_TYPES_H */ diff --git a/libc/sysdeps/linux/cris/bits/mathcalls.h b/libc/sysdeps/linux/cris/bits/mathcalls.h new file mode 100644 index 000000000..c1181f737 --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/mathcalls.h @@ -0,0 +1,333 @@ +/* Prototype declarations for math functions; helper file for <math.h>. + Copyright (C) 1996,1997,1998,1999,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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* NOTE: Because of the special way this file is used by <math.h>, this + file must NOT be protected from multiple inclusion as header files + usually are. + + This file provides prototype declarations for the math functions. + Most functions are declared using the macro: + + __MATHCALL (NAME,[_r], (ARGS...)); + + This means there is a function `NAME' returning `double' and a function + `NAMEf' returning `float'. Each place `_Mdouble_' appears in the + prototype, that is actually `double' in the prototype for `NAME' and + `float' in the prototype for `NAMEf'. Reentrant variant functions are + called `NAME_r' and `NAMEf_r'. + + Functions returning other types like `int' are declared using the macro: + + __MATHDECL (TYPE, NAME,[_r], (ARGS...)); + + This is just like __MATHCALL but for a function returning `TYPE' + instead of `_Mdouble_'. In all of these cases, there is still + both a `NAME' and a `NAMEf' that takes `float' arguments. + + Note that there must be no whitespace before the argument passed for + NAME, to make token pasting work with -traditional. */ + +#ifndef _MATH_H + #error "Never include <bits/mathcalls.h> directly; include <math.h> instead." +#endif + + +/* Trigonometric functions. */ + +/* Arc cosine of X. */ +__MATHCALL (acos,, (_Mdouble_ __x)); +/* Arc sine of X. */ +__MATHCALL (asin,, (_Mdouble_ __x)); +/* Arc tangent of X. */ +__MATHCALL (atan,, (_Mdouble_ __x)); +/* Arc tangent of Y/X. */ +__MATHCALL (atan2,, (_Mdouble_ __y, _Mdouble_ __x)); + +/* Cosine of X. */ +__MATHCALL (cos,, (_Mdouble_ __x)); +/* Sine of X. */ +__MATHCALL (sin,, (_Mdouble_ __x)); +/* Tangent of X. */ +__MATHCALL (tan,, (_Mdouble_ __x)); + +#ifdef __USE_GNU +/* Cosine and sine of X. */ +__MATHDECL (void,sincos,, + (_Mdouble_ __x, _Mdouble_ *__sinx, _Mdouble_ *__cosx)); +#endif + +/* Hyperbolic functions. */ + +/* Hyperbolic cosine of X. */ +__MATHCALL (cosh,, (_Mdouble_ __x)); +/* Hyperbolic sine of X. */ +__MATHCALL (sinh,, (_Mdouble_ __x)); +/* Hyperbolic tangent of X. */ +__MATHCALL (tanh,, (_Mdouble_ __x)); + +#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 +/* Hyperbolic arc cosine of X. */ +__MATHCALL (acosh,, (_Mdouble_ __x)); +/* Hyperbolic arc sine of X. */ +__MATHCALL (asinh,, (_Mdouble_ __x)); +/* Hyperbolic arc tangent of X. */ +__MATHCALL (atanh,, (_Mdouble_ __x)); +#endif + +/* Exponential and logarithmic functions. */ + +/* Exponential function of X. */ +__MATHCALL (exp,, (_Mdouble_ __x)); + +#ifdef __USE_GNU +/* A function missing in all standards: compute exponent to base ten. */ +__MATHCALL (exp10,, (_Mdouble_ __x)); +/* Another name occasionally used. */ +__MATHCALL (pow10,, (_Mdouble_ __x)); +#endif + +/* Break VALUE into a normalized fraction and an integral power of 2. */ +__MATHCALL (frexp,, (_Mdouble_ __x, int *__exponent)); + +/* X times (two to the EXP power). */ +__MATHCALL (ldexp,, (_Mdouble_ __x, int __exponent)); + +/* Natural logarithm of X. */ +__MATHCALL (log,, (_Mdouble_ __x)); + +/* Base-ten logarithm of X. */ +__MATHCALL (log10,, (_Mdouble_ __x)); + +/* Break VALUE into integral and fractional parts. */ +__MATHCALL (modf,, (_Mdouble_ __x, _Mdouble_ *__iptr)); + +#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 +/* Return exp(X) - 1. */ +__MATHCALL (expm1,, (_Mdouble_ __x)); + +/* Return log(1 + X). */ +__MATHCALL (log1p,, (_Mdouble_ __x)); + +/* Return the base 2 signed integral exponent of X. */ +__MATHCALL (logb,, (_Mdouble_ __x)); +#endif + +#ifdef __USE_ISOC99 +/* Compute base-2 exponential of X. */ +__MATHCALL (exp2,, (_Mdouble_ __x)); + +/* Compute base-2 logarithm of X. */ +__MATHCALL (log2,, (_Mdouble_ __x)); +#endif + + +/* Power functions. */ + +/* Return X to the Y power. */ +__MATHCALL (pow,, (_Mdouble_ __x, _Mdouble_ __y)); + +/* Return the square root of X. */ +__MATHCALL (sqrt,, (_Mdouble_ __x)); + +#if defined __USE_MISC || defined __USE_XOPEN || defined __USE_ISOC99 +/* Return `sqrt(X*X + Y*Y)'. */ +__MATHCALL (hypot,, (_Mdouble_ __x, _Mdouble_ __y)); +#endif + +#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 +/* Return the cube root of X. */ +__MATHCALL (cbrt,, (_Mdouble_ __x)); +#endif + + +/* Nearest integer, absolute value, and remainder functions. */ + +/* Smallest integral value not less than X. */ +__MATHCALL (ceil,, (_Mdouble_ __x)); + +/* Absolute value of X. */ +__MATHCALLX (fabs,, (_Mdouble_ __x), (__const__)); + +/* Largest integer not greater than X. */ +__MATHCALL (floor,, (_Mdouble_ __x)); + +/* Floating-point modulo remainder of X/Y. */ +__MATHCALL (fmod,, (_Mdouble_ __x, _Mdouble_ __y)); + + +/* Return 0 if VALUE is finite or NaN, +1 if it + is +Infinity, -1 if it is -Infinity. */ +__MATHDECL_1 (int,__isinf,, (_Mdouble_ __value)) __attribute__ ((__const__)); + +/* Return nonzero if VALUE is finite and not NaN. */ +__MATHDECL_1 (int,__finite,, (_Mdouble_ __value)) __attribute__ ((__const__)); + +#ifdef __USE_MISC +/* Return 0 if VALUE is finite or NaN, +1 if it + is +Infinity, -1 if it is -Infinity. */ +__MATHDECL_1 (int,isinf,, (_Mdouble_ __value)) __attribute__ ((__const__)); + +/* Return nonzero if VALUE is finite and not NaN. */ +__MATHDECL_1 (int,finite,, (_Mdouble_ __value)) __attribute__ ((__const__)); + +/* Return the remainder of X/Y. */ +__MATHCALL (drem,, (_Mdouble_ __x, _Mdouble_ __y)); + + +/* Return the fractional part of X after dividing out `ilogb (X)'. */ +__MATHCALL (significand,, (_Mdouble_ __x)); +#endif /* Use misc. */ + +#if defined __USE_MISC || defined __USE_ISOC99 +/* Return X with its signed changed to Y's. */ +__MATHCALLX (copysign,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)); +#endif + +#ifdef __USE_ISOC99 +/* Return representation of NaN for double type. */ +__MATHCALLX (nan,, (__const char *__tagb), (__const__)); +#endif + + +/* Return nonzero if VALUE is not a number. */ +__MATHDECL_1 (int,__isnan,, (_Mdouble_ __value)) __attribute__ ((__const__)); + +#if defined __USE_MISC || defined __USE_XOPEN +/* Return nonzero if VALUE is not a number. */ +__MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__)); + +/* Bessel functions. */ +__MATHCALL (j0,, (_Mdouble_)); +__MATHCALL (j1,, (_Mdouble_)); +__MATHCALL (jn,, (int, _Mdouble_)); +__MATHCALL (y0,, (_Mdouble_)); +__MATHCALL (y1,, (_Mdouble_)); +__MATHCALL (yn,, (int, _Mdouble_)); +#endif + + +#if defined __USE_MISC || defined __USE_XOPEN || defined __USE_ISOC99 +/* Error and gamma functions. */ +__MATHCALL (erf,, (_Mdouble_)); +__MATHCALL (erfc,, (_Mdouble_)); +__MATHCALL (lgamma,, (_Mdouble_)); +#endif + +#ifdef __USE_ISOC99 +__MATHCALL (tgamma,, (_Mdouble_)); +#endif + +#if defined __USE_MISC || defined __USE_XOPEN +/* Obsolete alias for `lgamma'. */ +__MATHCALL (gamma,, (_Mdouble_)); +#endif + +#ifdef __USE_MISC +/* Reentrant version of lgamma. This function uses the global variable + `signgam'. The reentrant version instead takes a pointer and stores + the value through it. */ +__MATHCALL (lgamma,_r, (_Mdouble_, int *__signgamp)); +#endif + + +#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 +/* Return the integer nearest X in the direction of the + prevailing rounding mode. */ +__MATHCALL (rint,, (_Mdouble_ __x)); + +/* Return X + epsilon if X < Y, X - epsilon if X > Y. */ +__MATHCALLX (nextafter,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)); +# ifdef __USE_ISOC99 +__MATHCALLX (nexttoward,, (_Mdouble_ __x, long double __y), (__const__)); +# endif + +/* Return the remainder of integer divison X / Y with infinite precision. */ +__MATHCALL (remainder,, (_Mdouble_ __x, _Mdouble_ __y)); + +# if defined __USE_MISC || defined __USE_XOPEN_EXTENDED +/* Return X times (2 to the Nth power). */ +__MATHCALL (scalb,, (_Mdouble_ __x, _Mdouble_ __n)); +# endif + +# if defined __USE_MISC || defined __USE_ISOC99 +/* Return X times (2 to the Nth power). */ +__MATHCALL (scalbn,, (_Mdouble_ __x, int __n)); +# endif + +/* Return the binary exponent of X, which must be nonzero. */ +__MATHDECL (int,ilogb,, (_Mdouble_ __x)); +#endif + +#ifdef __USE_ISOC99 +/* Return X times (2 to the Nth power). */ +__MATHCALL (scalbln,, (_Mdouble_ __x, long int __n)); + +/* Round X to integral value in floating-point format using current + rounding direction, but do not raise inexact exception. */ +__MATHCALL (nearbyint,, (_Mdouble_ __x)); + +/* Round X to nearest integral value, rounding halfway cases away from + zero. */ +__MATHCALL (round,, (_Mdouble_ __x)); + +/* Round X to the integral value in floating-point format nearest but + not larger in magnitude. */ +__MATHCALLX (trunc,, (_Mdouble_ __x), (__const__)); + +/* Compute remainder of X and Y and put in *QUO a value with sign of x/y + and magnitude congruent `mod 2^n' to the magnitude of the integral + quotient x/y, with n >= 3. */ +__MATHCALL (remquo,, (_Mdouble_ __x, _Mdouble_ __y, int *__quo)); + + +/* Conversion functions. */ + +/* Round X to nearest integral value according to current rounding + direction. */ +__MATHDECL (long int,lrint,, (_Mdouble_ __x)); +__MATHDECL (long long int,llrint,, (_Mdouble_ __x)); + +/* Round X to nearest integral value, rounding halfway cases away from + zero. */ +__MATHDECL (long int,lround,, (_Mdouble_ __x)); +__MATHDECL (long long int,llround,, (_Mdouble_ __x)); + + +/* Return positive difference between X and Y. */ +__MATHCALL (fdim,, (_Mdouble_ __x, _Mdouble_ __y)); + +/* Return maximum numeric value from X and Y. */ +__MATHCALL (fmax,, (_Mdouble_ __x, _Mdouble_ __y)); + +/* Return minimum numeric value from X and Y. */ +__MATHCALL (fmin,, (_Mdouble_ __x, _Mdouble_ __y)); + + +/* Classify given number. */ +__MATHDECL_1 (int, __fpclassify,, (_Mdouble_ __value)) + __attribute__ ((__const__)); + +/* Test for negative number. */ +__MATHDECL_1 (int, __signbit,, (_Mdouble_ __value)) + __attribute__ ((__const__)); + + +/* Multiply-add function computed as a ternary operation. */ +__MATHCALL (fma,, (_Mdouble_ __x, _Mdouble_ __y, _Mdouble_ __z)); +#endif /* Use ISO C99. */ diff --git a/libc/sysdeps/linux/cris/bits/mman.h b/libc/sysdeps/linux/cris/bits/mman.h new file mode 100644 index 000000000..16216855f --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/mman.h @@ -0,0 +1,93 @@ +/* Definitions for POSIX memory map interface. Linux/cris version. + Copyright (C) 1997, 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_MMAN_H +# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead." +#endif + +/* The following definitions basically come from the kernel headers. + But the kernel header is not namespace clean. */ + + +/* Protections are chosen from these bits, OR'd together. The + implementation does not necessarily support PROT_EXEC or PROT_WRITE + without PROT_READ. The only guarantees are that no writing will be + allowed without PROT_WRITE and no access will be allowed for PROT_NONE. */ + +#define PROT_READ 0x1 /* Page can be read. */ +#define PROT_WRITE 0x2 /* Page can be written. */ +#define PROT_EXEC 0x4 /* Page can be executed. */ +#define PROT_NONE 0x0 /* Page can not be accessed. */ + +/* Sharing types (must choose one and only one of these). */ +#define MAP_SHARED 0x01 /* Share changes. */ +#define MAP_PRIVATE 0x02 /* Changes are private. */ +#ifdef __USE_MISC +# define MAP_TYPE 0x0f /* Mask for type of mapping. */ +#endif + +/* Other flags. */ +#define MAP_FIXED 0x10 /* Interpret addr exactly. */ +#ifdef __USE_MISC +# define MAP_FILE 0 +# define MAP_ANONYMOUS 0x20 /* Don't use a file. */ +# define MAP_ANON MAP_ANONYMOUS +#endif + +/* These are Linux-specific. */ +#ifdef __USE_MISC +# define MAP_GROWSDOWN 0x0100 /* Stack-like segment. */ +# define MAP_DENYWRITE 0x0800 /* ETXTBSY */ +# define MAP_EXECUTABLE 0x1000 /* Mark it as an executable. */ +# define MAP_LOCKED 0x2000 /* Lock the mapping. */ +# define MAP_NORESERVE 0x4000 /* Don't check for reservations. */ +#endif + +/* Flags to `msync'. */ +#define MS_ASYNC 1 /* Sync memory asynchronously. */ +#define MS_SYNC 4 /* Synchronous memory sync. */ +#define MS_INVALIDATE 2 /* Invalidate the caches. */ + +/* Flags for `mlockall'. */ +#define MCL_CURRENT 1 /* Lock all currently mapped pages. */ +#define MCL_FUTURE 2 /* Lock all additions to address + space. */ + +/* Flags for `mremap'. */ +#ifdef __USE_GNU +# define MREMAP_MAYMOVE 1 +#endif + +/* Advice to `madvise'. */ +#ifdef __USE_BSD +# define MADV_NORMAL 0 /* No further special treatment. */ +# define MADV_RANDOM 1 /* Expect random page references. */ +# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */ +# define MADV_WILLNEED 3 /* Will need these pages. */ +# define MADV_DONTNEED 4 /* Don't need these pages. */ +#endif + +/* The POSIX people had to invent similar names for the same things. */ +#ifdef __USE_XOPEN2K +# define POSIX_MADV_NORMAL 0 /* No further special treatment. */ +# define POSIX_MADV_RANDOM 1 /* Expect random page references. */ +# define POSIX_MADV_SEQUENTIAL 2 /* Expect sequential page references. */ +# define POSIX_MADV_WILLNEED 3 /* Will need these pages. */ +# define POSIX_MADV_DONTNEED 4 /* Don't need these pages. */ +#endif diff --git a/libc/sysdeps/linux/cris/bits/setjmp.h b/libc/sysdeps/linux/cris/bits/setjmp.h new file mode 100644 index 000000000..ba9cbc93c --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/setjmp.h @@ -0,0 +1,64 @@ +/* Copyright (C) 1997, 1998 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 Library General Public License as + published by the Free Software Foundation; either version 2 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. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* Define the machine-dependent type `jmp_buf'. CRIS version. */ + +#ifndef _SETJMP_H +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead." +#endif + +/* + Note that we save and restore CCR to be able to + correctly handle DI/EI. Note also that the "move x,ccr" does NOT affect + the DMA enable bits (E and D). + + jmp_buf[0] - PC + jmp_buf[1] - SP (R14) + jmp_buf[2] - R13 + jmp_buf[3] - R12 + jmp_buf[4] - R11 + jmp_buf[5] - R10 + jmp_buf[6] - R9 + jmp_buf[7] - R8 + jmp_buf[8] - R7 + jmp_buf[9] - R6 + jmp_buf[10] - R5 + jmp_buf[11] - R4 + jmp_buf[12] - R3 + jmp_buf[13] - R2 + jmp_buf[14] - R1 + jmp_buf[15] - R0 + jmp_buf[16] - SRP + jmp_buf[17] - CCR + */ + +#define _JBLEN 18 +#if defined (__USE_MISC) || defined (_ASM) +#define JB_SP 1 +#endif + +#ifndef _ASM +typedef int __jmp_buf[_JBLEN]; +#endif + +/* Test if longjmp to JMPBUF would unwind the frame + containing a local variable at ADDRESS. */ +#define _JMPBUF_UNWINDS(jmpbuf, address) \ + ((void *) (address) < (void *) (jmpbuf)[JB_SP]) + + diff --git a/libc/sysdeps/linux/cris/bits/shm.h b/libc/sysdeps/linux/cris/bits/shm.h new file mode 100644 index 000000000..c7070595b --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/shm.h @@ -0,0 +1,84 @@ +/* Copyright (C) 1995, 1996, 1997 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 Library General Public License as + published by the Free Software Foundation; either version 2 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. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _SYS_SHM_H +# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead." +#endif + +#include <sys/types.h> + +/* Permission flag for shmget. */ +#define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */ +#define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */ + +/* Flags for `shmat'. */ +#define SHM_RDONLY 010000 /* attach read-only else read-write */ +#define SHM_RND 020000 /* round attach address to SHMLBA */ +#define SHM_REMAP 040000 /* take-over region on attach */ + +/* Commands for `shmctl'. */ +#define SHM_LOCK 11 /* lock segment (root only) */ +#define SHM_UNLOCK 12 /* unlock segment (root only) */ + + +/* Data structure describing a set of semaphores. */ +struct shmid_ds + { + struct ipc_perm shm_perm; /* operation permission struct */ + int shm_segsz; /* size of segment in bytes */ + __time_t shm_atime; /* time of last shmat() */ + __time_t shm_dtime; /* time of last shmdt() */ + __time_t shm_ctime; /* time of last change by shmctl() */ + __ipc_pid_t shm_cpid; /* pid of creator */ + __ipc_pid_t shm_lpid; /* pid of last shmop */ + unsigned short int shm_nattch; /* number of current attaches */ + unsigned short int __shm_npages; /* size of segment (pages) */ + unsigned long int *__shm_pages; /* array of ptrs to frames -> SHMMAX */ + struct vm_area_struct *__attaches; /* descriptors for attaches */ + }; + +#ifdef __USE_MISC + +/* ipcs ctl commands */ +# define SHM_STAT 13 +# define SHM_INFO 14 + +/* shm_mode upper byte flags */ +# define SHM_DEST 01000 /* segment will be destroyed on last detach */ +# define SHM_LOCKED 02000 /* segment will not be swapped */ + +struct shminfo + { + int shmmax; + int shmmin; + int shmmni; + int shmseg; + int shmall; + }; + +struct shm_info + { + int used_ids; + unsigned long int shm_tot; /* total allocated shm */ + unsigned long int shm_rss; /* total resident shm */ + unsigned long int shm_swp; /* total swapped shm */ + unsigned long int swap_attempts; + unsigned long int swap_successes; + }; + +#endif /* __USE_MISC */ diff --git a/libc/sysdeps/linux/cris/bits/syscalls.h b/libc/sysdeps/linux/cris/bits/syscalls.h new file mode 100644 index 000000000..5c30e2193 --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/syscalls.h @@ -0,0 +1,10 @@ +/* + * nothing needed here until we want pthread support or similar + */ + +#include <features.h> +/* Do something very evil for now. Until we include our out syscall + * macros, short circuit bits/syscall.h and use asm/unistd.h instead */ +#define _BITS_SYSCALL_H +#include <asm/unistd.h> + diff --git a/libc/sysdeps/linux/cris/bits/wordsize.h b/libc/sysdeps/linux/cris/bits/wordsize.h new file mode 100644 index 000000000..d6a2fc685 --- /dev/null +++ b/libc/sysdeps/linux/cris/bits/wordsize.h @@ -0,0 +1,19 @@ +/* Copyright (C) 1999 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 Library General Public License as + published by the Free Software Foundation; either version 2 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. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#define __WORDSIZE 32 diff --git a/libc/sysdeps/linux/cris/brk.c b/libc/sysdeps/linux/cris/brk.c new file mode 100644 index 000000000..7814d52c3 --- /dev/null +++ b/libc/sysdeps/linux/cris/brk.c @@ -0,0 +1,31 @@ +#include <unistd.h> +#include <sys/syscall.h> +#include <errno.h> +#include "sysdep.h" + +extern void * ___brk_addr; + +extern int __init_brk (void); + +int brk(void * end_data_seg) +{ + if (__init_brk () == 0) { + /* Notice that we don't need to save/restore the GOT + * register since that is not call clobbered by the syscall + */ + + asm ("move.d %1,$r10\n\t" + "movu.w " STR(__NR_brk) ",$r9\n\t" + "break 13\n\t" + "move.d $r10, %0" + : "=r" (___brk_addr) + : "g" (end_data_seg) + : "r9", "r10"); + + if (___brk_addr == end_data_seg) + return 0; + __set_errno(ENOMEM); + } + return -1; + +} diff --git a/libc/sysdeps/linux/cris/crt0.c b/libc/sysdeps/linux/cris/crt0.c new file mode 100644 index 000000000..03b0d6ff3 --- /dev/null +++ b/libc/sysdeps/linux/cris/crt0.c @@ -0,0 +1,49 @@ +/* $Id: crt0.c,v 1.1 2002/09/16 08:08:33 tobiasa Exp $ */ + +/* C base for Linux/CRIS 2.0/2.4 + */ + +//#define DEBUG + +/* The first piece of initialized data. */ +int __data_start = 0; + +/* N.B.: It is important that this be the first function. + This file is the first thing in the text section. */ + +void +_start () +{ + /* on the stack we have argc. we can calculate argv/envp + * from that and the succeeding stack location, but fix so + * we get the right calling convention (regs in r10/r11) + * + * to understand this you really ought to read fs/binfmt_elf.c + */ + __asm__ volatile("pop $r10"); + __asm__ volatile("move.d $sp, $r11"); + __asm__ volatile("jump start1"); +} + +void __uClibc_main(int argc, char **argv, char **envp) + __attribute__ ((__noreturn__)); + +static void +start1 (int argc, char **argv) +{ + char** environ; + + /* The environment starts just after ARGV. */ + environ = &argv[argc + 1]; + + /* If the first thing after ARGV is the arguments + themselves, there is no environment. */ + if ((char *) environ == *argv) + /* The environment is empty. Make environ + point at ARGV[ARGC], which is NULL. */ + --environ; + + /* Leave control to the libc */ + + __uClibc_main(argc, argv, environ); +} diff --git a/libc/sysdeps/linux/cris/fork.c b/libc/sysdeps/linux/cris/fork.c new file mode 100644 index 000000000..5ca8a723f --- /dev/null +++ b/libc/sysdeps/linux/cris/fork.c @@ -0,0 +1,10 @@ +#include <sysdep.h> + +SYSCALL__ (fork, 0) + /* R1 is now 0 for the parent and 1 for the child. Decrement it to + make it -1 (all bits set) for the parent, and 0 (no bits set) + for the child. Then AND it with R0, so the parent gets + R0&-1==R0, and the child gets R0&0==0. */ + /* i dunno what the blurb above is useful for. we just return. */ +__asm__("ret\n\tnop"); + diff --git a/libc/sysdeps/linux/cris/ipc.c b/libc/sysdeps/linux/cris/ipc.c new file mode 100644 index 000000000..574d99fcd --- /dev/null +++ b/libc/sysdeps/linux/cris/ipc.c @@ -0,0 +1,4 @@ +#include <syscall.h> + +_syscall6(int, ipc, unsigned int, call, int, first, int, second, int, third, + void *, ptr, long, fifth); diff --git a/libc/sysdeps/linux/cris/libc.map b/libc/sysdeps/linux/cris/libc.map new file mode 100644 index 000000000..6710c733d --- /dev/null +++ b/libc/sysdeps/linux/cris/libc.map @@ -0,0 +1,3 @@ +U { + local: __sigjmp_save; +}; diff --git a/libc/sysdeps/linux/cris/sbrk.c b/libc/sysdeps/linux/cris/sbrk.c new file mode 100644 index 000000000..79d924a44 --- /dev/null +++ b/libc/sysdeps/linux/cris/sbrk.c @@ -0,0 +1,36 @@ +/* From libc-5.3.12 */ + +#include <unistd.h> +#include <sys/syscall.h> +#include <errno.h> +#include "sysdep.h" + +extern void * ___brk_addr; + +extern int __init_brk (void); + +void * +sbrk(intptr_t increment) +{ + if (__init_brk () == 0) { + void * tmp = ___brk_addr + increment; + + /* Notice that we don't need to save/restore the GOT + * register since that is not call clobbered by the syscall + */ + + asm ("move.d %1,$r10\n\t" + "movu.w " STR(__NR_brk) ",$r9\n\t" + "break 13\n\t" + "move.d $r10, %0" + : "=r" (___brk_addr) + : "g" (tmp) + : "r9", "r10"); + + if (___brk_addr == tmp) + return tmp - increment; + __set_errno(ENOMEM); + return ((void *) -1); + } + return ((void *) -1); +} diff --git a/libc/sysdeps/linux/cris/setjmp.S b/libc/sysdeps/linux/cris/setjmp.S new file mode 100644 index 000000000..a5ea0e2d8 --- /dev/null +++ b/libc/sysdeps/linux/cris/setjmp.S @@ -0,0 +1,76 @@ +/* setjmp for CRIS. + Copyright (C) 1995, 1996, 1997 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 Library General Public License as + published by the Free Software Foundation; either version 2 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. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <sysdep.h> +#define _ASM +#define _SETJMP_H +#include <bits/setjmp.h> + + .syntax no_register_prefix + +ENTRY (__sigsetjmp) +.Local__sigsetjmp: + moveq 1,r9 + movem sp,[r10+1*4] +#ifdef __PIC__ + move.d pc,r9 + addq 0f-.,r9 +#else + move.d 0f,r9 +#endif + move.d r9,[r10] + move srp,[r10+16*4] + PLTJUMP (__sigjmp_save) +0: /* This is where longjmp returns. (Don't use "ret" - it's a macro. */ + Ret + move.d r9,r10 +END (__sigsetjmp) + +/* Binary compatibility entry points. Having these in separate files + is not meaningful and just adds library overhead. */ + +ENTRY (__setjmp) + ba .Local__sigsetjmp + moveq 0,r11 +END (__setjmp) + +ENTRY (_setjmp) + ba .Local__sigsetjmp + moveq 0,r11 +END (_setjmp) + +ENTRY (setjmp) + ba .Local__sigsetjmp + moveq 1,r11 +END (setjmp) + +/* +weak_extern (__setjmp) +weak_extern (_setjmp) +weak_extern (setjmp) +*/ + + + + + + + + + diff --git a/libc/sysdeps/linux/cris/sys/ucontext.h b/libc/sysdeps/linux/cris/sys/ucontext.h new file mode 100644 index 000000000..5f875453f --- /dev/null +++ b/libc/sysdeps/linux/cris/sys/ucontext.h @@ -0,0 +1,95 @@ +/* Copyright (C) 1997, 1999, 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* System V/cris ABI compliant context switching support. */ + +#ifndef _SYS_UCONTEXT_H +#define _SYS_UCONTEXT_H 1 + +#include <features.h> +#include <signal.h> + +#include <bits/sigcontext.h> + +/* Type for general register. */ +typedef long int greg_t; + +/* Number of general registers. */ +#define NGREG 20 + +/* Container for all general registers. */ +typedef greg_t gregset_t[NGREG]; + +/* Number of each register is the `gregset_t' array. */ +enum +{ + R0 = 0, +#define R0 R0 + R1 = 1, +#define R1 R1 + R2 = 2, +#define R2 R2 + R3 = 3, +#define R3 R3 + R4 = 4, +#define R4 R4 + R5 = 5, +#define R5 R5 + R6 = 6, +#define R6 R6 + R7 = 7, +#define R7 R7 + R8 = 8, +#define R8 R8 + R9 = 9, +#define R9 R9 + R10 = 10, +#define R10 R10 + R11 = 11, +#define R11 R11 + R12 = 12, +#define R12 R12 + R13 = 13, +#define R13 R13 + R14 = 14, +#define R14 R14 + R15 = 15, +#define R15 R15 + R_SP = R14, +#define R_SP R_SP + R_PC = R15, +#define R_PC R_PC +}; + +/* A placeholder; CRIS does not have any fp regs. */ +typedef unsigned long fpregset_t; + +/* A machine context is exactly a sigcontext. */ +typedef struct sigcontext mcontext_t; + +/* Userlevel context. */ +typedef struct ucontext + { + unsigned long int uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + __sigset_t uc_sigmask; + } ucontext_t; + +#endif /* sys/ucontext.h */ diff --git a/libc/sysdeps/linux/cris/syscall-cris.c b/libc/sysdeps/linux/cris/syscall-cris.c new file mode 100644 index 000000000..fa923ec9d --- /dev/null +++ b/libc/sysdeps/linux/cris/syscall-cris.c @@ -0,0 +1,41 @@ +/* syscall.c - generalized linux system call interface */ + +#include <stdarg.h> +#include <syscall.h> +#include <errno.h> + +/* perform a Linux/CRIS system call with variable number of arguments + * put them and the syscall number in the right registers and call + * break 13. + */ + +int +syscall(int number, ...) +{ + register long __a __asm__ ("r10"); + register long __b __asm__ ("r11"); + register long __c __asm__ ("r12"); + register long __d __asm__ ("r13"); + register long __e __asm__ ("r0"); + va_list args; + + va_start(args, number); + __a = va_arg(args, int); + __b = va_arg(args, int); + __c = va_arg(args, int); + __d = va_arg(args, int); + __e = va_arg(args, int); + va_end(args); + + __asm__ volatile ("movu.w %1,$r9\n\tbreak 13\n\t" + : "=r" (__a) + : "g" (number), "0" (__a), "r" (__b), "r" (__c), "r" (__d), + "r" (__e) + : "r10", "r9"); + + if (__a >= 0) + return __a; + + errno = -__a; + return -1; +} diff --git a/libc/sysdeps/linux/cris/syscall.S b/libc/sysdeps/linux/cris/syscall.S new file mode 100644 index 000000000..d52a6ba05 --- /dev/null +++ b/libc/sysdeps/linux/cris/syscall.S @@ -0,0 +1,18 @@ +#include <sys/syscall.h> + + .globl __syscall_error +__syscall_error: + + neg.d $r10,$r10 + + push $r10 + push $srp + jsr __errno_location + pop $srp + pop $r11 + move.d $r11,[$r10] + + moveq -1, $r10 + ret + nop + diff --git a/libc/sysdeps/linux/cris/sysdep.h b/libc/sysdeps/linux/cris/sysdep.h new file mode 100644 index 000000000..e01752ae9 --- /dev/null +++ b/libc/sysdeps/linux/cris/sysdep.h @@ -0,0 +1,125 @@ +/* Assembler macros for CRIS. + Copyright (C) 1999, 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 Library General Public License as + published by the Free Software Foundation; either version 2 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. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef C_LABEL + +/* Define a macro we can use to construct the asm name for a C symbol. */ +#ifdef __STDC__ +#define C_LABEL(name) name##: +#else +#define C_LABEL(name) name/**/: +#endif + +#endif /* C_LABEL */ + +#define __STR(x) #x +#define STR(x) __STR(x) + +/* Mark the end of function named SYM. This is used on some platforms + to generate correct debugging information. */ +#ifndef END +#define END(sym) +#endif + +#define C_SYMBOL_NAME(name) name + +#ifdef __ASSEMBLER__ + +/* Syntactic details of assembly-code. */ + +/* It is *not* generally true that "ELF uses byte-counts for .align, most + others use log2 of count of bytes", like some neighboring configs say. + See "align" in gas/read.c which is not overridden by + gas/config/obj-elf.c. It takes a log2 argument. *Some* targets + override it to take a byte argument. People should read source instead + of relying on hearsay. */ +#define ALIGNARG(log2) log2 + +#define ASM_GLOBAL_DIRECTIVE .globl +#define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg +#define ASM_SIZE_DIRECTIVE(name) .size name,.-name + +/* The non-PIC jump is preferred, since it does not stall, and does not + invoke generation of a PLT. These macros assume that $r0 is set up as + GOT register. */ +#ifdef __PIC__ +#define PLTJUMP(_x) \ + add.d C_SYMBOL_NAME (_x):PLT,$pc + +#define PLTCALL(_x) \ + jsr [$r0+C_SYMBOL_NAME (_x):GOTPLT16] + +#define SETUP_PIC \ + push $r0 @ \ + move.d $pc,$r0 @ \ + sub.d .:GOTOFF,$r0 + +#define TEARDOWN_PIC pop $r0 +#else +#define PLTJUMP(_x) jump C_SYMBOL_NAME (_x) +#define PLTCALL(_x) jsr C_SYMBOL_NAME (_x) +#define SETUP_PIC +#define TEARDOWN_PIC +#endif + +/* Define an entry point visible from C. */ +#define ENTRY(name) \ + .text @ \ + ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (name) @ \ + ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME (name), function) @ \ + .align ALIGNARG (2) @ \ + C_LABEL(name) @ \ + CALL_MCOUNT + +#undef END +#define END(name) \ + ASM_SIZE_DIRECTIVE (C_SYMBOL_NAME (name)) + +/* If compiled for profiling, call `mcount' at the start of each function. + FIXME: Note that profiling is not actually implemented. This is just + example code which might not even compile, though it is believed to be + correct. */ +#ifdef PROF +#define CALL_MCOUNT \ + push $srp @ \ + push $r9 @ \ + push $r10 @ \ + push $r11 @ \ + push $r12 @ \ + push $r13 @ \ + SETUP_PIC @ \ + PLTCALL (mcount) @ \ + TEARDOWN_PIC @ \ + pop $r13 @ \ + pop $r12 @ \ + pop $r11 @ \ + pop $r10 @ \ + pop $r9 @ \ + pop $srp +#else +#define CALL_MCOUNT /* Do nothing. */ +#endif + +/* Since C identifiers are not normally prefixed with an underscore + on this system, the asm identifier `syscall_error' intrudes on the + C name space. Make sure we use an innocuous name. */ +#define syscall_error __syscall_error +#define mcount _mcount + +#endif /* __ASSEMBLER__ */ diff --git a/libc/sysdeps/linux/cris/vfork.c b/libc/sysdeps/linux/cris/vfork.c new file mode 100644 index 000000000..54c6a47da --- /dev/null +++ b/libc/sysdeps/linux/cris/vfork.c @@ -0,0 +1,11 @@ +#include <sys/types.h> +#include <sys/syscall.h> +#include <unistd.h> + +__pid_t +__vfork __P ((void)) +{ + return fork(); +} + +weak_alias (__vfork, vfork) |