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 [2014/02/16 01:25] beckmanf [MIPS Cross Compiler build] changed script |
mips_cross_compiler [2014/06/04 17:52] (current) beckmanf simple project added |
||
---|---|---|---|
Line 91: | Line 91: | ||
# Set the destination | # Set the destination | ||
- | export MYMIPS=/home/fritz/site | + | export MYMIPS=${HOME}/site |
# Versions | # Versions | ||
Line 454: | Line 454: | ||
</code> | </code> | ||
- | === 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 <stdio.h>Ìý | ||
+ | Ìý | ||
+ | int myfunc(int a, int b){Ìý | ||
+ | int k; Ìý | ||
+ | k = a + b; Ìý | ||
+ | Ìý | ||
+ | k += 7; Ìý | ||
+ | k *= 6; Ìý | ||
+ | return k; Ìý | ||
+ | }Ìý | ||
+ | Ìý | ||
+ | int main(){Ìý | ||
+ | int i,j,m; Ìý | ||
+ | j = 3;Ìý | ||
+ | m = 2;Ìý | ||
+ | Ìý | ||
+ | for(i=0;i<5;i++){Ìý | ||
+ | m += myfunc(i,j); Ìý | ||
+ | printf("m is %d\n",m);Ìý | ||
+ | }Ìý | ||
+ | return 0;Ìý | ||
+ | }Ìý | ||
+ | </code> | ||
Compile to Assembler for viewing | Compile to Assembler for viewing | ||
- | mipsel-none-elf-gcc -S fir.c | + | <code>Ìý |
+ | mipsel-none-elf-gcc -S hello.cÌý | ||
+ | </code> | ||
- | The output is fir.s which is the assembler code. | + | The output assembler code is in hello.s. |
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 fir.c | + | <code>Ìý |
+ | mipsel-none-elf-gcc -o hello -Tidt.ld hello.cÌý | ||
+ | </code> | ||
Run the code | Run the code | ||
- | mipsel-none-elf-run fir | + | <code>Ìý |
+ | mipsel-none-elf-run helloÌý | ||
+ | </code> | ||
=== 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 | + | <code>Ìý |
+ | gcc -fprofile-arcs -ftest-coverage -o hello hello.cÌý | ||
+ | ./helloÌý | ||
+ | gcov hello.cÌý | ||
+ | </code> | ||
- | ./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 | ||
<code> | <code> | ||
- | 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 | ||
</code> | </code> | ||
Line 497: | Line 536: | ||
make check-gcc RUNTESTFLAGS=--target_board=mips-sim | make check-gcc RUNTESTFLAGS=--target_board=mips-sim | ||
</code> | </code> | ||
+ | |||
+ | ===== Install git and download a simple project ===== | ||
+ | |||
+ | Install git and download a simple project | ||
+ | |||
+ | <code> | ||
+ | sudo apt-get install git | ||
+ | cd | ||
+ | mkdir projects | ||
+ | cd projects | ||
+ | git clone https://git.etech.fh-augsburg.de/friedrich.beckmann/myfirst.git | ||
+ | </code> | ||
+ | |||
+ | Now you have the simple project "myfirst" in your directory. | ||
+ | |||
+ | === Try the MIPS Cross Compiler === | ||
+ | |||
+ | Change to the src directory and compile the code with the cross compiler. | ||
+ | |||
+ | <code> | ||
+ | cd myfirst | ||
+ | cd src | ||
+ | mipsel-none-elf-gcc -S hello.c | ||
+ | less hello.s | ||
+ | </code> | ||
+ | |||
+ | Now you have the compiled assembler code "hello.s". To compile to binary do: | ||
+ | |||
+ | <code> | ||
+ | mipsel-none-elf-gcc -o hello -Tidt.ld hello.c | ||
+ | </code> | ||
+ | |||
+ | Now you have the binary "hello". You can run the binary in the instruction set simulator with | ||
+ | |||
+ | <code> | ||
+ | mipsel-none-elf-run hello | ||
+ | </code> | ||
+ | |||
+ | This will run the binary with the mips instruction set simulator. You should see "Hello World". | ||
+ | |||
+ | |||
===== Open OCD ===== | ===== Open OCD ===== | ||
[[dt_openocd]] | [[dt_openocd]] | ||
- | |||