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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

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

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

armlink --map function.o main.o -o squared.axf<br />

The --map option displays <strong>the</strong> memory map of <strong>the</strong> image. Also, --autoat is <strong>the</strong> default.<br />

In this example, __attribute__((at(0x5000))) specifies that <strong>the</strong> global variable gSquared is to be<br />

placed at <strong>the</strong> absolute address 0x20000. gSquared is placed in <strong>the</strong> execution region<br />

ER$$.<strong>ARM</strong>.__AT_0x00005000 and load region LR$$.<strong>ARM</strong>.__AT_0x00005000.<br />

The memory map shows:<br />

...<br />

Load Region LR$$.<strong>ARM</strong>.__AT_0x00005000 (Base: 0x00005000, Size: 0x00000000, Max: 0x00000004, ABSOLUTE)<br />

Execution Region ER$$.<strong>ARM</strong>.__AT_0x00005000 (Base: 0x00005000, Size: 0x00000004, Max: 0x00000004, ABSOLUTE,<br />

UNINIT)<br />

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

0x00005000 0x00000004 Zero RW 15 .<strong>ARM</strong>.__AT_0x00005000 main.o<br />

8.11.2 Example of placing a variable in a named section with scatter-loading<br />

This example shows how to modify your source code to place code and data in a specific section<br />

using a scatter file:<br />

1. Create <strong>the</strong> source file main.c containing <strong>the</strong> following code:<br />

#include <br />

extern int sqr(int n1);<br />

int gSquared __attribute__((section("foo"))); // Place in section foo<br />

int main()<br />

{<br />

gSquared=sqr(3);<br />

printf("Value squared is: %d\n", gSquared);<br />

}<br />

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

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

LR1 0x0000 0x20000<br />

{<br />

ER1 0x0 0x2000<br />

{<br />

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

}<br />

ER2 0x8000 0x2000<br />

{<br />

main.o<br />

}<br />

ER3 0x10000 0x2000<br />

{<br />

function.o<br />

*(foo) ; Place gSquared in ER3<br />

}<br />

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

ID080411 Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!