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]] | ||
| - | |||