| |||
| Home > Using scatter files > Placement of sections with overlays | |||
You can use the OVERLAY attribute in a
scatter file to place multiple execution regions at the same address.
An overlay manager is required to make sure that only one execution
region is instantiated at a time. The ARM Compiler toolchain does
not provide an overlay manager.
The following example shows the definition of a static section in RAM followed by a series of overlays. Here, only one of these sections is instantiated at a time.
Example 28. Specifying a root region
EMB_APP 0x8000
{
.
.
STATIC_RAM 0x0 ; contains most of the RW and ZI code/data
{
* (+RW,+ZI)
}
OVERLAY_A_RAM 0x1000 OVERLAY ; start address of overlay...
{
module1.o (+RW,+ZI)
}
OVERLAY_B_RAM 0x1000 OVERLAY
{
module2.o (+RW,+ZI)
}
... ; rest of scatter-loading description...
}
A region marked as OVERLAY is not initialized
by the C library at startup. The contents of the memory used by
the overlay region are the responsibility of an overlay manager.
If the region contains initialized data, use the NOCOMPRESS attribute
to prevent RW data compression.
The linker defined symbols can be used to obtain the addresses required to copy the code and data.
The OVERLAY attribute can be used on a
single region that is not the same address as a different region.
Therefore, an overlay region can be used as a method to prevent
the initialization of particular regions by the C library startup
code. As with any overlay region these must be manually initialized
in your code.
An overlay region can have a relative base. The behavior of
an overlay region with a + base
address depends on the regions that precede it and the value of offset+.
The linker places consecutive offset+ regions
at the same base address if they have the same offset+ value.offset
When a + execution
region ER follows a contiguous overlapping block of overlay execution
regions the base address of ER is:offset
limit address of the overlapping block of overlay
execution regions + offset
The following table shows the effect of + when
used with the offsetOVERLAY attribute. REGION1 appears
immediately before REGION2 in the scatter file:
Table 16. Using relative offset in overlays
REGION1 is set with OVERLAY | +offset | REGION2 Base Address |
|---|---|---|
| NO | | REGION1 Limit + |
| YES | +0 | REGION1 Base Address |
| YES | | REGION1 Limit + |
The following example shows the use of relative offsets with overlays and the effect on execution region addresses:
Example 29. Example of relative offset in overlays
EMB_APP 0x8000{
CODE 0x8000
{
*(+RO)
}
# REGION1 Base = CODE limit
REGION1 +0 OVERLAY
{
module1.o(*)
}
# REGION2 Base = REGION1 Base
REGION2 +0 OVERLAY
{
module2.o(*)
}
# REGION3 Base = REGION2 Base = REGION1 Base
REGION3 +0 OVERLAY
{
module3.o(*)
}
# REGION4 Base = REGION3 Limit + 4
Region4 +4 OVERLAY
{
module4.o(*)
}
}
If the length of the non-overlay area is unknown, a zero relative offset can be used to specify the start address of an overlay so that it is placed immediately after the end of the static section.
You can use the following command-line options to add extra debug information to the image:
--emit_debug_overlay_relocs
--emit_debug_overlay_section.
These permit an overlay-aware debugger to track which overlay is currently active.