Nios® V Processor Software Developer Handbook

ID 743810
Date 4/01/2024
Public
Document Table of Contents

4.2.3.3.2. Dividing a Linker Region to Create a New Region and Section

This example works with any hardware design containing an on-chip memory named on_chip_mem connected to a Nios V processor instruction manager.

# Get region information for on_chip_mem memory region.
# Returned as a list.
set region_info [get_memory_region on_chip_mem]

# Extract fields from region information list.
set region_name [lindex $region_info 0]
set slave [lindex $region_info 1]
set offset [lindex $region_info 2]
set span [lindex $region_info 3]

# Remove the existing memory region.
delete_memory_region $region_name

# Compute memory ranges for replacement regions.
set split_span 1024
set new_span [expr $span-$split_span]
set split_offset [expr $offset+$new_span]

# Create two memory regions out of the original region.
add_memory_region on_chip_mem $slave $offset $new_span
add_memory_region isrs_region $slave $split_offset $split_span
add_section_mapping .isrs isrs_region

The above Tcl script splits off 1 KB of RAM from the region named on_chip_mem, gives it the name isrs_region, and then calls add_section_mapping to add the .isrs section to isrs_region.

Using the Create a New Region and Section Tcl Scrip

To use the Tcl script, execute the following steps:
  1. Create the Tcl script as shown in the example, above.
  2. Add the following argument to the niosv-bsp command line:

    --script=<script name>.tcl

  3. Rebuild the application by running cmake and make.

Excerpts from Object Dump Files

After cmake and make complete successfully, you can examine the object dump file, <project_name> .objdump. The object dump file shows that the new .isrs section is in the on_chip_mem. This object dump file excerpt shows a hardware design with an on-chip memory whose address range is 0x00010000 to 0x00019fff.

The following are the customized linker sections:
  • Default linker sections (Span from 0x00010000 to 0x000192bf)
  • on_chip_mem remaining on_chip_mem (Span from 0x000192c0 to 0x00019bff)
  • isrs customized linker region (Span from 0x00019c00 to 0x00019fff)
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  .
  .
  2 .isrs         00000000  00019c00  00019c00  00008770  2**0
                  CONTENTS
  .
  .
  8 .on_chip_mem  00000000  000192c0  000192c0  00008770  2**0
                  CONTENTS
  .
  .

SYMBOL TABLE:
00010000 l    d  .entry	00000000 .entry
00010020 l    d  .exceptions	00000000 .exceptions
00019c00 l    d  .isrs	00000000 .isrs
000102a0 l    d  .text	00000000 .text
00015cc0 l    d  .rodata	00000000 .rodata
00015cfc l    d  .rwdata	00000000 .rwdata
0001776c l    d  .init_array.00000	00000000 .init_array.00000
000191dc l    d  .bss	00000000 .bss
000192c0 l    d  .on_chip_mem	00000000 .on_chip_mem

Excerpt from Linker.x

If you examine the linker script file, linker.x, you can see that linker.x places the new region isrs_region in MEMORY, adjacent to the on_chip_mem region.

Excerpt From linker.x

MEMORY
{
    reset : ORIGIN = 0x10000, LENGTH = 32
    on_chip_mem : ORIGIN = 0x10020, LENGTH = 39904
    isrs_region : ORIGIN = 0x19c00, LENGTH = 1024
}