Compiler (Very Imp.)
Compiler (Very Imp.)
Compiler (Very Imp.)
Program in RAM
Sections: 0x40001fff
stack
• .text: Program code. Read only
_end
• .data: Initialized global and static variables
(startup value ≠ 0)
.bss
0x40000040
Vectors (RAM)
0x40000000
C compiler. Memory map. Program in Flash
Flash memory RAM memory
0x7fff 0x40001fff
stack
free Flash
free RAM
.data Copied
on startup
_end
.rodata
.bss
.text
.data
0x40 0x40000040
• The C runtime startup code (crt.S file) does some processing before
calling the “main” routine. In particular it:
• Copies the .data section into RAM, because variables have to be
stored in a read/write memory
• Fills the .bss section with zeroes
Implicit:
• libgcc.a: Compiler helper library
• Missing hardware arithmetic (division,…)
• Floating point emulation
• …
• libc.a: Standard C library (stdlib, stdio, string,…)
Libraries:
• libm.a: Mathematical functions (log, sin,…)
• …
C compiler. Command line options
arm-none-eabi-gcc -O2 -g -mcpu=arm7tdmi -nostartfiles –static -Wl,-Tlinker_ram.ld
-o code.elf -DCRLF crt.S main.c
objcopy -O <format> file.elf file.<format> can convert elf files into ihex or binary
Makefiles
• “make” is an standard Unix tool for compilation. Refer to the make man page
• Specifies the dependences between files and the actions to be taken in order to
generate the target files from sources
• Format:
target: <tab> source1 source2 … sourceN
<tab> command 1
<tab> command 2
…
• It also allows the definition and use of variables. Example:
CC = arm-none-eabi-gcc
CFLAGS=-I./ -O2 -g -mcpu=arm7tdmi -nostartfiles –static
…
code.elf:<tab> crt.S main.c
<tab> $(CC) $(CFLAGS) -Wl,-Tlinker_ram.ld -o $@ -DCRLF crt.S main.c
• Special variables:
• $< input source
• $@ output target