9.11.11 Space Variable Attribute
The space(memory-space)
attribute can be used to direct the compiler to allocate a variable in a
specific memory space. Valid memory spaces are prog for
program memory, data for data memory, and
serial_mem for serial memory such as SPI Flash. The
data space is the default space for non-const
variables.
The prog, data, and
serial_mem spaces normally correspond to the
kseg0_prog_mem, ksegN_data_mem,
and serial_mem memory regions, respectively, as specified
in the default device-specific linker scripts.
This attribute also controls how initialized data is handled.
The linker generates an entry in the data-initialization template for the
default space(data). But, it does not generate an entry for
space(prog) or space(serial_mem),
since the variable is located in non-volatile memory. Typically, this means
that space(data) applies to variables that will be
initialized at runtime startup; while space(prog) and
space(serial_mem) apply to variables that will be
programmed by an in-circuit programmer or a bootloader.
const unsigned int __attribute__((space(prog))) jack = 10;
const unsigned int __attribute__((space(serial_mem))) zori = 1;
signed int __attribute__((space(data))) oz = 5;