Article View: gnu.gcc.help
Article #54285Recipe for a sparc to mc68010 cross compiler
From: Thomas J. Trebisky
Date: Mon, 26 Nov 1990 19:48
Date: Mon, 26 Nov 1990 19:48
177 lines
6329 bytes
6329 bytes
GCC sparc to 68010 cross compiler, Part II
This is a companion to a prior post telling how to build the gnu as68 and
gcc to do cross compiling. Part II of the story is how to build the cross ld,
and some of the other binutils.
Here is the recipe to do it:
(1) Decide what you want to use for a.out.h. On my system the sun2 and sun3
a.out.h files are the same, so I use /usr/include/sun3/a.out.h; the GNU
binutils archive provides one as well, suit yourself.
What is important is that xas68 and xld both produce compatible a.out
files, and that they are suitable for whatever you intend to do with them.
(What I do is run a little utility to extract the text and data and write
it to a floppy disk in a fashion that the boot roms for my target system
are happy with).
A typical Makefile I use looks like this:
<CFLAGS= -mc68000 ${INCPATH} ${COPTS}
<COPTS= -DSTANDALONE
<
<MCC = xgcc
<MAS = xas68 -mc68010
<MLD = xld
<MCLIB = /u/tom/bin.sun4/gcc-xgnulib
<
<RELOC= 70000
<BOOT_LOC = 70000
<
<.c.o:
< ${MCC} ${CFLAGS} -c $*.c
<
<# this one is really assembly language source
<srt0.o: srt0.c
< $(MCC) -E -DRELOC=0x${RELOC} ${COPTS} srt0.c >srt0.s
< $(MAS) srt0.s -o srt0.o
<
<floppy: floppy.o srt0.o
< $(MLD) -N -T $(BOOT_LOC) -o floppy -s srt0.o floppy.o $(MCLIB)
(2) Get binutils.tar.Z, uncompress it and extract the files with tar.
(3) I made the following changes to the binutils Makefile.
<# tjt - use gcc
<#GNUCC = gcc -O
<CC = gcc -O
<
<# tjt - note, COMPILE.c was never in this Makefile
<# tjt - I am using sun's make, and I get tired of hearing about -target, so:
<#COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -target $(TARGET_ARCH:-%=%) -c
<COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
<
<# these lines added by tjt (for xld.o and xld)
<xld.o: ld.c
< $(CC) -o xld.o -c $(CFLAGS) -DCROSS -DCROSS_LINKER ld.c $(OUTPUT_OPTION)
<
<xld: xld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM)
< $(CC) $(CFLAGS) -o xld xld.o $(GNU_GETOPT_LONG) $(CPLUS_DEM) $(LIBS)
<
<xinstall: xld
< cp xld /u/tom/bin.sun4/xld
(4) Edit ld.c, making the following changes (Hope you can find these by context)
(a) First I include my choice of a.out file.
(I have ratholed copies of /usr/include/*.* in case some day Sun makes
changes that I don't like - at any point of time I can regenerate my
software, irregardless of what Sun does.)
<#ifdef A_OUT
<#ifdef COFF_ENCAPSULATE
<#include "a.out.encap.h"
<#else
<#ifdef CROSS
<#include "../sun_include/sun3/a.out.h"
<#else
<#include <a.out.h>
<#endif
<#endif
<#endif
(b) I make sure the machine type gets set right in the a.out header.
(I like the idea of getting this from the input *.o files.)
</* Define how to initialize system-dependent header fields. */
<#ifdef sun
<#ifdef sparc
<#ifndef CROSS
<#define INITIALIZE_HEADER \
< {outheader.a_machtype = M_SPARC; outheader.a_toolversion = 1;}
<#endif
<#endif /* sparc. */
<#if defined(mc68000) || defined(CROSS)
</* Set the machine type according to the machine type of the .o files.
< If they are all sun2 (68010), then the type of the executable is sun2.
< If any is sun3 (68020), then the type of the executable is sun3.
< This is consistent with the Sun loader and more useful than having
< it depend on which machine you are on when you run ld. */
<static int sun_machtype = M_68010;
<#define INITIALIZE_HEADER outheader.a_machtype = sun_machtype
<#define READ_HEADER_HOOK(machtype) \
< if (machtype == M_68020) \
< { \
< sun_machtype = M_68020; \
< }
<#endif /* mc68000. */
<#endif /* Sun. */
(c) I avoid the sparc-specific relocation macros and stuff.
<#if defined(sun) && defined(sparc)
<#ifndef CROSS
</* Sparc (Sun 4) macros */
<#undef relocation_info
<#define relocation_info reloc_info_sparc
<#define RELOC_ADDRESS(r) ((r)->r_address)
<#define RELOC_EXTERN_P(r) ((r)->r_extern)
<.....
<..... numerous lines deleted here ......
<.....
<static int reloc_target_bitsize[] = {
< 8, 16, 32, 8, 16, 32, 30, 22, 22, 22, 13, 10, 32, 32, 16,
<};
<
<#define MAX_ALIGNMENT (sizeof (double))
<#endif /* not CROSS */
<#endif /* (sun) and (sparc) */
<>#endif
(d) I avoid the sun DYNAMIC business - something to do with their shared
libraries I believe.
<#ifdef sun
<#ifndef CROSS
< {
< symbol *dynamic_symbol;
< symbol_define ("__DYNAMIC", N_ABS | N_EXT, &dynamic_symbol);
< if (dynamic_symbol)
< dynamic_symbol->value = 0;
< }
<#endif
<#endif
(e) One last thing is to set the page size in the target images.
(at this time I am not generating demand paged images, so this doesn't
really matter)
<#if defined(sun) && defined(sparc)
<int
<getpagesize ()
<{
<#ifdef CROSS
< return 4096;
<#else
< return 8192;
<#endif
<}
<#endif
(5) make xld and make xinstall and you should be on the air.
(6) nm, strip, and size are trivial to rebuild, I added a conditional
as for ld to include my chosen a.out.h file.
(7) The main remaining problem is to generate gnulib. What I am doing
is to write those routines I actually need in assembly language. So far
this has been udivsi3 and umodsi3. When ld starts griping about the ones
I haven't written I will worry about them. (I don't want to think about
floating point, and probably won't for a long time.) If you have sun2
libraries that might do the trick for you.
Of course, you also need your own assembly language startup routine.
If there is sufficient interest I can post these sources.
THE END: ttrebisky@as.arizona.edu (The Internet)
Technical Details
Message-ID:
<530@organpipe.UUCP>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!sunic!uupsi!cmcl2!yale!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!ncar!noao!amethyst!organpipe!as.arizona.eduShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,ef458b319906db00 X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1990-11-26 11:48:32 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!sunic!uupsi!cmcl2!yale!cs.utexas.edu!sdd.hp.com!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: <530@organpipe.UUCP> Date: 26 Nov 90 19:48:32 GMT Sender: news@organpipe.UUCP Organization: University of Arizona, Tucson, AZ Lines: 177 Posted: Mon Nov 26 20:48:32 1990