The near data model uses 16-bits absolute addressing for .data and .bss. The far data model uses 32-bits absolute addressing for .data and .bss.
It it possible to define a memory region of global data that uses relative addressing ( .sdata/.sbss), together these regions have a maximum size of 64K and uses A5 as reference. Using A5-relative data reduces code size.
The compiler, using the .sdata threshold size, will assign initialized data to .sdata sections and uninitialized (or set to zero) data to .sbss sections. Larger data objects will get assigned to .data or .bss.
It is possible to override the .sdata thereshold for a variable by using the far or near declaration specifier. Note that these near and far specifiers apply to declarations since they affect relocations.
The LCF needs to define the A5-relative base __SDA_BASE between .sdata and .sbss for linktime relocations.
/* visible declarations, typically in a .h include file */ extern far type varA; /* all references to varA will be 32-bits absolute */ extern near type varB; /* all references to varB will be 16-bits absolute */ extern type varC; /* all references to varC will use the current addressing setting */ /* definitions */ far type varA; /* varA will be in a .bss section */ near type varB; /* varB will be in a .bss section */ type varC; /* varC will use the current segment setting */ const type varD; /* varD will be in a .rodata section */ /* LCF example */ .data : { ___DATA_RAM = . ; *(.exception) . = ALIGN(0x10); __exception_table_start__ = .; EXCEPTION __exception_table_end__ = .; ___sinit__ = .; STATICINIT *(.data) . = ALIGN (0x10); ___DATA_END = .; __START_SDATA = .; *(.sdata) . = ALIGN (0x10); __END_SDATA = .; __SDA_BASE = .; . = ALIGN(0x10); } >> sram .bss : { . = ALIGN(0x10); __START_SBSS = .; *(.sbss) *(SCOMMON) __END_SBSS = .; . = ALIGN(0x10); __START_BSS = .; *(.bss) *(COMMON) __END_BSS = .; ___BSS_START = __START_SBSS; ___BSS_END = __END_BSS; . = ALIGN(0x10); } >> sram
The global data model can also be overriden using local pragmas, these pragmas affect addressing and in some cases section assignment.
This section contains the following topics: