This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

TI C6X port of newlib


This patch (diffs to and additions of generated files omitted) adds a port 
of newlib to TI C6X processors.  The binutils port is upstream; the GCC 
port isn't yet, but given various other existing newlib ports I don't 
think GCC needs to go upstream before newlib.  OK to commit?

New functions are variously taken from other targets, written specifically 
for C6X or taken from TI's BSD-licensed runtime library sources.  More 
functions from TI's sources may well be added in future; this is presently 
a fairly minimal newlib port that is sufficient for running compiler 
tests.

2010-10-01  Bernd Schmidt  <bernds@codesourcery.com>
            Joseph Myers  <joseph@codesourcery.com>

	* COPYING.LIBGLOSS: Add CodeSourcery notice.
	* COPYING.NEWLIB: Add Texas Instruments notice.

libgloss:
2010-10-01  Bernd Schmidt  <bernds@codesourcery.com>
            Joseph Myers  <joseph@codesourcery.com>

	* configure.in: Handle tic6x targets.
	* configure: Regenerate.
	* tic6x/Makefile.in, tic6x/configure.in, tic6x/crt0.S,
	tic6x/getpid.c, tic6x/kill.c, tic6x/sbrk.c, tic6x/syscalls.c: New.
	* tic6x/configure: New (generated).

newlib:
2010-10-01  Bernd Schmidt  <bernds@codesourcery.com>
            Joseph Myers  <joseph@codesourcery.com>

	* configure.host: Handle tic6x targets.
	* libc/include/machine/ieeefp.h: Define endianness for C6X.
	* libc/include/machine/setjmp.h: Add __TMS320C6X__ case.
	* libc/machine/configure.in: Handle tic6x targets.
	* libc/machine/configure: Regenerate.
	* libc/machine/tic6x/Makefile.am, libc/machine/tic6x/configure.in,
	libc/machine/tic6x/setjmp.S: New.
	* libc/machine/tic6x/Makefile.in, libc/machine/tic6x/aclocal.m4,
	libc/machine/tic6x/configure: New (generated).

diff -ruN newlib.orig/COPYING.LIBGLOSS newlib-c6x/COPYING.LIBGLOSS
--- newlib.orig/COPYING.LIBGLOSS	2009-12-17 13:12:49.000000000 -0800
+++ newlib-c6x/COPYING.LIBGLOSS	2010-10-01 15:59:51.000000000 -0700
@@ -260,3 +260,30 @@
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+
+(14) - CodeSourcery, Inc. (tic6x-* targets)
+
+Copyright (c) 2010 CodeSourcery, 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:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * 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.
+    * Neither the name of CodeSourcery 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 CODESOURCERY, INC. ``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 CODESOURCERY 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.
diff -ruN newlib.orig/COPYING.NEWLIB newlib-c6x/COPYING.NEWLIB
--- newlib.orig/COPYING.NEWLIB	2009-12-17 13:12:49.000000000 -0800
+++ newlib-c6x/COPYING.NEWLIB	2010-10-01 16:00:04.000000000 -0700
@@ -828,3 +828,37 @@
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+
+(37) Texas Instruments Incorporated (tic6x-* targets)
+
+Copyright (c) 1996-2010 Texas Instruments Incorporated
+http://www.ti.com/
+
+ Redistribution and  use in source  and binary forms, with  or without
+ modification,  are permitted provided  that the  following conditions
+ are met:
+
+    Redistributions  of source  code must  retain the  above copyright
+    notice, this list of conditions and the following disclaimer.
+
+    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.
+
+    Neither the  name of Texas Instruments Incorporated  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
+ OWNER 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.
diff -ruN newlib.orig/libgloss/configure.in newlib-c6x/libgloss/configure.in
--- newlib.orig/libgloss/configure.in	2010-07-23 10:52:36.000000000 -0700
+++ newlib-c6x/libgloss/configure.in	2010-10-01 15:47:12.000000000 -0700
@@ -129,6 +129,10 @@
 	config_testsuite=false
 	config_libnosys=false
 	;;
+  tic6x-*-*)
+	AC_CONFIG_SUBDIRS(tic6x)
+	config_testsuite=false
+	;;
   iq2000-*-*)
 	AC_CONFIG_SUBDIRS([iq2000])
 	;;
diff -ruN newlib.orig/libgloss/tic6x/Makefile.in newlib-c6x/libgloss/tic6x/Makefile.in
--- newlib.orig/libgloss/tic6x/Makefile.in	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/libgloss/tic6x/Makefile.in	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,126 @@
+#
+#
+
+DESTDIR =
+VPATH = @srcdir@ @srcdir@/..
+srcdir = @srcdir@
+objdir = .
+srcroot = $(srcdir)/../..
+objroot = $(objdir)/../..
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+host_alias = @host_alias@
+target_alias = @target_alias@
+
+bindir = @bindir@
+libdir = @libdir@
+tooldir = $(exec_prefix)/$(target_alias)
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+
+# Multilib support variables.
+# TOP is used instead of MULTI{BUILD,SRC}TOP.
+MULTIDIRS =
+MULTISUBDIR =
+
+SHELL =	/bin/sh
+
+CC = @CC@
+
+AS = @AS@
+AR = @AR@
+LD = @LD@
+RANLIB = @RANLIB@
+
+OBJDUMP = `if [ -f ${objroot}/../binutils/objdump ] ; \
+	then echo ${objroot}/../binutils/objdump ; \
+	else t='$(program_transform_name)'; echo objdump | sed -e $$t ; fi`
+OBJCOPY = `if [ -f ${objroot}/../binutils/objcopy ] ; \
+	then echo ${objroot}/../binutils/objcopy ; \
+	else t='$(program_transform_name)'; echo objcopy | sed -e $$t ; fi`
+
+CFLAGS		= -g
+SCRIPTS		=
+
+# Here is all of the simulator stuff
+SIM_SCRIPTS	=
+SIM_LDFLAGS	=
+SIM_BSP		= libsim.a
+SIM_CRT0	= crt0.o
+SIM_OBJS	= sbrk.o putnum.o getpid.o kill.o syscalls.o
+SIM_TEST	= sim-test
+SIM_INSTALL	= install-sim
+
+# Host specific makefile fragment comes in here.
+@host_makefile_frag@
+
+#
+# build a test program for each target board. Just trying to get
+# it to link is a good test, so we ignore all the errors for now.
+#
+all: ${SIM_CRT0} ${SIM_BSP}
+
+#
+# here's where we build the board support packages for each target
+#
+${SIM_BSP}: ${OBJS} ${SIM_OBJS}
+	${AR} ${ARFLAGS} ${SIM_BSP} ${SIM_OBJS} ${OBJS}
+	${RANLIB} ${SIM_BSP}
+
+
+#
+# here's where we build the test programs for each target
+#
+.PHONY: test
+test:	${SIM_TEST}
+
+sim-test:	sim-test.x sim-test.dis
+
+sim-test.x:	test.o ${SIM_CRT0} ${SIM_BSP}
+	${CC} ${LDFLAGS_FOR_TARGET} -L${objdir} \
+	${SIM_CRT0} test.o \
+	-o sim-test.x ${LIBS_FOR_TARGET} -lc ${SIM_BSP}
+
+sim-test.dis:	sim-test.x
+	${OBJDUMP} -d sim-test.x > sim-test.dis
+
+
+#
+#
+#
+.c.S:
+	${CC} ${CFLAGS_FOR_TARGET} -c $<
+
+clean mostlyclean:
+	rm -f a.out core *.i *.o *-test *.srec *.dis *.x $(SIM_BSP)
+
+distclean maintainer-clean realclean: clean
+	rm -f Makefile config.status *~
+
+.PHONY: install info install-info clean-info
+install: ${SIM_INSTALL}
+
+install-sim:
+	set -e;\
+	for x in ${SIM_CRT0} ${SIM_BSP}; do\
+	 ${INSTALL_DATA} $$x $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x;\
+	done
+	for x in ${SIM_SCRIPTS}; do\
+	 ${INSTALL_DATA} ${srcdir}/$${x} $(DESTDIR)${tooldir}/lib${MULTISUBDIR}/$$x; \
+	done
+
+
+doc:
+info:
+install-info:
+clean-info:
+
+Makefile: Makefile.in config.status @host_makefile_frag_path@
+	$(SHELL) config.status
+
+config.status: configure
+	$(SHELL) config.status --recheck
diff -ruN newlib.orig/libgloss/tic6x/configure.in newlib-c6x/libgloss/tic6x/configure.in
--- newlib.orig/libgloss/tic6x/configure.in	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/libgloss/tic6x/configure.in	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,54 @@
+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
diff -ruN newlib.orig/libgloss/tic6x/crt0.S newlib-c6x/libgloss/tic6x/crt0.S
--- newlib.orig/libgloss/tic6x/crt0.S	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/libgloss/tic6x/crt0.S	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,38 @@
+/*
+ * crt0.S for the TI C6X series of processors
+ */
+
+	.text
+	.align 	2
+
+	.global	_start
+_start:
+	/* Start by setting up a stack */
+	mvkl .s2	_STACK_START - 4, B15
+	mvkh .s2	_STACK_START - 4, B15
+	and .s2		-8, B15, B15
+
+	mvkl .s2	__c6xabi_DSBT_BASE, B14
+	mvkh .s2	__c6xabi_DSBT_BASE, B14
+
+#ifdef __DSBT__
+	stw .d2t2	B14, *B14
+#endif
+	/* Zero the memory in the .bss section.  */
+
+	/* Set up GOT pointer.  */
+
+	mvkl .s2	1f, B3
+	mvkh .s2	1f, B3
+	call .s2	_init
+	nop		5
+1:
+
+	mvkl .s2	1f, B3
+	mvkh .s2	1f, B3
+	call .s2	main
+	nop		5
+1:
+
+	b .s2		exit
+	nop		5
diff -ruN newlib.orig/libgloss/tic6x/getpid.c newlib-c6x/libgloss/tic6x/getpid.c
--- newlib.orig/libgloss/tic6x/getpid.c	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/libgloss/tic6x/getpid.c	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,26 @@
+/* getpid.c -- get the current process id.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * 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 <_ansi.h>
+#define __MYPID 1
+
+/*
+ * getpid -- only one process, so just return 1.
+ */
+int
+_DEFUN (getpid, (),
+        )
+{
+  return __MYPID;
+}
diff -ruN newlib.orig/libgloss/tic6x/kill.c newlib-c6x/libgloss/tic6x/kill.c
--- newlib.orig/libgloss/tic6x/kill.c	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/libgloss/tic6x/kill.c	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,29 @@
+/* kill.c -- remove a process.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * 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 <_ansi.h>
+#define __MYPID 1
+
+/*
+ * kill -- go out via exit...
+ */
+int
+_DEFUN (kill, (pid, sig),
+        int pid _AND 
+        int sig)
+{
+  if(pid == __MYPID)
+    _exit(sig);
+  return 0;
+}
diff -ruN newlib.orig/libgloss/tic6x/sbrk.c newlib-c6x/libgloss/tic6x/sbrk.c
--- newlib.orig/libgloss/tic6x/sbrk.c	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/libgloss/tic6x/sbrk.c	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,59 @@
+/* sbrk.c -- Implementation of the low-level sbrk() routine
+ *
+ * Copyright (c) 2004 National Semiconductor Corporation
+ *
+ * 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>
+#include <stddef.h> /* where ptrdiff_t is defined */
+#include <stdlib.h>
+
+/* Start of the heap.  */
+extern const char _HEAP_START __attribute__((section(".heap")));
+/* End of the heap (maximum value of heap_ptr).  */
+extern const char _HEAP_MAX __attribute__((section(".heap")));
+
+/* Extend heap space by size bytes.
+   Return start of new space allocated, or -1 for errors 
+   Error cases:
+    1. Allocation is not within heap range */
+
+void * sbrk (ptrdiff_t size)
+{
+  /*
+  * The following two memory locations should be defined in the linker script file
+  */
+
+  static const char * heap_ptr;  /* pointer to head of heap */
+  const char * old_heap_ptr;
+  static unsigned char init_sbrk = 0;
+
+  /* heap_ptr is initialized to HEAP_START */
+  if (init_sbrk == 0) 
+  {
+    heap_ptr = &_HEAP_START;
+    init_sbrk = 1;
+  }
+
+  old_heap_ptr = heap_ptr;
+
+  if ((heap_ptr + size) > &_HEAP_MAX)
+  { 
+    /* top of heap is bigger than _HEAP_MAX */
+    errno = ENOMEM;
+    return (void *) -1;
+  }
+
+  /* success: update heap_ptr and return previous value */
+  heap_ptr += size;
+  return (void *)old_heap_ptr;
+}
diff -ruN newlib.orig/libgloss/tic6x/syscalls.c newlib-c6x/libgloss/tic6x/syscalls.c
--- newlib.orig/libgloss/tic6x/syscalls.c	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/libgloss/tic6x/syscalls.c	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,361 @@
+/* Copyright (c) 2010 CodeSourcery, 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:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * 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.
+    * Neither the name of CodeSourcery 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 CODESOURCERY, INC. ``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 CODESOURCERY 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 <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#define _DTOPEN 0xf0
+#define _DTCLOSE 0xf1
+#define _DTREAD 0xf2
+#define _DTWRITE 0xf3
+#define _DTLSEEK 0xf4
+#define _DTUNLINK 0xf5
+#define _DTGETENV 0xf6
+#define _DTRENAME 0xf7
+#define _DTGETTIME 0xf8
+#define _DTGETCLK 0xf9
+#define _DTSYNC 0xff
+
+#define CIOBUFSIZ (BUFSIZ + 32)
+
+struct __attribute__((packed)) cio_open_to_host
+{
+  /* Suggested file descriptor (little endian).  */
+  short fd;
+  /* Flags (little endian).  */
+  short flags;
+};
+
+struct __attribute__((packed)) cio_open_from_host
+{
+  /* File descriptor (little endian).  */
+  short fd;
+};
+
+struct __attribute__((packed)) cio_close_to_host
+{
+  /* File descriptor (little endian).  */
+  short fd;
+};
+
+struct __attribute__((packed)) cio_close_from_host
+{
+  /* Result (little endian).  */
+  short result;
+};
+
+struct __attribute__((packed)) cio_read_to_host
+{
+  /* File descriptor (little endian).  */
+  short fd;
+  /* Length (little endian).  */
+  short length;
+};
+
+struct __attribute__((packed)) cio_read_from_host
+{
+  /* Result (little endian).  */
+  short result;
+};
+
+struct __attribute__((packed)) cio_write_to_host
+{
+  /* File descriptor (little endian).  */
+  short fd;
+  /* Length (little endian).  */
+  short length;
+};
+
+struct __attribute__((packed)) cio_write_from_host
+{
+  /* Result (little endian).  */
+  short result;
+};
+
+struct __attribute__((packed)) cio_lseek_to_host
+{
+  /* File descriptor (little endian).  */
+  short fd;
+  /* Offset (little endian).  */
+  int offset;
+  /* Whence (little endian).  */
+  short whence;
+};
+
+struct __attribute__((packed)) cio_lseek_from_host
+{
+  /* Result (little endian).  */
+  int result;
+};
+
+struct __attribute__((packed)) cio_unlink_to_host
+{
+  /* Empty.  */
+};
+
+struct __attribute__((packed)) cio_unlink_from_host
+{
+  /* Result (little endian).  */
+  short result;
+};
+
+struct __attribute__((packed)) cio_rename_to_host
+{
+  /* Empty.  */
+};
+
+struct __attribute__((packed)) cio_rename_from_host
+{
+  /* Result (little endian).  */
+  short result;
+};
+
+struct __attribute__((packed)) cio_gettime_to_host
+{
+  /* Empty.  */
+};
+
+struct __attribute__((packed)) cio_gettime_from_host
+{
+  /* Time (little endian).  */
+  int time;
+};
+
+struct __attribute__((packed)) cio_to_host
+{
+  /* Data length (target endian).  */
+  unsigned int length;
+  /* Command.  */
+  unsigned char command;
+  /* Parameters.  */
+  union
+  {
+    unsigned char buf[8];
+    struct cio_open_to_host open;
+    struct cio_close_to_host close;
+    struct cio_read_to_host read;
+    struct cio_write_to_host write;
+    struct cio_lseek_to_host lseek;
+    struct cio_unlink_to_host unlink;
+    struct cio_rename_to_host rename;
+    struct cio_gettime_to_host gettime;
+  } parms;
+  /* Variable-length data.  */
+  unsigned char data[];
+};
+
+struct __attribute__((packed)) cio_from_host
+{
+  /* Length (target endian).  */
+  unsigned int length;
+  /* Parameters.  */
+  union
+  {
+    unsigned char buf[8];
+    struct cio_open_from_host open;
+    struct cio_close_from_host close;
+    struct cio_read_from_host read;
+    struct cio_write_from_host write;
+    struct cio_lseek_from_host lseek;
+    struct cio_unlink_from_host unlink;
+    struct cio_rename_from_host rename;
+    struct cio_gettime_from_host gettime;
+  } parms;
+  /* Data.  */
+  unsigned char data[];
+};
+
+union
+{
+  unsigned char buf[CIOBUFSIZ];
+  int align;
+  union
+  {
+    struct cio_to_host to_host;
+    struct cio_from_host from_host;
+  } u;
+} _CIOBUF_ __attribute__((section(".cio")));
+
+#ifdef _BIG_ENDIAN
+#define SWAPSHORT(s)	((short)((((s) & 0xff) << 8) | (((s) & 0xff00) >> 8)))
+#define SWAPINT(i)	(__builtin_bswap32 (i))
+#else
+#define SWAPSHORT(s)	(s)
+#define SWAPINT(i)	(i)
+#endif
+
+static void __attribute__((noinline))
+do_semi_call (void)
+{
+  asm volatile (".globl C$$IO$$\nnop\nC$$IO$$:nop" : "+m" (_CIOBUF_));
+}
+
+static inline void
+semi_call_wrapper (unsigned char command, const char *data,
+		   unsigned int length)
+{
+  _CIOBUF_.u.to_host.length = length;
+  _CIOBUF_.u.to_host.command = command;
+  if (data != NULL)
+    memcpy (_CIOBUF_.u.to_host.data, data, length);
+  do_semi_call ();
+}
+
+static inline void
+semi_call_wrapper2 (unsigned char command, const char *data1,
+		    unsigned int length1, const char *data2,
+		    unsigned int length2)
+{
+  _CIOBUF_.u.to_host.length = length1 + length2;
+  _CIOBUF_.u.to_host.command = command;
+  if (data1 != NULL)
+    memcpy (_CIOBUF_.u.to_host.data, data1, length1);
+  if (data2 != NULL)
+    memcpy (_CIOBUF_.u.to_host.data + length1, data2, length2);
+  do_semi_call ();
+}
+
+void
+_exit (int status)
+{
+  /* The semihosting interface appears to provide no way to return an
+     exit status.  */
+  asm volatile (".globl C$$EXIT\nnop\nC$$EXIT:nop");
+}
+
+int
+open (const char *path, int flags, ...)
+{
+  /* ??? It's not clear what the suggested fd is for.  */
+  static short suggest_fd = 3;
+  short ret_fd;
+  ++suggest_fd;
+  _CIOBUF_.u.to_host.parms.open.fd = SWAPSHORT (suggest_fd);
+  _CIOBUF_.u.to_host.parms.open.flags = SWAPSHORT (flags);
+  semi_call_wrapper (_DTOPEN, path, strlen (path) + 1);
+  ret_fd = SWAPSHORT (_CIOBUF_.u.from_host.parms.open.fd);
+  if (ret_fd == -1)
+    return -1;
+  return suggest_fd;
+}
+
+int
+close (int fd)
+{
+  _CIOBUF_.u.to_host.parms.close.fd = SWAPSHORT (fd);
+  semi_call_wrapper (_DTCLOSE, NULL, 0);
+  return SWAPSHORT (_CIOBUF_.u.from_host.parms.close.result);
+}
+
+int
+read (int fd, char *ptr, int len)
+{
+  if (len > BUFSIZ)
+    len = BUFSIZ;
+  _CIOBUF_.u.to_host.parms.read.fd = SWAPSHORT (fd);
+  _CIOBUF_.u.to_host.parms.read.length = SWAPSHORT (len);
+  semi_call_wrapper (_DTREAD, NULL, 0);
+  memcpy (ptr, _CIOBUF_.u.from_host.data, _CIOBUF_.u.from_host.length);
+  return SWAPSHORT (_CIOBUF_.u.from_host.parms.read.result);
+}
+
+int
+write (int fd, char *ptr, int len)
+{
+  if (len > BUFSIZ)
+    len = BUFSIZ;
+  _CIOBUF_.u.to_host.parms.write.fd = SWAPSHORT (fd);
+  _CIOBUF_.u.to_host.parms.write.length = SWAPSHORT (len);
+  semi_call_wrapper (_DTWRITE, ptr, len);
+  return SWAPSHORT (_CIOBUF_.u.from_host.parms.write.result);
+}
+
+int
+lseek (int fd, int offset, int whence)
+{
+  _CIOBUF_.u.to_host.parms.lseek.fd = SWAPSHORT (fd);
+  _CIOBUF_.u.to_host.parms.lseek.offset = SWAPINT (offset);
+  _CIOBUF_.u.to_host.parms.lseek.whence = SWAPSHORT (whence);
+  semi_call_wrapper (_DTLSEEK, NULL, 0);
+  return SWAPINT (_CIOBUF_.u.from_host.parms.lseek.result);
+}
+
+int
+unlink (const char *path)
+{
+  semi_call_wrapper (_DTUNLINK, path, strlen (path) + 1);
+  return SWAPSHORT (_CIOBUF_.u.from_host.parms.unlink.result);
+}
+
+int
+rename (const char *oldpath, const char *newpath)
+{
+  semi_call_wrapper2 (_DTRENAME, oldpath, strlen (oldpath) + 1,
+		      newpath, strlen (newpath) + 1);
+  return SWAPSHORT (_CIOBUF_.u.from_host.parms.rename.result);
+}
+
+int
+gettimeofday (struct timeval *tp, void *tzvp)
+{
+  struct timezone *tzp = tzvp;
+
+  if (tp)
+    {
+      semi_call_wrapper (_DTGETTIME, NULL, 0);
+      tp->tv_sec = SWAPINT (_CIOBUF_.u.from_host.parms.gettime.time);
+      tp->tv_usec = 0;
+    }
+
+  if (tzp)
+    {
+      tzp->tz_minuteswest = 0;
+      tzp->tz_dsttime = 0;
+    }
+
+  return 0;
+}
+
+int
+isatty (int file __attribute__((unused)))
+{
+  errno = ENOSYS;
+  return 0;
+}
+
+int
+fstat (int fd, struct stat *buf)
+{
+  buf->st_mode = S_IFCHR;	/* Always pretend to be a tty */
+  buf->st_blksize = 0;
+
+  return (0);
+}
diff -ruN newlib.orig/newlib/configure.host newlib-c6x/newlib/configure.host
--- newlib.orig/newlib/configure.host	2010-07-23 11:11:26.000000000 -0700
+++ newlib-c6x/newlib/configure.host	2010-10-01 15:47:12.000000000 -0700
@@ -249,6 +249,9 @@
   tic4x|c4x)
 	machine_dir=tic4x
 	;;
+  tic6x)
+	machine_dir=tic6x
+	;;
   tic80*)
 	machine_dir=tic80
 	;;
@@ -496,6 +499,10 @@
 	  have_crt0="no"
 	fi
 	;;
+  tic6x*)
+	newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
+	have_crt0="no"
+	;;
   tic80*)
 	sys_dir=tic80
 	;;
@@ -762,6 +769,9 @@
 	  newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR"
 	fi
 	;;
+  tic6x*)
+	syscall_dir=
+	;;
   tic80*)
 	syscall_dir=syscalls
 	;;
diff -ruN newlib.orig/newlib/libc/include/machine/ieeefp.h newlib-c6x/newlib/libc/include/machine/ieeefp.h
--- newlib.orig/newlib/libc/include/machine/ieeefp.h	2010-06-18 09:26:25.000000000 -0700
+++ newlib-c6x/newlib/libc/include/machine/ieeefp.h	2010-10-01 15:47:12.000000000 -0700
@@ -166,6 +166,14 @@
 #define _DOUBLE_IS_32BITS
 #endif
 
+#ifdef __TMS320C6X__
+#ifdef _BIG_ENDIAN
+#define __IEEE_BIG_ENDIAN
+#else
+#define __IEEE_LITTLE_ENDIAN
+#endif
+#endif
+
 #ifdef __TIC80__
 #define __IEEE_LITTLE_ENDIAN
 #endif
diff -ruN newlib.orig/newlib/libc/include/machine/setjmp.h newlib-c6x/newlib/libc/include/machine/setjmp.h
--- newlib.orig/newlib/libc/include/machine/setjmp.h	2009-12-17 11:24:22.000000000 -0800
+++ newlib-c6x/newlib/libc/include/machine/setjmp.h	2010-10-01 15:47:12.000000000 -0700
@@ -174,6 +174,10 @@
 #define _JBLEN 9
 #endif
 
+#ifdef __TMS320C6X__
+#define _JBLEN 13
+#endif
+
 #ifdef __TIC80__
 #define _JBLEN 13
 #endif
diff -ruN newlib.orig/newlib/libc/machine/configure.in newlib-c6x/newlib/libc/machine/configure.in
--- newlib.orig/newlib/libc/machine/configure.in	2010-02-24 12:59:48.000000000 -0800
+++ newlib-c6x/newlib/libc/machine/configure.in	2010-10-01 15:47:12.000000000 -0700
@@ -58,6 +58,7 @@
 	sparc) AC_CONFIG_SUBDIRS(sparc) ;;
 	spu) AC_CONFIG_SUBDIRS(spu) ;;
 	tic4x) AC_CONFIG_SUBDIRS(tic4x) ;;
+	tic6x) AC_CONFIG_SUBDIRS(tic6x) ;;
 	tic80) AC_CONFIG_SUBDIRS(tic80) ;;
 	v850) AC_CONFIG_SUBDIRS(v850) ;;
 	w65) AC_CONFIG_SUBDIRS(w65) ;;
diff -ruN newlib.orig/newlib/libc/machine/tic6x/Makefile.am newlib-c6x/newlib/libc/machine/tic6x/Makefile.am
--- newlib.orig/newlib/libc/machine/tic6x/Makefile.am	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/newlib/libc/machine/tic6x/Makefile.am	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,16 @@
+## Process this file with automake to generate Makefile.in
+
+AUTOMAKE_OPTIONS = cygnus
+
+INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
+
+AM_CCASFLAGS = $(INCLUDES)
+
+noinst_LIBRARIES = lib.a
+
+lib_a_SOURCES = setjmp.S
+lib_a_CCASFLAGS=$(AM_CCASFLAGS)
+lib_a_CFLAGS=$(AM_CFLAGS)
+
+ACLOCAL_AMFLAGS = -I ../../.. -I ../../../..
+CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
diff -ruN newlib.orig/newlib/libc/machine/tic6x/configure.in newlib-c6x/newlib/libc/machine/tic6x/configure.in
--- newlib.orig/newlib/libc/machine/tic6x/configure.in	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/newlib/libc/machine/tic6x/configure.in	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,14 @@
+dnl This is the newlib/libc/machine/tic6x configure.in file.
+dnl Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.59)
+AC_INIT([newlib],[NEWLIB_VERSION])
+AC_CONFIG_SRCDIR([setjmp.S])
+
+dnl Can't be done in NEWLIB_CONFIGURE because that confuses automake. 
+AC_CONFIG_AUX_DIR(../../../..)
+
+NEWLIB_CONFIGURE(../../..)
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff -ruN newlib.orig/newlib/libc/machine/tic6x/setjmp.S newlib-c6x/newlib/libc/machine/tic6x/setjmp.S
--- newlib.orig/newlib/libc/machine/tic6x/setjmp.S	1969-12-31 16:00:00.000000000 -0800
+++ newlib-c6x/newlib/libc/machine/tic6x/setjmp.S	2010-10-01 15:47:12.000000000 -0700
@@ -0,0 +1,96 @@
+;******************************************************************************
+;* SETJMP  v7.2.0I10181                                                       *
+;*                                                                            *
+;* Copyright (c) 1996-2010 Texas Instruments Incorporated                     *
+;* http://www.ti.com/                                                         *
+;*                                                                            *
+;*  Redistribution and  use in source  and binary forms, with  or without     *
+;*  modification,  are permitted provided  that the  following conditions     *
+;*  are met:                                                                  *
+;*                                                                            *
+;*     Redistributions  of source  code must  retain the  above copyright     *
+;*     notice, this list of conditions and the following disclaimer.          *
+;*                                                                            *
+;*     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.                                                          *
+;*                                                                            *
+;*     Neither the  name of Texas Instruments Incorporated  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     *
+;*  OWNER 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.      *
+;*                                                                            *
+;******************************************************************************
+
+.text
+.globl setjmp
+.type setjmp,%function
+setjmp:
+	MV .L2X    A4, B4
+||	STW .D1T2  B3, *+A4(48)
+
+	STW .D1T1  A10, *+A4(0)
+||	STW .D2T2  B10, *+B4(4)
+||	RET .S2    B3
+
+	STW .D1T1  A11, *+A4(8)
+||	STW .D2T2  B11, *+B4(12)
+
+	STW .D1T1  A12, *+A4(16)
+||	STW .D2T2  B12, *+B4(20)
+
+	STW .D1T1  A13, *+A4(24)
+||	STW .D2T2  B13, *+B4(28)
+
+	STW .D1T1  A14, *+A4(32)
+||	STW .D2T2  B14, *+B4(36)
+
+	STW .D1T1  A15, *+A4(40)
+||	STW .D2T2  B15, *+B4(44)
+||	ZERO .S1   A4
+.size setjmp, . - setjmp
+
+.globl longjmp
+.type longjmp,%function
+longjmp:
+	 LDW .D1T1  *+A4(48), A3
+
+	 MV .L2X    A4, B6
+||	 MV .S1     A4, A6
+||	 MV .D2     B4, B2
+
+	 LDW .D1T1  *+A6(0), A10
+||	 LDW .D2T2  *+B6(4), B10
+|| [B2]  MV .L1X    B4, A4
+|| [!B2] MVK .S1    1, A4
+
+	 LDW .D1T1  *+A6(8), A11
+||	 LDW .D2T2  *+B6(12), B11 
+
+	 LDW .D1T1  *+A6(16), A12
+||	 LDW .D2T2  *+B6(20), B12
+ 
+	 LDW .D1T1  *+A6(24), A13
+||	 LDW .D2T2  *+B6(28), B13
+ 
+	 LDW .D1T1  *+A6(32), A14
+||	 LDW .D2T2  *+B6(36), B14
+ 
+	 LDW .D1T1  *+A6(40), A15
+||	 LDW .D2T2  *+B6(44), B15
+||	 RET .S2X   A3
+	 NOP    5
+.size longjmp, . - longjmp

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]