Add BSP and semihosting library for nios2-generic-nommu QEMU emulation.

This commit is contained in:
Sandra Loosemore 2018-08-07 14:15:47 -07:00 committed by Corinna Vinschen
parent 054ff18f5f
commit fddc74d12b
28 changed files with 5848 additions and 0 deletions

5
libgloss/configure vendored
View File

@ -710,6 +710,7 @@ spu
tic6x
iq2000
or1k
nios2
libnosys'
# Initialize some variables set by options.
@ -2585,6 +2586,10 @@ case "${target}" in
or1k-*-* | or1knd-*-* )
subdirs="$subdirs or1k"
;;
nios2-*-*)
subdirs="$subdirs nios2"
;;
esac

View File

@ -176,6 +176,9 @@ case "${target}" in
or1k-*-* | or1knd-*-* )
AC_CONFIG_SUBDIRS([or1k])
;;
nios2-*-*)
AC_CONFIG_SUBDIRS([nios2])
;;
esac
dnl For now, don't bother configuring testsuite

118
libgloss/nios2/Makefile.in Normal file
View File

@ -0,0 +1,118 @@
# Copyright (c) 1995, 1996, 2001 Cygnus Support -*- mode:makefile -*-
# Copyright (c) 2018, Mentor Graphics
#
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors
# and need not follow the licensing terms described here, provided that
# the new terms are clearly indicated on the first page of each file where
# they apply.
#
DESTDIR =
VPATH = @srcdir@
srcdir = @srcdir@
objdir = .
srcroot = $(srcdir)/../..
objroot = $(objdir)/../..
prefix = @prefix@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
target_alias = @target_alias@
program_transform_name = @program_transform_name@
bindir = @bindir@
libdir = @libdir@
tooldir = $(exec_prefix)/$(target_alias)
# Multilib support variables.
# TOP is used instead of MULTI{BUILD,SRC}TOP.
MULTIDIRS =
MULTISUBDIR =
MULTIDO = true
MULTICLEAN = true
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
SHELL = /bin/sh
CC = @CC@
AS = @AS@
AR = @AR@
LD = @LD@
RANLIB = @RANLIB@
AR_FLAGS = qv
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`
# Linker scripts.
BSP_SCRIPTS= qemu-hosted.ld
# Semihosting library.
HOSTED_BSP= libnios2.a
HOSTED_OBJS= io-gdb.o io-exit.o \
io-close.o io-fstat.o \
io-gettimeofday.o io-isatty.o io-lseek.o \
io-open.o io-read.o io-rename.o \
io-stat.o io-system.o io-time.o \
io-unlink.o io-write.o \
sbrk.o kill.o getpid.o
# Host specific makefile fragment comes in here.
@host_makefile_frag@
all :: ${HOSTED_BSP}
# Build semihosting library.
crt0.o: crt0.S
$(CC) $(CFLAGS_FOR_TARGET) $(CFLAGS) -c $< -o $@
io-nios2.o: io-nios2.S
$(CC) $(CFLAGS_FOR_TARGET) $(CFLAGS) -c $< -o $@
$(HOSTED_OBJS): %.o: %.c io.h
$(CC) $(CFLAGS_FOR_TARGET) $(CFLAGS) -DHOSTED=1 $(INCLUDES) -c $< -o $@
$(HOSTED_BSP): crt0.o io-nios2.o $(HOSTED_OBJS) $(OTHER_OBJS)
${AR} ${ARFLAGS} $@ $^
${RANLIB} $@
.PHONY: install info dvi doc install-info clean-info
install::
$(INSTALL_DATA) $(HOSTED_BSP) \
$(DESTDIR)$(tooldir)/lib${MULTISUBDIR}
for x in ${BSP_SCRIPTS}; do\
${INSTALL_DATA} ${srcdir}/$${x} $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x; \
done
# target specific makefile fragment comes in here.
@target_makefile_frag@
clean mostlyclean:
rm -f a.out core *.i *~ *.a *.o *-test *.srec *.dis *.x *.map
distclean maintainer-clean realclean: clean
rm -f Makefile config.cache config.log config.status
info dvi doc:
install-info:
clean-info:
Makefile: Makefile.in config.status @host_makefile_frag_path@ @target_makefile_frag_path@
$(SHELL) config.status
config.status: configure
$(SHELL) config.status --recheck

344
libgloss/nios2/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,344 @@
# generated automatically by aclocal 1.9.5 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 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.
# 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
# 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 7
# 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])
AC_SUBST([$1_FALSE])
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
# 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 8
# 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], 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
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
case $depmode in
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
;;
none) break ;;
esac
# 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.
if depmode=$depmode \
source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
$SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
>/dev/null 2>conftest.err &&
grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
grep sub/conftest.${OBJEXT-o} 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])
])
# Generate code to set up dependency tracking. -*- Autoconf -*-
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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 3
# _AM_OUTPUT_DEPENDENCY_COMMANDS
# ------------------------------
AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
[for mf in $CONFIG_FILES; 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.
# So let's grep whole file.
if grep '^#.*generated by automake' $mf > /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 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 3
# 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 done
.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
# We grep out `Entering directory' and `Leaving directory'
# messages which can occur if `w' ends up in MAKEFLAGS.
# In particular we don't look at `^make:' because GNU make might
# be invoked under some other name (usually "gmake"), in which
# case it prints its new name instead of `make'.
if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then
am__include=include
am__quote=
_am_result=GNU
fi
# Now try BSD make style include.
if test "$am__include" = "#"; then
echo '.include "confinc"' > confmf
if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then
am__include=.include
am__quote="\""
_am_result=BSD
fi
fi
AC_SUBST([am__include])
AC_SUBST([am__quote])
AC_MSG_RESULT([$_am_result])
rm -f confinc confmf
])
m4_include([../acinclude.m4])

3850
libgloss/nios2/configure vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
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="${with_multisrctop}../../.."
else
libgloss_topdir="${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
target_makefile_frag=${srcdir}/../config/default.mt
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)
target_makefile_frag_path=$target_makefile_frag
AC_SUBST(target_makefile_frag_path)
AC_SUBST_FILE(target_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

140
libgloss/nios2/crt0.S Normal file
View File

@ -0,0 +1,140 @@
/* crt0.S -- startup code for Nios II QEMU generic-nommu board emulation.
Copyright (c) 2018 Mentor Graphics
The authors hereby grant permission to use, copy, modify, distribute,
and license this software and its documentation for any purpose, provided
that existing copyright notices are retained in all copies and that this
notice is included verbatim in any distributions. No written agreement,
license, or royalty fee is required for any of the authorized uses.
Modifications to this software may be copyrighted by their authors
and need not follow the licensing terms described here, provided that
the new terms are clearly indicated on the first page of each file where
they apply.
Parts of this file were derived from code written by Altera Corporation
and distributed under the following license:
Copyright (c) 2006 Altera Corporation, San Jose, California, USA.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
This agreement shall be governed in all respects by the laws of the State
of California and by the laws of the United States of America.
*/
/* Cache sizes. */
#define NIOS2_ICACHE_LINE_SIZE 32
#define NIOS2_ICACHE_SIZE 32768
#define NIOS2_DCACHE_LINE_SIZE 32
#define NIOS2_DCACHE_SIZE 32768
/* External symbols. */
.globl __stack
.globl __gp
.globl __bss_start
.globl __bss_end
.weak exit
/* Processor reset code lives at the base of RAM. At reset, only the cache
line that contains the reset vector is initialized; the reset code has
to fit in this cache line and initialize the remainder of the instruction
cache. */
.section .text.entry, "ax"
.align 5
.set noat
.globl __reset
.type __reset, @function
__reset:
/* Initialize the icache. */
movui r2, NIOS2_ICACHE_SIZE
0:
initi r2
addi r2, r2, -NIOS2_ICACHE_LINE_SIZE
bgt r2, zero, 0b
1:
/* Jump to the __start entry point. */
movhi r1, %hi(__start)
ori r1, r1, %lo(__start)
jmp r1
.size __reset, . - __reset
/* __start is the ELF entry point. */
.section .text.start, "ax"
.align 4
.globl __start
.type __start, @function
__start:
/* Initialize the data cache. */
movui r2, NIOS2_DCACHE_SIZE
0:
initd 0(r2)
addi r2, r2, -NIOS2_DCACHE_LINE_SIZE
bgt r2, zero, 0b
1:
/* Initialize the stack pointer. */
movhi sp, %hi(__stack)
ori sp, sp, %lo(__stack)
/* Initialize the GP. */
movhi gp, %hi(_gp)
ori gp, gp, %lo(_gp)
/* Clear BSS. */
movhi r2, %hi(__bss_start)
ori r2, r2, %lo(__bss_start)
movhi r3, %hi(__bss_end)
ori r3, r3, %lo(__bss_end)
beq r2, r3, 1f
0:
stw zero, (r2)
addi r2, r2, 4
bltu r2, r3, 0b
1:
/* Run initializers. */
call __libc_init_array
/* Call the C entry point. */
mov r4, zero /* argc */
mov r5, zero /* argv */
call main
/* If main returns, call exit if it is defined. */
movhi r3, %hi(exit)
ori r3, r3, %lo(exit)
beq r3, zero, 2f
mov r4, r2 /* exit status from main */
callr r3
/* Otherwise sit in busy loop. */
2:
br 2b
.size __start, . - __start

22
libgloss/nios2/getpid.c Normal file
View File

@ -0,0 +1,22 @@
/*
* kill.c
*
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
/* Minimal implementation of getpid for a target system without processes. */
int
getpid ()
{
return 1;
}

43
libgloss/nios2/io-close.c Normal file
View File

@ -0,0 +1,43 @@
/*
* io-close.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <unistd.h>
#include <errno.h>
#define IO close
#include "io.h"
/*
* close -- close a file descriptor.
* input parameters:
* 0 : file descriptor
* output parameters:
* 0 : result
* 1 : errno
*/
int close (int fd)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) fd;
__io_hosted (HOSTED_CLOSE, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
return 0;
#endif
}

30
libgloss/nios2/io-exit.c Normal file
View File

@ -0,0 +1,30 @@
/*
* io-exit.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#if HOSTED
#include "io.h"
/*
* _exit -- Exit from the application.
*/
void __attribute__ ((noreturn)) _exit (int code)
{
while (1)
__io_hosted (HOSTED_EXIT, (void *)code);
}
#endif

50
libgloss/nios2/io-fstat.c Normal file
View File

@ -0,0 +1,50 @@
/*
* io-fstat.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#define IO fstat
#include "io.h"
/*
* fstat -- get file information
* input parameters:
* 0 : file descriptor
* 1 : stat buf ptr
* output parameters:
* 0 : result
* 1 : errno
*/
int fstat (int fd, struct stat *buf)
{
#if HOSTED
gdb_parambuf_t parameters;
struct gdb_stat gbuf;
parameters[0] = (uint32_t) fd;
parameters[1] = (uint32_t) &gbuf;
__io_hosted (HOSTED_FSTAT, parameters);
__hosted_from_gdb_stat (&gbuf, buf);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

152
libgloss/nios2/io-gdb.c Normal file
View File

@ -0,0 +1,152 @@
/*
* hosted io support for GDB's remote fileio protocol
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include "io.h"
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
gdb_mode_t
__hosted_to_gdb_mode_t (mode_t m)
{
gdb_mode_t result = 0;
if (m & S_IFREG)
result |= GDB_S_IFREG;
if (m & S_IFDIR)
result |= GDB_S_IFDIR;
if (m & S_IRUSR)
result |= GDB_S_IRUSR;
if (m & S_IWUSR)
result |= GDB_S_IWUSR;
if (m & S_IXUSR)
result |= GDB_S_IXUSR;
if (m & S_IRGRP)
result |= GDB_S_IRGRP;
if (m & S_IWGRP)
result |= GDB_S_IWGRP;
if (m & S_IXGRP)
result |= GDB_S_IXGRP;
if (m & S_IROTH)
result |= GDB_S_IROTH;
if (m & S_IWOTH)
result |= GDB_S_IWOTH;
if (m & S_IXOTH)
result |= GDB_S_IXOTH;
return result;
}
int32_t
__hosted_to_gdb_open_flags (int f)
{
int32_t result = 0;
if (f & O_RDONLY)
result |= GDB_O_RDONLY;
if (f & O_WRONLY)
result |= GDB_O_WRONLY;
if (f & O_RDWR)
result |= GDB_O_RDWR;
if (f & O_APPEND)
result |= GDB_O_APPEND;
if (f & O_CREAT)
result |= GDB_O_CREAT;
if (f & O_TRUNC)
result |= GDB_O_TRUNC;
if (f & O_EXCL)
result |= GDB_O_EXCL;
return result;
}
int32_t
__hosted_to_gdb_lseek_flags (int f)
{
if (f == SEEK_CUR)
return GDB_SEEK_CUR;
else if (f == SEEK_END)
return GDB_SEEK_END;
else
return GDB_SEEK_SET;
}
/* The GDB remote protocol documentation specifies that integer fields
within structures are stored in big-endian byte order. On little-endian
targets, we have to byte-swap the values to match the target. */
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define SWAP32(n) __builtin_bswap32 (n)
#define SWAP64(n) __builtin_bswap64 (n)
#else
#define SWAP32(n) (n)
#define SWAP64(n) (n)
#endif /* __BYTE_ORDER__ */
void
__hosted_from_gdb_stat (const struct gdb_stat *gs,
struct stat *s)
{
s->st_dev = SWAP32 (gs->st_dev);
s->st_ino = SWAP32 (gs->st_ino);
s->st_mode = SWAP32 (gs->st_mode);
s->st_nlink = SWAP32 (gs->st_nlink);
s->st_uid = SWAP32 (gs->st_uid);
s->st_gid = SWAP32 (gs->st_gid);
s->st_rdev = SWAP32 (gs->st_rdev);
s->st_size = SWAP64 (gs->st_size);
s->st_blksize = SWAP64 (gs->st_blksize);
s->st_blocks = SWAP64 (gs->st_blocks);
s->st_atime = SWAP32 (gs->st_atime);
s->st_mtime = SWAP32 (gs->st_mtime);
s->st_ctime = SWAP32 (gs->st_ctime);
}
void
__hosted_from_gdb_timeval (const struct gdb_timeval *gt,
struct timeval *t)
{
t->tv_sec = SWAP32 (gt->tv_sec);
t->tv_usec = SWAP64 (gt->tv_usec);
}
int
__hosted_from_gdb_errno (int32_t err)
{
switch (err)
{
case 0: return 0;
case GDB_EPERM: return EPERM;
case GDB_ENOENT: return ENOENT;
case GDB_EINTR: return EINTR;
case GDB_EBADF: return EBADF;
case GDB_EACCES: return EACCES;
case GDB_EFAULT: return EFAULT;
case GDB_EBUSY: return EBUSY;
case GDB_EEXIST: return EEXIST;
case GDB_ENODEV: return ENODEV;
case GDB_ENOTDIR: return ENOTDIR;
case GDB_EISDIR: return EISDIR;
case GDB_EINVAL: return EINVAL;
case GDB_ENFILE: return ENFILE;
case GDB_EMFILE: return EMFILE;
case GDB_EFBIG: return EFBIG;
case GDB_ENOSPC: return ENOSPC;
case GDB_ESPIPE: return ESPIPE;
case GDB_EROFS: return EROFS;
case GDB_ENAMETOOLONG: return ENAMETOOLONG;
case GDB_EUNKNOWN:
default:
return EIO;
}
}

View File

@ -0,0 +1,54 @@
/*
* io-gettimeofday.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <sys/time.h>
#include <errno.h>
#define IO gettimeofday
#include "io.h"
/*
* gettimeofday -- get the current time
* input parameters:
* 0 : timeval ptr
* output parameters:
* 0 : result
* 1 : errno
*/
int gettimeofday (struct timeval *tv, void *tzvp)
{
#if HOSTED
gdb_parambuf_t parameters;
struct gdb_timeval gtv;
struct timezone *tz = tzvp;
if (!tv)
return 0;
if (tz)
{
errno = EINVAL;
return -1;
}
parameters[0] = (uint32_t) &gtv;
__io_hosted (HOSTED_GETTIMEOFDAY, parameters);
__hosted_from_gdb_timeval (&gtv, tv);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

View File

@ -0,0 +1,43 @@
/*
* io-isatty.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <unistd.h>
#include <errno.h>
#define IO isatty
#include "io.h"
/*
* isatty -- check if fd is a terminal
* input parameters:
* 0 : file descriptor
* output parameters:
* 0 : result
* 1 : errno
*/
int isatty (int fd)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) fd;
__io_hosted (HOSTED_ISATTY, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
return 1;
#endif
}

52
libgloss/nios2/io-lseek.c Normal file
View File

@ -0,0 +1,52 @@
/*
* io-lseek.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#define IO lseek
#include "io.h"
/*
* lseek -- reposition a file descriptor
* input parameters:
* 0 : file descriptor
* 1 : high word of offset
* 2 : low word of offset
* 3 : seek flag
* output parameters:
* 0 : high word of result
* 1 : low word of result
* 2 : errno
*/
off_t lseek (int fd, off_t offset, int whence)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) fd;
parameters[1] = (uint32_t) ((offset >> 32) & 0xffffffff);
parameters[2] = (uint32_t) (offset & 0xffffffff);
parameters[3] = __hosted_to_gdb_lseek_flags (whence);
__io_hosted (HOSTED_LSEEK, parameters);
errno = __hosted_from_gdb_errno (parameters[2]);
return ((uint64_t)parameters[0] << 32) | ((uint64_t)parameters[1]);
#else
errno = ENOSYS;
return -1;
#endif
}

31
libgloss/nios2/io-nios2.S Normal file
View File

@ -0,0 +1,31 @@
/*
* Low-level semihosting primitive for csky.
*
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
/* Implement
void __io_hosted (int func, void *args);
by causing a break 1. The break handler can find the two parameters in
r4 and r5 per the normal C calling convention. */
.text
.align 2
.global __io_hosted
.type _io_hosted, @function
__io_hosted:
break 1
ret
.size __io_hosted, .-__io_hosted

62
libgloss/nios2/io-open.c Normal file
View File

@ -0,0 +1,62 @@
/*
* io-open.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#define IO open
#include "io.h"
/*
* open -- Open a file.
* input parameters:
* 0 : fname ptr
* 1 : fname length
* 2 : flags
* 3 : mode
* output parameters:
* 0 : result
* 1 : errno
*/
int open (const char *fname, int flags, ...)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) fname;
parameters[1] = strlen (fname) + 1;
parameters[2] = __hosted_to_gdb_open_flags (flags);
if (flags & O_CREAT)
{
va_list ap;
va_start (ap, flags);
parameters[3] = __hosted_to_gdb_mode_t (va_arg (ap, mode_t));
va_end (ap);
}
else
parameters[3] = 0;
__io_hosted (HOSTED_OPEN, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

48
libgloss/nios2/io-read.c Normal file
View File

@ -0,0 +1,48 @@
/*
* io-read.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <unistd.h>
#include <errno.h>
#define IO read
#include "io.h"
/*
* read -- read from a file descriptor
* input parameters:
* 0 : file descriptor
* 1 : buf ptr
* 2 : count
* output parameters:
* 0 : result
* 1 : errno
*/
ssize_t read (int fd, void *buf, size_t count)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) fd;
parameters[1] = (uint32_t) buf;
parameters[2] = (uint32_t) count;
__io_hosted (HOSTED_READ, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

View File

@ -0,0 +1,51 @@
/*
* io-rename.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define IO rename
#include "io.h"
/*
* rename -- rename a file
* input parameters:
* 0 : oldname ptr
* 1 : oldname length
* 2 : newname ptr
* 3 : newname length
* output parameters:
* 0 : result
* 1 : errno
*/
int _rename (const char *oldpath, const char *newpath)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) oldpath;
parameters[1] = (uint32_t) strlen (oldpath) + 1;
parameters[2] = (uint32_t) newpath;
parameters[3] = (uint32_t) strlen (newpath) + 1;
__io_hosted (HOSTED_RENAME, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

54
libgloss/nios2/io-stat.c Normal file
View File

@ -0,0 +1,54 @@
/*
* io-stat.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#define IO stat
#include "io.h"
/*
* stat -- get file information
* input parameters:
* 0 : filename ptr
* 1 : filename length
* 2 : stat buf ptr
* output parameters:
* 0 : result
* 1 : errno
*/
int stat (const char *__restrict filename, struct stat *__restrict buf)
{
#if HOSTED
gdb_parambuf_t parameters;
struct gdb_stat gbuf;
parameters[0] = (uint32_t) filename;
parameters[1] = (uint32_t) strlen (filename) + 1;
parameters[2] = (uint32_t) &gbuf;
__io_hosted (HOSTED_STAT, parameters);
__hosted_from_gdb_stat (&gbuf, buf);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

View File

@ -0,0 +1,64 @@
/*
* io-system.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/wait.h>
#define IO _system
#include "io.h"
/*
* system: execute command on (remote) host
* input parameters:
* 0 : command ptr
* 1 : command length
* output parameters:
* 0 : result
* 1 : errno
*/
int _system (const char *command)
{
#if HOSTED
int e;
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) command;
parameters[1] = command ? (uint32_t) strlen (command) + 1 : 0;
__io_hosted (HOSTED_SYSTEM, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
e = parameters[0];
if (e >= 0 && command)
{
/* We have to convert e, an exit status to the encoded status of
the command. To avoid hard coding the exit status, we simply
loop until we find the right position. */
int exit_code;
for (exit_code = e; e && WEXITSTATUS (e) != exit_code; e <<= 1)
continue;
}
return e;
#else
if (!command)
return 0;
errno = ENOSYS;
return -1;
#endif
}

46
libgloss/nios2/io-time.c Normal file
View File

@ -0,0 +1,46 @@
/*
* io-time.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <sys/time.h>
#include <errno.h>
#define IO time
#include "io.h"
/*
* time -- get the current time
* input parameters:
* 0 : timeval ptr
* output parameters:
* 0 : result
* 1 : errno
*/
time_t time (time_t *t)
{
#if HOSTED
struct timeval tv;
if (gettimeofday (&tv, NULL))
return -1;
if (t)
*t = tv.tv_sec;
return tv.tv_sec;
#else
errno = ENOSYS;
return -1;
#endif
}

View File

@ -0,0 +1,47 @@
/*
* io-unlink.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define IO unlink
#include "io.h"
/*
* unlink -- unlink (delete) a file
* input parameters:
* 0 : filename ptr
* 1 : filename length
* output parameters:
* 0 : result
* 1 : errno
*/
int unlink (const char *path)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) path;
parameters[1] = (uint32_t) strlen (path) + 1;
__io_hosted (HOSTED_UNLINK, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

48
libgloss/nios2/io-write.c Normal file
View File

@ -0,0 +1,48 @@
/*
* io-write.c --
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <unistd.h>
#include <errno.h>
#define IO write
#include "io.h"
/*
* write -- write to a file descriptor
* input parameters:
* 0 : file descriptor
* 1 : buf ptr
* 2 : count
* output parameters:
* 0 : result
* 1 : errno
*/
ssize_t write (int fd, const void *buf, size_t count)
{
#if HOSTED
gdb_parambuf_t parameters;
parameters[0] = (uint32_t) fd;
parameters[1] = (uint32_t) buf;
parameters[2] = (uint32_t) count;
__io_hosted (HOSTED_WRITE, parameters);
errno = __hosted_from_gdb_errno (parameters[1]);
return parameters[0];
#else
errno = ENOSYS;
return -1;
#endif
}

154
libgloss/nios2/io.h Normal file
View File

@ -0,0 +1,154 @@
/*
* hosted & unhosted io support.
*
* Copyright (c) 2006 CodeSourcery Inc
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#if HOSTED
#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#define HOSTED_EXIT 0
#define HOSTED_INIT_SIM 1
#define HOSTED_OPEN 2
#define HOSTED_CLOSE 3
#define HOSTED_READ 4
#define HOSTED_WRITE 5
#define HOSTED_LSEEK 6
#define HOSTED_RENAME 7
#define HOSTED_UNLINK 8
#define HOSTED_STAT 9
#define HOSTED_FSTAT 10
#define HOSTED_GETTIMEOFDAY 11
#define HOSTED_ISATTY 12
#define HOSTED_SYSTEM 13
/* This function is provided by the board's BSP, because the precise
mechanism of informing gdb is board specific. */
extern void __io_hosted (int func, void *args);
/* Protocol specific representation of datatypes, as specified in D.9.11
* of the GDB manual. The values here are stored in big-endian order. */
typedef uint32_t gdb_mode_t;
typedef uint32_t gdb_time_t;
struct gdb_stat {
uint32_t st_dev; /* device */
uint32_t st_ino; /* inode */
gdb_mode_t st_mode; /* protection */
uint32_t st_nlink; /* number of hard links */
uint32_t st_uid; /* user ID of owner */
uint32_t st_gid; /* group ID of owner */
uint32_t st_rdev; /* device type (if inode device) */
uint64_t st_size; /* total size, in bytes */
uint64_t st_blksize; /* blocksize for filesystem I/O */
uint64_t st_blocks; /* number of blocks allocated */
gdb_time_t st_atime; /* time of last access */
gdb_time_t st_mtime; /* time of last modification */
gdb_time_t st_ctime; /* time of last change */
};
struct gdb_timeval {
gdb_time_t tv_sec; /* second */
uint64_t tv_usec; /* microsecond */
};
/* Parameters are passed between the library and the debugging stub
* in a fixed-size buffer.
*/
typedef uint32_t gdb_parambuf_t[4];
/* open flags */
#define GDB_O_RDONLY 0x0
#define GDB_O_WRONLY 0x1
#define GDB_O_RDWR 0x2
#define GDB_O_APPEND 0x8
#define GDB_O_CREAT 0x200
#define GDB_O_TRUNC 0x400
#define GDB_O_EXCL 0x800
/* mode_t values */
#define GDB_S_IFREG 0100000
#define GDB_S_IFDIR 040000
#define GDB_S_IRUSR 0400
#define GDB_S_IWUSR 0200
#define GDB_S_IXUSR 0100
#define GDB_S_IRGRP 040
#define GDB_S_IWGRP 020
#define GDB_S_IXGRP 010
#define GDB_S_IROTH 04
#define GDB_S_IWOTH 02
#define GDB_S_IXOTH 01
/* errno values */
#define GDB_EPERM 1
#define GDB_ENOENT 2
#define GDB_EINTR 4
#define GDB_EBADF 9
#define GDB_EACCES 13
#define GDB_EFAULT 14
#define GDB_EBUSY 16
#define GDB_EEXIST 17
#define GDB_ENODEV 19
#define GDB_ENOTDIR 20
#define GDB_EISDIR 21
#define GDB_EINVAL 22
#define GDB_ENFILE 23
#define GDB_EMFILE 24
#define GDB_EFBIG 27
#define GDB_ENOSPC 28
#define GDB_ESPIPE 29
#define GDB_EROFS 30
#define GDB_ENAMETOOLONG 91
#define GDB_EUNKNOWN 9999
/* lseek flags */
#define GDB_SEEK_SET 0
#define GDB_SEEK_CUR 1
#define GDB_SEEK_END 2
/* conversion functions */
extern gdb_mode_t __hosted_to_gdb_mode_t (mode_t m);
extern int32_t __hosted_to_gdb_open_flags (int f);
extern int32_t __hosted_to_gdb_lseek_flags (int f);
extern void __hosted_from_gdb_stat (const struct gdb_stat *gs,
struct stat *s);
extern void __hosted_from_gdb_timeval (const struct gdb_timeval *gt,
struct timeval *t);
extern int __hosted_from_gdb_errno (int32_t err);
#else
#ifdef IO
#define IO_NAME_(IO) __hosted_##IO
#define IO_NAME(IO) IO_NAME_(IO)
#define IO_STRING_(IO) #IO
#define IO_STRING(IO) IO_STRING_(IO)
/* Emit an object that causes a gnu linker warning. */
static const char IO_NAME (IO) []
__attribute__ ((section (".gnu.warning"), used)) =
"IO function '" IO_STRING (IO) "' used";
#endif
#endif

27
libgloss/nios2/kill.c Normal file
View File

@ -0,0 +1,27 @@
/*
* kill.c
*
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
/* Minimal implementation of kill for a target system without processes. */
extern void _exit (int);
int
kill (int pid, int sig)
{
if (pid == 1)
_exit (sig);
return 0;
}

View File

@ -0,0 +1,210 @@
/* qemu-hosted.ld -- Linker script for QEMU generic-nommu board emulation.
Copyright (c) 2018 Mentor Graphics
The authors hereby grant permission to use, copy, modify, distribute,
and license this software and its documentation for any purpose, provided
that existing copyright notices are retained in all copies and that this
notice is included verbatim in any distributions. No written agreement,
license, or royalty fee is required for any of the authorized uses.
Modifications to this software may be copyrighted by their authors
and need not follow the licensing terms described here, provided that
the new terms are clearly indicated on the first page of each file where
they apply.
Parts of this file were derived from code written by Altera Corporation
and distributed under the following license:
Copyright (c) 2008
Altera Corporation, San Jose, California, USA.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
This agreement shall be governed in all respects by the laws of the State
of California and by the laws of the United States of America.
*/
ENTRY(__start)
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnios2)
MEMORY
{
rom (rx) : ORIGIN = 0x0, LENGTH = 64M
ram (rwx) : ORIGIN = 0x10000000, LENGTH = 128M
tlbmiss (rwx) : ORIGIN = 0x7fff400, LENGTH = 1K
descriptor (rwx) : ORIGIN = 0x8002000, LENGTH = 8K
}
/* Force the linker to search for these symbols from
the start of the link process. */
EXTERN(__reset)
EXTERN(__start)
EXTERN(main __stack __heap_start __heap_end __heap_end)
/* Where to put the stack and heap. Allocate 1M heap space. */
PROVIDE(__heap_start = _end);
PROVIDE(__heap_end = _end + 100000);
PROVIDE(__stack = 0x18000000);
/* Force exit to be picked up in a hosted environment. */
EXTERN(exit atexit)
/* Ensure that newlib runs the finalizers. */
__libc_fini = _fini;
SECTIONS
{
.text :
{
_ftext = .;
*(.text.entry)
*(.text.start)
*(.text .text.* .gnu.linkonce.t.*)
. = ALIGN(0x4);
KEEP (*crtbegin.o(.jcr))
KEEP (*(EXCLUDE_FILE (*crtend.o) .jcr))
KEEP (*crtend.o(.jcr))
. = ALIGN(0x4);
*(.gcc_except_table .gcc_except_table.*)
*(.gnu_extab .gnu_extab.*)
} > ram
.eh_frame_hdr : ALIGN (4)
{
KEEP (*(.eh_frame_hdr))
*(.eh_frame_entry .eh_frame_entry.*)
} > ram
.eh_frame : ALIGN (4)
{
KEEP (*(.eh_frame)) *(.eh_frame.*)
} > ram
.note.gnu.build-id : ALIGN (4)
{
KEEP (*(.note.gnu.build-id))
} > ram
.rodata : ALIGN (4)
{
*(.rodata .rodata.* .gnu.linkonce.r.*)
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
. = ALIGN(0x4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
. = ALIGN(0x4);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
*(.lit)
. = ALIGN (8);
_etext = .;
} > ram
.data : ALIGN (8)
{
*(.shdata)
*(.data .data.* .gnu.linkonce.d.*)
. = ALIGN(8);
_gp = ABSOLUTE(. + 0x8000);
*(.got.plt) *(.got)
*(.lit8)
*(.lit4)
*(.sdata .sdata.* .gnu.linkonce.s.*)
. = ALIGN (8);
*(.ram)
. = ALIGN (8);
_edata = .;
} > ram
.bss : ALIGN (8)
{
__bss_start = ABSOLUTE(.);
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN (8);
__bss_end = ABSOLUTE(.);
_end = .;
__end = .;
} > ram
.stab 0 (NOLOAD) : { *(.stab) }
.stabstr 0 (NOLOAD) : { *(.stabstr) }
/* DWARF debug sections.
* Symbols in the DWARF debugging sections are relative to
* the beginning of the section so we begin them at 0.
*/
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* DWARF 2.1 */
.debug_ranges 0 : { *(.debug_ranges) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
.debug_alt_sim_info 0 : { *(.debug_alt_sim_info) }
}

42
libgloss/nios2/sbrk.c Normal file
View File

@ -0,0 +1,42 @@
/*
* sbrk.c
*
* Copyright (c) 2018 Mentor Graphics
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <errno.h>
/*
* sbrk -- changes heap size size. Get nbytes more
* RAM. We just increment a pointer in what's
* left of memory on the board.
*/
/* Provided by the linker script. */
extern char __heap_start[] __attribute__ ((aligned (8)));
extern char __heap_end[] __attribute__ ((aligned (8)));
void *
sbrk (int nbytes)
{
static char *heap = __heap_start;
char *base = heap;
char *new_heap = heap + nbytes;
if (nbytes < 0 || new_heap > __heap_end)
{
errno = ENOMEM;
return (void *)-1;
}
heap = new_heap;
return base;
}