AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel

AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel

06.02.2013 Views

2 Memory map 2 ong>AVR32795ong> The Atmel ® AVR UC3 microcontroller architecture has a 32-bit memory space and separate memory types (program and data) connected with distinct buses. Such a memory architecture allows ong>theong> processor to access both program and data memories at ong>theong> same time. Each memory type has its own address space. Figure 2-1. Example of ong>theong> Atmel AT32UC3A3256 memory map. 32158A-AVR-01/11

3 Basic linker script concepts 3.1 Sections 3.2 Section properties 3.3 VMA and LMA 3.4 Symbols 3.5 Well-known sections 32158A-AVR-01/11 ong>AVR32795ong> The linker combines input files (object file format) into a single output file (executable). Each object file has, among oong>theong>r things, a list of sections. We refer to a section in an input file as an input section. Similarly, a section in ong>theong> output file is an output section. Each section in an object file has a name and a size. Most sections also have an associated block of data (ong>theong> section contents). A section may be marked as loadable, which means that its contents should be loaded into memory when ong>theong> executable is run. A section with no contents may be allocatable, which means that an area in memory should be set aside, but nothing in particular should be loaded ong>theong>re (and, in some cases, this memory must be zeroed out). A section which is neiong>theong>r loadable nor allocatable typically contains some sort of debugging information. Every loadable or allocatable output section has two addresses. The first is ong>theong> VMA, or virtual memory address. This is ong>theong> address ong>theong> section will have when ong>theong> output file is run. The second is ong>theong> LMA, or load memory address. This is ong>theong> address at which ong>theong> section will be loaded. In most cases ong>theong> two addresses will be ong>theong> same. An example of when ong>theong> LMA and VMA might be different is when a data section is loaded into ROM, and ong>theong>n copied into RAM when ong>theong> program starts up (a technique often used to initialize global variables in a ROM-based system). In this case, ong>theong> ROM address would be ong>theong> LMA and ong>theong> RAM address would be ong>theong> VMA. Every object file also has a list of symbols, known as ong>theong> symbol table. A symbol may be defined or undefined. Each symbol has a name, and each defined symbol has an address, among oong>theong>r information. The compilation of a C or C++ program into an object file will generate a defined symbol for every defined function and global or static variable. Every undefined function or global variable which is referenced in ong>theong> input file will become an undefined symbol. .text: usually contains ong>theong> code, and is usually loaded to a non-volatile memory, such as ong>theong> internal flash. .data: initialized data; usually contains initialized variables. .bss: usually contains non-initialized data. 3

3 Basic linker script c<strong>on</strong>cepts<br />

3.1 Secti<strong>on</strong>s<br />

3.2 Secti<strong>on</strong> properties<br />

3.3 VMA and LMA<br />

3.4 Symbols<br />

3.5 Well-known secti<strong>on</strong>s<br />

32158A-<strong>AVR</strong>-01/11<br />

<str<strong>on</strong>g><strong>AVR</strong>32795</str<strong>on</strong>g><br />

The linker combines input files (object file format) into a single output file<br />

(executable).<br />

Each object file has, am<strong>on</strong>g o<str<strong>on</strong>g>the</str<strong>on</strong>g>r things, a list of secti<strong>on</strong>s. We refer to a secti<strong>on</strong> in an<br />

input file as an input secti<strong>on</strong>. Similarly, a secti<strong>on</strong> in <str<strong>on</strong>g>the</str<strong>on</strong>g> output file is an output secti<strong>on</strong>.<br />

Each secti<strong>on</strong> in an object file has a name and a size. Most secti<strong>on</strong>s also have an<br />

associated block of data (<str<strong>on</strong>g>the</str<strong>on</strong>g> secti<strong>on</strong> c<strong>on</strong>tents).<br />

A secti<strong>on</strong> may be marked as loadable, which means that its c<strong>on</strong>tents should be<br />

loaded into memory when <str<strong>on</strong>g>the</str<strong>on</strong>g> executable is run.<br />

A secti<strong>on</strong> with no c<strong>on</strong>tents may be allocatable, which means that an area in memory<br />

should be set aside, but nothing in particular should be loaded <str<strong>on</strong>g>the</str<strong>on</strong>g>re (and, in some<br />

cases, this memory must be zeroed out).<br />

A secti<strong>on</strong> which is nei<str<strong>on</strong>g>the</str<strong>on</strong>g>r loadable nor allocatable typically c<strong>on</strong>tains some sort of<br />

debugging informati<strong>on</strong>.<br />

Every loadable or allocatable output secti<strong>on</strong> has two addresses. The first is <str<strong>on</strong>g>the</str<strong>on</strong>g> VMA,<br />

or virtual memory address. This is <str<strong>on</strong>g>the</str<strong>on</strong>g> address <str<strong>on</strong>g>the</str<strong>on</strong>g> secti<strong>on</strong> will have when <str<strong>on</strong>g>the</str<strong>on</strong>g> output<br />

file is run. The sec<strong>on</strong>d is <str<strong>on</strong>g>the</str<strong>on</strong>g> LMA, or load memory address. This is <str<strong>on</strong>g>the</str<strong>on</strong>g> address at<br />

which <str<strong>on</strong>g>the</str<strong>on</strong>g> secti<strong>on</strong> will be loaded. In most cases <str<strong>on</strong>g>the</str<strong>on</strong>g> two addresses will be <str<strong>on</strong>g>the</str<strong>on</strong>g> same.<br />

An example of when <str<strong>on</strong>g>the</str<strong>on</strong>g> LMA and VMA might be different is when a data secti<strong>on</strong> is<br />

loaded into ROM, and <str<strong>on</strong>g>the</str<strong>on</strong>g>n copied into RAM when <str<strong>on</strong>g>the</str<strong>on</strong>g> program starts up (a technique<br />

often used to initialize global variables in a ROM-based system). In this case, <str<strong>on</strong>g>the</str<strong>on</strong>g><br />

ROM address would be <str<strong>on</strong>g>the</str<strong>on</strong>g> LMA and <str<strong>on</strong>g>the</str<strong>on</strong>g> RAM address would be <str<strong>on</strong>g>the</str<strong>on</strong>g> VMA.<br />

Every object file also has a list of symbols, known as <str<strong>on</strong>g>the</str<strong>on</strong>g> symbol table. A symbol may<br />

be defined or undefined. Each symbol has a name, and each defined symbol has an<br />

address, am<strong>on</strong>g o<str<strong>on</strong>g>the</str<strong>on</strong>g>r informati<strong>on</strong>.<br />

The compilati<strong>on</strong> of a C or C++ program into an object file will generate a defined<br />

symbol for every defined functi<strong>on</strong> and global or static variable. Every undefined<br />

functi<strong>on</strong> or global variable which is referenced in <str<strong>on</strong>g>the</str<strong>on</strong>g> input file will become an<br />

undefined symbol.<br />

.text: usually c<strong>on</strong>tains <str<strong>on</strong>g>the</str<strong>on</strong>g> code, and is usually loaded to a n<strong>on</strong>-volatile memory,<br />

such as <str<strong>on</strong>g>the</str<strong>on</strong>g> internal flash.<br />

.data: initialized data; usually c<strong>on</strong>tains initialized variables.<br />

.bss: usually c<strong>on</strong>tains n<strong>on</strong>-initialized data.<br />

3

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

Saved successfully!

Ooh no, something went wrong!