06.02.2013 Views

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2. Create <strong>the</strong> source file function.c containing <strong>the</strong> following code:<br />

int sqr(int n1)<br />

{<br />

return n1*n1;<br />

}<br />

<strong>Using</strong> scatter files<br />

3. Create <strong>the</strong> scatter file scatter.scat containing <strong>the</strong> following load region:<br />

LR1 0x0<br />

{<br />

ER1 0x0<br />

{<br />

*(+RO) ; rest of code and read-only data<br />

}<br />

ER2 +0<br />

{<br />

function.o<br />

*(.<strong>ARM</strong>.__at_0x10000) ; Place gValue at 0x10000<br />

}<br />

RAM 0x200000 (0x1FF00-0x2000) ; RW & ZI data to be placed at 0x200000<br />

{<br />

*(+RW, +ZI)<br />

}<br />

<strong>ARM</strong>_LIB_STACK 0x800000 EMPTY -0x10000<br />

{<br />

}<br />

<strong>ARM</strong>_LIB_HEAP +0 EMPTY 0x10000<br />

{<br />

}<br />

}<br />

The <strong>ARM</strong>_LIB_STACK and <strong>ARM</strong>_LIB_HEAP regions are required because <strong>the</strong> program is being<br />

linked with <strong>the</strong> semihosting libraries.<br />

4. Compile and link <strong>the</strong> sources:<br />

armcc -c -g function.c<br />

armcc -c -g main.c<br />

armlink --no_autoat --scatter=scatter.scat --map function.o main.o -o squared.axf<br />

The --map option displays <strong>the</strong> memory map of <strong>the</strong> image.<br />

The memory map shows that <strong>the</strong> variable is placed in <strong>the</strong> ER2 execution region at address<br />

0x11000:<br />

...<br />

Execution Region ER2 (Base: 0x00001598, Size: 0x0000ea6c, Max: 0xffffffff, ABSOLUTE)<br />

Base Addr Size Type Attr Idx E Section Name Object<br />

0x00001598 0x0000000c Code RO 3 .text function.o<br />

0x000015a4 0x0000ea5c PAD<br />

0x00010000 0x00000004 Data RO 15 .<strong>ARM</strong>.__at_0x10000 main.o...<br />

8.11.4 See also<br />

In this example, <strong>the</strong> size of ER1 is uknown. Therefore, gValue might be placed in ER1 or ER2. To<br />

make sure that gValue is placed in ER2, you must include <strong>the</strong> corresponding selector in ER2 and<br />

link with <strong>the</strong> --no_autoat command-line option. If you omit --no_autoat, gValue is to placed in<br />

a separate load region LR$$.<strong>ARM</strong>.__AT_0x00010000 that contains <strong>the</strong> execution region<br />

ER$$.<strong>ARM</strong>.__AT_0x00020000.<br />

Tasks<br />

• Placing a named section explicitly using scatter-loading on page 8-23<br />

<strong>ARM</strong> DUI 0474C Copyright © 2010-2011 <strong>ARM</strong>. All rights reserved. 8-21<br />

ID080411 Non-Confidential

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!