Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| mips_cross_compiler [2013/05/07 08:56] – moved instructions from virtual_cae beckmanf | mips_cross_compiler [2014/06/04 17:52] (current) – simple project added beckmanf | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| < | < | ||
| - | sudo apt-get install build-essential m4 texinfo libncurses5-dev | + | sudo apt-get install build-essential m4 texinfo libncurses5-dev |
| </ | </ | ||
| Line 78: | Line 78: | ||
| # -e => exit on error | # -e => exit on error | ||
| # -v => verbose output | # -v => verbose output | ||
| - | |||
| - | # YOU MUST APPEND 91Âþ»T to your .profile file | ||
| - | # export PATH=$HOME/ | ||
| # Mips Cross Compiler | # Mips Cross Compiler | ||
| Line 93: | Line 90: | ||
| mkdir -p mips/orig | mkdir -p mips/orig | ||
| - | # Set the destination | + | # Set the destinationÌý |
| - | export MYMIPS=$HOME/ | + | export MYMIPS=${HOME}/site |
| # Versions | # Versions | ||
| - | GMPVERSION=4.3.2 | + | GMPVERSION="4.3.2" |
| PPLVERSION=" | PPLVERSION=" | ||
| - | BINUTILSVERSION=" | + | BINUTILSVERSION=" |
| MPFRVERSION=" | MPFRVERSION=" | ||
| - | MPCVERSION=" | + | MPCVERSION=" |
| - | ISLVERSION=" | + | ISLVERSION=" |
| - | CLOOGVERSION=" | + | CLOOGVERSION=" |
| - | GCCVERSION=" | + | GCCVERSION=" |
| NEWLIBVERSION=" | NEWLIBVERSION=" | ||
| GDBVERSION=" | GDBVERSION=" | ||
| + | |||
| + | |||
| + | ######################################## | ||
| + | # Binutils | ||
| + | ######################################## | ||
| # Get the archives | # Get the archives | ||
| cd mips/ | cd mips/ | ||
| - | if [ ! -e "gmp-4.3.2.tar.bz2" | + | if [ ! -e "binutils-${BINUTILSVERSION}.tar.bz2" |
| - | wget http://ftp.halifax.rwth-aachen.de/gnu/gmp/gmp-4.3.2.tar.bz2 | + | wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVERSION}.tar.bz2 |
| fi | fi | ||
| # Unpack to source directory | # Unpack to source directory | ||
| cd ../src | cd ../src | ||
| - | if [ ! -d "gmp-4.3.2" ] ; thenÌý | + | if [ ! -d "binutils-${BINUTILSVERSION}" ] ; thenÌý |
| - | tar -xjvf ../orig/gmp-4.3.2.tar.bz2 | + | tar -xvjf ../orig/binutils-${BINUTILSVERSION}.tar.bz2 |
| fi | fi | ||
| - | # Build | ||
| cd ../build | cd ../build | ||
| - | mkdir -p gmpÌý | + | mkdir -p binutilsÌý |
| - | cd gmpÌý | + | cd binutilsÌý |
| - | if [ ! -e " | + | if [ ! -e " |
| - | ../../src/gmp-4.3.2/configure --prefix=$MYMIPS | + | ../../src/binutils-${BINUTILSVERSION}/configure --target=mipsel-none-elf \Ìý |
| + | --prefix=$MYMIPS | ||
| fi | fi | ||
| - | if [ ! -e " | + | Ìý |
| + | if [ ! -e " | ||
| make | make | ||
| make install | make install | ||
| Line 133: | Line 136: | ||
| cd ../../.. | cd ../../.. | ||
| + | ######################################## | ||
| + | # GMP | ||
| + | ######################################## | ||
| # Get the archives | # Get the archives | ||
| cd mips/ | cd mips/ | ||
| - | if [ ! -e "ppl-${PPLVERSION}.tar.bz2" | + | if [ ! -e "gmp-${GMPVERSION}.tar.bz2" |
| - | wget ftp://ftp.cs.unipr.it/pub/ppl/releases/ | + | wget ftp://ftp.halifax.rwth-aachen.de/gnu/gmp/gmp-4.3.2.tar.bz2 |
| fi | fi | ||
| # Unpack to source directory | # Unpack to source directory | ||
| cd ../src | cd ../src | ||
| - | if [ ! -d "ppl-${PPLVERSION}" ] ; thenÌý | + | if [ ! -d "gmp-${GMPVERSION}" ] ; thenÌý |
| - | tar -xjvf ../orig/ppl-${PPLVERSION}.tar.bz2 | + | tar -xjvf ../orig/gmp-${GMPVERSION}.tar.bz2 |
| fi | fi | ||
| + | # Build | ||
| cd ../build | cd ../build | ||
| - | mkdir -p pplÌý | + | mkdir -p gmpÌý |
| - | cd pplÌý | + | cd gmpÌý |
| - | if [ ! -e " | + | if [ ! -e " |
| - | ../../src/ppl-${PPLVERSION}/configure --prefix=$MYMIPS --with-gmp=$MYMIPS --with-sysroot=$MYMIPS | + | ../../src/gmp-${GMPVERSION}/configure --prefix=$MYMIPS --enable-cxx |
| fi | fi | ||
| - | if [ ! -e " | + | if [ ! -e " |
| - | make | + | make |
| make install | make install | ||
| fi | fi | ||
| cd ../../.. | cd ../../.. | ||
| + | |||
| ######################################## | ######################################## | ||
| - | # Binutils | + | # PPL |
| ######################################## | ######################################## | ||
| # Get the archives | # Get the archives | ||
| - | cd mips/orig Ìý | + | #cd mips/orig Ìý |
| - | if [ ! -e "binutils-${BINUTILSVERSION}.tar.bz2" | + | #if [ ! -e "ppl-${PPLVERSION}.tar.bz2" |
| - | wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVERSION}.tar.bz2Ìý | + | # |
| - | fi | + | #fi |
| # Unpack to source directory | # Unpack to source directory | ||
| - | cd ../srcÌý | + | #cd ../srcÌý |
| - | if [ ! -d "binutils-${BINUTILSVERSION}" ] ; thenÌý | + | #if [ ! -d "ppl-${PPLVERSION}" ] ; thenÌý |
| - | tar -xvjf ../orig/binutils-${BINUTILSVERSION}.tar.bz2Ìý | + | #tar -xjvf ../orig/ppl-${PPLVERSION}.tar.bz2Ìý |
| - | fi | + | #fi |
| - | cd ../buildÌý | + | #cd ../buildÌý |
| - | mkdir -p binutilsÌý | + | #mkdir -p pplÌý |
| - | cd binutilsÌý | + | #cd pplÌý |
| - | if [ ! -e " | + | #if [ ! -e " |
| - | ../../src/binutils-${BINUTILSVERSION}/configure --target=mipsel-none-elf \Ìý | + | #../../src/ppl-${PPLVERSION}/configure --prefix=$MYMIPS |
| - | --prefix=$MYMIPS | + | #fiÌý |
| - | --with-ppl=$MYMIPS | + | #if [ ! -e " |
| - | fi | + | #make Ìý |
| + | #make installÌý | ||
| + | #fiÌý | ||
| + | #cd ../../.. | ||
| - | if [ ! -e " | ||
| - | make | ||
| - | make install | ||
| - | fi | ||
| - | cd ../../.. | ||
| ###################################### | ###################################### | ||
| Line 196: | Line 202: | ||
| cd mips/ | cd mips/ | ||
| if [ ! -e " | if [ ! -e " | ||
| - | wget http:// | + | wget ftp:// |
| fi | fi | ||
| Line 225: | Line 231: | ||
| cd mips/ | cd mips/ | ||
| if [ ! -e " | if [ ! -e " | ||
| - | wget http:// | + | wget ftp:// |
| fi | fi | ||
| Line 300: | Line 306: | ||
| cd cloog | cd cloog | ||
| if [ ! -e " | if [ ! -e " | ||
| - | ../ | + | ../ |
| - | --with-gmp-prefix=$MYMIPS | + | |
| - | --with-isl=system | + | |
| - | --with-isl-prefix=$MYMIPS | + | |
| fi | fi | ||
| Line 311: | Line 314: | ||
| fi | fi | ||
| cd ../ | cd ../ | ||
| + | |||
| ######################################## | ######################################## | ||
| Line 338: | Line 342: | ||
| cd mips/ | cd mips/ | ||
| if [ ! -e " | if [ ! -e " | ||
| - | wget http:// | + | wget ftp:// |
| fi | fi | ||
| Line 423: | Line 427: | ||
| cd mips/ | cd mips/ | ||
| if [ ! -e " | if [ ! -e " | ||
| - | wget http:// | + | wget ftp:// |
| fi | fi | ||
| Line 437: | Line 441: | ||
| if [ ! -e " | if [ ! -e " | ||
| ../ | ../ | ||
| + | --enable-sim-trace \ | ||
| --enable-sim-stdio \ | --enable-sim-stdio \ | ||
| --prefix=$MYMIPS | --prefix=$MYMIPS | ||
| Line 446: | Line 451: | ||
| fi | fi | ||
| cd ../../.. | cd ../../.. | ||
| - | |||
| </ | </ | ||
| - | === Compile and Run === | + | ===== Compile and Run an example =====Ìý |
| + | Ìý | ||
| + | Here is an example mini c code to test the compiler. Ìý | ||
| + | Ìý | ||
| + | <code c hello.c> | ||
| + | /* Hello world */Ìý | ||
| + | #include < | ||
| + | Ìý | ||
| + | int myfunc(int a, int b){Ìý | ||
| + | int k; Ìý | ||
| + | k = a + b; Ìý | ||
| + | Ìý | ||
| + | k += 7; Ìý | ||
| + | k *= 6; Ìý | ||
| + | return k; Ìý | ||
| + | }Ìý | ||
| + | Ìý | ||
| + | int main(){Ìý | ||
| + | int i, | ||
| + | j = 3;Ìý | ||
| + | m = 2;Ìý | ||
| + | Ìý | ||
| + | for(i=0; | ||
| + | m += myfunc(i, | ||
| + | printf(" | ||
| + | }Ìý | ||
| + | return 0;Ìý | ||
| + | }Ìý | ||
| + | </ | ||
| Compile to Assembler for viewing | Compile to Assembler for viewing | ||
| - | mipsel-none-elf-gcc -S fir.c | + | < |
| + | mipsel-none-elf-gcc -S hello.cÌý | ||
| + | </ | ||
| - | The output is fir.s which is the assembler code. | + | The output |
| Compile and link ready for simulation with instruction set simulator | Compile and link ready for simulation with instruction set simulator | ||
| - | mipsel-none-elf-gcc -o fir -Tidt.ld | + | < |
| + | mipsel-none-elf-gcc -o hello -Tidt.ld | ||
| + | </ | ||
| Run the code | Run the code | ||
| - | mipsel-none-elf-run | + | < |
| + | mipsel-none-elf-run | ||
| + | </ | ||
| === Analyze === | === Analyze === | ||
| - | Produce an annoted source code | + | Produce an annoted source code showing how often lines are executed. |
| - | gcc -fprofile-arcs -ftest-coverage -o fir fir.c | + | < |
| + | gcc -fprofile-arcs -ftest-coverage -o hello hello.cÌý | ||
| + | ./helloÌý | ||
| + | gcov hello.cÌý | ||
| + | </ | ||
| - | ./fir | + | This produces the file hello.c.gcov showing the annotated source file. |
| - | gcov fir.c | + | === Tracing in instruction set simulator === |
| Run with instruction tracing in the simulator | Run with instruction tracing in the simulator | ||
| - | mipsel-none-elf-run --trace-insn=on --trace-file trace fir | + | < |
| + | mipsel-none-elf-gcc -Tidt.ld -o hello hello.cÌý | ||
| + | mipsel-none-elf-run --trace-insn=on --trace-file trace helloÌý | ||
| + | </ | ||
| + | Ìý | ||
| + | ===== Test the compiler =====Ìý | ||
| + | Ìý | ||
| + | < | ||
| + | sudo apt-get install dejagnuÌý | ||
| + | </ | ||
| + | Ìý | ||
| + | < | ||
| + | cdÌý | ||
| + | cd mips/ | ||
| + | make check-gcc RUNTESTFLAGS=--target_board=mips-simÌý | ||
| + | </ | ||
| + | Ìý | ||
| + | ===== Install git and download a simple project | ||
| + | Ìý | ||
| + | Install git and download a simple projectÌý | ||
| + | Ìý | ||
| + | < | ||
| + | sudo apt-get install gitÌý | ||
| + | cdÌý | ||
| + | mkdir projectsÌý | ||
| + | cd projectsÌý | ||
| + | git clone https:// | ||
| + | </ | ||
| + | Ìý | ||
| + | Now you have the simple project " | ||
| + | Ìý | ||
| + | === Try the MIPS Cross Compiler ===Ìý | ||
| + | Ìý | ||
| + | Change to the src directory and compile the code with the cross compiler. Ìý | ||
| + | Ìý | ||
| + | < | ||
| + | cd myfirstÌý | ||
| + | cd srcÌý | ||
| + | mipsel-none-elf-gcc -S hello.cÌý | ||
| + | less hello.sÌý | ||
| + | </ | ||
| + | Ìý | ||
| + | Now you have the compiled assembler code " | ||
| + | Ìý | ||
| + | < | ||
| + | mipsel-none-elf-gcc -o hello -Tidt.ld hello.cÌý | ||
| + | </ | ||
| + | Ìý | ||
| + | Now you have the binary " | ||
| + | Ìý | ||
| + | < | ||
| + | mipsel-none-elf-run helloÌý | ||
| + | </ | ||
| + | Ìý | ||
| + | This will run the binary with the mips instruction set simulator. You should see "Hello World" | ||
| + | Ìý | ||
| + | Ìý | ||
| + | Ìý | ||
| + | ===== Open OCD =====Ìý | ||
| + | Ìý | ||
| + | [[dt_openocd]]Ìý | ||
| + | Ìý | ||