Commit acdfcb0a authored by Anton Kolesov's avatar Anton Kolesov Committed by Corinna Vinschen

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.
parent e945a19c
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.
......
......@@ -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"
;;
......
......@@ -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"
;;
......
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
......
#
#
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
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
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
/*
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
/*
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;
}
This diff is collapsed.
/*
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;