CRIS/CRISv32 port, libgloss part (second and last part)

Jeff Johnston jjohnstn@redhat.com
Thu Jan 27 23:02:00 GMT 2005


Patch checked in.  All that's waiting is the revised newlib patch.

-- Jeff J.

Hans-Peter Nilsson wrote:
> Currently, there are no simple start-up and driver files for
> "bare iron"; just stubs, mostly falling back to libnosys.a.  I
> hope Axis can contribute some working minimal drivers soon,
> enough for, say, a working "hello, world" outputting to a
> suitable on-chip serial port.  (One goal is to run such programs
> on the SID port.)  I'm delegating those driver parts.  However,
> a user can today, given such a library (necessarily named
> libbsp.a), make programs link and hopefully work by overriding
> the existing libbsp.a just by passing a -L/where/it/is at link
> time.  No other options are necessary.
> 
> Using the cris-axis-{elf,aout}-gcc "-sim" and "-sim3" options,
> syscalls and start-up-files appropriate for the recently
> submitted GDB simulator are chosen.  Modulo a few correcting GCC
> patches I have to commit, that is.  Programs linked with -sim
> also happens by design to execute on a real cris-axis-linux-gnu
> system and vice versa; programs linked "-static" work in the
> simulator (for the subset of syscalls implemented in the
> simulator, that is).
> 
> The binutils aout support is unfortunately broken at the moment:
> the link_warning stuff seems to cause a SEGV, but linking with
> overridden libnosys functions work.  I know this has worked in
> the past and besides the interest for cris-aout should be
> negligible.  I plan to fix aout in binutils and there shouldn't
> be any changes to newlib or libgloss.
> 
> As with the newlib part, before committing please (re)generate:
> configure
> libnosys/configure
> cris/configure
> Again, if wanted, I can commit this patch and the generated
> files myself.
> 
> libgloss:
> 
> 2005-01-25  Hans-Peter Nilsson  <hp@axis.com>
> 
>         * configure.in: Support cris-*-* and crisv32-*-*.
>         * libnosys/configure.in: Ditto.
> 	* configure, libnosys/configure: Regenerate.
> 	* cris: New directory.
> 
> Index: configure.in
> ===================================================================
> RCS file: /cvs/src/src/libgloss/configure.in,v
> retrieving revision 1.10
> diff -c -p -r1.10 configure.in
> *** configure.in	28 Oct 2004 08:18:18 -0000	1.10
> --- configure.in	25 Jan 2005 20:05:48 -0000
> *************** case "${target}" in
> *** 85,90 ****
> --- 85,93 ----
>     mn10300-*-*)
>   	configdirs="${configdirs} mn10300 testsuite"
>   	;;
> +   cris-*-* | crisv32-*-*)
> + 	configdirs="${configdirs} cris testsuite"
> + 	;;
>     crx-*-*)
>   	configdirs="${configdirs} crx"
>   	;;
> Index: libnosys/configure.in
> ===================================================================
> RCS file: /cvs/src/src/libgloss/libnosys/configure.in,v
> retrieving revision 1.4
> diff -c -p -r1.4 configure.in
> *** libnosys/configure.in	18 Jan 2005 19:23:36 -0000	1.4
> --- libnosys/configure.in	25 Jan 2005 20:05:48 -0000
> *************** case "${target}" in
> *** 89,94 ****
> --- 89,96 ----
>   	;;
>     strongarm-*-*)
>   	;;
> +   cris-*-* | crisv32-*-*)
> + 	;;
>     d10v*)
>   	;;
>     h8300*-*-*)
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/crt0.S	Wed Jan 26 01:41:26 2005
> @@ -0,0 +1,83 @@
> +/* Generic simplistic start-up-stub for CRIS/CRISv32.
> +   Copyright (C) 1993-2005 Axis Communications.
> +   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. Neither the name of Axis Communications nor the names of its
> +      contributors may be used to endorse or promote products derived
> +      from this software without specific prior written permission.
> +
> +   THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS 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 AXIS
> +   COMMUNICATIONS OR ITS 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.  */
> +
> +#undef cris
> +#undef L
> +#ifdef __NO_UNDERSCORES__
> +#define L(x) x
> +#else
> +#define L(x) _ ## x
> +#endif
> +
> +; Rudimentary v0..v32-compatible startup stub.
> +
> +#ifdef __ELF__
> + .section .startup,"ax"
> +#endif
> + .global __start
> + nop
> +__start:
> + ba 0f
> + nop
> +
> + .rept 256 - 2
> + .dword _.int
> + .endr
> +
> +_.int:
> +#ifdef __arch_common_v10_v32
> + ; This is just to allow the multilib to compile without
> + ; hackery: the "common" subset doesn't recognize
> + ; interrupt-return insns.
> +#elif __CRIS_arch_version >= 32
> + rete
> + rfe
> +#else
> + reti
> + nop
> +#endif
> +
> +0:
> + move.d __setup,$r9
> + jsr $r9
> + nop
> +#ifdef __ELF__
> + jsr L(_init)
> + nop
> + move.d L(_fini),$r10
> + jsr L(atexit)
> + nop
> +#endif
> + jsr L(main)
> + nop
> + jsr L(exit)
> + nop
> +0:
> + nop
> + ba 0b
> + nop
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/setup.S	Wed Jan 26 00:26:31 2005
> @@ -0,0 +1,44 @@
> +/* Support for standalone CRIS/CRISv32 code.
> +   Copyright (C) 2005 Axis Communications.
> +   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. Neither the name of Axis Communications nor the names of its
> +      contributors may be used to endorse or promote products derived
> +      from this software without specific prior written permission.
> +
> +   THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS 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 AXIS
> +   COMMUNICATIONS OR ITS 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.  */
> +
> + .text
> + .global __setup
> +__setup:
> + /* Make sure to save SRP.  */
> +#ifdef __arch_common_v10_v32
> + /* Can't do anything if we don't know for which arch.  This file is
> +    then only a placeholder.  Oh, and we can't use the "ret" insn in
> +    "common" code.  */
> +#else
> + /* Code missing:
> +    - Initialize RAM circuits.
> +    - Initialize serial output and input.
> +    - Set stack-pointer.  */
> + ret
> + nop
> +#endif
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/gensyscalls	Tue Jan 25 19:32:45 2005
> @@ -0,0 +1,252 @@
> +#! /bin/sh
> +#  Copyright (C) 2005 Axis Communications.
> +#  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. Neither the name of Axis Communications nor the names of its
> +#     contributors may be used to endorse or promote products derived
> +#     from this software without specific prior written permission.
> +#
> +#  THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS 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 AXIS
> +#  COMMUNICATIONS OR ITS 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.
> +
> +# To avoid an abundance of copyright/license messages for boilerplate
> +# code, we instead generate them from this file.  Generating the
> +# function code could also be done automatically, but at the cost of
> +# slightly more intricate build machinery and/or scattered syscall
> +# information.  Beware that the cat-lines must match the sed regexp
> +# "^cat > \([^ ]*\).*".
> +
> +lu='/* -*- buffer-read-only: t -*-
> +   THIS FILE IS AUTOMATICALLY GENERATED
> +   FROM "'$0'".  */
> +#include "linunistd.h"
> +#define R(x) return (x); }
> +'
> +lui="$lu int"
> +r=") { R (_Sys_"
> +
> +cat > close.c <<EOF
> +$lui _close (int fd${r}close (fd))
> +EOF
> +cat > execve.c <<EOF
> +$lui _execve (char *path, char **argv, char **env${r}execve (path, argv, env))
> +EOF
> +cat > exit.c <<EOF
> +$lu void _exit (int val) { _Sys_exit (val); /* Appease GCC: */ while (1) ; }
> +EOF
> +cat > fcntl.c <<EOF
> +$lui _fcntl (int fd, int cmd, long arg${r}fcntl (fd, cmd, arg))
> +EOF
> +cat > fork.c <<EOF
> +$lui _fork (void${r}fork ())
> +EOF
> +cat > fstat.c <<EOF
> +$lu#include <string.h>
> +#include <sys/stat.h>
> +int
> +_fstat (int fd, struct stat *buf)
> +{
> +  struct new_stat ks;
> +  int retval = _Sys_fstat (fd, &ks);
> +
> +  /* Blank before filling it in.  */
> +  memset (buf, 0, sizeof (*buf));
> +
> +  /* We have to translate from the linux struct new_stat.
> +     It seems we don't have to translate the contents, though.  */
> +  buf->st_dev = ks.st_dev;
> +  buf->st_ino = ks.st_ino;
> +  buf->st_mode = ks.st_mode;
> +  buf->st_nlink = ks.st_nlink;
> +  buf->st_uid = ks.st_uid;
> +  buf->st_gid = ks.st_gid;
> +  buf->st_rdev = ks.st_rdev;
> +  buf->st_size = ks.st_size;
> +  buf->st_blksize = ks.st_blksize;
> +  buf->st_blocks = ks.st_blocks;
> +  buf->st_atime = ks.st_atime;
> +  buf->st_mtime = ks.st_mtime;
> +  buf->st_ctime = ks.st_ctime;
> +  R (retval)
> +EOF
> +cat > getpid.c <<EOF
> +$lui _getpid (void${r}getpid ())
> +EOF
> +cat > gettod.c <<EOF
> +$lu#include <sys/time.h>
> +#include <sys/times.h>
> +int
> +_gettimeofday (struct timeval *tp, struct timezone *tzp
> +${r}gettimeofday (tp, tzp))
> +EOF
> +cat > isatty.c <<EOF
> +$lu
> +typedef unsigned int tcflag_t;
> +typedef unsigned char cc_t;
> +#define NCCS 19
> +
> +struct termios {
> +	tcflag_t c_iflag;		/* input mode flags */
> +	tcflag_t c_oflag;		/* output mode flags */
> +	tcflag_t c_cflag;		/* control mode flags */
> +	tcflag_t c_lflag;		/* local mode flags */
> +	cc_t c_line;			/* line discipline */
> +	cc_t c_cc[NCCS];		/* control characters */
> +};
> +
> +/* From asm-etrax100/ioctls.h: beware of updates.  */
> +#define TCGETS          0x5401
> +
> +/* Note that this name does not have a prepended underscore.  */
> +int
> +isatty (int fd)
> +{
> +  struct termios dummy;
> +  int save_errno = errno;
> +  int ret = _Sys_ioctl (fd, TCGETS, (unsigned long) &dummy);
> +  errno = save_errno;
> +  R (ret == 0)
> +EOF
> +cat > kill.c <<EOF
> +$lui _kill (int pid, int sig${r}kill (pid, sig))
> +EOF
> +cat > link.c <<EOF
> +$lui _link (const char *old, const char *new${r}link (old, new))
> +EOF
> +cat > lseek.c <<EOF
> +$lui _lseek (int fd, int offset, int whence${r}lseek (fd, offset, whence))
> +EOF
> +cat > open.c <<EOF
> +$lui _open (const char *fnam, int flags, int mode${r}open (fnam, flags, mode))
> +EOF
> +cat > read.c <<EOF
> +$lui _read (int fd, char *buf, int nbytes${r}read (fd, buf, nbytes))
> +EOF
> +cat > rename.c <<EOF
> +$lui _rename (const char *old, const char *new${r}rename (old, new))
> +EOF
> +cat > sbrk.c <<EOF
> +$lu
> +/* From asm-etrax100/mman.h: beware of updates.  */
> +#define PROT_READ	0x1		/* page can be read */
> +#define PROT_WRITE	0x2		/* page can be written */
> +#define MAP_ANONYMOUS	0x20		/* don't use a file */
> +char *
> +_sbrk (int d)
> +{
> +  static long last_alloc = 0;
> +
> +  /* FIXME: Things are a whole lot different than elinux.  */
> +#ifdef __elinux__
> +
> +  /* We can't promise linear memory from a predetermined location.
> +     We're NO_MM.  We're paria.  We have to rely on tweaks and unclean
> +     behavior.  We abuse the fact that the malloc function in newlib
> +     accepts nonlinear chunks in return to its sbrk calls (with a minor
> +     patch).  */
> +
> +  /* We use an "old" type mmap, which takes a pointer to a vector of 6
> +     longs where the parameters are stored.  */
> +  long buffer[6];
> +
> +  /* We can't return memory.  Well we could, but we would have to keep a
> +     list of previous allocations.  FIXME:  Seems reasonable to do that
> +     later.  */
> +  if (d < 0)
> +    return (char *) last_alloc;
> +
> +  buffer[3] = MAP_ANONYMOUS;    /* Not associated with a file.  */
> +  buffer[4] = -1;               /* No file.  */
> +  buffer[0] = 0;                /* Address 0: let mmap pick one.  */
> +  buffer[1] = d;                /* Length.  */
> +  buffer[2] = (PROT_READ | PROT_WRITE); /* Protection flags.  */
> +  buffer[5] = 0;                /* Offset into file.  */
> +
> +  last_alloc = _Sys_mmap (buffer);
> +
> +  return (char *) last_alloc;
> +
> +#else /* not __elinux__ */
> +
> +  long prev_brk;
> +
> +  if (last_alloc == 0)
> +  {
> +    last_alloc = _Sys_brk (0);
> +
> +    if (last_alloc < 0)
> +      return (char *) -1;
> +  }
> +
> +  prev_brk = last_alloc;
> +
> +  if (_Sys_brk (last_alloc + d) < last_alloc + d)
> +    return (char *) -1;
> +
> +  last_alloc += d;
> +
> +  return (char *) prev_brk;
> +#endif
> +}
> +EOF
> +cat > stat.c <<EOF
> +$lu#include <string.h>
> +#include <sys/stat.h>
> +int
> +_stat (const char *path, struct stat *buf)
> +{
> +  struct new_stat ks;
> +  int retval = _Sys_stat (path, &ks);
> +
> +  /* Blank before filling it in.  */
> +  memset (buf, 0, sizeof (*buf));
> +
> +  /* We have to translate from the linux struct new_stat.
> +     It seems we don't have to translate the contents, though.  */
> +  buf->st_dev = ks.st_dev;
> +  buf->st_ino = ks.st_ino;
> +  buf->st_mode = ks.st_mode;
> +  buf->st_nlink = ks.st_nlink;
> +  buf->st_uid = ks.st_uid;
> +  buf->st_gid = ks.st_gid;
> +  buf->st_rdev = ks.st_rdev;
> +  buf->st_size = ks.st_size;
> +  buf->st_blksize = ks.st_blksize;
> +  buf->st_blocks = ks.st_blocks;
> +  buf->st_atime = ks.st_atime;
> +  buf->st_mtime = ks.st_mtime;
> +  buf->st_ctime = ks.st_ctime;
> +  R (retval)
> +EOF
> +cat > times.c <<EOF
> +$lu#include <sys/times.h>
> +clock_t
> +_times (struct tms * tp${r}times (tp))
> +EOF
> +cat > unlink.c <<EOF
> +$lui _unlink (const char *f${r}unlink (f))
> +EOF
> +cat > wait.c <<EOF
> +$lui _wait (int *status${r}wait4 (_getpid(), status, 0, 0))
> +EOF
> +cat > write.c <<EOF
> +$lui _write (int fd, char *buf, int nbytes${r}write (fd, buf, nbytes))
> +EOF
> +exit 0
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/lcrt0.c	Tue Jan 25 03:54:41 2005
> @@ -0,0 +1,128 @@
> +/* Support for cris*-axis-linux-gnu and src/sim/cris simulator.
> +   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Axis Communications.
> +   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. Neither the name of Axis Communications nor the names of its
> +      contributors may be used to endorse or promote products derived
> +      from this software without specific prior written permission.
> +
> +   THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS 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 AXIS
> +   COMMUNICATIONS OR ITS 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 "linunistd.h"
> +
> +extern void exit (int) __attribute ((__noreturn__));
> +
> +__asm__ (".syntax no_register_prefix");
> +
> +#ifdef __ELF__
> +/* This simulator magic for an earlier simulator was supposed to be
> +   found two bytes before _start.  Let's keep it for sake of
> +   compatibility.  Trying to emit them with an ordinary const char[]
> +   and attribute section makes gcc barf; it doesn't like having the
> +   same section attribute for both code and data.
> +   The code is supposed to cause a crash if someone jumps to 0.  */
> +__asm__
> + (
> +  " .section .startup,\"ax\",@progbits\n"
> +  " .byte 55,55\n"
> +  " move.d 0xbadacce5,r9\n"
> +  " clear.d [r9]\n"
> +  " setf\n"
> +  " setf\n"
> +  " .previous");
> +#endif
> +
> +__asm__
> + (
> +#ifdef __AOUT__
> +  " .text\n\t"
> +#elif defined (__ELF__)
> +  " .section .startup,\"ax\",@progbits\n"
> +#endif
> +  " .global __start\n"
> +  "__start:\n"
> +  /* SP must be set up by the simulator or the system.  */
> +
> +  /* Find ARGC, ARGV and ENV.  */
> +  /* ARGC.  */
> +  " move.d [sp],r10\n"
> +
> +  /* ARGV.  */
> +  " move.d sp,r11\n"
> +  " addq 4,r11\n"
> +
> +  /* ENVP.  */
> +  " move.d sp,r12\n"
> +  " addi r10.d,r12\n"
> +  " addq 8,r12\n"
> +
> +  /* Terminate R9 and R6; we don't have a "console_print_etrax" or system
> +     call function.  */
> +  " clear.d r9\n"
> +  " clear.d r6\n"
> +  " move.d __start1,r13\n"
> +  " jump r13\n"
> +  " setf\n"
> +#ifndef __AOUT__
> +  /* We rely on a.out not being in .data here.  Quite fragile, but
> +     covered by e.g. running the GCC test-suite for cris-unknown-aout. */
> +  " .previous"
> +#endif
> +  );
> +
> +extern void _Libctors (void);
> +extern void _Libdtors (void);
> +
> +extern void __init__start (void) __attribute ((weak));
> +extern void __aout__ctors (void) __attribute ((weak));
> +
> +static void start1 () __asm__ ("__start1") __attribute ((__used__));
> +static void
> +start1 (int argc, char **argv, char **env)
> +{
> +#ifdef __ELF__
> +  /* For ELF systems, we call _init and register _fini with atexit.  */
> +  {
> +    extern void _init (void);
> +    extern void _fini (void);
> +    _init ();
> +    if (atexit (_fini) != 0)
> +      exit (-1);
> +  }
> +#else
> +  /* Constructors which may get here through the ELF .init section, when
> +     linking ELF and producing a.out.  */
> +  if (__init__start)
> +    __init__start ();
> +
> +  if (__aout__ctors)
> +    __aout__ctors ();
> +
> +  /* Call constructors in shared libraries. */
> +  _Libctors ();
> +
> +  if (atexit (_Libdtors) != 0)
> +    exit (-1);
> +#endif
> +
> +  /* Call the user program.  */
> +  exit (main (argc, argv, env));
> +}
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/configure.in	Mon Jan 24 02:07:54 2005
> @@ -0,0 +1,90 @@
> +dnl This file is based on ../mcore/configure.in
> +dnl Process this file with autoconf to produce a configure script.
> +AC_PREREQ(2.5)dnl
> +AC_INIT(Makefile.in)
> +
> +if test "${enable_shared}" = "yes" ; then
> +    echo "Shared libraries not supported for cross compiling, ignored"
> +fi
> +
> +if test "$srcdir" = "." ; then
> +  if test "${with_target_subdir}" != "." ; then
> +    libgloss_topdir="${srcdir}/${with_multisrctop}../../.."
> +  else
> +    libgloss_topdir="${srcdir}/${with_multisrctop}../.."
> +  fi
> +else
> +  libgloss_topdir="${srcdir}/../.."
> +fi
> +AC_CONFIG_AUX_DIR($libgloss_topdir)
> +
> +AC_CANONICAL_SYSTEM
> +AC_ARG_PROGRAM
> +
> +AC_PROG_INSTALL
> +
> +# FIXME: We temporarily define our own version of AC_PROG_CC.  This is
> +# copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS.  We
> +# are probably using a cross compiler, which will not be able to fully
> +# link an executable.  This should really be fixed in autoconf
> +# itself.
> +
> +AC_DEFUN(LIB_AC_PROG_CC,
> +[AC_BEFORE([$0], [AC_PROG_CPP])dnl
> +AC_CHECK_PROG(CC, gcc, gcc)
> +if test -z "$CC"; then
> +  AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
> +  test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
> +fi
> +
> +AC_PROG_CC_GNU
> +
> +if test $ac_cv_prog_gcc = yes; then
> +  GCC=yes
> +dnl Check whether -g works, even if CFLAGS is set, in case the package
> +dnl plays around with CFLAGS (such as to build both debugging and
> +dnl normal versions of a library), tasteless as that idea is.
> +  ac_test_CFLAGS="${CFLAGS+set}"
> +  ac_save_CFLAGS="$CFLAGS"
> +  CFLAGS=
> +  AC_PROG_CC_G
> +  if test "$ac_test_CFLAGS" = set; then
> +    CFLAGS="$ac_save_CFLAGS"
> +  elif test $ac_cv_prog_cc_g = yes; then
> +    CFLAGS="-g -O2"
> +  else
> +    CFLAGS="-O2"
> +  fi
> +else
> +  GCC=
> +  test "${CFLAGS+set}" = set || CFLAGS="-g"
> +fi
> +])
> +
> +LIB_AC_PROG_CC
> +AS=${AS-as}
> +AC_SUBST(AS)
> +AR=${AR-ar}
> +AC_SUBST(AR)
> +LD=${LD-ld}
> +AC_SUBST(LD)
> +AC_PROG_RANLIB
> +
> +host_makefile_frag=${srcdir}/../config/default.mh
> +
> +dnl We have to assign the same value to other variables because autoconf
> +dnl doesn't provide a mechanism to substitute a replacement keyword with
> +dnl arbitrary data or pathnames.
> +dnl
> +host_makefile_frag_path=$host_makefile_frag
> +AC_SUBST(host_makefile_frag_path)
> +AC_SUBST_FILE(host_makefile_frag)
> +
> +AC_OUTPUT(Makefile,
> +. ${libgloss_topdir}/config-ml.in,
> +srcdir=${srcdir}
> +target=${target}
> +ac_configure_args="${ac_configure_args} --enable-multilib"
> +CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
> +libgloss_topdir=${libgloss_topdir}
> +)
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/crti.c	Tue Jan 25 03:54:15 2005
> @@ -0,0 +1,77 @@
> +/* Executable and DSO init/fini start for cris*-axis-linux-gnu and simulators
> +   Copyright (C) 2000, 2001, 2004, 2005 Axis Communications.
> +   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. Neither the name of Axis Communications nor the names of its
> +      contributors may be used to endorse or promote products derived
> +      from this software without specific prior written permission.
> +
> +   THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS 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 AXIS
> +   COMMUNICATIONS OR ITS 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.  */
> +
> +#ifdef __ELF__
> +__asm__ (".syntax no_register_prefix");
> +
> +__asm__ (".section .init\n"
> +#ifdef __NO_UNDERSCORES__
> +         " .globl _init\n"
> +         "_init:\n"
> +#else /* not __NO_UNDERSCORES__ */
> +         " .globl __init\n"
> +         "__init:\n"
> +#endif /* not __NO_UNDERSCORES__ */
> +         "\tsubq 4,sp\n"
> +	 "\tmove srp,[sp]\n"
> +#ifdef __PIC__
> +         "\tsubq 4,sp\n"
> +	 "\tmove.d r0,[sp]\n"
> +#if __CRIS_arch_version >= 32
> +	 "\tlapc _GLOBAL_OFFSET_TABLE_,$r0\n"
> +#else /* not __CRIS_arch_version >= 32 */
> +	 "\tmove.d $pc,$r0\n"
> +	 "\tsub.d .:GOTOFF,$r0\n"
> +#endif /* not __CRIS_arch_version >= 32 */
> +#endif /* __PIC__ */
> +
> +         "\t.section .fini\n"
> +#ifdef __NO_UNDERSCORES__
> +         " .globl _fini\n"
> +         "_fini:\n"
> +#else /* not __NO_UNDERSCORES__ */
> +         " .globl __fini\n"
> +         "__fini:\n"
> +#endif /* not __NO_UNDERSCORES__ */
> +         "\tsubq 4,sp\n"
> +	 "\tmove srp,[sp]\n"
> +#ifdef __PIC__
> +         "\tsubq 4,sp\n"
> +	 "\tmove.d r0,[sp]\n"
> +#if __CRIS_arch_version >= 32
> +	 "\tlapc _GLOBAL_OFFSET_TABLE_,$r0\n"
> +#else /* not __CRIS_arch_version >= 32 */
> +	 "\tmove.d $pc,$r0\n"
> +	 "\tsub.d .:GOTOFF,$r0\n"
> +#endif /* not __CRIS_arch_version >= 32 */
> +#endif /* __PIC__ */
> +);
> +
> +#else /* not __ELF__ */
> +extern int Dummy;
> +#endif /* not __ELF__ */
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/crtn.c	Tue Jan 25 03:54:22 2005
> @@ -0,0 +1,51 @@
> +/* Executable and DSO init/fini end for cris*-axis-linux-gnu and simulators
> +   Copyright (C) 2000, 2001, 2004, 2005 Axis Communications.
> +   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. Neither the name of Axis Communications nor the names of its
> +      contributors may be used to endorse or promote products derived
> +      from this software without specific prior written permission.
> +
> +   THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS 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 AXIS
> +   COMMUNICATIONS OR ITS 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.  */
> +
> +#ifdef __ELF__
> +
> +__asm__ (".syntax no_register_prefix");
> +
> +__asm__ (".section .init\n"
> +#ifdef __PIC__
> +	 "\tmove.d [sp+],r0\n"
> +#endif
> +         "\tmove.d [sp+],r9\n"
> +         "\tjump r9\n"
> +         "\tnop\n"
> +
> +         "\t.section .fini\n"
> +#ifdef __PIC__
> +	 "\tmove.d [sp+],r0\n"
> +#endif
> +         "\tmove.d [sp+],r9\n"
> +         "\tjump r9\n"
> +         "\tnop\n");
> +
> +#else
> +extern int Dummy;
> +#endif
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/Makefile.in	Tue Jan 25 18:59:39 2005
> @@ -0,0 +1,254 @@
> +#
> +# libgloss Makefile.in for CRIS.  Copied and modified from mcore long ago.
> +#
> +
> +DESTDIR =
> +VPATH = @srcdir@
> +srcdir = @srcdir@
> +objdir = .
> +srcroot = $(srcdir)/../..
> +objroot = $(objdir)/../..
> +
> +prefix = @prefix@
> +exec_prefix = @exec_prefix@
> +
> +host_alias = @host_alias@
> +target_alias = @target_alias@
> +
> +bindir = @bindir@
> +libdir = @libdir@
> +tooldir = $(exec_prefix)/$(target_alias)
> +
> +INSTALL = @INSTALL@
> +INSTALL_PROGRAM = @INSTALL_PROGRAM@
> +INSTALL_DATA = @INSTALL_DATA@
> +
> +# Multilib support variables.
> +# TOP is used instead of MULTI{BUILD,SRC}TOP.
> +MULTIDIRS =
> +MULTISUBDIR =
> +
> +SHELL =	/bin/sh
> +
> +CC = @CC@
> +
> +AS = @AS@
> +AR = @AR@
> +LD = @LD@
> +RANLIB = @RANLIB@
> +
> +OBJDUMP = `if [ -f ${objroot}/../binutils/objdump ] ; \
> +	then echo ${objroot}/../binutils/objdump ; \
> +	else t='$(program_transform_name)'; echo objdump | sed -e $$t ; fi`
> +OBJCOPY = `if [ -f ${objroot}/../binutils/objcopy ] ; \
> +	then echo ${objroot}/../binutils/objcopy ; \
> +	else t='$(program_transform_name)'; echo objcopy | sed -e $$t ; fi`
> +
> +CFLAGS		= -g
> +SCRIPTS		=
> +
> +OBJS = outbyte.o
> +
> +# Beware: GNU make construct used (shell call).  Since GCC at the time
> +# of this writing requires GNU make >= 3.79.1, this should pose no
> +# problem.
> +SYSCALL_CFILES := $(shell sed -ne 's/^cat > \([^ ]*\).*/\1/p' < $(srcdir)/gensyscalls)
> +
> +# Here is all of the simulator stuff.
> +# Actually, now it's just the GNU/Linux stuff, as that's also the
> +# simulator ABI.  The name of the library is different, though.
> +SIM_SCRIPTS	=
> +SIM_LDFLAGS	=
> +SIM_BSP		= libsyssim.a
> +SIM_CRT0	= $(LIN_CRT0)
> +SIM_OBJS	= $(LIN_OBJS)
> +SIM_TEST	= sim-test
> +SIM_INSTALL	= install-sim
> +
> +# Here is all of the GNU/Linux stuff.  At present we don't build newlib
> +# and libgloss for cris*-linux-gnu*, but it's nice to keep that as an
> +# option.
> +LIN_PREFIX	=
> +LIN_LDFLAGS	=
> +LIN_BSP		= libsyslinux.a
> +LIN_CRT0	= lcrt0.o
> +LIN_EXTRA	= crti.o crtn.o crt1.o
> +LIN_OBJS	= close.o execve.o exit.o fcntl.o fork.o fstat.o getpid.o \
> + gettod.o isatty.o kill.o link.o lseek.o open.o read.o \
> + rename.o sbrk.o stat.o times.o unlink.o wait.o write.o ${OBJS}
> +LIN_SCRIPTS	=
> +LIN_TEST	=
> +LIN_INSTALL	= install-lin
> +
> +# In (over)due time, here will be all stuff necessary for a development
> +# board.
> +BSP_PREFIX	=
> +BSP_LDFLAGS	=
> +BSP_BSP		= libbsp.a
> +BSP_CRT0	= crt0.o
> +BSP_OBJS	= ${OBJS} setup.o
> +BSP_SCRIPTS	=
> +BSP_TEST	=
> +BSP_INSTALL	= install-bsp
> +
> +# Host specific makefile fragment comes in here.
> +@host_makefile_frag@
> +
> +# Need to augment the definition from host_makefile_frag above.
> +INCLUDES += -I$(srcdir)
> +
> +all: ${SIM_CRT0} ${LIN_CRT0} ${BSP_CRT0} ${SIM_BSP} ${LIN_BSP} ${BSP_BSP} \
> + libnosys.a ${LIN_EXTRA}
> +
> +#
> +# Here's where we build the board support packages for each target.
> +#
> +${SIM_BSP}: ${SIM_OBJS}
> +	${AR} ${ARFLAGS} ${SIM_BSP} ${SIM_OBJS}
> +	${RANLIB} ${SIM_BSP}
> +
> +${BSP_BSP}: ${BSP_OBJS}
> +	${AR} ${ARFLAGS} ${BSP_BSP} ${BSP_OBJS}
> +	${RANLIB} ${BSP_BSP}
> +
> +${LIN_BSP}: ${LIN_OBJS}
> +	${AR} ${ARFLAGS} ${LIN_BSP} ${LIN_OBJS}
> +	${RANLIB} ${LIN_BSP}
> +
> +# We need a link to libnosys.a in this directory, since this is the
> +# directory used when test-compiling for configuration for other parts and
> +# when running the testsuite.  By using a symbolic link, it does not
> +# matter whether libnosys.a is built yet when the rule is executed.
> +libnosys.a:
> +	ln -s ../libnosys/libnosys.a
> +
> +#
> +# Build a test program for each target board. Just trying to get
> +# it to link is a good test, so we ignore all the errors for now.
> +#
> +#
> +# Here's where we build the test programs for each target.
> +#
> +.PHONY: test
> +test:	${SIM_TEST} ${BSP_TEST}
> +
> +sim-test:	sim-test.x sim-test.dis
> +
> +sim-test.x:	test.o ${SIM_CRT0} ${SIM_BSP}
> +	${CC} ${LDFLAGS_FOR_TARGET} -L${objdir} \
> +	${SIM_CRT0} test.o \
> +	-o sim-test.x ${LIBS_FOR_TARGET} -lc ${SIM_BSP}
> +
> +sim-test.dis:	sim-test.x
> +	${OBJDUMP} -d sim-test.x > sim-test.dis
> +
> +
> +test.o: ${srcdir}/m68k/test.c
> +
> +# Debug usage.
> +.c.S:
> +	${CC} ${CFLAGS_FOR_TARGET} $(INCLUDES) $(CFLAGS) -c $<
> +
> +# Caveat: for the -melinux multilib in cris-axis-aout, crt0.o is the
> +# same as lcrt0.o, while elsewhere (other cris-axis-aout multilib and
> +# cris-axis-elf) it's crt0.c compiled.
> +crt0.o: lcrt0.o crt0.S
> +	case "${MULTISUBDIR}" in \
> +          */elinux) \
> +	   cp -p $< $@; st=$$?;; \
> +          *) \
> +           case "$?" in \
> +            *crt0.S) \
> +	     $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) -xassembler-with-cpp -c $(srcdir)/crt0.S;; \
> +            *) touch $@;; \
> +            esac; \
> +	   st=$$?;; \
> +	esac; exit $$st
> +
> +crt1.o: lcrt0.o
> +	cp -p $< $@
> +
> +clean mostlyclean:
> +	rm -f a.out core *.i *.o *-test *.srec *.dis *.x $(SIM_BSP) $(BSP_BSP) $(LIN_BSP) libnosys.a
> +
> +distclean maintainer-clean realclean: clean
> +	rm -f Makefile config.status *~
> +
> +.PHONY: install info install-info clean-info
> +install: ${SIM_INSTALL} ${BSP_INSTALL} ${LIN_INSTALL}
> +
> +# Note that bsp and elinux objects are exclusive: do not overlap
> +# installed files.
> +install-bsp:
> +	case "${MULTISUBDIR}" in \
> +          */elinux) ;; \
> +	  *) set -e; \
> +	     for x in ${BSP_CRT0} ${BSP_BSP} ${BSP_SCRIPTS}; do \
> +		${INSTALL_DATA} $$x $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x; \
> +	     done;; \
> +	esac
> +
> +install-sim:
> +	set -e; \
> +	for x in ${SIM_CRT0} ${SIM_BSP} ${SIM_SCRIPTS}; do \
> +	  ${INSTALL_DATA} $$x $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x; \
> +	done
> +
> +install-lin:
> +	case "${MULTISUBDIR}" in \
> +          */elinux) \
> +	    ${INSTALL_DATA} ${LIN_CRT0} $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/crt0.o; \
> +	    set -e; \
> +	    for x in ${LIN_BSP} ${LIN_SCRIPTS}; do \
> +	      ${INSTALL_DATA} $$x $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x; \
> +	    done;; \
> +          *) \
> +	    set -e; \
> +	    for x in ${LIN_BSP} ${LIN_SCRIPTS} ${LIN_EXTRA}; do \
> +	      ${INSTALL_DATA} $$x ${tooldir}/lib${MULTISUBDIR}/$$x; \
> +	    done;; \
> +	esac
> +
> +doc:
> +info:
> +install-info:
> +clean-info:
> +
> +Makefile: Makefile.in config.status @host_makefile_frag_path@
> +	$(SHELL) config.status
> +
> +config.status: configure
> +	$(SHELL) config.status --recheck
> +
> +$(SYSCALL_CFILES): syscalls.stamp
> +
> +syscalls.stamp: gensyscalls
> +	$(SHELL) $(srcdir)/gensyscalls
> +	touch $@
> +
> +# Dependencies that could and should be auto-generated.
> +close.o: close.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +execve.o: execve.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +exit.o: exit.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +fork.o: fork.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +fstat.o: fstat.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +fcntl.o: fcntl.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +getpid.o: getpid.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +gettod.o: gettod.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +isatty.o: isatty.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +kill.o: kill.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +link.o: link.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +lseek.o: lseek.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +open.o: open.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +read.o: read.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +rename.o: rename.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +sbrk.o: sbrk.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +stat.o: stat.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +times.o: times.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +unlink.o: unlink.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +wait.o: wait.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +write.o: write.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +lcrt0.o: lcrt0.c linunistd.h $(objdir)/../libnosys/config.h $(srcdir)/../libnosys/warning.h
> +setup.o: setup.S
> +crti.o: crti.c
> +crtn.o: crtn.c
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/outbyte.c	Tue Jan 25 01:42:42 2005
> @@ -0,0 +1,9 @@
> +/* Low-level kind-of-support for CRIS.  Mostly used as a placeholder
> +   function.  Too small and obvious to warrant a copyright notice.  */
> +
> +#include <stdio.h>
> +void
> +outbyte (int ch)
> +{
> +  write (1, &ch, 1);
> +}
> --- /dev/null	Tue Oct 29 15:57:07 2002
> +++ cris/linunistd.h	Tue Jan 25 03:54:49 2005
> @@ -0,0 +1,423 @@
> +/* Support for syscalls for cris*-axis-linux-gnu and simulators
> +   Copyright (C) 1998-2005 Axis Communications.
> +   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. Neither the name of Axis Communications nor the names of its
> +      contributors may be used to endorse or promote products derived
> +      from this software without specific prior written permission.
> +
> +   THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS 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 AXIS
> +   COMMUNICATIONS OR ITS 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.  */
> +
> +/* Derived from asm-etrax100/unistd.h with minor modifications to fit as
> +   LOSS for newlib.  */
> +
> +#ifndef _ASM_ELINUX_UNISTD_H_
> +#define _ASM_ELINUX_UNISTD_H_
> +
> +/* Our callers might want to use link_warning, so provide it from here.  */
> +#include "../libnosys/config.h"
> +#include "libnosys/warning.h"
> +
> +#include <errno.h>
> +#undef errno
> +extern int errno;
> +
> +/*
> + * This file contains the system call numbers, and stub macros for libc.
> + */
> +
> +#define __NR_setup		  0	/* used only by init, to get system going */
> +#define __NR_exit		  1
> +#define __NR_fork		  2
> +#define __NR_read		  3
> +#define __NR_write		  4
> +#define __NR_open		  5
> +#define __NR_close		  6
> +#define __NR_waitpid		  7
> +#define __NR_creat		  8
> +#define __NR_link		  9
> +#define __NR_unlink		 10
> +#define __NR_execve		 11
> +#define __NR_chdir		 12
> +#define __NR_time		 13
> +#define __NR_mknod		 14
> +#define __NR_chmod		 15
> +#define __NR_chown		 16
> +#define __NR_break		 17
> +#define __NR_oldstat		 18
> +#define __NR_lseek		 19
> +#define __NR_getpid		 20
> +#define __NR_mount		 21
> +#define __NR_umount		 22
> +#define __NR_setuid		 23
> +#define __NR_getuid		 24
> +#define __NR_stime		 25
> +#define __NR_ptrace		 26
> +#define __NR_alarm		 27
> +#define __NR_oldfstat		 28
> +#define __NR_pause		 29
> +#define __NR_utime		 30
> +#define __NR_stty		 31
> +#define __NR_gtty		 32
> +#define __NR_access		 33
> +#define __NR_nice		 34
> +#define __NR_ftime		 35
> +#define __NR_sync		 36
> +#define __NR_kill		 37
> +#define __NR_rename		 38
> +#define __NR_mkdir		 39
> +#define __NR_rmdir		 40
> +#define __NR_dup		 41
> +#define __NR_pipe		 42
> +#define __NR_times		 43
> +#define __NR_prof		 44
> +#define __NR_brk		 45
> +#define __NR_setgid		 46
> +#define __NR_getgid		 47
> +#define __NR_signal		 48
> +#define __NR_geteuid		 49
> +#define __NR_getegid		 50
> +#define __NR_acct		 51
> +#define __NR_phys		 52
> +#define __NR_lock		 53
> +#define __NR_ioctl		 54
> +#define __NR_fcntl		 55
> +#define __NR_mpx		 56
> +#define __NR_setpgid		 57
> +#define __NR_ulimit		 58
> +#define __NR_oldolduname	 59
> +#define __NR_umask		 60
> +#define __NR_chroot		 61
> +#define __NR_ustat		 62
> +#define __NR_dup2		 63
> +#define __NR_getppid		 64
> +#define __NR_getpgrp		 65
> +#define __NR_setsid		 66
> +#define __NR_sigaction		 67
> +#define __NR_sgetmask		 68
> +#define __NR_ssetmask		 69
> +#define __NR_setreuid		 70
> +#define __NR_setregid		 71
> +#define __NR_sigsuspend		 72
> +#define __NR_sigpending		 73
> +#define __NR_sethostname	 74
> +#define __NR_setrlimit		 75
> +#define __NR_getrlimit		 76
> +#define __NR_getrusage		 77
> +#define __NR_gettimeofday	 78
> +#define __NR_settimeofday	 79
> +#define __NR_getgroups		 80
> +#define __NR_setgroups		 81
> +#define __NR_select		 82
> +#define __NR_symlink		 83
> +#define __NR_oldlstat		 84
> +#define __NR_readlink		 85
> +#define __NR_uselib		 86
> +#define __NR_swapon		 87
> +#define __NR_reboot		 88
> +#define __NR_readdir		 89
> +#define __NR_mmap		 90
> +#define __NR_munmap		 91
> +#define __NR_truncate		 92
> +#define __NR_ftruncate		 93
> +#define __NR_fchmod		 94
> +#define __NR_fchown		 95
> +#define __NR_getpriority	 96
> +#define __NR_setpriority	 97
> +#define __NR_profil		 98
> +#define __NR_statfs		 99
> +#define __NR_fstatfs		100
> +#define __NR_ioperm		101
> +#define __NR_socketcall		102
> +#define __NR_syslog		103
> +#define __NR_setitimer		104
> +#define __NR_getitimer		105
> +#define __NR_stat		106
> +#define __NR_lstat		107
> +#define __NR_fstat		108
> +#define __NR_olduname		109
> +#define __NR_iopl		110
> +#define __NR_vhangup		111
> +#define __NR_idle		112
> +#define __NR_vm86		113
> +#define __NR_wait4		114
> +#define __NR_swapoff		115
> +#define __NR_sysinfo		116
> +#define __NR_ipc		117
> +#define __NR_fsync		118
> +#define __NR_sigreturn		119
> +#define __NR_clone		120
> +#define __NR_setdomainname	121
> +#define __NR_uname		122
> +#define __NR_modify_ldt		123
> +#define __NR_adjtimex		124
> +#define __NR_mprotect		125
> +#define __NR_sigprocmask	126
> +#define __NR_create_module	127
> +#define __NR_init_module	128
> +#define __NR_delete_module	129
> +#define __NR_get_kernel_syms	130
> +#define __NR_quotactl		131
> +#define __NR_getpgid		132
> +#define __NR_fchdir		133
> +#define __NR_bdflush		134
> +#define __NR_sysfs		135
> +#define __NR_personality	136
> +#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
> +#define __NR_setfsuid		138
> +#define __NR_setfsgid		139
> +#define __NR__llseek		140
> +#define __NR_getdents		141
> +#define __NR__newselect		142
> +#define __NR_flock		143
> +#define __NR_msync		144
> +#define __NR_readv		145
> +#define __NR_writev		146
> +#define __NR_getsid		147
> +#define __NR_fdatasync		148
> +#define __NR__sysctl		149
> +#define __NR_mlock		150
> +#define __NR_munlock		151
> +#define __NR_mlockall		152
> +#define __NR_munlockall		153
> +#define __NR_sched_setparam		154
> +#define __NR_sched_getparam		155
> +#define __NR_sched_setscheduler		156
> +#define __NR_sched_getscheduler		157
> +#define __NR_sched_yield		158
> +#define __NR_sched_get_priority_max	159
> +#define __NR_sched_get_priority_min	160
> +#define __NR_sched_rr_get_interval	161
> +#define __NR_nanosleep		162
> +#define __NR_mremap		163
> +
> +#define __NR_mmap2		192
> +
> +#define PASTE(x,y) x##y
> +#define XSTR(x) # x
> +#define STR(x) XSTR (x)
> +
> +#ifdef __elinux__
> +# define CRIS_SYSCALL "jir .$System.call"
> +# define CALLNO_REG r1
> +# define ARG5_REG r0
> +# define MOVE_ARG5 "move.d"
> +# define COLON_ARG5_CLOBBER : "r0"
> +#else
> +# define CRIS_SYSCALL "break 13"
> +# define CALLNO_REG r9
> +# define ARG5_REG srp
> +# define MOVE_ARG5 "move"
> +# define COLON_ARG5_CLOBBER
> +#endif
> +
> +/* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar. */
> +#define _syscall0(type,name) \
> +type PASTE(_Sys_,name) (void) \
> +{ \
> +  register long __a __asm__ ("r10"); \
> +  register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
> +  __asm__ __volatile__ (CRIS_SYSCALL \
> +			: "=r" (__a) \
> +			: "r" (__n_)); \
> +  if (__a >= 0) \
> +     return (type) __a; \
> +  errno = -__a; \
> +  return -1; \
> +}
> +
> +#define _syscall1(type,name,type1,arg1) \
> +type PASTE(_Sys_,name) (type1 arg1) \
> +{ \
> +  register long __a __asm__ ("r10") = (long) arg1; \
> +  register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
> +  __asm__ __volatile__ (CRIS_SYSCALL \
> +			: "=r" (__a) \
> +			: "r" (__n_), "0" (__a)); \
> +  if (__a >= 0) \
> +     return (type) __a; \
> +  errno = -__a; \
> +  return -1; \
> +}
> +
> +#define _syscall2(type,name,type1,arg1,type2,arg2) \
> +type PASTE(_Sys_,name) (type1 arg1,type2 arg2) \
> +{ \
> +  register long __a __asm__ ("r10") = (long) arg1; \
> +  register long __b __asm__ ("r11") = (long) arg2; \
> +  register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
> +  __asm__ __volatile__ (CRIS_SYSCALL \
> +			: "=r" (__a) \
> +			: "r" (__n_), "0" (__a), "r" (__b)); \
> +  if (__a >= 0) \
> +     return (type) __a; \
> +  errno = -__a; \
> +  return -1; \
> +}
> +
> +#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
> +type PASTE(_Sys_,name) (type1 arg1,type2 arg2,type3 arg3) \
> +{ \
> +  register long __a __asm__ ("r10") = (long) arg1; \
> +  register long __b __asm__ ("r11") = (long) arg2; \
> +  register long __c __asm__ ("r12") = (long) arg3; \
> +  register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
> +  __asm__ __volatile__ (CRIS_SYSCALL \
> +			: "=r" (__a) \
> +			: "r" (__n_), "0" (__a), "r" (__b), "r" (__c)); \
> +  if (__a >= 0) \
> +     return (type) __a; \
> +  errno = -__a; \
> +  return -1; \
> +}
> +
> +#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
> +type PASTE(_Sys_,name) (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
> +{ \
> +  register long __a __asm__ ("r10") = (long) arg1; \
> +  register long __b __asm__ ("r11") = (long) arg2; \
> +  register long __c __asm__ ("r12") = (long) arg3; \
> +  register long __d __asm__ ("r13") = (long) arg4; \
> +  register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
> +  __asm__ __volatile__ (CRIS_SYSCALL \
> +			: "=r" (__a) \
> +			: "r" (__n_), "0" (__a), "r" (__b), \
> +			  "r" (__c), "r" (__d)); \
> +  if (__a >= 0) \
> +     return (type) __a; \
> +  errno = -__a; \
> +  return -1; \
> +}
> +
> +#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
> +	  type5,arg5) \
> +type PASTE(_Sys_,name) (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
> +{ \
> +  register long __a __asm__ ("r10") = (long) arg1; \
> +  register long __b __asm__ ("r11") = (long) arg2; \
> +  register long __c __asm__ ("r12") = (long) arg3; \
> +  register long __d __asm__ ("r13") = (long) arg4; \
> +  register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
> +  __asm__ __volatile__ (MOVE_ARG5 " %6,$" STR (ARG5_REG) "\n\t" \
> +			CRIS_SYSCALL \
> +			: "=r" (__a) \
> +			: "r" (__n_), "0" (__a), "r" (__b), \
> +			  "r" (__c), "r" (__d), "g" (arg5) \
> +			COLON_ARG5_CLOBBER); \
> +  if (__a >= 0) \
> +     return (type) __a; \
> +  errno = -__a; \
> +  return -1; \
> +}
> +
> +#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
> +	  type5,arg5,type6,arg6) \
> +type PASTE(_Sys_,name) (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
> +{ \
> +  register long __a __asm__ ("r10") = (long) arg1; \
> +  register long __b __asm__ ("r11") = (long) arg2; \
> +  register long __c __asm__ ("r12") = (long) arg3; \
> +  register long __d __asm__ ("r13") = (long) arg4; \
> +  register long __n_ __asm__ (STR (CALLNO_REG)) = (__NR_##name); \
> +  __asm__ __volatile__ (MOVE_ARG5 " %6,$" STR (ARG5_REG) "\n\t" \
> +			"move %7,$mof\n\t" \
> +			CRIS_SYSCALL \
> +			: "=r" (__a) \
> +			: "r" (__n_), "0" (__a), "r" (__b), \
> +			  "r" (__c), "r" (__d), "g" (arg5), "g" (arg6) \
> +			COLON_ARG5_CLOBBER); \
> +  if (__a >= 0) \
> +     return (type) __a; \
> +  errno = -__a; \
> +  return -1; \
> +}
> +
> +#define __NR__exit __NR_exit
> +static inline _syscall0(int,idle)
> +static inline _syscall0(int,fork)
> +static inline _syscall2(int,clone,unsigned long,flags,char *,esp)
> +static inline _syscall0(int,pause)
> +static inline _syscall0(int,setup)
> +static inline _syscall0(int,sync)
> +static inline _syscall3(int,write,int,fd,const char *,buf,unsigned,count)
> +static inline _syscall1(int,dup,int,fd)
> +static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
> +static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
> +static inline _syscall1(int,close,int,fd)
> +static inline _syscall1(int,_exit,int,exitcode)
> +static inline _syscall1(int,exit,int,exitcode)
> +static inline _syscall3(int,waitpid,int,pid,int *,wait_stat,int,options)
> +static inline _syscall3(int,read,int,fd,char *,buf,unsigned,count)
> +static inline _syscall2(int,socketcall,int,call,unsigned long *,args)
> +static inline _syscall3(int,ioctl,unsigned int,fd,unsigned int,cmd,unsigned long,arg)
> +static inline _syscall3(int,fcntl,unsigned int,fd,unsigned int,cmd,unsigned long,arg)
> +static inline _syscall5(int,mount,const char *,a,const char *,b,const char *,c,unsigned long,rwflag,const void *,data)
> +static inline _syscall2(int,rename,const char *,a,const char*,b)
> +
> +#ifndef __elinux__
> +/* Make sure these are only used where they are supported.  */
> +static inline _syscall6(int,mmap2,unsigned long, addr, unsigned long, len,
> +			unsigned long, prot, unsigned long, flags,
> +			unsigned long, fd, unsigned long, pgoff)
> +static inline _syscall1(long,brk,long,addr)
> +#endif
> +
> +/* This structure is ripped from asm-etrax100/stat.h: beware of updates.  */
> +struct new_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;
> +};
> +
> +static inline _syscall2(int,stat,const char *,path,struct new_stat *,statbuf)
> +static inline _syscall2(int,fstat,int,fd,struct new_stat *,statbuf)
> +static inline _syscall0(int,getpid)
> +static inline _syscall2(int,kill,int,pid,int,sig)
> +static inline _syscall3(int,lseek,int,fd,int,offset,int,whence)
> +struct tms;
> +static inline _syscall1(long,times,struct tms *,tbuf)
> +static inline _syscall1(long,mmap,long *, buf)
> +struct timeval;
> +struct timezone;
> +static inline _syscall2(int,gettimeofday,struct timeval *,tp,
> +                        struct timezone *, tzp)
> +static inline _syscall2(int,link,const char *,old,const char *,new)
> +static inline _syscall1(int,unlink,const char *, f)
> +struct rusage;
> +static inline _syscall4(int,wait4,int,pid,int *,sa,int,op,struct rusage *,ru)
> +#endif /* _ASM_ELINUX_UNISTD_H_ */
> 
> brgds, H-P



More information about the Newlib mailing list