You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
18 KiB
HTML
241 lines
18 KiB
HTML
<!-- HTML header for doxygen 1.8.7-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.6.3"/>
|
|
<!--BEGIN PROJECT_NAME--><title>avr-libc: avr-libc: Memory Sections</title><!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME--><title>avr-libc: Memory Sections</title><!--END !PROJECT_NAME-->
|
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
|
$treeview
|
|
$search
|
|
$mathjax
|
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
|
$extrastylesheet
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
|
|
<!--BEGIN TITLEAREA-->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<!--BEGIN PROJECT_LOGO-->
|
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
|
<!--END PROJECT_LOGO-->
|
|
<!--BEGIN PROJECT_NAME-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">avr-libc
|
|
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">2.0.0</span><!--END PROJECT_NUMBER-->
|
|
</div>
|
|
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
|
</td>
|
|
<!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME-->
|
|
<!--BEGIN PROJECT_BRIEF-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectbrief">$projectbrief</div>
|
|
</td>
|
|
<!--END PROJECT_BRIEF-->
|
|
<!--END !PROJECT_NAME-->
|
|
<!--BEGIN DISABLE_INDEX-->
|
|
<!--BEGIN SEARCHENGINE-->
|
|
<td>$searchbox</td>
|
|
<!--END SEARCHENGINE-->
|
|
<!--END DISABLE_INDEX-->
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table>
|
|
<tr>
|
|
<td align="left"><a href="http://www.nongnu.org/avr-libc/"><h2>AVR Libc Home Page</h2></a></td>
|
|
<td align="center" colspan=4><img src="avrs.png" alt="AVRs" align="middle" border="0"></td>
|
|
<td align="right"><a href="https://savannah.nongnu.org/projects/avr-libc/"><h2>AVR Libc Development Pages</h2></a></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" width="20%"><a href="index.html"><h2>Main Page</h2></a></td>
|
|
<td align="center" width="20%"><a href="pages.html"><h2>User Manual</h2></a></td>
|
|
<td align="center" width="20%"><a href="modules.html"><h2>Library Reference</h2></a></td>
|
|
<td align="center" width="20%"><a href="FAQ.html"><h2>FAQ</h2></a></td>
|
|
<td align="center" width="20%"><a href="group__demos.html"><h2>Example Projects</h2></a></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<!--END TITLEAREA-->
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.6.3 -->
|
|
<script type="text/javascript"><!--
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
--></script>
|
|
<div class="contents">
|
|
|
|
|
|
<h1><a class="anchor" id="mem_sections">Memory Sections </a></h1><dl class="remark"><dt><b>Remarks:</b></dt><dd>Need to list all the sections which are available to the avr.</dd></dl>
|
|
<dl class="user"><dt><b>Weak Bindings</b></dt><dd>FIXME: need to discuss the .weak directive.</dd></dl>
|
|
<p>The following describes the various sections available.</p>
|
|
<h2><a class="anchor" id="sec_dot_text">
|
|
The .text Section</a></h2>
|
|
<p>The .text section contains the actual machine instructions which make up your program. This section is further subdivided by the .initN and .finiN sections dicussed below.</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd>The <code>avr-size</code> program (part of binutils), coming from a Unix background, doesn't account for the .data initialization space added to the .text section, so in order to know how much flash the final program will consume, one needs to add the values for both, .text and .data (but not .bss), while the amount of pre-allocated SRAM is the sum of .data and .bss.</dd></dl>
|
|
<h2><a class="anchor" id="sec_dot_data">
|
|
The .data Section</a></h2>
|
|
<p>This section contains static data which was defined in your code. Things like the following would end up in .data:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="keywordtype">char</span> err_str[] = <span class="stringliteral">"Your program has died a horrible death!"</span>;
|
|
|
|
<span class="keyword">struct </span>point pt = { 1, 1 };
|
|
</pre></div><p>It is possible to tell the linker the SRAM address of the beginning of the .data section. This is accomplished by adding <b><code>-Wl,-Tdata,<em>addr</em></code></b> to the <code>avr-gcc</code> command used to the link your program. Not that <em><code>addr</code></em> must be offset by adding 0x800000 the to real SRAM address so that the linker knows that the address is in the SRAM memory space. Thus, if you want the .data section to start at 0x1100, pass 0x801100 at the address to the linker. [offset <a class="el" href="mem__sections.html#harvard_arch">explained</a>]</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd>When using <code><a class="el" href="group__avr__stdlib.html#ga4996af830ebe744d9678e5251dfd3ebd">malloc()</a></code> in the application (which could even happen inside library calls), <a class="el" href="malloc.html#malloc_extram">additional adjustments</a> are required.</dd></dl>
|
|
<h2><a class="anchor" id="sec_dot_bss">
|
|
The .bss Section</a></h2>
|
|
<p>Uninitialized global or static variables end up in the .bss section.</p>
|
|
<h2><a class="anchor" id="sec_dot_eeprom">
|
|
The .eeprom Section</a></h2>
|
|
<p>This is where eeprom variables are stored.</p>
|
|
<h2><a class="anchor" id="sec_dot_noinit">
|
|
The .noinit Section</a></h2>
|
|
<p>This sections is a part of the .bss section. What makes the .noinit section special is that variables which are defined as such:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> foo <a class="code" href="group__avr__watchdog.html#gadaa6dd28b5d08df35e49b1248d7e5fb0">__attribute__</a> ((section (<span class="stringliteral">".noinit"</span>)));
|
|
</pre></div><p>will not be initialized to zero during startup as would normal .bss data.</p>
|
|
<p>Only uninitialized variables can be placed in the .noinit section. Thus, the following code will cause <code>avr-gcc</code> to issue an error:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> bar <a class="code" href="group__avr__watchdog.html#gadaa6dd28b5d08df35e49b1248d7e5fb0">__attribute__</a> ((section (<span class="stringliteral">".noinit"</span>))) = 0xaa;
|
|
</pre></div><p>It is possible to tell the linker explicitly where to place the .noinit section by adding <code>-Wl,--section-start=.noinit=0x802000</code> to the <code>avr-gcc</code> command line at the linking stage. For example, suppose you wish to place the .noinit section at SRAM address 0x2000:</p>
|
|
<div class="fragment"><pre class="fragment">
|
|
$ avr-gcc ... -Wl,--section-start=.noinit=0x802000 ...
|
|
</pre></div><p><a class="anchor" id="harvard_arch"></a> </p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd>Because of the Harvard architecture of the AVR devices, you must manually add 0x800000 to the address you pass to the linker as the start of the section. Otherwise, the linker thinks you want to put the .noinit section into the .text section instead of .data/.bss and will complain.</dd></dl>
|
|
<p>Alternatively, you can write your own linker script to automate this. [FIXME: need an example or ref to dox for writing linker scripts.]</p>
|
|
<h2><a class="anchor" id="sec_dot_init">
|
|
The .initN Sections</a></h2>
|
|
<p>These sections are used to define the startup code from reset up through the start of main(). These all are subparts of the <a class="el" href="mem__sections.html#sec_dot_text">.text section</a>.</p>
|
|
<p>The purpose of these sections is to allow for more specific placement of code within your program.</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd>Sometimes, it is convenient to think of the .initN and .finiN sections as functions, but in reality they are just symbolic names which tell the linker where to stick a chunk of code which is <em>not</em> a function. Notice that the examples for <a class="el" href="mem__sections.html#asm_sections">asm</a> and <a class="el" href="mem__sections.html#c_sections">C</a> can not be called as functions and should not be jumped into.</dd></dl>
|
|
<p>The <b>.initN</b> sections are executed in order from 0 to 9.</p>
|
|
<dl class="user"><dt><b>.init0:</b></dt><dd>Weakly bound to __init(). If user defines __init(), it will be jumped into immediately after a reset.</dd></dl>
|
|
<dl class="user"><dt><b>.init1:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.init2:</b></dt><dd>In C programs, weakly bound to initialize the stack, and to clear __zero_reg__ (r1).</dd></dl>
|
|
<dl class="user"><dt><b>.init3:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.init4:</b></dt><dd></dd></dl>
|
|
<p>For devices with > 64 KB of ROM, .init4 defines the code which takes care of copying the contents of .data from the flash to SRAM. For all other devices, this code as well as the code to zero out the .bss section is loaded from libgcc.a.</p>
|
|
<dl class="user"><dt><b>.init5:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.init6:</b></dt><dd>Unused for C programs, but used for constructors in C++ programs.</dd></dl>
|
|
<dl class="user"><dt><b>.init7:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.init8:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.init9:</b></dt><dd>Jumps into main().</dd></dl>
|
|
<h2><a class="anchor" id="sec_dot_fini">
|
|
The .finiN Sections</a></h2>
|
|
<p>These sections are used to define the exit code executed after return from main() or a call to <a class="el" href="group__avr__stdlib.html#ga137096a48cc0c731052cadfb69c39b34">exit()</a>. These all are subparts of the <a class="el" href="mem__sections.html#sec_dot_text">.text section</a>.</p>
|
|
<p>The <b>.finiN</b> sections are executed in descending order from 9 to 0.</p>
|
|
<dl class="user"><dt><b>.finit9:</b></dt><dd>Unused. User definable. This is effectively where _exit() starts.</dd></dl>
|
|
<dl class="user"><dt><b>.fini8:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.fini7:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.fini6:</b></dt><dd>Unused for C programs, but used for destructors in C++ programs.</dd></dl>
|
|
<dl class="user"><dt><b>.fini5:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.fini4:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.fini3:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.fini2:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.fini1:</b></dt><dd>Unused. User definable.</dd></dl>
|
|
<dl class="user"><dt><b>.fini0:</b></dt><dd>Goes into an infinite loop after program termination and completion of any _exit() code (execution of code in the .fini9 -> .fini1 sections).</dd></dl>
|
|
<h2><a class="anchor" id="sec_dot_note">
|
|
The .note.gnu.avr.deviceinfo Section</a></h2>
|
|
<p>This section contains device specific information picked up from the device header file and compiler builtin macros. The layout conforms to the standard ELF note section layout (<a href="http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-18048.html">http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-18048.html</a>).</p>
|
|
<p>The section contents are laid out as below.</p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor">#define __NOTE_NAME_LEN 4</span>
|
|
<span class="preprocessor"></span><span class="keyword">struct </span>__note_gnu_avr_deviceinfo
|
|
{
|
|
<span class="keyword">struct</span>
|
|
{
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> namesz; <span class="comment">/* = __NOTE_NAME_LEN */</span>
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> descsz; <span class="comment">/* = size of avr_desc */</span>
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> type; <span class="comment">/* = 1 - no other AVR note types exist */</span>
|
|
<span class="keywordtype">char</span> note_name[__NOTE_NAME_LEN]; <span class="comment">/* = "AVR\0" */</span>
|
|
}
|
|
note_header;
|
|
<span class="keyword">struct</span>
|
|
{
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> flash_start;
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> flash_size;
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> sram_start;
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> sram_size;
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> eeprom_start;
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> eeprom_size;
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> offset_table_size;
|
|
<a class="code" href="group__avr__stdint.html#ga33594304e786b158f3fb30289278f5af">uint32_t</a> offset_table[1]; <span class="comment">/* Offset table containing byte offsets into</span>
|
|
<span class="comment"> string table that immediately follows it.</span>
|
|
<span class="comment"> index 0: Device name byte offset</span>
|
|
<span class="comment"> */</span>
|
|
<span class="keywordtype">char</span> str_table [2 +
|
|
<a class="code" href="group__avr__string.html#ga7fd4936b86eb6b87e98587044c562715" title="Calculate the length of a string.">strlen</a>(__AVR_DEVICE_NAME__)]; <span class="comment">/* Standard ELF string table.</span>
|
|
<span class="comment"> index 0 : NULL</span>
|
|
<span class="comment"> index 1 : Device name</span>
|
|
<span class="comment"> index 2 : NULL</span>
|
|
<span class="comment"> */</span>
|
|
}
|
|
avr_desc;
|
|
};
|
|
</pre></div><h2><a class="anchor" id="asm_sections">
|
|
Using Sections in Assembler Code</a></h2>
|
|
<p>Example:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
|
|
.section .init1,<span class="stringliteral">"ax"</span>,@progbits
|
|
ldi r0, 0xff
|
|
out _SFR_IO_ADDR(PORTB), r0
|
|
out _SFR_IO_ADDR(DDRB), r0
|
|
</pre></div><dl class="note"><dt><b>Note:</b></dt><dd>The <b><code>,"ax",@progbits</code></b> tells the assembler that the section is allocatable ("a"), executable ("x") and contains data ("@progbits"). For more detailed information on the .section directive, see the gas user manual.</dd></dl>
|
|
<h2><a class="anchor" id="c_sections">
|
|
Using Sections in C Code</a></h2>
|
|
<p>Example:</p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
|
|
<span class="keywordtype">void</span> my_init_portb (<span class="keywordtype">void</span>) <a class="code" href="group__avr__watchdog.html#gadaa6dd28b5d08df35e49b1248d7e5fb0">__attribute__</a> ((naked)) \
|
|
<a class="code" href="group__avr__watchdog.html#gadaa6dd28b5d08df35e49b1248d7e5fb0">__attribute__</a> ((section (".init3")))
|
|
<a class="code" href="group__avr__watchdog.html#gadaa6dd28b5d08df35e49b1248d7e5fb0">__attribute__</a> ((used));
|
|
|
|
<span class="keywordtype">void</span>
|
|
my_init_portb (<span class="keywordtype">void</span>)
|
|
{
|
|
PORTB = 0xff;
|
|
DDRB = 0xff;
|
|
}
|
|
</pre></div><dl class="note"><dt><b>Note:</b></dt><dd>Section .init3 is used in this example, as this ensures the inernal <code>__zero_reg__</code> has already been set up. The code generated by the compiler might blindly rely on <code>__zero_reg__</code> being really 0. <code>__attribute__ ((used))</code> tells the compiler that code must be generated for this function even if it appears that the function is not referenced - this is necessary to prevent compiler optimizations (like LTO) from eliminating the function. </dd></dl>
|
|
</div>
|
|
<!--- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Defines</a></div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<!-- HTML footer for doxygen 1.8.7-->
|
|
<!-- start footer part -->
|
|
<!--BEGIN GENERATE_TREEVIEW-->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
$navpath
|
|
<li class="footer">$generatedby
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/></a> 1.6.3 </li>
|
|
</ul>
|
|
</div>
|
|
<!--END GENERATE_TREEVIEW-->
|
|
<!--BEGIN !GENERATE_TREEVIEW-->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
$generatedby  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/>
|
|
</a> 1.6.3
|
|
</small></address>
|
|
<!--END !GENERATE_TREEVIEW-->
|
|
</body>
|
|
</html>
|