MicroBlaze - Where can I find information on the switches for MB-GCC/GCC?

原文:https://www.xilinx.com/support/answers/12030.html

AR# 12030

MicroBlaze - Where can I find information on the switches for MB-GCC/GCC?

Description
Where can I find information on the switches for MB-GCC? And how do I compile a C-file?

Solution
Running the GNU Tools

Given a set of C source files, you can create a MicroBlaze executable as follows:

1. Ensure that the MicroBlaze GNU tools are in your path.

2. Ensure that the files "init.o" and "libxil.a" are in the current directory (this requirement will be removed in a future version).

3. Run mb-gcc file1.c file2.c.

These steps compile and link the files "file1.c" and "file2.c" to create the MicroBlaze executable "file a.out".

If you want to debug the code using MB-GDB, run the following to create the MicroBlaze executable file "a.out", which contains debugging information that can be accessed by MB-GDB:
mb-gcc -g -mgas file1.c file2.c
When you are satisfied that your program is correct, recompile your program with optimization turned On. This step reduces the size of your executable, and reduces the number of cycles it needs to execute. This is achieved with the following option:
mb-gcc -O2 file1.c file2.c
By default, all data is accessed using absolute addressing. This can be a problem for large programs, as they may require two instructions for each data access. To address this problem, MicroBlaze has introduced the concept of small data areas, which can always be accessed using a single instruction. To force MB-GCC to use small data areas, use the following:
mb-gcc -mxl-gp-opt file1.c file2.c
Xilinx recommends that you always use the "-mxl-gp-opt" option. This can be combined with the "-O2" option to further improve the performance of your program.

For further information on MB-GCC options, use "mb-gcc --help" or "info mb-gcc" (the latter provides the information page for Solaris GCC, on which MB-GCC is based.)


4. Set the stack size. By default, the MicroBlaze tools build the executable with a default stack size of 0x100 (256) bytes. If you need to change the stack size, use the following:
mb-gcc -S file1.c file2.c
This command compiles the files without assembling them (any other GCC options can be used, as well), and creates the files "file1.s" and "file2.s".
Assemble these using the following:
mb-as -o file1.o file1.s
mb-as -o file2.o file2.s
Link using the following:
mb-ld -relax -defsym _STACK_SIZE=0x400 init.o file1.o file2.o -lxil

This step sets the stack size to 0x400 (1024) bytes.


5. Debug using GDB. To debug a MicroBlaze executable, your source files must have been compiled with the "-g -mgas" options. Start MB-GDB with the following, where "a.out" is your MicroBlaze executable:
mb-gdb a.out
When the GDB prompt appears, enter the following commands, where "a.out" is the name of your MicroBlaze executable:
target sim
load a.out
You can now provide standard GDB commands to test your program. Use "help" within MB-GDB to obtain a list of these commands.
Here is a list of the commonly used commands:
b main = to set a breakpoint in function main
r = to run the program
c = to continue after a break point
l = to see a listing of the program (at the current point)
n = to step one line (stepping over function calls)
s = to step one line (stepping into function calls)
info reg = to see the values of registers
info target = to see the number of instructions executed, and the number of cycles

p xyz = to print the value of data xyz


6. Dump an object/executable file. The "objdump" utility lets you see the contents of an object (.o) or executable (.out) file. To see your symbol table, the size of your file, and the names/sizes of the sections in the file, use "mb-objdump -x a.out".
To see a listing of the (assembly) code in your object or executable file, use "mb-objdump -d a.out".
For a list of other options, use "mb-objdump --help".
The official GCC page is located at:
http://gcc.gnu.org
The documents page is at:
http://gcc.gnu.org/onlinedocs/
Command line options for GCC are at:
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html#SEC2
The above are the basic, generic compiler options that work for all CPUs/platforms that GCC supports.


Was this Answer Record helpful?

猜你喜欢

转载自blog.csdn.net/liuzq/article/details/79887805