🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #54284

Recipe for a sparc to mc68010 cross compiler

#54284
From: Thomas J. Trebisky
Date: Mon, 26 Nov 1990 19:44
301 lines
14011 bytes
GCC sparc to 68010 cross compiler, Part I

About a week ago, I advertised that I was having good results running
gcc on a sparc host to produce code for a 68010.  Quite a number of people
have responded with interest, so I thought I would post the recipe.
This is simply the way I did it, you may have other and better ideas
about how to do things, suit yourself.  That all of this works with so few
changes is a is a real tribute to the job the GNU people did writing good
portable code.

I did all this back in August, but I have done my best to dredge out my
notes.  I based what I did on the gcc 1.35 release, and gas 1.35, both of
which are available in newer versions now. I haven't had time to fit my
changes to the newer releases, but I don't think that will be much trouble.
At the time I did this, I was running Sun-OS 4.0.1, now am on 4.1;
no telling what difference that will make, but my old executables still run
just fine.  I did get the latest release of binutils and apply my hacks to
that version of the tools.

What I am doing is using my Sparcstation to compile and link code to run
on a standalone 68010 board. I have no intention to link against the sun2
libraries. (I insist on having source code for everything that runs on the
other machine.  In particular I don't (and can't) rely upon the local cc to
generate gnulib, but have written the necessary routines in assembly language.

Anyway here is the recipe, this post tells how to build xgcc and xas68,
I will put the recipe for xld in a separate posting, very soon to follow.

(1) First step, get the latest release (or whatever release you like) of gcc
for the sparc and install it as per the standard instructions. While you are
getting, get the archive for gas and binutils as well.  I installed the sparc
native "gas", but I suppose you could use "as" if you like (?).

(2) Suit yourself on this one, I edited gcc.c to alter STANDARD_EXEC_PREFIX
to be /my/directory/bin.sun4/gcc-  I am not installing gcc for public use
at our site, and don't want to type -B/pathname everywhere.
(You can do this from the Makefile, rather that fiddling with the source)
After doing this, the native gcc works fine without the -B switch.

(3) Again, suit yourself on what follows, I edited gcc.c so when invoked
as gcc, it runs the native compiler, and when invoked as xgcc it runs
the cross compiler pieces (xcc1,xcpp,xas68,xld) rather than the native
pieces (cc1,cpp,as68,ld).  I suspect cpp and xcpp are identical, but have
not checked. The diff for this is rather bulky, so I have put it at the end
of this posting as an appendix.
I put all my source code hacking conditional on CROSS and added -DCROSS
to the Makefile.

(4) I pondered different ways to do this, but this works.  Edit config.gcc
and add a new target type. I called it "cross" which is not too unique or
descriptive, as follows:
< 		;;
< 	cross )			# to compile for sun2 on a sparc
< 		cpu_type=m68k
< 		configuration_file=xm-sunos4.h
< 		target_machine=tm-sun2.h

(5) I edited Makefile, making the following changes:
<#CC = cc
< CC = gcc
<#libdir = $(prefix)/usr/local/lib
##(I wanted everything in one place)
< libdir = /my/directory/bin.sun4
<#	./move-if-change tmp-insn-config.h insn-config.h
< 	./move-if-change "tmp-insn-config.h" "insn-config.h"
<#	./move-if-change tmp-insn-flags.h insn-flags.h
< 	./move-if-change "tmp-insn-flags.h" "insn-flags.h"
<#	./move-if-change tmp-insn-codes.h insn-codes.h
< 	./move-if-change "tmp-insn-codes.h" "insn-codes.h"
<#	./move-if-change tmp-insn-emit.c insn-emit.c
< 	./move-if-change "tmp-insn-emit.c" "insn-emit.c"
<#	./move-if-change tmp-insn-recog.c insn-recog.c
< 	./move-if-change "tmp-insn-recog.c" "insn-recog.c"
<#	./move-if-change tmp-insn-extract.c insn-extract.c
< 	./move-if-change "tmp-insn-extract.c" "insn-extract.c"
<#	./move-if-change tmp-insn-peep.c insn-peep.c
< 	./move-if-change "tmp-insn-peep.c" "insn-peep.c"
<#	./move-if-change tmp-insn-output.c insn-output.c
< 	./move-if-change "tmp-insn-output.c" "insn-output.c"
I don't know (or care) why the quotes are needed on the script invocations,
this problem may have evaporated in new releases of various things. Anyhow,
who cares, I put the quotes on, it wouldn't work without them. (It sure was
a pain in the gazoona figuring out they were needed though.)

(6) Now you are ready to go, I would do a "make clean", "config.gcc cross"
and then "make", and stand back.

(7) Put the compiler pieces where they belong.  I didn't actually do it,
but you might add a line to the Makefile like this:

<xinstall: all
<	-mkdir $(libdir)
<	-if [ -f cc1 ] ; then $(INSTALL) cc1 $(libdir)/gcc-xcc1 ;fi
<	$(INSTALL) gnulib $(libdir)/gcc-xgnulib
<	-if [ -f /usr/bin/ranlib ] ; then (cd $(libdir); ranlib gcc-xgnulib) ;fi
<	$(INSTALL) cpp $(libdir)/gcc-xcpp
<	$(INSTALL) gcc $(libdir)/xgcc

(8) unpack the gas archive, edit the Makefile to make CC=gcc.
One thing you might do is to #include your own a.out.h file to be compatible
with the way you build xld.
Now do a "make a68"  (Wish everything was that easy!!).
Put this in it's place via:	"mv a68 /my/directory/bin.sun4/xas68"
You can run this on it's own using "xas68 -mc68010". Without the -mc68010
switch, it will generate 68020 branch instructions (bsr becomes bsrl) and the
68010 won't be happy trying to execute them. The -mc68010 switch makes these
a nice jsr to an external symbol.  Also this switch sets the proper
machine type in the a.out header (which is good with the new xld).
Never mind what the FSF document says about the switch not doing much.

(9) When you are all done, the contents of /my/directory/bin.sun4 should
be as follows (more or less)
gcc
gcc-cc1
gcc-cpp
gcc-gnulib	[see Part II]
gcc-include
gcc-xcc1
gcc-xcpp
gcc-xgnulib
nm	(optional) [see Part II]
size	(optional) [see Part II]
strip	(optional) [see Part II]
xas68
xgcc	(could be a link to gcc)
xld	[see Part II]

Of course you then want to put /my/directory/bin.sun4 on your search path.

(10) Recipes for xld and other parts of binutils to follow in separate post.

=========================================================================

APPENDIX A -- my hacking of gcc.c


diff -r gcc-1.35/gcc.c mygcc-1.35/gcc.c
118a119,123
< /* tjt added this option 7/31/90 to activate some special
<  * tricks to run cross-compiler pieces.
<  */
< #define CROSS
< 
224a230,345
< #ifdef CROSS
< /* normal sequence */
< struct compiler ncompilers[] =
< {
<   {".c",
<    "cpp %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} %{trigraphs} -undef \
<         -D__GNUC__ %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!ansi:%p} %P\
<         %c %{O:-D__OPTIMIZE__} %{traditional} %{pedantic}\
< 	%{Wcomment*} %{Wtrigraphs} %{Wall} %C\
<         %i %{!M*:%{!E:%{!pipe:%g.cpp}}}%{E:%{o*}}%{M*:%{o*}} |\n\
<     %{!M*:%{!E:cc1 %{!pipe:%g.cpp} %1 \
< 		   %{!Q:-quiet} -dumpbase %i %{Y*} %{d*} %{m*} %{f*} %{a}\
< 		   %{g} %{O} %{W*} %{w} %{pedantic} %{ansi} %{traditional}\
< 		   %{v:-version} %{gg:-symout %g.sym} %{pg:-p} %{p}\
< 		   %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
< 		   %{S:%{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
<               %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
< 		      %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
<                       %{!pipe:%g.s}\n }}}"},
<   {".cc",
<    "cpp -+ %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} \
<         -undef -D__GNUC__ %p %P\
<         %c %{O:-D__OPTIMIZE__} %{traditional} %{pedantic}\
< 	%{Wcomment*} %{Wtrigraphs} %{Wall} %C\
<         %i %{!M*:%{!E:%{!pipe:%g.cpp}}}%{E:%{o*}}%{M*:%{o*}} |\n\
<     %{!M*:%{!E:cc1plus %{!pipe:%g.cpp} %1\
< 		   %{!Q:-quiet} -dumpbase %i %{Y*} %{d*} %{m*} %{f*} %{a}\
< 		   %{g} %{O} %{W*} %{w} %{pedantic} %{traditional}\
< 		   %{v:-version} %{gg:-symout %g.sym} %{pg:-p} %{p}\
< 		   %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
< 		   %{S:%{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
<               %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
< 		      %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
<                       %{!pipe:%g.s}\n }}}"},
<   {".i",
<    "cc1 %i %1 %{!Q:-quiet} %{Y*} %{d*} %{m*} %{f*} %{a}\
< 	%{g} %{O} %{W*} %{w} %{pedantic} %{ansi} %{traditional}\
< 	%{v:-version} %{gg:-symout %g.sym} %{pg:-p} %{p}\
< 	%{S:%{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
<     %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
<             %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %{!pipe:%g.s}\n }"},
<   {".s",
<    "%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
<             %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %i\n }"},
<   {".S",
<    "cpp %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} %{trigraphs} \
<         -undef -D__GNUC__ -$ %p %P\
<         %c %{O:-D__OPTIMIZE__} %{traditional} %{pedantic}\
< 	%{Wcomment*} %{Wtrigraphs} %{Wall} %C\
<         %i %{!M*:%{!E:%{!pipe:%g.cpp}}}%{E:%{o*}}%{M*:%{o*}} |\n\
<     %{!M*:%{!E:%{!S:as %{R} %{j} %{J} %{h} %{d2} %a \
<                     %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
< 		    %{!pipe:%g.s}\n }}}"},
<   /* Mark end of table */
<   {0, 0}
< };
< 
< /* cross - compilation sequence */
< struct compiler xcompilers[] =
< {
<   {".c",
<    "xcpp %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} %{trigraphs} -undef \
<         -D__GNUC__ %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!ansi:%p} %P\
<         %c %{O:-D__OPTIMIZE__} %{traditional} %{pedantic}\
< 	%{Wcomment*} %{Wtrigraphs} %{Wall} %C\
<         %i %{!M*:%{!E:%{!pipe:%g.cpp}}}%{E:%{o*}}%{M*:%{o*}} |\n\
<     %{!M*:%{!E:xcc1 %{!pipe:%g.cpp} %1 \
< 		   %{!Q:-quiet} -dumpbase %i %{Y*} %{d*} %{m*} %{f*} %{a}\
< 		   %{g} %{O} %{W*} %{w} %{pedantic} %{ansi} %{traditional}\
< 		   %{v:-version} %{gg:-symout %g.sym} %{pg:-p} %{p}\
< 		   %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
< 		   %{S:%{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
<               %{!S:xas68 %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
< 		      %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
<                       %{!pipe:%g.s}\n }}}"},
<   {".cc",
<    "xcpp -+ %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} \
<         -undef -D__GNUC__ %p %P\
<         %c %{O:-D__OPTIMIZE__} %{traditional} %{pedantic}\
< 	%{Wcomment*} %{Wtrigraphs} %{Wall} %C\
<         %i %{!M*:%{!E:%{!pipe:%g.cpp}}}%{E:%{o*}}%{M*:%{o*}} |\n\
<     %{!M*:%{!E:xcc1plus %{!pipe:%g.cpp} %1\
< 		   %{!Q:-quiet} -dumpbase %i %{Y*} %{d*} %{m*} %{f*} %{a}\
< 		   %{g} %{O} %{W*} %{w} %{pedantic} %{traditional}\
< 		   %{v:-version} %{gg:-symout %g.sym} %{pg:-p} %{p}\
< 		   %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
< 		   %{S:%{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
<               %{!S:xas68 %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
< 		      %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
<                       %{!pipe:%g.s}\n }}}"},
<   {".i",
<    "xcc1 %i %1 %{!Q:-quiet} %{Y*} %{d*} %{m*} %{f*} %{a}\
< 	%{g} %{O} %{W*} %{w} %{pedantic} %{ansi} %{traditional}\
< 	%{v:-version} %{gg:-symout %g.sym} %{pg:-p} %{p}\
< 	%{S:%{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
<     %{!S:xas68 %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
<             %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %{!pipe:%g.s}\n }"},
<   {".s",
<    "%{!S:xas68 %{R} %{j} %{J} %{h} %{d2} %a \
<             %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %i\n }"},
<   {".S",
<    "xcpp %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} %{trigraphs} \
<         -undef -D__GNUC__ -$ %p %P\
<         %c %{O:-D__OPTIMIZE__} %{traditional} %{pedantic}\
< 	%{Wcomment*} %{Wtrigraphs} %{Wall} %C\
<         %i %{!M*:%{!E:%{!pipe:%g.cpp}}}%{E:%{o*}}%{M*:%{o*}} |\n\
<     %{!M*:%{!E:%{!S:xas68 %{R} %{j} %{J} %{h} %{d2} %a \
<                     %{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
< 		    %{!pipe:%g.s}\n }}}"},
<   /* Mark end of table */
<   {0, 0}
< };
< 
< struct compiler *compilers = ncompilers;	/* normal by default */
< 
< #else
278a400
< #endif
280a403,413
< #ifdef CROSS
< char *link_spec;
< char *nlink_spec = "%{!c:%{!M*:%{!E:%{!S:ld %{o*} %l\
<  %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
<  %{y*} %{!nostdlib:%S} \
<  %{L*} %o %{!nostdlib:gnulib%s %{g:-lg} %L}\n }}}}";
< char *xlink_spec = "%{!c:%{!M*:%{!E:%{!S:xld %{o*} %l\
<  %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
<  %{y*} %{!nostdlib:%S} \
<  %{L*} %o %{!nostdlib:gnulib%s %{g:-lg} %L}\n }}}}";
< #else
284a418,419
< #endif
< 
445a581,589
< #ifdef CROSS
< /* order of search is:
< 	user (-Boption), env, std, std_1 */
< #ifdef sparc
< #define STANDARD_EXEC_PREFIX "/u/tom/bin.sun4/gcc-"
< #else
< #define STANDARD_EXEC_PREFIX "/u/tom/bin.sun3/gcc-"
< #endif
< #else
446a591
< #endif
1468a1614,1621
< #ifdef CROSS
<   link_spec = nlink_spec;
<   /* no special pains here to strip leading pathname stuff */
<   if ( !strcmp(programname,"xgcc") ) {
<     compilers = xcompilers;
<     link_spec = xlink_spec;
<   }
< #endif

THE END:		ttrebisky@as.arizona.edu
Technical Details
Message-ID: <529@organpipe.UUCP>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!sunic!uupsi!cmcl2!yale!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!ncar!noao!amethyst!organpipe!as.arizona.edu

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,ef458b319906db00,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1990-11-26 11:44:32 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!sunic!uupsi!cmcl2!yale!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!ncar!noao!amethyst!organpipe!as.arizona.edu
From: ttrebisky@as.arizona.edu (Thomas J. Trebisky)
Newsgroups: gnu.gcc.help
Subject: Recipe for a sparc to mc68010 cross compiler
Keywords: sparc cross-compiler 68010 ld
Message-ID: <529@organpipe.UUCP>
Date: 26 Nov 90 19:44:32 GMT
Sender: news@organpipe.UUCP
Organization: University of Arizona, Tucson, AZ
Lines: 301
Posted: Mon Nov 26 20:44:32 1990