From: Alan Modra Date: Thu, 11 Jan 2007 06:24:40 +0000 (+0000) Subject: * embedspu.sh: New file. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=669a9a2af6922f748d451486770ea70ce02385ba;p=binutils-gdb.git * embedspu.sh: New file. * Makefile.am (embedspu): Add rule. * configure.in (BUILD_MISC): Add embedspu for powerpc-linux. * Makefile.in: Regenerate. * configure: Regenerate. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index f5d49e452b4..679da1c4860 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,11 @@ +2007-01-11 Alan Modra + + * embedspu.sh: New file. + * Makefile.am (embedspu): Add rule. + * configure.in (BUILD_MISC): Add embedspu for powerpc-linux. + * Makefile.in: Regenerate. + * configure: Regenerate. + 2007-01-11 Alan Modra * bucomm.h (make_tempdir): Declare independently of HAVE_MKDTEMP. diff --git a/binutils/Makefile.am b/binutils/Makefile.am index 5aaf72fd929..298908303e1 100644 --- a/binutils/Makefile.am +++ b/binutils/Makefile.am @@ -277,6 +277,10 @@ sysinfo.o: $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) $(srcdir)/sysinfo.c -Wno-error ; \ fi +embedspu: embedspu.sh + sed "s@^program_transform_name=@program_transform_name=$(program_transform_name)@" < $< > $@ + chmod a+x $@ + # We need these for parallel make. arparse.h: arparse.c defparse.h: defparse.c diff --git a/binutils/Makefile.in b/binutils/Makefile.in index cc70931f1e5..02d568bced6 100644 --- a/binutils/Makefile.in +++ b/binutils/Makefile.in @@ -237,7 +237,6 @@ GENCAT = @GENCAT@ GENINSRC_NEVER_FALSE = @GENINSRC_NEVER_FALSE@ GENINSRC_NEVER_TRUE = @GENINSRC_NEVER_TRUE@ GMSGFMT = @GMSGFMT@ -GREP = @GREP@ HDEFINES = @HDEFINES@ INCINTL = @INCINTL@ INSTALL_DATA = @INSTALL_DATA@ @@ -284,8 +283,9 @@ VERSION = @VERSION@ WARN_CFLAGS = @WARN_CFLAGS@ XGETTEXT = @XGETTEXT@ YACC = `if [ -f ../bison/bison ]; then echo ../bison/bison -y -L$(srcdir)/../bison/; else echo @YACC@; fi` -YFLAGS = -d ac_ct_CC = @ac_ct_CC@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ am__include = @am__include@ @@ -302,7 +302,6 @@ build_vendor = @build_vendor@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ -dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ @@ -315,15 +314,12 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ -localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ -psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ sysconfdir = @sysconfdir@ @@ -335,6 +331,7 @@ target_vendor = @target_vendor@ AUTOMAKE_OPTIONS = cygnus dejagnu SUBDIRS = doc po tooldir = $(exec_prefix)/$(target_alias) +YFLAGS = -d AM_CFLAGS = $(WARN_CFLAGS) # these two are almost the same program @@ -1033,6 +1030,10 @@ sysinfo.o: $(CC_FOR_BUILD) -c -I. $(AM_CFLAGS) $(CFLAGS) $(srcdir)/sysinfo.c -Wno-error ; \ fi +embedspu: embedspu.sh + sed "s@^program_transform_name=@program_transform_name=$(program_transform_name)@" < $< > $@ + chmod a+x $@ + # We need these for parallel make. arparse.h: arparse.c defparse.h: defparse.c diff --git a/binutils/configure b/binutils/configure index fd0d32b0d9b..30ff85862b0 100755 --- a/binutils/configure +++ b/binutils/configure @@ -8679,6 +8679,9 @@ do DLLTOOL_DEFS="$DLLTOOL_DEFS -DDLLTOOL_PPC" BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)' ;; + powerpc*-*-linux* | powerpc*-*-elf*) + BUILD_MISC=embedspu + ;; sh*-*-pe) BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)' DLLTOOL_DEFS="$DLLTOOL_DEFS -DDLLTOOL_SH" diff --git a/binutils/configure.in b/binutils/configure.in index 40369530a05..383dbcdae10 100644 --- a/binutils/configure.in +++ b/binutils/configure.in @@ -296,6 +296,9 @@ changequote([,])dnl DLLTOOL_DEFS="$DLLTOOL_DEFS -DDLLTOOL_PPC" BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)' ;; + powerpc*-*-linux* | powerpc*-*-elf*) + BUILD_MISC=embedspu + ;; sh*-*-pe) BUILD_DLLTOOL='$(DLLTOOL_PROG)$(EXEEXT)' DLLTOOL_DEFS="$DLLTOOL_DEFS -DDLLTOOL_SH" diff --git a/binutils/embedspu.sh b/binutils/embedspu.sh new file mode 100644 index 00000000000..b3f8a89ab13 --- /dev/null +++ b/binutils/embedspu.sh @@ -0,0 +1,187 @@ +#! /bin/sh +# Embed an SPU ELF executable into a PowerPC object file. +# +# Copyright 2006 Free Software Foundation, Inc. +# +# This file is part of GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. + +usage () +{ + echo "Usage: embedspu [flags] symbol_name input_filename output_filename" + echo + echo " input_filename: SPU ELF executable to be embedded" + echo " output_filename: Resulting PowerPC object file" + echo " symbol_name: Name of program handle struct to be defined" + echo " flags: GCC flags defining PowerPC object file format" + echo " (e.g. -m32 or -m64)" + exit 1 +} + +program_transform_name= +mydir=`dirname "$0"` + +find_prog () +{ + prog=`echo $1 | sed "$program_transform_name"` + which $prog > /dev/null 2> /dev/null && return 0 + prog="$mydir/$prog" + test -x "$prog" && return 0 + prog="$mydir/$1" + test -x "$prog" && return 0 + prog=`echo $1 | sed "$program_transform_name"` + return 1 +} + +SYMBOL= +INFILE= +OUTFILE= +FLAGS= + +parse_args () +{ + while test -n "$1"; do + case "$1" in + -*) FLAGS="${FLAGS} $1" ;; + *) if test -z "$SYMBOL"; then + SYMBOL="$1" + elif test -z "$INFILE"; then + INFILE="$1" + elif test -z "$OUTFILE"; then + OUTFILE="$1" + else + echo "Too many arguments!" + usage + fi ;; + esac + shift + done + if test -z "$OUTFILE"; then + usage + fi + if test ! -r "$INFILE"; then + echo "${INFILE}: File not found" + usage + fi +} + +main () +{ + parse_args "$@" + + # Find a powerpc gcc. Support running from a combined tree build. + if test -x "$mydir/../gcc/xgcc"; then + CC="$mydir/../gcc/xgcc -B$mydir/../gcc/" + else + find_prog gcc + if test $? -ne 0; then + echo "Cannot find $prog" + exit 1 + fi + CC="$prog" + fi + + # Find readelf. Any old readelf should do. We only want to read syms. + find_prog readelf + if test $? -ne 0; then + if which readelf > /dev/null 2> /dev/null; then + prog=readelf + else + echo "Cannot find $prog" + exit 1 + fi + fi + READELF="$prog" + + # Sanity check the input file + if ! ${READELF} -h ${INFILE} | grep 'Class:.*ELF32' >/dev/null 2>/dev/null \ + || ! ${READELF} -h ${INFILE} | grep 'Type:.*EXEC' >/dev/null 2>/dev/null \ + || ! ${READELF} -h ${INFILE} | egrep 'Machine:.*(SPU|17)' >/dev/null 2>/dev/null + then + echo "${INFILE}: Does not appear to be an SPU executable" + exit 1 + fi + + # Build embedded SPU image. + # 1. The whole SPU ELF file is written to .rodata.speelf + # 2. Symbols starting with the string "_EAR_" in the SPU ELF image are + # special. They allow an SPU program to access corresponding symbols + # (ie. minus the _EAR_ prefix), in the PowerPC program. _EAR_ without + # a suffix is used to refer to the addrress of the SPU image in + # PowerPC address space. _EAR_* symbols must all be defined in one + # section at 16 byte intervals. + # Find all _EAR_ symbols using readelf, sort by address, and write + # the address of the corresponding PowerPC symbol in a table built + # in .data.spetoe. + # 3. Write a struct spe_program_handle to .data. + ${CC} ${FLAGS} -x assembler-with-cpp -nostartfiles -nostdlib \ + -Wa,-mbig -Wl,-r -Wl,-x -o ${OUTFILE} - <