Specifications
• .text—All remaining code
• .rodata—The read-only data
• .rwdata—Read-write data
• .bss—Zero-initialized data
You can control the placement of .text, .rodata, .rwdata, and all other memory partitions by
manipulating BSP settings.
For more information about how to control BSP settings, refer to the “HAL BSP Settings” chapter.
The Nios II BSP Editor is a very convenient way to manipulate the linker’s memory map. The BSP Editor
displays memory section and region assignments graphically, allowing you to see overlapping or unused
sections of memory. The BSP Editor is available either through the Nios II SBT for Eclipse, or at the
command line of the Nios II SBT.
For more information, refer to the "Getting Started from the Command Line" chapter.
Related Information
• HAL BSP Settings on page 6-1
• Getting Started from the Command Line on page 3-1
Advanced Placement Options
In your program source code, you can specify a target memory section for each piece of code. In C or C+
+, you can use the section attribute. This attribute must be placed in a function prototype; you cannot
place it in the function declaration itself.
Example 6–16. Manually Assigning C Code to a Specific Memory Section
/* data should be initialized when using the section attribute */
int foo __attribute__ ((section (".ext_ram.rwdata"))) = 0;
void bar (void) __attribute__ ((section (".sdram.txt")));
void bar (void)
{
foo++;
}
Note:
A variable foo is placed in the memory named ext_ram, and the function bar() is placed in the
memory named sdram.
In assembly you do this using the .section directive. For example, all code after the following line is
placed in the memory device named ext_ram:
.section .ext_ram.txt
Note:
The section names ext_ram and sdram are examples. You need to use section names
corresponding to your hardware. When creating section names, use the following extensions:
• .txt for code: for example, .sdram.txt
• .rodata for read-only data: for example, .cfi_flash.rodata
• .rwdata for read-write data: for example, .ext_ram.rwdata
For more information about the use of these features, refer to the GNU compiler and assembler
documentation. This documentation is installed with the Nios II EDS. To find it, open the Nios
II EDS documentation launchpad, scroll down to Software Development, and click Using the
GNU Compiler Collection (GCC).
Note: A powerful way to manipulate the linker memory map is by using the Nios II BSP Editor. With the
BSP Editor, you can assign linker sections to specific physical regions, and then review a graphical
6-38
Advanced Placement Options
NII5V2
2015.05.14
Altera Corporation
Developing Programs Using the Hardware Abstraction Layer
Send Feedback