Add support for ARC to libgloss

ChangeLog:
2015-11-12  Anton Kolesov  <Anton.Kolesov@synopsys.com>

	* configure.in: Add ARC support to libgloss.
	* configure: Regenerate.

libgloss/ChangeLog:
2015-11-12  Anton Kolesov  <Anton.Kolesov@synopsys.com>

	* configure: Add ARC support.
	* configure.in: Likewise.
	* arc/Makefile.in: Likewise.
	* arc/aclocal.m4: Likewise.
	* arc/configure: Likewise.
	* arc/configure.in: Likewise.
	* arc/crt0.S: Likewise.
	* arc/libcfunc.c: Likewise.
	* arc/nsim-syscall.h: Likewise.
	* arc/nsim-syscalls.c: Likewise.
	* arc/nsim.specs: Likewise.
	* arc/sbrk.c: Likewise.
This commit is contained in:
Anton Kolesov 2015-10-23 21:24:06 +03:00 committed by Corinna Vinschen
parent e945a19cb2
commit acdfcb0a0a
16 changed files with 5568 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2015-11-12 Anton Kolesov <Anton.Kolesov@synopsys.com>
* configure.in: Add ARC support to libgloss.
* configure: Regenerate.
2015-09-22 Mike Frysinger <vapier@gentoo.org>
* config.guess: Update from config repo.

3
configure vendored
View File

@ -3623,9 +3623,6 @@ case "${target}" in
sh*-*-pe|mips*-*-pe|*arm-wince-pe)
noconfigdirs="$noconfigdirs tcl tk itcl libgui sim"
;;
arc-*-*|arceb-*-*)
noconfigdirs="$noconfigdirs target-libgloss"
;;
arm-*-pe*)
noconfigdirs="$noconfigdirs target-libgloss"
;;

View File

@ -956,9 +956,6 @@ case "${target}" in
sh*-*-pe|mips*-*-pe|*arm-wince-pe)
noconfigdirs="$noconfigdirs tcl tk itcl libgui sim"
;;
arc-*-*|arceb-*-*)
noconfigdirs="$noconfigdirs target-libgloss"
;;
arm-*-pe*)
noconfigdirs="$noconfigdirs target-libgloss"
;;

View File

@ -1,3 +1,18 @@
2015-11-12 Anton Kolesov <Anton.Kolesov@synopsys.com>
* configure: Add ARC support.
* configure.in: Likewise.
* arc/Makefile.in: Likewise.
* arc/aclocal.m4: Likewise.
* arc/configure: Likewise.
* arc/configure.in: Likewise.
* arc/crt0.S: Likewise.
* arc/libcfunc.c: Likewise.
* arc/nsim-syscall.h: Likewise.
* arc/nsim-syscalls.c: Likewise.
* arc/nsim.specs: Likewise.
* arc/sbrk.c: Likewise.
2015-10-20 Kaushik Phatak <kaushik.phatak@kpit.com>
* rl78/crt0.S (_start): Fixed code that clears .bss

113
libgloss/arc/Makefile.in Normal file
View File

@ -0,0 +1,113 @@
#
#
DESTDIR =
VPATH = @srcdir@ @srcdir@/..
srcdir = @srcdir@
objdir = .
srcroot = $(srcdir)/../..
objroot = $(objdir)/../..
mkinstalldirs = $(SHELL) $(srcroot)/mkinstalldirs
prefix = @prefix@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
target_alias = @target_alias@
bindir = @bindir@
libdir = @libdir@
tooldir = $(exec_prefix)/$(target_alias)
objtype = @objtype@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
# Multilib support variables.
# TOP is used instead of MULTI{BUILD,SRC}TOP.
MULTIDIRS =
MULTISUBDIR =
MULTIDO = true
MULTICLEAN = true
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`
CRT0 = crt0.o
CRT0_INSTALL = install-crt0
NSIM_BSP = libnsim.a
NSIM_OBJS = \
libcfunc.o \
nsim-syscalls.o \
sbrk.o
NSIM_INSTALL = install-nsim
NSIM_SCRIPTS = nsim.specs
CFLAGS = -g
# Host specific makefile fragment comes in here.
@host_makefile_frag@
all: $(CRT0) $(NSIM_BSP)
$(NSIM_BSP): $(NSIM_OBJS)
$(AR) $(ARFLAGS) $@ $?
$(RANLIB) $@
libcfunc.o: libcfunc.c
nsim-syscalls.o: nsim-syscalls.c
sbrk.o: sbrk.c
#
$(CRT0): crt0.S
clean mostlyclean:
rm -f *.o *.a
distclean maintainer-clean realclean: clean
rm -f Makefile config.status config.log config.cache *~
.PHONY: install info install-info clean-info doc dvi
install: $(CRT0_INSTALL) $(NSIM_INSTALL)
# multilibdir may not exist yet - libgcc for ARC depends on libc, hence
# newlib/libgloss is built before libgcc. And in parallel build libgloss maybe
# built and installed before newlib, therefore libgloss has to create target
# directory.
$(CRT0_INSTALL):
$(mkinstalldirs) $(DESTDIR)${tooldir}/lib${MULTISUBDIR}
${INSTALL_DATA} ${CRT0} $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$(CRT0)
$(NSIM_INSTALL):
$(mkinstalldirs) $(DESTDIR)${tooldir}/lib${MULTISUBDIR}
$(INSTALL_DATA) $(NSIM_BSP) $(DESTDIR)$(tooldir)/lib$(MULTISUBDIR)/$(NSIM_BSP)
for x in $(NSIM_SCRIPTS); do \
$(INSTALL_DATA) $(srcdir)/$$x $(DESTDIR)$(tooldir)/lib$(MULTISUBDIR)/$$x; done
doc:
info:
dvi:
install-info:
clean-info:
Makefile: Makefile.in config.status @host_makefile_frag_path@
$(SHELL) config.status
config.status: configure
$(SHELL) config.status --recheck

404
libgloss/arc/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,404 @@
# generated automatically by aclocal 1.11.1 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
# AM_CONDITIONAL -*- Autoconf -*-
# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 9
# AM_CONDITIONAL(NAME, SHELL-CONDITION)
# -------------------------------------
# Define a conditional.
AC_DEFUN([AM_CONDITIONAL],
[AC_PREREQ(2.52)dnl
ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
AC_SUBST([$1_TRUE])dnl
AC_SUBST([$1_FALSE])dnl
_AM_SUBST_NOTMAKE([$1_TRUE])dnl
_AM_SUBST_NOTMAKE([$1_FALSE])dnl
m4_define([_AM_COND_VALUE_$1], [$2])dnl
if $2; then
$1_TRUE=
$1_FALSE='#'
else
$1_TRUE='#'
$1_FALSE=
fi
AC_CONFIG_COMMANDS_PRE(
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
AC_MSG_ERROR([[conditional "$1" was never defined.
Usually this means the macro was only invoked conditionally.]])
fi])])
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 10
# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
# written in clear, in which case automake, when reading aclocal.m4,
# will think it sees a *use*, and therefore will trigger all it's
# C support machinery. Also note that it means that autoscan, seeing
# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
# _AM_DEPENDENCIES(NAME)
# ----------------------
# See how the compiler implements dependency checking.
# NAME is "CC", "CXX", "GCJ", or "OBJC".
# We try a few techniques and use that to set a single cache variable.
#
# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
# dependency, and given that the user is not expected to run this macro,
# just rely on AC_PROG_CC.
AC_DEFUN([_AM_DEPENDENCIES],
[AC_REQUIRE([AM_SET_DEPDIR])dnl
AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
AC_REQUIRE([AM_MAKE_INCLUDE])dnl
AC_REQUIRE([AM_DEP_TRACK])dnl
ifelse([$1], CC, [depcc="$CC" am_compiler_list=],
[$1], CXX, [depcc="$CXX" am_compiler_list=],
[$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
[$1], UPC, [depcc="$UPC" am_compiler_list=],
[$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'],
[depcc="$$1" am_compiler_list=])
AC_CACHE_CHECK([dependency style of $depcc],
[am_cv_$1_dependencies_compiler_type],
[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
# We make a subdir and do the tests there. Otherwise we can end up
# making bogus files that we don't know about and never remove. For
# instance it was reported that on HP-UX the gcc test will end up
# making a dummy file named `D' -- because `-MD' means `put the output
# in D'.
mkdir conftest.dir
# Copy depcomp to subdir because otherwise we won't find it if we're
# using a relative directory.
cp "$am_depcomp" conftest.dir
cd conftest.dir
# We will build objects and dependencies in a subdirectory because
# it helps to detect inapplicable dependency modes. For instance
# both Tru64's cc and ICC support -MD to output dependencies as a
# side effect of compilation, but ICC will put the dependencies in
# the current directory while Tru64 will put them in the object
# directory.
mkdir sub
am_cv_$1_dependencies_compiler_type=none
if test "$am_compiler_list" = ""; then
am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
fi
am__universal=false
m4_case([$1], [CC],
[case " $depcc " in #(
*\ -arch\ *\ -arch\ *) am__universal=true ;;
esac],
[CXX],
[case " $depcc " in #(
*\ -arch\ *\ -arch\ *) am__universal=true ;;
esac])
for depmode in $am_compiler_list; do
# Setup a source with many dependencies, because some compilers
# like to wrap large dependency lists on column 80 (with \), and
# we should not choose a depcomp mode which is confused by this.
#
# We need to recreate these files for each test, as the compiler may
# overwrite some of them when testing with obscure command lines.
# This happens at least with the AIX C compiler.
: > sub/conftest.c
for i in 1 2 3 4 5 6; do
echo '#include "conftst'$i'.h"' >> sub/conftest.c
# Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
# Solaris 8's {/usr,}/bin/sh.
touch sub/conftst$i.h
done
echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
# We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
# handle `-M -o', and we need to detect this. Also, some Intel
# versions had trouble with output in subdirs
am__obj=sub/conftest.${OBJEXT-o}
am__minus_obj="-o $am__obj"
case $depmode in
gcc)
# This depmode causes a compiler race in universal mode.
test "$am__universal" = false || continue
;;
nosideeffect)
# after this tag, mechanisms are not by side-effect, so they'll
# only be used when explicitly requested
if test "x$enable_dependency_tracking" = xyes; then
continue
else
break
fi
;;
msvisualcpp | msvcmsys)
# This compiler won't grok `-c -o', but also, the minuso test has
# not run yet. These depmodes are late enough in the game, and
# so weak that their functioning should not be impacted.
am__obj=conftest.${OBJEXT-o}
am__minus_obj=
;;
none) break ;;
esac
if depmode=$depmode \
source=sub/conftest.c object=$am__obj \
depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
$SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
>/dev/null 2>conftest.err &&
grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
${MAKE-make} -s -f confmf > /dev/null 2>&1; then
# icc doesn't choke on unknown options, it will just issue warnings
# or remarks (even with -Werror). So we grep stderr for any message
# that says an option was ignored or not supported.
# When given -MP, icc 7.0 and 7.1 complain thusly:
# icc: Command line warning: ignoring option '-M'; no argument required
# The diagnosis changed in icc 8.0:
# icc: Command line remark: option '-MP' not supported
if (grep 'ignoring option' conftest.err ||
grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
am_cv_$1_dependencies_compiler_type=$depmode
break
fi
fi
done
cd ..
rm -rf conftest.dir
else
am_cv_$1_dependencies_compiler_type=none
fi
])
AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
AM_CONDITIONAL([am__fastdep$1], [
test "x$enable_dependency_tracking" != xno \
&& test "$am_cv_$1_dependencies_compiler_type" = gcc3])
])
# AM_SET_DEPDIR
# -------------
# Choose a directory name for dependency files.
# This macro is AC_REQUIREd in _AM_DEPENDENCIES
AC_DEFUN([AM_SET_DEPDIR],
[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
])
# AM_DEP_TRACK
# ------------
AC_DEFUN([AM_DEP_TRACK],
[AC_ARG_ENABLE(dependency-tracking,
[ --disable-dependency-tracking speeds up one-time build
--enable-dependency-tracking do not reject slow dependency extractors])
if test "x$enable_dependency_tracking" != xno; then
am_depcomp="$ac_aux_dir/depcomp"
AMDEPBACKSLASH='\'
fi
AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
AC_SUBST([AMDEPBACKSLASH])dnl
_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
])
# Generate code to set up dependency tracking. -*- Autoconf -*-
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
# Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#serial 5
# _AM_OUTPUT_DEPENDENCY_COMMANDS
# ------------------------------
AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
[{
# Autoconf 2.62 quotes --file arguments for eval, but not when files
# are listed without --file. Let's play safe and only enable the eval
# if we detect the quoting.
case $CONFIG_FILES in
*\'*) eval set x "$CONFIG_FILES" ;;
*) set x $CONFIG_FILES ;;
esac
shift
for mf
do
# Strip MF so we end up with the name of the file.
mf=`echo "$mf" | sed -e 's/:.*$//'`
# Check whether this is an Automake generated Makefile or not.
# We used to match only the files named `Makefile.in', but
# some people rename them; so instead we look at the file content.
# Grep'ing the first line is not enough: some people post-process
# each Makefile.in and add a new line on top of each file to say so.
# Grep'ing the whole file is not good either: AIX grep has a line
# limit of 2048, but all sed's we know have understand at least 4000.
if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
dirpart=`AS_DIRNAME("$mf")`
else
continue
fi
# Extract the definition of DEPDIR, am__include, and am__quote
# from the Makefile without running `make'.
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
test -z "$DEPDIR" && continue
am__include=`sed -n 's/^am__include = //p' < "$mf"`
test -z "am__include" && continue
am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
# When using ansi2knr, U may be empty or an underscore; expand it
U=`sed -n 's/^U = //p' < "$mf"`
# Find all dependency output files, they are included files with
# $(DEPDIR) in their names. We invoke sed twice because it is the
# simplest approach to changing $(DEPDIR) to its actual value in the
# expansion.
for file in `sed -n "
s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
fdir=`AS_DIRNAME(["$file"])`
AS_MKDIR_P([$dirpart/$fdir])
# echo "creating $dirpart/$file"
echo '# dummy' > "$dirpart/$file"
done
done
}
])# _AM_OUTPUT_DEPENDENCY_COMMANDS
# AM_OUTPUT_DEPENDENCY_COMMANDS
# -----------------------------
# This macro should only be invoked once -- use via AC_REQUIRE.
#
# This code is only required when automatic dependency tracking
# is enabled. FIXME. This creates each `.P' file that we will
# need in order to bootstrap the dependency handling code.
AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
[AC_CONFIG_COMMANDS([depfiles],
[test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
[AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
])
# Copyright (C) 2003, 2005 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 2
# Check whether the underlying file-system supports filenames
# with a leading dot. For instance MS-DOS doesn't.
AC_DEFUN([AM_SET_LEADING_DOT],
[rm -rf .tst 2>/dev/null
mkdir .tst 2>/dev/null
if test -d .tst; then
am__leading_dot=.
else
am__leading_dot=_
fi
rmdir .tst 2>/dev/null
AC_SUBST([am__leading_dot])])
# Check to see how 'make' treats includes. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 4
# AM_MAKE_INCLUDE()
# -----------------
# Check to see how make treats includes.
AC_DEFUN([AM_MAKE_INCLUDE],
[am_make=${MAKE-make}
cat > confinc << 'END'
am__doit:
@echo this is the am__doit target
.PHONY: am__doit
END
# If we don't find an include directive, just comment out the code.
AC_MSG_CHECKING([for style of include used by $am_make])
am__include="#"
am__quote=
_am_result=none
# First try GNU make style include.
echo "include confinc" > confmf
# Ignore all kinds of additional output from `make'.
case `$am_make -s -f confmf 2> /dev/null` in #(
*the\ am__doit\ target*)
am__include=include
am__quote=
_am_result=GNU
;;
esac
# Now try BSD make style include.
if test "$am__include" = "#"; then
echo '.include "confinc"' > confmf
case `$am_make -s -f confmf 2> /dev/null` in #(
*the\ am__doit\ target*)
am__include=.include
am__quote="\""
_am_result=BSD
;;
esac
fi
AC_SUBST([am__include])
AC_SUBST([am__quote])
AC_MSG_RESULT([$_am_result])
rm -f confinc confmf
])
# Copyright (C) 2006, 2008 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# serial 2
# _AM_SUBST_NOTMAKE(VARIABLE)
# ---------------------------
# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
# This macro is traced by Automake.
AC_DEFUN([_AM_SUBST_NOTMAKE])
# AM_SUBST_NOTMAKE(VARIABLE)
# ---------------------------
# Public sister of _AM_SUBST_NOTMAKE.
AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
m4_include([../acinclude.m4])

3872
libgloss/arc/configure vendored Executable file

File diff suppressed because it is too large Load Diff

55
libgloss/arc/configure.in Normal file
View File

@ -0,0 +1,55 @@
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(crt0.S)
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
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
LIB_AM_PROG_AS
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_CONFIG_FILES(Makefile,
. ${libgloss_topdir}/config-ml.in,
srcdir=${srcdir}
target=${target}
with_multisubdir=${with_multisubdir}
ac_configure_args="${ac_configure_args} --enable-multilib"
CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
libgloss_topdir=${libgloss_topdir}
)
AC_OUTPUT

241
libgloss/arc/crt0.S Normal file
View File

@ -0,0 +1,241 @@
/*
Copyright (c) 2015, Synopsys, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/*
The startup code for the ARC family of processors does the following before
transferring control to user defined main label:
1. Set sp to __stack_top (link time variable)
2. Set fp to zero
3. Zero out the bss section (for uninitialized globals)
After returning from main, the processor is halted and the pipeline is
flushed out.
We expect argc in r0 and argv in r1. These are saved in r13 / r14 during
the initialization code.
*/
.file "crt0.S"
.extern main
#if defined (__EM__) || defined (__HS__)
.section .ivt, "a", @progbits
; handler's name, type, number,name, offset in IVT (hex/dec)
.word __start ; exception 0 program entry point 0x0 0
.word memory_error ; exception 1 memory_error 0x4 4
.word instruction_error ; exception 2 instruction_error 0x8 8
.word EV_MachineCheck ; exception 3 EV_MachineCheck 0xC 12
.word EV_TLBMissI ; exception 4 EV_TLBMissI 0x10 16
.word EV_TLBMissD ; exception 5 EV_TLBMissD 0x14 20
.word EV_ProtV ; exception 6 EV_ProtV 0x18 24
.word EV_PrivilegeV ; exception 7 EV_PrivilegeV 0x1C 28
.word EV_SWI ; exception 8 EV_SWI 0x20 32
.word EV_Trap ; exception 9 EV_Trap 0x24 36
.word EV_Extension ; exception 10 EV_Extension 0x28 40
.word EV_DivZero ; exception 11 EV_DivZero 0x2C 44
.word EV_DCError ; exception 12 EV_DCError 0x30 48
.word EV_Malignedr ; exception 13 EV_Maligned 0x34 52
.word _exit_halt ; exception 14 unused 0x38 56
.word _exit_halt ; exception 15 unused 0x3C 60
.word IRQ_Timer0 ; IRQ 16 Timer 0 0x40 64
.word IRQ_Timer1 ; IRQ 17 Timer 1 0x44 68
.word IRQ_18 ; IRQ 18 0x48 72
.word IRQ_19 ; IRQ 19 0x4C 76
.word IRQ_20 ; IRQ 20 0x50 80
.section .text.__startup, "ax", @progbits
#else
.text
#endif
.global __start
.type __start, @function
#ifdef __ARC601__
; Startup code for the ARC601 processor
__start:
mov gp, @__SDATA_BEGIN__
mov sp, @__stack_top ; Point to top of stack
mov r5, 0 ; Zero value
mov_s r2, @__sbss_start ; r2 = start of the bss section
sub r3, @_end, r2 ; r3 = size of the bss section in bytes
asr_s r3, r3
asr_s r3, r3 ; r3 = size of bss in words
.Lbss_loop:
cmp r3, 0xff ; Check for max lp_count
mov.le lp_count, r3
mov.gt lp_count, 0xff
lpnz 2f ; Loop to zero bss
st.ab r5,[r2, 4] ; Write word of zeros
nop
2:
sub.f r3, r3, 0xff ; Decrement word count
jp .Lbss_loop
#else /* __ARC601__ */
; Startup code for the ARC600, ARC700 and ARCv2 processors
; NOTE: The following restrictions apply on zero overhead loops (other
; restrictions are not pertinent to this code)
; - loop end should be 4 instruction words away from the lp_count setting
; instruction
; - loop body should have at least two instruction words
__start:
#if defined (__HS__)
; Allow unaligned accesses.
lr r2, [0xA]
bset r2, r2, 19
flag r2
#endif
mov gp, @__SDATA_BEGIN__
mov_s r2, @__sbss_start ; r2 = start of the bss section
sub r3, @_end, r2 ; r3 = size of the bss section in bytes
; set up the loop counter register to the size (in words) of the bss section
asr.f lp_count, r3, 2
#if defined (__ARC600__)
; loop to zero out the bss. Enter loop only if lp_count != 0
lpnz @.Lend_zbss
add r3, pcl, 20
sr r3, [2] ; LP_END
; initialize stack pointer, and this instruction has 2 words
mov sp, @__stack_top
mov_s r3, 0
st.ab r3, [r2, 4] ; zero out the word
.Lend_zbss:
#else
mov sp, @__stack_top ; initialize stack pointer
mov_s r3,0
; loop to zero out the bss. Enter loop only if lp_count != 0
lpnz @.Lend_zbss
st.ab r3,[r2, 4] ; zero out the word
nop
.Lend_zbss:
#endif
#endif /* !__ARC601__ */
; Some targets use the .init and .fini sections to create constructors and
; destructors, and for these targets we need to call the _init function and
; arrange for _fini to be called at program exit.
mov_s r13, r0
mov_s r14, r1
; calling atexit drags in malloc, so instead poke the function
; address directly into the reent structure
ld r1, [gp, @_impure_ptr@sda]
mov_s r0, @_fini
add r1, r1, 0x14c ; &_GLOBAL_REENT->atexit0
st r1, [r1, -4] ; _GLOBAL_REENT->atexit
st_s r0, [r1, 8] ; _GLOBAL_REENT->atexit0._fns[0]
mov_s r0, 1
st_s r0, [r1, 4] ; _GLOBAL_REENT->atexit0._ind
; branch to _init
#if defined (__EM__) || defined (__HS__)
jl @_init
#else
bl @_init
#endif
mov_s r0, r13
mov_s r1, r14
; branch to main
#if defined (__EM__) || defined (__HS__)
mov fp,0 ; initialize frame pointer
jl @main
#else
bl.d @main
mov fp, 0 ; initialize frame pointer
#endif
; r0 contains exit code
j @exit
#if defined (__EM__) || defined (__HS__)
; ARCv2 default interrupt routines, defined as weak symbols.
; Default implementation halts the core. To conserve code size those symbols
; share a single implementation, however as a downside debugger and
; disassembler will not be able to distinguish one from another.
.weak memory_error
.weak instruction_error
.weak EV_MachineCheck
.weak EV_TLBMissI
.weak EV_TLBMissD
.weak EV_ProtV
.weak EV_PrivilegeV
.weak EV_SWI
.weak EV_Trap
.weak EV_Extension
.weak EV_DivZero
.weak EV_DCError
.weak EV_Malignedr
.weak IRQ_Timer0
.weak IRQ_Timer1
.weak IRQ_18
.weak IRQ_19
.weak IRQ_20
.balign 4
memory_error :
instruction_error :
EV_MachineCheck :
EV_TLBMissI :
EV_TLBMissD :
EV_ProtV :
EV_PrivilegeV :
EV_SWI :
EV_Trap :
EV_Extension :
EV_DivZero :
EV_DCError :
EV_Malignedr :
IRQ_Timer0 :
IRQ_Timer1 :
IRQ_18 :
IRQ_19 :
IRQ_20 :
.Lloop_halt:
flag 0x01
nop
b .Lloop_halt
nop
#endif
.section .text._exit_halt,"ax",@progbits
.global _exit_halt
.type _exit_halt, @function
_exit_halt:
; r0 contains exit code
flag 0x01
nop
nop ; ARCompact requires 3 nops after flag 1
nop
b @_exit_halt
nop

92
libgloss/arc/libcfunc.c Normal file
View File

@ -0,0 +1,92 @@
/*
Copyright (c) 2015, Synopsys, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* This file has been copied from libgloss/arm/libcfuncs.c.
Support files for GNU libc. Files in the C namespace go here.
Files in the system namespace (ie those that start with an underscore)
go in syscalls.c.
Note: These functions are in a seperate file so that OS providers can
overrride the system call stubs (defined in syscalls.c) without having
to provide libc functions as well. */
#include <errno.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
unsigned __attribute__((weak))
alarm (unsigned seconds)
{
(void)seconds;
return 0;
}
clock_t _clock (void);
clock_t __attribute__((weak))
clock (void)
{
return _clock ();
}
int _isatty (int fildes);
int __attribute__((weak))
isatty (int fildes)
{
return _isatty (fildes);
}
int __attribute__((weak))
pause (void)
{
errno = ENOSYS;
return -1;
}
unsigned __attribute__((weak))
sleep (unsigned seconds)
{
clock_t t0 = _clock ();
clock_t dt = seconds * CLOCKS_PER_SEC;
while (_clock () - t0 < dt);
return 0;
}
int __attribute__((weak))
usleep (useconds_t useconds)
{
clock_t t0 = _clock ();
clock_t dt = useconds / (1000000/CLOCKS_PER_SEC);
while (_clock () - t0 < dt);
return 0;
}

457
libgloss/arc/nsim-syscall.h Normal file
View File

@ -0,0 +1,457 @@
/*
Copyright (c) 2015, Synopsys, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ASM_ARC_UNISTD_H
#define _ASM_ARC_UNISTD_H
#include <stdint.h>
#ifndef __ASSEMBLY__
/* This file contains the system call numbers. Not all are implemented in nSIM
hostlink. Numbers correspond to the old ARCLinux syscalls, but during
upstreaming of ARC Linux, those numbers has been changed, hence today ARC
Linux and nSIM hostlink use different system call numbers. */
#define SYS_exit 1
#define SYS__exit SYS_exit
#define SYS_fork 2
#define SYS_read 3
#define SYS_write 4
#define SYS_open 5
#define SYS_close 6
#define SYS_waitpid 7
#define SYS_creat 8
#define SYS_link 9
#define SYS_unlink 10
#define SYS_execve 11
#define SYS_chdir 12
#define SYS_time 13
#define SYS_mknod 14
#define SYS_chmod 15
#define SYS_chown 16
#define SYS_break 17
#define SYS_oldstat 18
#define SYS_lseek 19
#define SYS_getpid 20
#define SYS_mount 21
#define SYS_umount 22
#define SYS_setuid 23
#define SYS_getuid 24
#define SYS_stime 25
#define SYS_ptrace 26
#define SYS_alarm 27
#define SYS_oldfstat 28
#define SYS_pause 29
#define SYS_utime 30
#define SYS_stty 31
#define SYS_gtty 32
#define SYS_access 33
#define SYS_nice 34
#define SYS_ftime 35
#define SYS_sync 36
#define SYS_kill 37
#define SYS_rename 38
#define SYS_mkdir 39
#define SYS_rmdir 40
#define SYS_dup 41
#define SYS_pipe 42
#define SYS_times 43
#define SYS_prof 44
#define SYS_brk 45
#define SYS_setgid 46
#define SYS_getgid 47
#define SYS_signal 48
#define SYS_geteuid 49
#define SYS_getegid 50
#define SYS_acct 51
#define SYS_umount2 52
#define SYS_lock 53
#define SYS_ioctl 54
#define SYS_fcntl 55
#define SYS_mpx 56
#define SYS_setpgid 57
#define SYS_ulimit 58
#define SYS_oldolduname 59
#define SYS_umask 60
#define SYS_chroot 61
#define SYS_ustat 62
#define SYS_dup2 63
#define SYS_getppid 64
#define SYS_getpgrp 65
#define SYS_setsid 66
#define SYS_sigaction 67
#define SYS_sgetmask 68
#define SYS_ssetmask 69
#define SYS_setreuid 70
#define SYS_setregid 71
#define SYS_sigsuspend 72
#define SYS_sigpending 73
#define SYS_sethostname 74
#define SYS_setrlimit 75
#define SYS_old_getrlimit 76
#define SYS_getrusage 77
#define SYS_gettimeofday 78
#define SYS_settimeofday 79
#define SYS_getgroups 80
#define SYS_setgroups 81
#define SYS_select 82
#define SYS_symlink 83
#define SYS_oldlstat 84
#define SYS_readlink 85
#define SYS_uselib 86
#define SYS_swapon 87
#define SYS_reboot 88
#define SYS_readdir 89
#define SYS_mmap 90
#define SYS_munmap 91
#define SYS_truncate 92
#define SYS_ftruncate 93
#define SYS_fchmod 94
#define SYS_fchown 95
#define SYS_getpriority 96
#define SYS_setpriority 97
#define SYS_profil 98
#define SYS_statfs 99
#define SYS_fstatfs 100
#define SYS_ioperm 101
#define SYS_socketcall 102
#define SYS_syslog 103
#define SYS_setitimer 104
#define SYS_getitimer 105
#define SYS_stat 106
#define SYS_lstat 107
#define SYS_fstat 108
#define SYS_olduname 109
#define SYS_iopl 110 /* not supported */
#define SYS_vhangup 111
#define SYS_idle 112 /* Obsolete */
#define SYS_vm86 113 /* not supported */
#define SYS_wait4 114
#define SYS_swapoff 115
#define SYS_sysinfo 116
#define SYS_ipc 117
#define SYS_fsync 118
#define SYS_sigreturn 119
#define SYS_clone 120
#define SYS_setdomainname 121
#define SYS_uname 122
#define SYS_cacheflush 123
#define SYS_adjtimex 124
#define SYS_mprotect 125
#define SYS_sigprocmask 126
#define SYS_create_module 127
#define SYS_init_module 128
#define SYS_delete_module 129
#define SYS_get_kernel_syms 130
#define SYS_quotactl 131
#define SYS_getpgid 132
#define SYS_fchdir 133
#define SYS_bdflush 134
#define SYS_sysfs 135
#define SYS_personality 136
#define SYS_afs_syscall 137 /* Syscall for Andrew File System */
#define SYS_setfsuid 138
#define SYS_setfsgid 139
#define SYS__llseek 140
#define SYS_getdents 141
#define SYS__newselect 142
#define SYS_flock 143
#define SYS_msync 144
#define SYS_readv 145
#define SYS_writev 146
#define SYS_getsid 147
#define SYS_fdatasync 148
#define SYS__sysctl 149
#define SYS_mlock 150
#define SYS_munlock 151
#define SYS_mlockall 152
#define SYS_munlockall 153
#define SYS_sched_setparam 154
#define SYS_sched_getparam 155
#define SYS_sched_setscheduler 156
#define SYS_sched_getscheduler 157
#define SYS_sched_yield 158
#define SYS_sched_get_priority_max 159
#define SYS_sched_get_priority_min 160
#define SYS_sched_rr_get_interval 161
#define SYS_nanosleep 162
#define SYS_mremap 163
#define SYS_setresuid 164
#define SYS_getresuid 165
#define SYS_query_module 167
#define SYS_poll 168
#define SYS_nfsservctl 169
#define SYS_setresgid 170
#define SYS_getresgid 171
#define SYS_prctl 172
#define SYS_rt_sigreturn 173
#define SYS_rt_sigaction 174
#define SYS_rt_sigprocmask 175
#define SYS_rt_sigpending 176
#define SYS_rt_sigtimedwait 177
#define SYS_rt_sigqueueinfo 178
#define SYS_rt_sigsuspend 179
#define SYS_pread 180
#define SYS_pwrite 181
#define SYS_lchown 182
#define SYS_getcwd 183
#define SYS_capget 184
#define SYS_capset 185
#define SYS_sigaltstack 186
#define SYS_sendfile 187
#define SYS_getpmsg 188 /* some people actually want streams */
#define SYS_putpmsg 189 /* some people actually want streams */
#define SYS_vfork 190
#define SYS_getrlimit 191
#define SYS_mmap2 192
#define SYS_truncate64 193
#define SYS_ftruncate64 194
#define SYS_stat64 195
#define SYS_lstat64 196
#define SYS_fstat64 197
#define SYS_chown32 198
#define SYS_getuid32 199
#define SYS_getgid32 200
#define SYS_geteuid32 201
#define SYS_getegid32 202
#define SYS_setreuid32 203
#define SYS_setregid32 204
#define SYS_getgroups32 205
#define SYS_setgroups32 206
#define SYS_fchown32 207
#define SYS_setresuid32 208
#define SYS_getresuid32 209
#define SYS_setresgid32 210
#define SYS_getresgid32 211
#define SYS_lchown32 212
#define SYS_setuid32 213
#define SYS_setgid32 214
#define SYS_setfsuid32 215
#define SYS_setfsgid32 216
#define SYS_pivot_root 217
#define SYS_getdents64 220
#define SYS_fcntl64 221
#define SYS_gettid 224
#endif /* ! __ASSEMBLY__ */
#ifdef __ARC700__
#define SYSCALL \
"trap0 \n\t"
#else
#define SYSCALL \
"swi \n\t"\
"nop \n\t"\
"nop \n\t"
#endif /* __ARC700__ */
/* There are two variants of macroses here:
- _syscall is a complete function definition of system call
- _naked_syscall only invokes system call and can be inserted into other
functions. This macro is defined only for those syscall<N>, where it is
actually used. */
#define _syscall0(type, name) \
type _##name () \
{ \
long __res; \
__asm__ __volatile__ ("mov r8, %1\n\t" \
SYSCALL \
"mov %0, r0" \
: "=r" (__res) \
: "i" (SYS_##name) \
: "cc", "r0", "r8"); \
if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
errno = -__res; \
__res = -1; \
} \
return (type)__res; \
}
#define _syscall1(type, name, atype, a) \
type _##name (atype a) \
{ \
long __res; \
__asm__ __volatile__ ("mov r0, %2\n\t" \
"mov r8, %1\n\t" \
SYSCALL \
"mov %0, r0" \
: "=r" (__res) \
: "i" (SYS_##name), \
"r" ((long)a) \
: "cc", "r0", "r8"); \
if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
errno = -__res; \
__res = -1; \
} \
return (type)__res; \
}
#define _naked_syscall2(__res, name, a, b) \
__asm__ __volatile__ ("mov r1, %3\n\t" \
"mov r0, %2\n\t" \
"mov r8, %1\n\t" \
SYSCALL \
"mov %0, r0" \
: "=r" (__res) \
: "i" (SYS_##name), \
"r" ((long)a), \
"r" ((long)b) \
: "cc", "r0", "r1", "r8"); \
if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
errno = -__res; \
__res = -1; \
}
#define _syscall2(type, name, atype, a, btype, b) \
type _##name (atype a, btype b) \
{ \
long __res; \
_naked_syscall2 (__res, name, a, b) \
return (type)__res; \
}
#define _naked_syscall3(__res, name, a, b, c) \
__asm__ __volatile__ ( \
"mov r2, %4\n\t" \
"mov r1, %3\n\t" \
"mov r0, %2\n\t" \
"mov r8, %1\n\t" \
SYSCALL \
"mov %0, r0" \
: "=r" (__res) \
: "i" (SYS_##name), \
"r" ((long)a), \
"r" ((long)b), \
"r" ((long)c) \
: "cc", "r0", "r1", "r2", "r8"); \
if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
errno = -__res; \
__res = -1; \
}
#define _syscall3(type,name,atype,a,btype,b,ctype,c) \
type _##name (atype a, btype b, ctype c) \
{ \
long __res; \
_naked_syscall3 (__res, name, a, b, c) \
return (type)__res; \
}
#define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \
type _##name (atype a, btype b, ctype c, dtype d) \
{ \
long __res; \
__asm__ __volatile__ ( \
"mov r3, %5\n\t" \
"mov r2, %4\n\t" \
"mov r1, %3\n\t" \
"mov r0, %2\n\t" \
"mov r8, %1\n\t" \
SYSCALL \
"mov %0, r0" \
: "=r" (__res) \
: "i" (SYS_##name), \
"r" ((long)a), \
"r" ((long)b), \
"r" ((long)c), \
"r" ((long)d) \
: "cc", "r0", "r1", "r2", "r3", "r8"); \
if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
errno = -__res; \
__res = -1; \
} \
return (type)__res; \
}
#define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, \
etype, e) \
type _##name (atype a, btype b, ctype c, dtype d, etype e) \
{ \
long __res; \
__asm__ __volatile__ ( \
"mov r4, %6\n\t" \
"mov r3, %5\n\t" \
"mov r2, %4\n\t" \
"mov r1, %3\n\t" \
"mov r0, %2\n\t" \
"mov r8, %1\n\t" \
SYSCALL \
"mov %0, r0" \
: "=r" (__res) \
: "i" (SYS_##name), \
"r" ((long)a), \
"r" ((long)b), \
"r" ((long)c), \
"r" ((long)d), \
"r" ((long)e) \
: "cc", "r0", "r1", "r2", "r3", "r4", "r8"); \
if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
errno = -__res; \
__res = -1; \
} \
return (type)__res; \
}
/* open() flags that are used by nSIM hostlink. See comment for _open()
implementation in nsim-syscalls.c. */
#define ARC_LINUX_RDONLY 0
#define ARC_LINUX_WRONLY 1
#define ARC_LINUX_RDWR 2
#define ARC_LINUX_CREAT 0x0040
#define ARC_LINUX_APPEND 0x0400
#define ARC_LINUX_TRUNC 0x0200
#define ARC_LINUX_EXCL 0x0080
/* stat structure as defined in nSIM hostlink. */
struct nsim_stat {
uint16_t dev;
uint16_t __pad1;
uint32_t ino;
uint16_t mode;
uint16_t nlink;
uint16_t uid;
uint16_t gid;
uint16_t rdev;
uint16_t __pad2;
uint32_t size;
uint32_t blksize;
uint32_t blocks;
uint32_t atime;
uint32_t __unused1;
uint32_t mtime;
uint32_t __unused2;
uint32_t ctime;
uint32_t __unused3;
uint32_t __unused4;
uint32_t __unused5;
};
#endif /* _ASM_ARC_UNISTD_H */

View File

@ -0,0 +1,235 @@
/*
Copyright (c) 2015, Synopsys, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <_ansi.h>
#include <_syslist.h>
#include <errno.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include "glue.h"
#include "nsim-syscall.h"
/* Those system calls are implemented in both nSIM and CGEN. */
_syscall3 (_ssize_t, read, int, fd, void *, buf, size_t, count)
_syscall3 (_ssize_t, write, int, fd, const void *, buf, size_t, count)
_syscall1 (int, unlink, const char *, pathname)
_syscall3 (off_t, lseek, int, fd, off_t, offset, int, whence)
_syscall2 (int, gettimeofday, struct timeval *, tv, void *, tz)
_syscall1 (_CLOCK_T_, time, _CLOCK_T_ *, t)
_syscall1 (int, close, int, fd)
_syscall1 (_CLOCK_T_, times, struct tms *, buf)
/* stat requires custom implementation. */
/* _syscall2 (int, stat, const char *, path, struct stat *, st)
_syscall2 (int, fstat, int, file, struct stat *, st) */
/* nSIM implements brk and sbrk, but instead sbrk.c is used. */
/* _syscall1 (int, brk, void *, addr) */
/* open requires custom implementation. */
/* _syscall3 (int, open, const char *, pathname, int, flags, int, mode) */
/* Those syscalls are not available in CGEN simulator. */
_syscall1 (int, rmdir, const char *, pathname)
_syscall2 (char *, getcwd, char *, buf, size_t, size)
/* stat requires custom implementation. */
/* _syscall2 (int, lstat, const char *, path, struct stat *, st) */
/* Historically "open" flags defined by default in newlib and in Linux for ARC
are different - this is true for some other architectures as well, e.g.
ARM. To provide compatibility ARC port of newlib had a custom fcntl.h file
that has "open" flags identical to Linux ones. Some other architectures
(spart64, cris) override default fcntl.h as well, but I'm not sure this is
really a good idea. Unlike system call numbers that can be unique to each
BSP in libgloss, "open" flags are not abstracted from the application code
itself, hence it is not possible to have fcntl.h in the libgloss. To make
matters worse, existing simulators already has been built for the Linux-like
"open" flags. To preserve compatibility with existing hostlink
implementations in simulators, but avoid custom fcntl.h in the future,
simulator BSP has to do dynamic rewriting of "open" flags from the newlib
default into old ARC Linux flags. Simulators support only most basic flags,
therefore only those are translated in this implementation. */
int
_open (const char * pathname, int flags, int mode)
{
int nsim_flags = 0;
/* RDONLY, WRONLY, RDWR are same as newlib default. */
nsim_flags |= flags & O_RDONLY;
nsim_flags |= flags & O_WRONLY;
nsim_flags |= flags & O_RDWR;
nsim_flags |= (flags & O_CREAT) ? ARC_LINUX_CREAT : 0;
nsim_flags |= (flags & O_APPEND) ? ARC_LINUX_APPEND : 0;
nsim_flags |= (flags & O_TRUNC) ? ARC_LINUX_TRUNC : 0;
nsim_flags |= (flags & O_EXCL) ? ARC_LINUX_EXCL : 0;
/* There are other fcntl flags that are different between newlib and ARC
uClibc, however they are not supported by nSIM hostlink, therefore there
is no need to translate them. */
long __res;
_naked_syscall3 (__res, open, pathname, nsim_flags, mode)
return __res;
}
/* Should be provided by crt0.S. */
extern void __attribute__((noreturn)) _exit_halt ();
void
__attribute__((noreturn))
_exit (int ret)
{
/* Doing an "exit" system call would work on nSIM with hostlink, but call to
_exit_halt, which will do a CPU halt is more universal and will work in
many other cases as well, including an FPGA/SoC. */
_exit_halt ();
}
/* This is a copy of newlib/libc/posix/_isatty.c. It is needed because nSIM
hostlink doesn't implement isatty system call. Hardware boards on the other
hand would want isatty implementation that always returns 1, since they are
connected to console and doesn't have file IO. */
int
_isatty (int fd)
{
struct stat buf;
if (fstat (fd, &buf) < 0)
{
errno = EBADF;
return 0;
}
if (S_ISCHR (buf.st_mode))
{
return 1;
}
errno = ENOTTY;
return 0;
}
/* System call "getpid" is implemented in nSIM hostlink, but it is better not
to expose it in libgloss. */
int
_getpid (void)
{
return __MYPID;
}
/* System call "kill" is implemented in nSIM hostlink on Linux hosts, but it
seems dangerous to expose it. Instead, like most of the other "_kill"
implementations in libgloss, this will kill only self. */
int
_kill (int pid, int sig)
{
if (pid == __MYPID)
{
_exit (sig);
}
errno = ENOSYS;
return -1;
}
static void
translate_stat (struct nsim_stat *nsim, struct stat *buf)
{
#define TR(field, type) buf->st_ ## field = (type) nsim->field
TR (dev, dev_t);
TR (ino, ino_t);
TR (mode, mode_t);
TR (nlink, nlink_t);
TR (uid, uid_t);
TR (gid, gid_t);
TR (rdev, dev_t);
TR (size, off_t);
TR (atime, time_t);
TR (mtime, time_t);
TR (ctime, time_t);
TR (blksize, long);
TR (blocks, long);
#undef TR
}
/* stat/fstat implementation. Situation is similiar to open and its flags -
structure is defined in libc, hence cannot be customized in libgloss, yet we
have a case where nSIM uses some definition which is not compatible with
neither old ARC-custom definition of "struct stat" in newlib, nor with
generic newlib implementation. */
int
_stat (const char * path, struct stat *buf)
{
struct nsim_stat nsim_stat;
long __res;
_naked_syscall2 (__res, stat, path, &nsim_stat)
translate_stat (&nsim_stat, buf);
return __res;
}
int
_lstat (const char * path, struct stat *buf)
{
struct nsim_stat nsim_stat;
long __res;
_naked_syscall2 (__res, stat, path, &nsim_stat)
translate_stat (&nsim_stat, buf);
return __res;
}
int
_fstat (int fd, struct stat *buf)
{
struct nsim_stat nsim_stat;
long __res;
_naked_syscall2 (__res, stat, fd, &nsim_stat)
translate_stat (&nsim_stat, buf);
return __res;
}
/* Some system calls are implemented in nSIM hostlink, but are available only
on Linux hosts. To minimize potential compatibility issues they are by
default disabled in libgloss build. */
#ifdef ARC_NSIM_WIN32_HOST
_syscall3 (int, ioctl, int, fd, int, request, char *, argp)
_syscall3 (_ssize_t, readv, int, fd, const struct iovec *, iov, int, iovcnt)
_syscall3 (_ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt)
_syscall5 (off_t, llseek, int, fd, unsigned long, offset_high,
unsigned long, offset_low, loff_t *, result,
unsigned int, whence)
_syscall2 (int, getrusage, int, who, struct rusage *, usage)
_syscall2 (int, setrlimit, int, resource, const struct rlimit *, rlim)
_syscall2 (int, getrlimit, int, resource, struct rlimit *, rlim)
_syscall3 (int, sigaction, int signum, const struct sigaction *, act,
struct sigaction *, oldact)
_syscall0 (uid_t, getuid)
_syscall0 (gid_t, getgid)
_syscall0 (uid_t, geteuid)
_syscall0 (gid_t, getegid)
_syscall2 (int, kill, pid_t, pid, int, sig)
_syscall3 (_ssize_t, readlink, const char *, path, char *, buf, size_t, bufsize)
#endif

5
libgloss/arc/nsim.specs Normal file
View File

@ -0,0 +1,5 @@
%rename link_gcc_c_sequence nsim_link_gcc_c_sequence
*link_gcc_c_sequence:
%(nsim_link_gcc_c_sequence) --start-group %G -lc -lnsim --end-group

61
libgloss/arc/sbrk.c Normal file
View File

@ -0,0 +1,61 @@
/*
Copyright (c) 2015, Synopsys, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/errno.h>
extern char __start_heap;
extern char __end_heap;
caddr_t
_sbrk (size_t nbytes)
{
static char* heap_ptr = NULL;
char* prev_heap_ptr;
if (heap_ptr == NULL)
{
heap_ptr = &__start_heap;
}
/* Align the 'heap_ptr' so that memory will always be allocated at word
boundaries. */
heap_ptr = (char *) ((((unsigned long) heap_ptr) + 7) & ~7);
prev_heap_ptr = heap_ptr;
if ((heap_ptr + nbytes) < &__end_heap)
{
heap_ptr += nbytes;
return (caddr_t) prev_heap_ptr;
}
errno = ENOMEM;
return (caddr_t) -1;
}

10
libgloss/configure vendored
View File

@ -666,6 +666,7 @@ CCAS
CCASFLAGS'
ac_subdirs_all='doc
aarch64
arc
epiphany
i386
m32r
@ -688,6 +689,7 @@ crx
d30v
fr30
frv
ft32
lm32
mcore
mep
@ -2400,6 +2402,10 @@ case "${target}" in
subdirs="$subdirs aarch64"
config_testsuite=true
;;
arc*-*-*)
subdirs="$subdirs arc"
;;
epiphany-*-*)
subdirs="$subdirs epiphany"
@ -2489,6 +2495,10 @@ case "${target}" in
frv*-*-*)
subdirs="$subdirs frv"
;;
ft32*-*-*)
subdirs="$subdirs ft32"
;;
lm32*-*-*)
subdirs="$subdirs lm32"

View File

@ -38,6 +38,9 @@ case "${target}" in
AC_CONFIG_SUBDIRS(aarch64)
config_testsuite=true
;;
arc*-*-*)
AC_CONFIG_SUBDIRS(arc)
;;
epiphany-*-*)
AC_CONFIG_SUBDIRS(epiphany)
config_testsuite=true