new port: msp430

Jeff Johnston jjohnstn@redhat.com
Mon May 13 16:04:00 GMT 2013


On 05/08/2013 10:13 PM, DJ Delorie wrote:
> The attached patch and new files add support for the TI MSP430
> (msp430*-*-elf).  This is a pretty standard port, with minimal
> chip-variant-specific support (users typically have highly
> variant-specific runtimes).
>
> Proposed maintainers are nickc and myself.
>
> Ok?
>

Could you please change the licenses to match the Red Hat license form 
in COPYING.NEWLIB and COPYING.LIBGLOSS?  When that is done, feel free to 
check in and to modify the MAINTAINERS file.

-- Jeff J.

> [newlib]
>
> 	* configure.host (msp430: Add.
> 	* libc/include/machine/ieeefp.h: Add MSP430 support.
> 	* libc/include/machine/setjmp.h: Likewise.
> 	* libc/include/sys/config.h: Likewise.
> 	* libc/machine/configure.in (msp430): Add.
> 	* libc/machine/configure: Regenerate.
> 	* libc/machine/msp430: New directory.
>
> [libgloss]
>
> 	* configure.in (msp430*-*-elf): Add.
> 	* configure: Regenerate.
> 	* msp430: New directory.
>
>
> Index: libgloss/configure.in
> ===================================================================
> RCS file: /cvs/src/src/libgloss/configure.in,v
> retrieving revision 1.37
> diff -p -U 5 -r1.37 configure.in
> --- libgloss/configure.in	26 Sep 2012 20:11:54 -0000	1.37
> +++ libgloss/configure.in	9 May 2013 01:58:07 -0000
> @@ -130,10 +130,14 @@ case "${target}" in
>   	AC_CONFIG_SUBDIRS([xstormy16])
>   	;;
>     m32c-*-*)
>   	AC_CONFIG_SUBDIRS([m32c])
>   	;;
> +  msp430*-*-elf)
> +	AC_CONFIG_SUBDIRS([msp430])
> +	config_libnosys=false
> +	;;
>     rl78*-*-elf)
>   	AC_CONFIG_SUBDIRS([rl78])
>   	;;
>     rx*-*-elf)
>   	AC_CONFIG_SUBDIRS([rx])
> Index: newlib/configure.host
> ===================================================================
> RCS file: /cvs/src/src/newlib/configure.host,v
> retrieving revision 1.128
> diff -p -U 5 -r1.128 configure.host
> --- newlib/configure.host	6 May 2013 18:23:08 -0000	1.128
> +++ newlib/configure.host	9 May 2013 01:58:07 -0000
> @@ -77,11 +77,11 @@ lpfx="lib_a-"
>
>   case "${target_optspace}:${host}" in
>     yes:*)
>       newlib_cflags="${newlib_cflags} -Os"
>       ;;
> -  :m32r-* | :d10v-* | :d30v-* | :avr-* | :m32c-* )
> +  :m32r-* | :d10v-* | :d30v-* | :avr-* | :m32c-* | :msp430*-* )
>       newlib_cflags="${newlib_cflags} -Os"
>       ;;
>     no:* | :*)
>       ;;
>   esac
> @@ -222,10 +222,16 @@ case "${host_cpu}" in
>   	machine_dir=mn10300
>   	;;
>     moxie)
>   	machine_dir=moxie
>           ;;
> +  msp430*)
> +	newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
> +	newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
> +	newlib_cflags="${newlib_cflags} -mOs "
> +	machine_dir=msp430
> +	;;
>     mt*)
>   	machine_dir=mt
>   	;;
>     nios2*)
>   	machine_dir=nios2
> Index: newlib/libc/include/machine/ieeefp.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/machine/ieeefp.h,v
> retrieving revision 1.53
> diff -p -U 5 -r1.53 ieeefp.h
> --- newlib/libc/include/machine/ieeefp.h	6 May 2013 18:23:08 -0000	1.53
> +++ newlib/libc/include/machine/ieeefp.h	9 May 2013 01:58:07 -0000
> @@ -357,10 +357,15 @@
>
>   #ifdef __MICROBLAZE__
>   #define __IEEE_BIG_ENDIAN
>   #endif
>
> +#ifdef __MSP430__
> +#define __IEEE_LITTLE_ENDIAN
> +#define __SMALL_BITFIELDS	/* 16 Bit INT */
> +#endif
> +
>   #ifdef __RL78__
>   #define __IEEE_LITTLE_ENDIAN
>   #define __SMALL_BITFIELDS	/* 16 Bit INT */
>   #define _DOUBLE_IS_32BITS
>   #endif
> Index: newlib/libc/include/machine/setjmp.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/machine/setjmp.h,v
> retrieving revision 1.50
> diff -p -U 5 -r1.50 setjmp.h
> --- newlib/libc/include/machine/setjmp.h	6 May 2013 18:23:08 -0000	1.50
> +++ newlib/libc/include/machine/setjmp.h	9 May 2013 01:58:07 -0000
> @@ -279,10 +279,20 @@ _BEGIN_STD_C
>   #define _JBLEN (34/2)
>   #endif
>   #define _JBTYPE unsigned short
>   #endif /* __m32c__ */
>
> +#ifdef __MSP430__
> +#define _JBLEN 9
> +
> +#ifdef __MSP430X_LARGE__
> +#define _JBTYPE unsigned long
> +#else
> +#define _JBTYPE unsigned short
> +#endif
> +#endif
> +
>   #ifdef __RL78__
>   /* Three banks of registers, SP, CS, ES, PC */
>   #define _JBLEN (8*3+8)
>   #define _JBTYPE unsigned char
>   #endif
> Index: newlib/libc/include/sys/config.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/sys/config.h,v
> retrieving revision 1.61
> diff -p -U 5 -r1.61 config.h
> --- newlib/libc/include/sys/config.h	26 Sep 2012 20:06:47 -0000	1.61
> +++ newlib/libc/include/sys/config.h	9 May 2013 01:58:07 -0000
> @@ -143,10 +143,25 @@
>   #define MALLOC_ALIGNMENT 8
>   #define _POINTER_INT short
>   #define __BUFSIZ__ 16
>   #define _REENT_SMALL
>   #endif
> +
> +#if defined __MSP430__
> +#ifndef _REENT_SMALL
> +#define _REENT_SMALL
> +#endif
> +
> +#define __SMALL_BITFIELDS
> +
> +#ifdef __MSP430X_LARGE__
> +#define _POINTER_INT long
> +#else
> +#define _POINTER_INT int
> +#endif
> +#endif
> +
>   #ifdef __m32c__
>   #define __SMALL_BITFIELDS
>   #undef INT_MAX
>   #undef UINT_MAX
>   #define INT_MAX __INT_MAX__
> Index: newlib/libc/machine/configure.in
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/machine/configure.in,v
> retrieving revision 1.22
> diff -p -U 5 -r1.22 configure.in
> --- newlib/libc/machine/configure.in	6 May 2013 18:23:08 -0000	1.22
> +++ newlib/libc/machine/configure.in	9 May 2013 01:58:10 -0000
> @@ -51,10 +51,11 @@ if test -n "${machine_dir}"; then
>   	microblaze ) AC_CONFIG_SUBDIRS(microblaze) ;;
>   	mips) AC_CONFIG_SUBDIRS(mips) ;;
>   	mn10200) AC_CONFIG_SUBDIRS(mn10200) ;;
>   	mn10300) AC_CONFIG_SUBDIRS(mn10300) ;;
>   	moxie) AC_CONFIG_SUBDIRS(moxie) ;;
> +	msp430) AC_CONFIG_SUBDIRS(msp430) ;;
>   	mt) AC_CONFIG_SUBDIRS(mt) ;;
>   	necv70) AC_CONFIG_SUBDIRS(necv70) ;;
>   	nios2) AC_CONFIG_SUBDIRS(nios2) ;;
>   	powerpc) AC_CONFIG_SUBDIRS(powerpc) ;;
>   	rl78) AC_CONFIG_SUBDIRS(rl78) ;;
>
> ==================================================
> Index: newlib/libc/machine/msp430/Makefile.am
>
> # Copyright (c) 2013 Red Hat Inc
> #
> # 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.
>
> ## 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
>
> ==================================================
> Index: newlib/libc/machine/msp430/Makefile.in
>
> ** omitted **
>
> ==================================================
> Index: newlib/libc/machine/msp430/aclocal.m4
>
> ** omitted **
>
> ==================================================
> Index: newlib/libc/machine/msp430/configure
>
> ** omitted **
>
> ==================================================
> Index: newlib/libc/machine/msp430/configure.in
>
> # Copyright (c) 2013 Red Hat Inc
> #
> # 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.
>
> dnl This is the newlib/libc/machine/msp430 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
>
> ==================================================
> Index: newlib/libc/machine/msp430/setjmp.S
>
> /* Copyright (c) 2013 Red Hat Inc
>
>    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.
> */
>
> # setjmp/longjmp for msp430.  The jmpbuf looks like this:
> #
> # Register	Jmpbuf offset
> #               small   large	
> # r0 (pc)	0x00     0x00
> # r1 (sp)	0x02	 0x04	
> # r4		0x04	 0x08
> # r5		0x06	 0x0c
> # r6		0x08	 0x10
> # r7		0x0a	 0x14
> # r8		0x0c	 0x18
> # r9		0x0e	 0x1c
> # r10		0x10	 0x20
>
> 	.text
> 	.global	setjmp
> setjmp:
> 	; Upon entry r12 points to the jump buffer.
> 	; Returns 0 to caller.
> 	
> #if   defined __MSP430X_LARGE__
> 	mova   @r1, r13
> 	mova    r13, 0(r12)
> 	mova	r1,  4(r12)
> 	mova	r4,  8(r12)
> 	mova	r5,  12(r12)
> 	mova	r6,  16(r12)
> 	mova	r7,  20(r12)
> 	mova	r8,  24(r12)
> 	mova	r9,  28(r12)
> 	mova	r10, 32(r12)
> 	clr   	r12
> 	reta
> #else
> 	;; Get the return address off the stack
> 	mov.w  @r1,  r13
> 	mov.w   r13, 0(r12)
> 	mov.w	r1,  2(r12)
> 	mov.w	r4,  4(r12)
> 	mov.w	r5,  6(r12)
> 	mov.w	r6,  8(r12)
> 	mov.w	r7,  10(r12)
> 	mov.w	r8,  12(r12)
> 	mov.w	r9,  14(r12)
> 	mov.w	r10, 16(r12)
> 	clr   	r12
> 	ret
> #endif	
>
> 	
> 	.global	longjmp
> longjmp:
> 	; Upon entry r12 points to the jump buffer and
>          ; r13 contains the value to be returned by setjmp.
>
> #if   defined __MSP430X_LARGE__
> 	mova	@r12+, r14
> 	mova	@r12+, r1
> 	mova	@r12+, r4
> 	mova	@r12+, r5
> 	mova	@r12+, r6
> 	mova	@r12+, r7
> 	mova	@r12+, r8
> 	mova	@r12+, r9
> 	mova	@r12+, r10
> #else
> 	mov.w	@r12+, r14
> 	mov.w	@r12+, r1
> 	mov.w	@r12+, r4
> 	mov.w	@r12+, r5
> 	mov.w	@r12+, r6
> 	mov.w	@r12+, r7
> 	mov.w	@r12+, r8
> 	mov.w	@r12+, r9
> 	mov.w	@r12+, r10
> #endif
> 	; If caller attempts to return 0, return 1 instead.
> 	cmp.w   #0, r13
> 	jne	.Lnot_zero
> 	mov.w	#1, r13
> .Lnot_zero:
> 	mov.w	r13, r12
>
> #if   defined __MSP430X_LARGE__
> 	adda     #4, r1
> 	mova	r14, r0
> #else
> 	add.w    #2, r1
> 	mov.w	r14, r0
> #endif
>
>
> ==================================================
> Index: libgloss/msp430/Makefile.in
>
> # Copyright (c) 2008, 2009, 2011, 2013 Red Hat Inc
> #
> # 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.
>
> # Makefile for libgloss/msp430.
>
> VPATH = @srcdir@
> srcdir = @srcdir@
> objdir = .
> srcroot = $(srcdir)/../..
> objroot = $(objdir)/../..
>
> prefix = @prefix@
> exec_prefix = @exec_prefix@
>
> host_alias = @host_alias@
> target_alias = @target_alias@
>
> bindir = @bindir@
> libdir = @libdir@
> tooldir = $(exec_prefix)/$(target_alias)
>
> # 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 = rc
>
> 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`
>
> SCRIPTS = $(srcdir)/msp430.ld $(srcdir)/msp430-sim.ld
> SCRIPTS += $(srcdir)/msp430xl-sim.ld
> SCRIPTS += $(srcdir)/msp430F5438A-s.ld
> SCRIPTS += $(srcdir)/msp430F5438A-l.ld
> CRT = gcrt0.o crt0.o crtn.o
> SIM_BSP = libsim.a
> LIBNOSYS = libnosys.a
>
> SIM_OBJS = syscalls.o \
> 	cio.o \
> 	write.o \
> 	sbrk.o
>
> NOSYS_OBJS = nosyscalls.o \
> 	cio.o \
> 	write.o \
> 	sbrk.o
>
> #### Host specific Makefile fragment comes in here.
> @host_makefile_frag@
>
>
> # Override .S.o rule to pass assembler debugging flags
> .S.o:
> 	$(CC) -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $<
>
> all: $(CRT) $(SIM_BSP) $(LIBNOSYS) copy_scripts_to_objdir
>
> $(SIM_BSP): $(SIM_OBJS)
> 	$(AR) $(ARFLAGS) $@ $?
> 	$(RANLIB) $@
>
>
> $(LIBNOSYS): $(NOSYS_OBJS)
> 	$(AR) $(ARFLAGS) $@ $?
> 	$(RANLIB) $@
>
> copy_scripts_to_objdir: $(SCRIPTS)
> 	cp $(SCRIPTS) $(objdir)
>
> # Dependencies
>
> SDEPS = $(srcdir)/cio.h
>
> abort.o : $(SDEPS)
> argv.o : $(SDEPS)
> argvlen.o : $(SDEPS)
> chdir.o : $(SDEPS)
> chmod.o : $(SDEPS)
> close.o : $(SDEPS)
> exit.o : $(SDEPS)
> fstat.o : $(SDEPS)
> getpid.o : $(SDEPS)
> gettimeofday.o : $(SDEPS)
> gcrt0.o: gcrt0.S crt0.S
> kill.o : $(SDEPS)
> link.o : $(SDEPS)
> lseek.o : $(SDEPS)
> mcount.o : $(SDEPS)
> open.o : $(SDEPS)
> read.o : $(SDEPS)
> sigprocmask.o : $(SDEPS)
> sleep.o : $(SDEPS)
> stat.o : $(SDEPS)
> time.o : $(SDEPS)
> times.o : $(SDEPS)
> unlink.o : $(SDEPS)
> utime.o : $(SDEPS)
> write.o : $(SDEPS)
>
> install: $(CRT) $(SIM_BSP) $(LIBNOSYS) $(SCRIPTS)
> 	for c in $(CRT) $(SIM_BSP) $(LIBNOSYS); do \
> 	  $(INSTALL_DATA) $$c $(tooldir)/lib${MULTISUBDIR}/$$c ;\
> 	done
> 	for c in $(SCRIPTS); do \
> 	  b=`basename $$c`; \
> 	  $(INSTALL_DATA) $$c $(tooldir)/lib${MULTISUBDIR}/$$b ;\
> 	done
>
> clean mostlyclean:
> 	rm -f *.o *.a
>
> distclean maintainer-clean realclean: clean
> 	rm -f Makefile config.cache config.log config.status
>
> .PHONY: info dvi doc install-info clean-info
> info doc dvi:
> install-info:
> clean-info:
>
> Makefile: Makefile.in config.status @host_makefile_frag_path@
> 	$(SHELL) config.status
>
> config.status: configure
> 	$(SHELL) config.status --recheck
>
> ==================================================
> Index: libgloss/msp430/cio.c
>
> /*
>
> Copyright (c) 2013 Red Hat Incorporated.
> 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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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 "cio.h"
>
> __CIOBUF__TYPE__ __CIOBUF__;
>
> void
> _libgloss_cio_hook (void)
> {
>    __asm__ __volatile__ (" .global C$$IO$$");
>    __asm__ __volatile__ ("C$$IO$$: nop");
> }
>
> ==================================================
> Index: libgloss/msp430/cio.h
>
> /*
>
> Copyright (c) 2013 Red Hat Incorporated.
> 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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED BE LIABLE FOR ANY
> DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>
> */
>
> #ifndef CIO_BUF_SIZE
> #define CIO_BUF_SIZE 64
> #endif
>
> typedef struct {
>    unsigned char length[2];
>    unsigned char parms[9];
>    unsigned char buf[CIO_BUF_SIZE];
> } __CIOBUF__TYPE__;
>
> extern __CIOBUF__TYPE__ __CIOBUF__;
>
> extern void _libgloss_cio_hook (void);
>
> #define CIO_OPEN    (0xF0)
> #define CIO_CLOSE   (0xF1)
> #define CIO_READ    (0xF2)
> #define CIO_WRITE   (0xF3)
> #define CIO_LSEEK   (0xF4)
> #define CIO_UNLINK  (0xF5)
> #define CIO_GETENV  (0xF6)
> #define CIO_RENAME  (0xF7)
> #define CIO_GETTIME (0xF8)
> #define CIO_GETCLK  (0xF9)
> #define CIO_SYNC    (0xFF)
>
>
> ==================================================
> Index: libgloss/msp430/configure
>
> ** omitted **
>
> ==================================================
> Index: libgloss/msp430/configure.in
>
> # Copyright (c) 2008, 2009, 2011, 2013 Red Hat Inc
> #
> # 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.
>
> 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
>
> ==================================================
> Index: libgloss/msp430/crt0.S
>
> /* Copyright (c) 2012-2013 Red Hat Incorporated.
>     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.
>
>       The name of Red Hat Incorporated may not 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 Red Hat
>     incorporated 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 "memmodel.h"
>
> 	.section ".resetvec", "a"
> __msp430_resetvec_hook:
> 	.word	__start
>
> 	.section ".lowtext", "ax", @progbits
> 	.global __start
> __start:
> 	mov_	#__stack, R1
>
> 	;; Disable watchdog timer.
> 	MOV	#0x5a80, &0x15C
>
> 	mov_	#__bssstart, R12
> 	clr.w	R13
> 	mov.w	#__bsssize, R14
> #ifdef __MSP430X_LARGE__
> 	clr.w	R15		; We assume that __bsssize is never > 64M
> #endif
> 	call_	#memset
>
> 	mov_	#__datastart, R12
> 	mov_	#__romdatastart, R13
>
> 	;;  memmove and memcpy do not currently work when src == dst
> 	cmp_	R12, R13
> 	jeq	1f
>
> 	mov.w	#__romdatacopysize, R14
> #ifdef __MSP430X_LARGE__
> 	clr.w	R15		; We assume that __romdatacopysize is never > 64M
> #endif
> 	call_	#memmove
> 1:	
> 	call_	#__msp430_init
>
> 	clr.w	R12		; Set argc == 0
> 	call_	#main
>
> 	call_	#_exit
>
> 	.word	__msp430_resetvec_hook
>
> ;----------------------------------------
>
> 	.global	_msp430_run_init_array
> 	.type	_msp430_run_init_array,@function
> _msp430_run_init_array:
> 	mov_	#__init_array_start, R4
> 	mov_	#__init_array_end, R5
> 	mov_	#PTRsz, R6
> 	br_	#_msp430_run_array
>
> 	.global	_msp430_run_preinit_array
> 	.type	_msp430_run_preinit_array,@function
> _msp430_run_preinit_array:
> 	mov_	#__preinit_array_start, R4
> 	mov_	#__preinit_array_end, R5
> 	mov_	#PTRsz, R6
> 	br_	#_msp430_run_array
>
> 	.global	_msp430_run_fini_array
> 	.type	_msp430_run_fini_array,@function
> _msp430_run_fini_array:
> 	mov_	#__fini_array_start, R4
> 	mov_	#__fini_array_end, R5
> 	mov_	#-PTRsz, R6
> 	br_	#_msp430_run_array
>
> _msp430_run_array:
> 	cmp_	R4, R5
> 	jeq	_msp430_run_done
> 	mov_	@R4, R7
> 	add_	R6, R4
> 	call_	@R7
> 	br_	_msp430_run_array
>
> _msp430_run_done:
> 	ret_
>
> ;----------------------------------------
>
> 	.section	.init,"ax"
>
> 	.global __msp430_init
> __msp430_init:
>
> 	.section	.fini,"ax"
>
> 	.global __msp430_fini
> __msp430_fini:
> 	call_	#_msp430_run_fini_array
>
> ==================================================
> Index: libgloss/msp430/crtn.S
>
> /* Copyright (c) 2013 Red Hat Incorporated.
>     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.
>
>       The name of Red Hat Incorporated may not 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 Red Hat
>     incorporated 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 "memmodel.h"
>
> 	.section	.init,"ax"
> 	call_	#_msp430_run_preinit_array
> 	call_	#_msp430_run_init_array
> 	ret_
> 	.global	__msp430_init_end
> __msp430_init_end:
>
> 	.section	.fini,"ax"
>
> 	ret_
> 	.global	__msp430_fini_end
> __msp430_fini_end:
>
> 	.text
>
>
> ==================================================
> Index: libgloss/msp430/gcrt0.S
>
> /* Copyright (c) 2013 Red Hat Incorporated.
>     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.
>
>       The name of Red Hat Incorporated may not 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 Red Hat
>     incorporated be liable for any direct, indirect, incidental, special,
>     exemplary, or consequential damages (including, but not limited to,
>     procurement of substitute goods or services; loss of use, data, or
>     profits; or business interruption) however caused and on any theory of
>     liability, whether in contract, strict liability, or tort (including
>     negligence or otherwise) arising in any way out of the use of this
>     software, even if advised of the possibility of such damage.  */
>
> 	.text
> 	.global	_mcount
> _mcount:
> 	ret
>
> ==================================================
> Index: libgloss/msp430/memmodel.h
>
> /* Copyright (c) 2012,2013 Red Hat Incorporated.
>     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.
>
>       The name of Red Hat Incorporated may not 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 Red Hat
>     incorporated 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 provides macros for various MSP430 instructions
>     which have similar, but not identical, versions when assembling
>     for the LARGE memory model.  */
>
> #ifdef __MSP430X_LARGE__
>
> #define call_	CALLA
> #define ret_	RETA
> #define mov_	MOVA
> #define movx_	MOVX
> #define br_	BRA
> #define cmp_	CMPA
> #define add_	ADDA
> #define PTRsz	4
>
> #else
>
> #define call_	CALL
> #define ret_	RET
> #define mov_	MOV
> #define movx_	MOV
> #define br_	BR
> #define cmp_	CMP
> #define add_	ADD
> #define PTRsz	2
>
>
> #endif
>
> ==================================================
> Index: libgloss/msp430/msp430-sim.ld
>
> /*
>
> Copyright (c) 2005,2008,2009,2011,2013 Red Hat Incorporated.
> 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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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.
>
> */
>
> /* Default linker script, for normal executables */
> OUTPUT_ARCH(msp430)
> ENTRY(_start)
>
> /* Do we need any of these for elf?
>     __DYNAMIC = 0;    */
>
> MEMORY {
> 	RAM (w)      : ORIGIN = 0x00200, LENGTH = 0x0ee00
> 	RESETVEC (w) : ORIGIN = 0x0fffe, LENGTH = 0x00002
> }
>
> SECTIONS
> {
>    .resetvec :
>    {
>      *(.resetvec)
>    } > RESETVEC
>
>    .rodata : {
>      . = ALIGN(2);
>      *(.plt)
>      *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*)
>      *(.rodata1)
>      *(.eh_frame_hdr)
>      KEEP (*(.eh_frame))
>      KEEP (*(.gcc_except_table)) *(.gcc_except_table.*)
>      PROVIDE (__preinit_array_start = .);
>      KEEP (*(.preinit_array))
>      PROVIDE (__preinit_array_end = .);
>      PROVIDE (__init_array_start = .);
>      KEEP (*(SORT(.init_array.*)))
>      KEEP (*(.init_array))
>      PROVIDE (__init_array_end = .);
>      PROVIDE (__fini_array_start = .);
>      KEEP (*(.fini_array))
>      KEEP (*(SORT(.fini_array.*)))
>      PROVIDE (__fini_array_end = .);
>      LONG(0); /* Sentinel.  */
>
>      /* gcc uses crtbegin.o to find the start of the constructors, so
>         we make sure it is first.  Because this is a wildcard, it
>         doesn't matter if the user does not actually link against
>         crtbegin.o; the linker won't look for a file to match a
>         wildcard.  The wildcard also means that it doesn't matter which
>         directory crtbegin.o is in.  */
>      KEEP (*crtbegin*.o(.ctors))
>
>      /* We don't want to include the .ctor section from from the
>         crtend.o file until after the sorted ctors.  The .ctor section
>         from the crtend file contains the end of ctors marker and it
>         must be last */
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
>      KEEP (*(SORT(.ctors.*)))
>      KEEP (*(.ctors))
>
>      KEEP (*crtbegin*.o(.dtors))
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
>      KEEP (*(SORT(.dtors.*)))
>      KEEP (*(.dtors))
>    } > RAM
>
>    .text           :
>    {
>      . = ALIGN(2);
>      PROVIDE (_start = .);
>      *(.lowtext .text .stub .text.* .gnu.linkonce.t.* .text:*)
>      KEEP (*(.text.*personality*))
>      /* .gnu.warning sections are handled specially by elf32.em.  */
>      *(.gnu.warning)
>      *(.interp .hash .dynsym .dynstr .gnu.version*)
>      PROVIDE (__etext = .);
>      PROVIDE (_etext = .);
>      PROVIDE (etext = .);
>      . = ALIGN(2);
>      KEEP (*(.init))
>      KEEP (*(.fini))
>    } > RAM
>
>    .data : {
>      . = ALIGN(2);
>      PROVIDE (__datastart = .);
>
>      KEEP (*(.jcr))
>      *(.data.rel.ro.local) *(.data.rel.ro*)
>      *(.dynamic)
>
>      *(.data .data.* .gnu.linkonce.d.*)
>      KEEP (*(.gnu.linkonce.d.*personality*))
>      SORT(CONSTRUCTORS)
>      *(.data1)
>      *(.got.plt) *(.got)
>
>      /* We want the small data sections together, so single-instruction offsets
>         can access them all, and initialized data all before uninitialized, so
>         we can shorten the on-disk segment size.  */
>      . = ALIGN(2);
>      *(.sdata .sdata.* .gnu.linkonce.s.* D_2 D_1)
>
>      . = ALIGN(2);
>      _edata = .;
>      PROVIDE (edata = .);
>      PROVIDE (__dataend = .);
>    } > RAM
>
>    /* Note that crt0 assumes this is a multiple of two; all the
>       start/stop symbols are also assumed word-aligned.  */
>    PROVIDE(__romdatastart = LOADADDR(.data));
>    PROVIDE (__romdatacopysize = SIZEOF(.data));
>
>    .bss : {
>      . = ALIGN(2);
>      PROVIDE (__bssstart = .);
>      *(.dynbss)
>      *(.sbss .sbss.*)
>      *(.bss .bss.* .gnu.linkonce.b.*)
>      . = ALIGN(2);
>      *(COMMON)
>      . = ALIGN(2);
>      PROVIDE (__bssend = .);
>      _end = .;
>      PROVIDE (end = .);
>    } > RAM
>    PROVIDE (__bsssize = SIZEOF(.bss));
>
>    .stack (ORIGIN (RAM) + LENGTH(RAM)) :
>    {
>      PROVIDE (__stack = .);
>      *(.stack)
>    }
>
>    /* The rest are all not normally part of the runtime image.  */
>
>    .MP430.attributes 0 :
>    {
>      KEEP (*(.MSP430.attributes))
>      KEEP (*(.gnu.attributes))
>      KEEP (*(__TI_build_attributes))
>    }
>
>    /* Stabs debugging sections.  */
>    .stab          0 : { *(.stab) }
>    .stabstr       0 : { *(.stabstr) }
>    .stab.excl     0 : { *(.stab.excl) }
>    .stab.exclstr  0 : { *(.stab.exclstr) }
>    .stab.index    0 : { *(.stab.index) }
>    .stab.indexstr 0 : { *(.stab.indexstr) }
>    .comment       0 : { *(.comment) }
>    /* 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) }
>    /* 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) }
>    /* DWARF 3 */
>    .debug_pubtypes 0 : { *(.debug_pubtypes) }
>    .debug_ranges   0 : { *(.debug_ranges) }
>    /* DWARF Extension.  */
>    .debug_macro    0 : { *(.debug_macro) }
>
>    /DISCARD/ : { *(.note.GNU-stack) }
> }
>
> ==================================================
> Index: libgloss/msp430/msp430.ld
>
> /*
>
> Copyright (c) 2005,2008,2009,2011,2013 Red Hat Incorporated.
> 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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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.
>
> */
>
> /* Default linker script, for normal executables */
> OUTPUT_ARCH(msp430)
> ENTRY(_start)
>
> /* Do we need any of these for elf?
>     __DYNAMIC = 0;    */
>
> MEMORY {
> 	RAM (w)      : ORIGIN = 0x00200, LENGTH = 0x0ee00
> 	RESETVEC (w) : ORIGIN = 0x0fffe, LENGTH = 0x00002
> }
>
> SECTIONS
> {
>    .resetvec :
>    {
>      *(.resetvec)
>    } > RESETVEC
>
>    .rodata : {
>      . = ALIGN(2);
>      *(.plt)
>      *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*)
>      *(.rodata1)
>      *(.eh_frame_hdr)
>      KEEP (*(.eh_frame))
>      KEEP (*(.gcc_except_table)) *(.gcc_except_table.*)
>      PROVIDE (__preinit_array_start = .);
>      KEEP (*(.preinit_array))
>      PROVIDE (__preinit_array_end = .);
>      PROVIDE (__init_array_start = .);
>      KEEP (*(SORT(.init_array.*)))
>      KEEP (*(.init_array))
>      PROVIDE (__init_array_end = .);
>      PROVIDE (__fini_array_start = .);
>      KEEP (*(.fini_array))
>      KEEP (*(SORT(.fini_array.*)))
>      PROVIDE (__fini_array_end = .);
>      LONG(0); /* Sentinel.  */
>
>      /* gcc uses crtbegin.o to find the start of the constructors, so
>         we make sure it is first.  Because this is a wildcard, it
>         doesn't matter if the user does not actually link against
>         crtbegin.o; the linker won't look for a file to match a
>         wildcard.  The wildcard also means that it doesn't matter which
>         directory crtbegin.o is in.  */
>      KEEP (*crtbegin*.o(.ctors))
>
>      /* We don't want to include the .ctor section from from the
>         crtend.o file until after the sorted ctors.  The .ctor section
>         from the crtend file contains the end of ctors marker and it
>         must be last */
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
>      KEEP (*(SORT(.ctors.*)))
>      KEEP (*(.ctors))
>
>      KEEP (*crtbegin*.o(.dtors))
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
>      KEEP (*(SORT(.dtors.*)))
>      KEEP (*(.dtors))
>    } > RAM
>
>    .text           :
>    {
>      . = ALIGN(2);
>      PROVIDE (_start = .);
>      *(.lowtext .text .stub .text.* .gnu.linkonce.t.* .text:*)
>      KEEP (*(.text.*personality*))
>      /* .gnu.warning sections are handled specially by elf32.em.  */
>      *(.gnu.warning)
>      *(.interp .hash .dynsym .dynstr .gnu.version*)
>      PROVIDE (__etext = .);
>      PROVIDE (_etext = .);
>      PROVIDE (etext = .);
>      . = ALIGN(2);
>      KEEP (*(.init))
>      KEEP (*(.fini))
>    } > RAM
>
>    .data : {
>      . = ALIGN(2);
>      PROVIDE (__datastart = .);
>
>      KEEP (*(.jcr))
>      *(.data.rel.ro.local) *(.data.rel.ro*)
>      *(.dynamic)
>
>      *(.data .data.* .gnu.linkonce.d.*)
>      KEEP (*(.gnu.linkonce.d.*personality*))
>      SORT(CONSTRUCTORS)
>      *(.data1)
>      *(.got.plt) *(.got)
>
>      /* We want the small data sections together, so single-instruction offsets
>         can access them all, and initialized data all before uninitialized, so
>         we can shorten the on-disk segment size.  */
>      . = ALIGN(2);
>      *(.sdata .sdata.* .gnu.linkonce.s.* D_2 D_1)
>
>      . = ALIGN(2);
>      _edata = .;
>      PROVIDE (edata = .);
>      PROVIDE (__dataend = .);
>    } > RAM
>
>    /* Note that crt0 assumes this is a multiple of two; all the
>       start/stop symbols are also assumed word-aligned.  */
>    PROVIDE(__romdatastart = LOADADDR(.data));
>    PROVIDE (__romdatacopysize = SIZEOF(.data));
>
>    .bss : {
>      . = ALIGN(2);
>      PROVIDE (__bssstart = .);
>      *(.dynbss)
>      *(.sbss .sbss.*)
>      *(.bss .bss.* .gnu.linkonce.b.*)
>      . = ALIGN(2);
>      *(COMMON)
>      . = ALIGN(2);
>      PROVIDE (__bssend = .);
>      _end = .;
>      PROVIDE (end = .);
>    } > RAM
>    PROVIDE (__bsssize = SIZEOF(.bss));
>
>    .stack (ORIGIN (RAM) + LENGTH(RAM)) :
>    {
>      PROVIDE (__stack = .);
>      *(.stack)
>    }
>
>    .MP430.attributes 0 :
>    {
>      KEEP (*(.MSP430.attributes))
>      KEEP (*(.gnu.attributes))
>      KEEP (*(__TI_build_attributes))
>    }
>
>    /* The rest are all not normally part of the runtime image.  */
>
>    /* Stabs debugging sections.  */
>    .stab          0 : { *(.stab) }
>    .stabstr       0 : { *(.stabstr) }
>    .stab.excl     0 : { *(.stab.excl) }
>    .stab.exclstr  0 : { *(.stab.exclstr) }
>    .stab.index    0 : { *(.stab.index) }
>    .stab.indexstr 0 : { *(.stab.indexstr) }
>    .comment       0 : { *(.comment) }
>    /* 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) }
>    /* 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) }
>    /DISCARD/ : { *(.note.GNU-stack) }
> }
>
> ==================================================
> Index: libgloss/msp430/msp430F5438A-l.ld
>
> /*  Copyright (c) 2013 Red Hat Incorporated.
>      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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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.
>
> */
>
> /* Default linker script, for normal executables */
> OUTPUT_ARCH(msp430)
> ENTRY(_start)
>
> /* Do we need any of these for elf?
>     __DYNAMIC = 0;    */
>
> MEMORY {
> 	RAM (w)      : ORIGIN = 0x01c00, LENGTH = 0x04000
> 	LOWROM (w)   : ORIGIN = 0x05c00, LENGTH = 0x0a3fe
> 	RESETVEC (w) : ORIGIN = 0x0fffe, LENGTH = 0x00002
> 	ROM (w)      : ORIGIN = 0x10000, LENGTH = 0x35c00
> }
>
> SECTIONS
> {
>    .resetvec :
>    {
>      *(.resetvec)
>    } > RESETVEC
>
>    .rodata : {
>      . = ALIGN(2);
>      *(.plt)
>      *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*)
>      *(.rodata1)
>      *(.eh_frame_hdr)
>      KEEP (*(.eh_frame))
>      KEEP (*(.gcc_except_table)) *(.gcc_except_table.*)
>      PROVIDE (__preinit_array_start = .);
>      KEEP (*(.preinit_array))
>      PROVIDE (__preinit_array_end = .);
>      PROVIDE (__init_array_start = .);
>      KEEP (*(SORT(.init_array.*)))
>      KEEP (*(.init_array))
>      PROVIDE (__init_array_end = .);
>      PROVIDE (__fini_array_start = .);
>      KEEP (*(.fini_array))
>      KEEP (*(SORT(.fini_array.*)))
>      PROVIDE (__fini_array_end = .);
>      LONG(0); /* Sentinel.  */
>
>      /* gcc uses crtbegin.o to find the start of the constructors, so
>         we make sure it is first.  Because this is a wildcard, it
>         doesn't matter if the user does not actually link against
>         crtbegin.o; the linker won't look for a file to match a
>         wildcard.  The wildcard also means that it doesn't matter which
>         directory crtbegin.o is in.  */
>      KEEP (*crtbegin*.o(.ctors))
>
>      /* We don't want to include the .ctor section from from the
>         crtend.o file until after the sorted ctors.  The .ctor section
>         from the crtend file contains the end of ctors marker and it
>         must be last */
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
>      KEEP (*(SORT(.ctors.*)))
>      KEEP (*(.ctors))
>
>      KEEP (*crtbegin*.o(.dtors))
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
>      KEEP (*(SORT(.dtors.*)))
>      KEEP (*(.dtors))
>    } > ROM
>
>    .data : {
>      . = ALIGN(2);
>      PROVIDE (__datastart = .);
>
>      KEEP (*(.jcr))
>      *(.data.rel.ro.local) *(.data.rel.ro*)
>      *(.dynamic)
>
>      *(.data .data.* .gnu.linkonce.d.*)
>      KEEP (*(.gnu.linkonce.d.*personality*))
>      SORT(CONSTRUCTORS)
>      *(.data1)
>      *(.got.plt) *(.got)
>
>      /* We want the small data sections together, so single-instruction offsets
>         can access them all, and initialized data all before uninitialized, so
>         we can shorten the on-disk segment size.  */
>      . = ALIGN(2);
>      *(.sdata .sdata.* .gnu.linkonce.s.* D_2 D_1)
>
>      . = ALIGN(2);
>      _edata = .;
>      PROVIDE (edata = .);
>      PROVIDE (__dataend = .);
>    } > RAM AT>ROM
>
>    /* Note that crt0 assumes this is a multiple of two; all the
>       start/stop symbols are also assumed word-aligned.  */
>    PROVIDE(__romdatastart = LOADADDR(.data));
>    PROVIDE (__romdatacopysize = SIZEOF(.data));
>
>    .bss : {
>      . = ALIGN(2);
>      PROVIDE (__bssstart = .);
>      *(.dynbss)
>      *(.sbss .sbss.*)
>      *(.bss .bss.* .gnu.linkonce.b.*)
>      . = ALIGN(2);
>      *(COMMON)
>      . = ALIGN(2);
>      PROVIDE (__bssend = .);
>      _end = .;
>      PROVIDE (end = .);
>    } > RAM
>    PROVIDE (__bsssize = SIZEOF(.bss));
>
>    .stack (ORIGIN (RAM) + LENGTH(RAM)) :
>    {
>      PROVIDE (__stack = .);
>      *(.stack)
>    }
>
>    /* This is just for crt0.S */
>    .lowtext           :
>    {
>      PROVIDE (_start = .);
>      . = ALIGN(2);
>      *(.lowtext)
>    } > LOWROM
>
>    .text           :
>    {
>      . = ALIGN(2);
>      *(.text .stub .text.* .gnu.linkonce.t.* .text:*)
>      KEEP (*(.text.*personality*))
>      /* .gnu.warning sections are handled specially by elf32.em.  */
>      *(.gnu.warning)
>      *(.interp .hash .dynsym .dynstr .gnu.version*)
>      PROVIDE (__etext = .);
>      PROVIDE (_etext = .);
>      PROVIDE (etext = .);
>      . = ALIGN(2);
>      KEEP (*(.init))
>      KEEP (*(.fini))
>    } > ROM
>
>    /* The rest are all not normally part of the runtime image.  */
>
>    .MP430.attributes 0 :
>    {
>      KEEP (*(.MSP430.attributes))
>      KEEP (*(.gnu.attributes))
>      KEEP (*(__TI_build_attributes))
>    }
>
>    /* Stabs debugging sections.  */
>    .stab          0 : { *(.stab) }
>    .stabstr       0 : { *(.stabstr) }
>    .stab.excl     0 : { *(.stab.excl) }
>    .stab.exclstr  0 : { *(.stab.exclstr) }
>    .stab.index    0 : { *(.stab.index) }
>    .stab.indexstr 0 : { *(.stab.indexstr) }
>    .comment       0 : { *(.comment) }
>    /* 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) }
>    /* 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) }
>    /* DWARF 3 */
>    .debug_pubtypes 0 : { *(.debug_pubtypes) }
>    .debug_ranges   0 : { *(.debug_ranges) }
>    /* DWARF Extension.  */
>    .debug_macro    0 : { *(.debug_macro) }
>
>    /DISCARD/ : { *(.note.GNU-stack) }
> }
>
> ==================================================
> Index: libgloss/msp430/msp430F5438A-s.ld
>
> /*
>
> Copyright (c) 2005,2008,2009,2011,2013 Red Hat Incorporated.
> 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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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.
>
> */
>
> /* Default linker script, for normal executables */
> OUTPUT_ARCH(msp430)
> ENTRY(_start)
>
> /* Do we need any of these for elf?
>     __DYNAMIC = 0;    */
>
> MEMORY {
> 	RAM (w)      : ORIGIN = 0x01c00, LENGTH = 0x04000
> 	ROM (w)      : ORIGIN = 0x05c00, LENGTH = 0x0a3fe
> 	RESETVEC (w) : ORIGIN = 0x0fffe, LENGTH = 0x00002
> }
>
> SECTIONS
> {
>    .resetvec :
>    {
>      *(.resetvec)
>    } > RESETVEC
>
>    .rodata : {
>      . = ALIGN(2);
>      *(.plt)
>      *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*)
>      *(.rodata1)
>      *(.eh_frame_hdr)
>      KEEP (*(.eh_frame))
>      KEEP (*(.gcc_except_table)) *(.gcc_except_table.*)
>      PROVIDE (__preinit_array_start = .);
>      KEEP (*(.preinit_array))
>      PROVIDE (__preinit_array_end = .);
>      PROVIDE (__init_array_start = .);
>      KEEP (*(SORT(.init_array.*)))
>      KEEP (*(.init_array))
>      PROVIDE (__init_array_end = .);
>      PROVIDE (__fini_array_start = .);
>      KEEP (*(.fini_array))
>      KEEP (*(SORT(.fini_array.*)))
>      PROVIDE (__fini_array_end = .);
>      LONG(0); /* Sentinel.  */
>
>      /* gcc uses crtbegin.o to find the start of the constructors, so
>         we make sure it is first.  Because this is a wildcard, it
>         doesn't matter if the user does not actually link against
>         crtbegin.o; the linker won't look for a file to match a
>         wildcard.  The wildcard also means that it doesn't matter which
>         directory crtbegin.o is in.  */
>      KEEP (*crtbegin*.o(.ctors))
>
>      /* We don't want to include the .ctor section from from the
>         crtend.o file until after the sorted ctors.  The .ctor section
>         from the crtend file contains the end of ctors marker and it
>         must be last */
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
>      KEEP (*(SORT(.ctors.*)))
>      KEEP (*(.ctors))
>
>      KEEP (*crtbegin*.o(.dtors))
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
>      KEEP (*(SORT(.dtors.*)))
>      KEEP (*(.dtors))
>    } > ROM
>
>    .text           :
>    {
>      . = ALIGN(2);
>      PROVIDE (_start = .);
>      *(.lowtext .text .stub .text.* .gnu.linkonce.t.* .text:*)
>      KEEP (*(.text.*personality*))
>      /* .gnu.warning sections are handled specially by elf32.em.  */
>      *(.gnu.warning)
>      *(.interp .hash .dynsym .dynstr .gnu.version*)
>      PROVIDE (__etext = .);
>      PROVIDE (_etext = .);
>      PROVIDE (etext = .);
>      . = ALIGN(2);
>      KEEP (*(.init))
>      KEEP (*(.fini))
>    } > ROM
>
>    .data : {
>      . = ALIGN(2);
>      PROVIDE (__datastart = .);
>
>      KEEP (*(.jcr))
>      *(.data.rel.ro.local) *(.data.rel.ro*)
>      *(.dynamic)
>
>      *(.data .data.* .gnu.linkonce.d.*)
>      KEEP (*(.gnu.linkonce.d.*personality*))
>      SORT(CONSTRUCTORS)
>      *(.data1)
>      *(.got.plt) *(.got)
>
>      /* We want the small data sections together, so single-instruction offsets
>         can access them all, and initialized data all before uninitialized, so
>         we can shorten the on-disk segment size.  */
>      . = ALIGN(2);
>      *(.sdata .sdata.* .gnu.linkonce.s.* D_2 D_1)
>
>      . = ALIGN(2);
>      _edata = .;
>      PROVIDE (edata = .);
>      PROVIDE (__dataend = .);
>    } > RAM AT>ROM
>
>    /* Note that crt0 assumes this is a multiple of two; all the
>       start/stop symbols are also assumed word-aligned.  */
>    PROVIDE(__romdatastart = LOADADDR(.data));
>    PROVIDE (__romdatacopysize = SIZEOF(.data));
>
>    .bss : {
>      . = ALIGN(2);
>      PROVIDE (__bssstart = .);
>      *(.dynbss)
>      *(.sbss .sbss.*)
>      *(.bss .bss.* .gnu.linkonce.b.*)
>      . = ALIGN(2);
>      *(COMMON)
>      . = ALIGN(2);
>      PROVIDE (__bssend = .);
>      _end = .;
>      PROVIDE (end = .);
>    } > RAM
>    PROVIDE (__bsssize = SIZEOF(.bss));
>
>    .stack (ORIGIN (RAM) + LENGTH(RAM)) :
>    {
>      PROVIDE (__stack = .);
>      *(.stack)
>    }
>
>    .MP430.attributes 0 :
>    {
>      KEEP (*(.MSP430.attributes))
>      KEEP (*(.gnu.attributes))
>      KEEP (*(__TI_build_attributes))
>    }
>
>    /* The rest are all not normally part of the runtime image.  */
>
>    /* Stabs debugging sections.  */
>    .stab          0 : { *(.stab) }
>    .stabstr       0 : { *(.stabstr) }
>    .stab.excl     0 : { *(.stab.excl) }
>    .stab.exclstr  0 : { *(.stab.exclstr) }
>    .stab.index    0 : { *(.stab.index) }
>    .stab.indexstr 0 : { *(.stab.indexstr) }
>    .comment       0 : { *(.comment) }
>    /* 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) }
>    /* 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) }
>    /DISCARD/ : { *(.note.GNU-stack) }
> }
>
> ==================================================
> Index: libgloss/msp430/msp430xl-sim.ld
>
> /*  Copyright (c) 2013 Red Hat Incorporated.
>      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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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.
>
> */
>
> /* Default linker script, for normal executables */
> OUTPUT_ARCH(msp430)
> ENTRY(_start)
>
> /* Do we need any of these for elf?
>     __DYNAMIC = 0;    */
>
> MEMORY {
> 	RAM (rx)     : ORIGIN = 0x00200, LENGTH = 0x0ee00
> 	LOWROM (w)    : ORIGIN = 0x0f000, LENGTH = 0x00800
> 	ROM (w)      : ORIGIN = 0x10000, LENGTH = 0x80000
> 	RESETVEC (w) : ORIGIN = 0x0fffe, LENGTH = 0x00002
> }
>
> SECTIONS
> {
>    .resetvec :
>    {
>      *(.resetvec)
>    } > RESETVEC
>
>    .rodata : {
>      . = ALIGN(2);
>      *(.plt)
>      *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*)
>      *(.rodata1)
>      *(.eh_frame_hdr)
>      KEEP (*(.eh_frame))
>      KEEP (*(.gcc_except_table)) *(.gcc_except_table.*)
>      PROVIDE (__preinit_array_start = .);
>      KEEP (*(.preinit_array))
>      PROVIDE (__preinit_array_end = .);
>      PROVIDE (__init_array_start = .);
>      KEEP (*(SORT(.init_array.*)))
>      KEEP (*(.init_array))
>      PROVIDE (__init_array_end = .);
>      PROVIDE (__fini_array_start = .);
>      KEEP (*(.fini_array))
>      KEEP (*(SORT(.fini_array.*)))
>      PROVIDE (__fini_array_end = .);
>      LONG(0); /* Sentinel.  */
>
>      /* gcc uses crtbegin.o to find the start of the constructors, so
>         we make sure it is first.  Because this is a wildcard, it
>         doesn't matter if the user does not actually link against
>         crtbegin.o; the linker won't look for a file to match a
>         wildcard.  The wildcard also means that it doesn't matter which
>         directory crtbegin.o is in.  */
>      KEEP (*crtbegin*.o(.ctors))
>
>      /* We don't want to include the .ctor section from from the
>         crtend.o file until after the sorted ctors.  The .ctor section
>         from the crtend file contains the end of ctors marker and it
>         must be last */
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .ctors))
>      KEEP (*(SORT(.ctors.*)))
>      KEEP (*(.ctors))
>
>      KEEP (*crtbegin*.o(.dtors))
>      KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
>      KEEP (*(SORT(.dtors.*)))
>      KEEP (*(.dtors))
>    } > ROM
>
>    .data : {
>      . = ALIGN(2);
>      PROVIDE (__datastart = .);
>
>      KEEP (*(.jcr))
>      *(.data.rel.ro.local) *(.data.rel.ro*)
>      *(.dynamic)
>
>      *(.data .data.* .gnu.linkonce.d.*)
>      KEEP (*(.gnu.linkonce.d.*personality*))
>      SORT(CONSTRUCTORS)
>      *(.data1)
>      *(.got.plt) *(.got)
>
>      /* We want the small data sections together, so single-instruction offsets
>         can access them all, and initialized data all before uninitialized, so
>         we can shorten the on-disk segment size.  */
>      . = ALIGN(2);
>      *(.sdata .sdata.* .gnu.linkonce.s.* D_2 D_1)
>
>      . = ALIGN(2);
>      _edata = .;
>      PROVIDE (edata = .);
>      PROVIDE (__dataend = .);
>    } > RAM AT>ROM
>
>    /* Note that crt0 assumes this is a multiple of two; all the
>       start/stop symbols are also assumed word-aligned.  */
>    PROVIDE(__romdatastart = LOADADDR(.data));
>    PROVIDE (__romdatacopysize = SIZEOF(.data));
>
>    .bss : {
>      . = ALIGN(2);
>      PROVIDE (__bssstart = .);
>      *(.dynbss)
>      *(.sbss .sbss.*)
>      *(.bss .bss.* .gnu.linkonce.b.*)
>      . = ALIGN(2);
>      *(COMMON)
>      . = ALIGN(2);
>      PROVIDE (__bssend = .);
>      _end = .;
>      PROVIDE (end = .);
>    } > RAM
>    PROVIDE (__bsssize = SIZEOF(.bss));
>
>    .stack (ORIGIN (RAM) + LENGTH(RAM)) :
>    {
>      PROVIDE (__stack = .);
>      *(.stack)
>    }
>
>    /* This is just for crt0.S */
>    .lowtext           :
>    {
>      PROVIDE (_start = .);
>      . = ALIGN(2);
>      *(.lowtext)
>    } > LOWROM
>    .text           :
>    {
>      . = ALIGN(2);
>      *(.text .stub .text.* .gnu.linkonce.t.* .text:*)
>      KEEP (*(.text.*personality*))
>      /* .gnu.warning sections are handled specially by elf32.em.  */
>      *(.gnu.warning)
>      *(.interp .hash .dynsym .dynstr .gnu.version*)
>      PROVIDE (__etext = .);
>      PROVIDE (_etext = .);
>      PROVIDE (etext = .);
>      . = ALIGN(2);
>      KEEP (*(.init))
>      KEEP (*(.fini))
>    } > ROM
>
>    /* The rest are all not normally part of the runtime image.  */
>
>    .MP430.attributes 0 :
>    {
>      KEEP (*(.MSP430.attributes))
>      KEEP (*(.gnu.attributes))
>      KEEP (*(__TI_build_attributes))
>    }
>
>    /* Stabs debugging sections.  */
>    .stab          0 : { *(.stab) }
>    .stabstr       0 : { *(.stabstr) }
>    .stab.excl     0 : { *(.stab.excl) }
>    .stab.exclstr  0 : { *(.stab.exclstr) }
>    .stab.index    0 : { *(.stab.index) }
>    .stab.indexstr 0 : { *(.stab.indexstr) }
>    .comment       0 : { *(.comment) }
>    /* 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) }
>    /* 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) }
>    /* DWARF 3 */
>    .debug_pubtypes 0 : { *(.debug_pubtypes) }
>    .debug_ranges   0 : { *(.debug_ranges) }
>    /* DWARF Extension.  */
>    .debug_macro    0 : { *(.debug_macro) }
>
>    /DISCARD/ : { *(.note.GNU-stack) }
> }
>
> ==================================================
> Index: libgloss/msp430/nosyscalls.S
>
> /* Copyright (c) 2012, 2013 Red Hat Incorporated.
>     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.
>
>       The name of Red Hat Incorporated may not 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 Red Hat
>     incorporated 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.  */
>
> /* Empty syscall definitions for when we run on real hardware.  */
>
> #include "../syscall.h"
> #include "memmodel.h"
> 	
> #define ENOSYS 88
>
> .macro	sc,a
> 	sc2 \a,\a
> .endm
> 	
> .macro	sc2,name,num
> 	.weak	\name
> 	.global	\name
> \name:
>          call_   #__errno
>          movx_   #ENOSYS, @R12
> 	MOV.W	#-1,R12
> 	ret_
> .endm
>
> 	.weak	exit
> 	.weak	_exit
> 	.global	exit
> 	.global	_exit
> exit:
> _exit:
> 	/* For some reason, the board fails to stop at a breakpoint
> 	   placed on top of a software breakpoint instruction.  */
> /*	MOV.B	#0,R3		; this is a software breakpoint instruction */
> 1:	br_	#1b
>
> #define SC(n) sc2 n,SYS_##n
>
> 	SC (open)
> 	SC (close)
> 	SC (read)
> /*	SC (write)*/
> 	SC (fstat)
> 	SC (lseek)
> 	SC (kill)
>
> 	.weak	isatty
> 	.global	isatty
> isatty:
> 	.weak	_isatty
> 	.global	_isatty
> _isatty:
> 	MOV	#1,R12
> 	ret_
> 	
> 	.weak	getpid
> 	.global	getpid
> getpid:
> 	MOV	#42,R12
> 	ret_
>
> ==================================================
> Index: libgloss/msp430/sbrk.c
>
> /*
>
> Copyright (c) 2013 Red Hat Incorporated.
> 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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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.
>
> */
>
> char *
> _sbrk (int adj)
> {
>    extern char    end[];		/* Defined in the linker script.  */
>    static char *  heap = end;
>    char *         rv = heap;
>    char *        sp = (char *) & sp;	/* Stack grows down, heap grows up...  */
>
>    if (heap + adj > sp)
>      {
> #define MESSAGE "Heap and stack collision\n"
>        write (1, MESSAGE, sizeof MESSAGE);
>        abort ();
>      }
>
>    heap += adj;
>    return rv;
> }
>
> char * sbrk (int) __attribute__((weak, alias ("_sbrk")));
>
> ==================================================
> Index: libgloss/msp430/syscalls.S
>
> /* Copyright (c) 2012, 2013 Red Hat Incorporated.
>     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.
>
>       The name of Red Hat Incorporated may not 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 Red Hat
>     incorporated 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.  */
>
> /* Be wary: the lower N bits of the *address* of the function
>     determines the syscall used by the simulator.  Thus, the addresses
>     listed here depend on the syscall numbers in ../syscalls.h.  */
>
> /* As per the MSP430x200 Family Users Guide, section 1.5, "An
>     instruction fetch from the address range 0x0000 - 0x01FF will reset
>     the device."  We take advantage of that to do syscalls in the
>     simulator, by trying to execute specific addresses in that range
>     and letting the simulator catch them while simulating the CALL
>     instruction.  In theory, this is an operation that the physical
>     hardware will never attempt to do, so it won't interfere with the
>     simulation's accuracy (i.e. we aren't abusing holes in the opcode
>     map, for example).  */
>
> #include "../syscall.h"
> #include "memmodel.h"
> 	
> .macro	sc,a
> 	sc2 \a,\a
> .endm
> 	
> .macro	sc2,name,num
> 	.weak	\name
> 	.global	\name
> 	\name = 0x180 + \num
> .endm
>
> #define SC(n) sc2 n,SYS_##n
>
> 	sc2	_exit,SYS_exit
> 	SC (exit)
> 	SC (open)
> 	SC (close)
> 	SC (read)
> /*	SC (write)*/
> 	SC (fstat)
> 	SC (lseek)
> 	SC (kill)
>
> 	.weak	isatty
> 	.global	isatty
> isatty:
> 	.weak	_isatty
> 	.global	_isatty
> _isatty:
> 	MOV	#1,R12
> 	ret_
> 	
> 	.weak	getpid
> 	.global	getpid
> getpid:
> 	MOV	#42,R12
> 	ret_
>
> ==================================================
> Index: libgloss/msp430/write.c
>
> /*
>
> Copyright (c) 2013 Red Hat Incorporated.
> 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.
>
>      The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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 <string.h>
>
> #include "cio.h"
>
> static int
> write_chunk (int fd, char *buf, int len)
> {
>    __CIOBUF__.length[0] = len;
>    __CIOBUF__.length[1] = len >> 8;
>    __CIOBUF__.parms[0] = CIO_WRITE;
>    __CIOBUF__.parms[1] = fd;
>    __CIOBUF__.parms[2] = fd >> 8;
>    __CIOBUF__.parms[3] = len;
>    __CIOBUF__.parms[4] = len >> 8;
>    memcpy (__CIOBUF__.buf, buf, len);
>
>    _libgloss_cio_hook ();
>
>    return __CIOBUF__.parms[0] + __CIOBUF__.parms[1] * 256;
> }
>
> #include <stdio.h>
>
> int
> write (int fd, char *buf, int len)
> {
>    int rv = 0;
>    int c;
> #if 0
>    if (fd == 2)
>      fprintf (stderr, "%.*s", buf, len);
>    else if (fd == 1)
>      printf ("%.*s", buf, len);
> #endif
>    while (len > 0)
>      {
>        int l = (len > CIO_BUF_SIZE) ? CIO_BUF_SIZE : len;
>        c = write_chunk (fd, buf, l);
>        if (c < 0)
> 	return c;
>        rv += l;
>        len -= l;
>        buf += l;
>      }
>    return c;
> }
>



More information about the Newlib mailing list