Nios® V Processor Software Developer Handbook

ID 743810
Date 7/08/2024
Public
Document Table of Contents

7.13.2.2. Advanced Placement Options

In your program source code, you can specify a target memory section for each piece of data or 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.

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.text")));
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.text 

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:
  • .text for code: for example, .sdram.text
  • .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.

Note: A powerful way to manipulate the linker memory map is by using the BSP Editor. With the BSP Editor, you can assign linker sections to specific physical regions, and then review a graphical representation of memory showing unused or overlapping regions.