jason miller spring '10

Post on 03-Jul-2022

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Building a cross compiler.

Jason MillerSpring '10

Source: Your PC

Target: Linksys WRT54G● 216 MHz MIPS­32 processor

● 16 MB RAM

● 4 MB Flash Memory

● 1 802.11B/G wireless interface

● 5 100Mbs ethernet ports 

Courtesy www.tomsguide.com

The processors

X86 MIPS

Designer Intel / AMD MIPS Computer SystemsDesign CISC RISC

Bits 16,32,64 32,64Little Bi

Type Register-Memory Register-RegisterEndian *

The operating systems

● Fedora Core 9  Linux

● Kernel 2.6.27.25­78.2.56.fc9.x86_64 #1 SMP

● OpenWrt Linux

● Kernel 2.6.25.20 #4

The compiler

Courtesy http://www.acm.uiuc.edu/sigmil/RevEng/ch02.html

● The Gnu Compiler Collection

● Includes front ends for C, C++, Objective­C, Fortran, Java, Ada, and associated libraries

● A 5­stage compiler (preprocessing, parsing, translation, assembly, linkage)

What do we need?● The obvious answer is that we need a version of the GCC C compiler that can 

run on x86 hardware and can output machine code for the MIPS hardware.

● The not­so­obvious addendum to that is that, since we are writing software for an embedded device, we need to keep the machine code as small as possible.

● Having said that, we decide to use Newlib (http://sourceware.org/newlib/).  It is a drop­in replacement for libc (the C standard library) that is specifically designed to provide a functional subset of capability on platforms with extremely limited resources.  This includes many different embedded devices as well as software environments such as Cygwin.  

The conundrum● In order to build our required version of GCC, we 

need to have an already­built version of Newlib to link against.

● However, in order to build Newlib, we need a working version of our compiler that can output code for our target platform.

What ever shall we do?

The givensA natively-built x86 C compiler (provided by the GCC package as part of the Fedora linux distribution)

A natively-built x86 assembler (provided by the GCC package as part of the Fedora linux distribution)

The source code for the GCC C compiler (from http://gcc.gnu.org)

The source code for the binutils assembler (from http://www.gnu.org/software/binutils/)

The bootstrap

*

*

*

* Configured before compilation

Building the MIPS assembler.

Building the MIPS assembler.

Building the MIPS compiler.

Newlib

Our compiler/assembler from the last step.

Re­build GCCWe need to re-build GCC and have it link against the Newlib that we just built.

The codemain.c

foo.c

bar.c

*

*

*

The Makefile*

Demo timeThings to do:

● Build the test program● What can 'file' tell us about the programs?● Run them both on x86. What happens?● Deploy to and run on the WRT● Look at the intermediate output files

top related